#include "ioset.h"
#include "modcmd.h"
#include "saxdb.h"
-#include "sendmail.h"
+#include "mail.h"
#include "timeq.h"
+#include "sar.h"
#include "chanserv.h"
#include "global.h"
#include "modules.h"
#include "opserv.h"
+#include "spamserv.h"
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#include <sys/wait.h>
#endif
-#ifndef SIGCHLD
-#define SIGCHLD SIGCLD
-#endif
-
#include "main-common.c"
void sigaction_writedb(int x)
do_reopen = 1;
}
-void usage(char *self) {
- /* We can assume we have getopt_long(). */
- printf("Usage: %s [-c config] [-r log] [-d] [-f] [-v|-h]\n"
- "-c, --config selects a different configuration file.\n"
- "-d, --debug enables debug mode.\n"
- "-f, --foreground run srvx in the foreground.\n"
- "-h, --help prints this usage message.\n"
- "-k, --check checks the configuration file's syntax.\n"
- "-r, --replay replay a log file (for debugging)\n"
- "-v, --version prints this program's version.\n"
- , self);
-}
-
-void version() {
- printf(" --------------------------------------------------\n"
- " - "PACKAGE_STRING" ("CODENAME"), Built: " __DATE__ ", " __TIME__".\n"
- " - Copyright (C) 2000 - 2005, srvx Development Team\n"
- " --------------------------------------------------\n");
-}
-
-void license() {
- printf("\n"
- "This program is free software; you can redistribute it and/or modify\n"
- "it under the terms of the GNU General Public License as published by\n"
- "the Free Software Foundation; either version 2 of the License, or\n"
- "(at your option) any later version.\n"
- "\n"
- "This program is distributed in the hope that it will be useful,\n"
- "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
- "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
- "GNU General Public License for more details.\n"
- "\n"
- "You should have received a copy of the GNU General Public License\n"
- "along with this program; if not, write to the Free Software\n"
- "Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\n");
-}
-
#if WITH_MALLOC_BOEHM_GC
void
gc_warn_proc(char *msg, GC_word arg)
int main(int argc, char *argv[])
{
- int daemon, debug;
+ int run_as_daemon;
+ int debug;
pid_t pid = 0;
FILE *file_out;
struct sigaction sv;
GC_enable_incremental();
#endif
- daemon = 1;
+ run_as_daemon = 1;
debug = 0;
tools_init();
sigaction(SIGCHLD, &sv, NULL);
if (argc > 1) { /* parse command line, if any */
- int c;
- struct option options[] =
- {
- {"config", 1, 0, 'c'},
+ int c;
+ struct option options[] =
+ {
+ {"config", 1, 0, 'c'},
{"debug", 0, 0, 'd'},
- {"foreground", 0, 0, 'f'},
- {"help", 0, 0, 'h'},
- {"check", 0, 0, 'k'},
+ {"foreground", 0, 0, 'f'},
+ {"help", 0, 0, 'h'},
+ {"check", 0, 0, 'k'},
{"replay", 1, 0, 'r'},
- {"version", 0, 0, 'v'},
- {"verbose", 0, 0, 'V'},
- {0, 0, 0, 0}
- };
+ {"version", 0, 0, 'v'},
+ {0, 0, 0, 0}
+ };
- while ((c = getopt_long(argc, argv, "c:kr:dfvVh", options, NULL)) != -1) {
- switch(c) {
- case 'c':
- services_config = optarg;
- break;
- case 'k':
- if (conf_read(services_config)) {
- printf("%s appears to be a valid configuration file.\n", services_config);
- } else {
- printf("%s is an invalid configuration file.\n", services_config);
- }
- exit(0);
+ while ((c = getopt_long(argc, argv, "c:dfhkr:v", options, NULL)) != -1) {
+ switch (c) {
+ case 'c':
+ services_config = optarg;
+ break;
+ case 'k':
+ if (conf_read(services_config)) {
+ printf("%s appears to be a valid configuration file.\n", services_config);
+ } else {
+ printf("%s is an invalid configuration file.\n", services_config);
+ }
+ exit(0);
case 'r':
replay_file = fopen(optarg, "r");
if (!replay_file) {
case 'd':
debug = 1;
break;
- case 'f':
- daemon = 0;
- break;
- case 'v':
- version();
- license();
- exit(0);
- case 'h':
- default:
- usage(argv[0]);
- exit(0);
- }
- }
+ case 'f':
+ run_as_daemon = 0;
+ break;
+ case 'v':
+ version();
+ license();
+ exit(0);
+ case 'h':
+ default:
+ usage(argv[0]);
+ exit(0);
+ }
+ }
}
version();
* mostly to get the right value of "now" for when we do the
* irc_introduce. */
replay_read_line();
- boot_time = now;
} else {
- boot_time = time(&now);
+ now = time(NULL);
}
+ boot_time = now;
- log_module(MAIN_LOG, LOG_INFO, "Initializing daemon...");
+ fprintf(stdout, "Initializing daemon...\n");
if (!conf_read(services_config)) {
- log_module(MAIN_LOG, LOG_FATAL, "Unable to read %s.", services_config);
- exit(0);
+ fprintf(stderr, "Unable to read %s.\n", services_config);
+ exit(1);
}
conf_register_reload(uplink_compile);
- if (daemon) {
- /* Attempt to fork into the background if daemon mode is on. */
- pid = fork();
- if (pid < 0) {
- log_module(MAIN_LOG, LOG_FATAL, "Unable to fork: %s", strerror(errno));
+ if (run_as_daemon) {
+ /* Attempt to fork into the background if daemon mode is on. */
+ pid = fork();
+ if (pid < 0) {
+ fprintf(stderr, "Unable to fork: %s\n", strerror(errno));
} else if (pid > 0) {
- log_module(MAIN_LOG, LOG_INFO, "Forking into the background (pid: %i)...", pid);
- exit(0);
- }
- setsid();
+ fprintf(stdout, "Forking into the background (pid: %d)...\n", pid);
+ exit(0);
+ }
+ setsid();
+ }
+
+ file_out = fopen(PID_FILE, "w");
+ if (file_out == NULL) {
+ /* Create the main process' pid file */
+ fprintf(stderr, "Unable to create PID file: %s", strerror(errno));
+ } else {
+ fprintf(file_out, "%i\n", (int)getpid());
+ fclose(file_out);
+ }
+
+ if (run_as_daemon) {
/* Close these since we should not use them from now on. */
fclose(stdin);
fclose(stdout);
fclose(stderr);
}
- if ((file_out = fopen(PID_FILE, "w")) == NULL) {
- /* Create the main process' pid file */
- log_module(MAIN_LOG, LOG_ERROR, "Unable to create PID file: %s", strerror(errno));
- } else {
- fprintf(file_out, "%i\n", (int)getpid());
- fclose(file_out);
- }
-
services_argc = argc;
services_argv = argv;
init_parse();
modcmd_init();
saxdb_init();
+ sar_init();
gline_init();
- sendmail_init();
+ mail_init();
helpfile_init();
conf_globals(); /* initializes the core services */
conf_rlimits();
free(msg);
}
} else {
- srand(time(&now));
+ now = time(NULL);
+ srand(now);
ioset_run();
}
return 0;