/* * Program: multisuck (msuck) * * $Id: main.c,v 1.9 2002/06/10 03:10:42 conrads Exp $ * * a multi-server, multi-connection Usenet news sucking system * * continuously sucks all groups in local active file (except control* and junk) * until user interrupt * * all program output is logged in one of three different files: one for errors, * one for filter results, one for general suck info * * no output is written directly to terminal, so may be run automatically on * system startup as a quasi-daemon * * uses "mode reader" on all servers, except for using "ihave" to post articles * to the local server and "check" to test if an article already exists * locally, and of course, "list active" * * the main process (the parent) forks a separate process for each remote server * connection, then exits, leaving the children to do the actual work. this * allows a quick visual check of how many sucks are actually running via * "ps" command */ #include #include #include #include #include #include #include "msuck.h" /* * define *most* global variables here */ SERVER server[MAXNEWSRCS]; int numservers; CONNECTION local, remote; ACTIVE_INFO active[MAX_LOCAL_GROUPS]; int local_active_groups; /* actual number of local groups */ /* various filenames in user's config */ char *errlogpath; char *killlogpath; char *sucklogpath; char *filterspath; char *newsrc_path_template; /* logfiles */ FILE *sucklog, *killlog, *errlog; int main(void) { int s; pid_t pid; fprintf(stderr, "%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION); /* remove any old junk in /tmp */ cleanup(); /* read user's configuration */ if ((numservers = read_config()) <= 0) { fprintf(stderr, "suck: error in parse_config(), exiting\n"); exit(EXIT_FAILURE); } /* open log files */ if (open_logs() == -1) { perror("suck: error in open_logs(), exiting"); exit(EXIT_FAILURE); } /* fill the active array from local active file */ if ((local_active_groups = read_active()) <= 0) { fprintf(stderr, "suck: no groups found in local active file!\n"); exit(EXIT_FAILURE); } for (s = 0; s < numservers; ++s) { if (server[s].maxconns > 0) { pid = fork(); switch (pid) { case -1: /* fork error */ { perror("suck: fork() error"); exit(EXIT_FAILURE); } case 0: /* child */ { /* this never returns */ suck_server(&server[s]); } default: /* parent */ { sleep(5); } } } } return 0; }