5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2001 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
21 * Created: Wed Mar 19 00:17:12 1997
23 * This is the main program for the SILC daemon. This parses command
24 * line arguments and creates the server object.
28 #include "serverincludes.h"
29 #include "server_internal.h"
32 /* Long command line options */
33 static struct option long_opts[] =
35 { "config-file", 1, NULL, 'f' },
36 { "generate-config-file", 0, NULL, 'c' },
37 { "debug", 0, NULL, 'd' },
38 { "help", 0, NULL, 'h' },
39 { "version", 0, NULL,'V' },
43 /* Prints out the usage of silc client */
47 printf("Usage: silcd [options]\n");
49 printf(" -f --config-file=FILE Alternate configuration file\n");
50 printf(" -c --generate-config-file Generate example configuration "
52 printf(" -d --debug Enable debugging (no daemon)\n");
53 printf(" -h --help Display this message\n");
54 printf(" -V --version Display version\n");
58 int main(int argc, char **argv)
61 int opt, option_index;
62 char *config_file = NULL;
67 /* Parse command line arguments */
69 while ((opt = getopt_long(argc, argv, "cf:dhV",
70 long_opts, &option_index)) != EOF) {
77 printf("SILCd Secure Internet Live Conferencing daemon, "
78 "version %s\n", silc_version);
79 printf("(c) 1997 - 2000 Pekka Riikonen "
80 "<priikone@poseidon.pspt.fi>\n");
84 /* Print out example configuration file */
85 silc_server_config_print();
92 config_file = strdup(optarg);
101 /* Default configuration file */
103 config_file = strdup(SILC_SERVER_CONFIG_FILE);
105 /* Create SILC Server object */
106 ret = silc_server_alloc(&silcd);
110 /* Read configuration files */
111 silcd->config = silc_server_config_alloc(config_file);
112 if (silcd->config == NULL)
115 /* Initialize the server */
116 ret = silc_server_init(silcd);
120 if (silc_debug == FALSE)
121 /* Before running the server, fork to background and set
122 both user and group no non-root */
123 silc_server_daemonise(silcd);
125 /* Run the server. When this returns the server has been stopped
127 silc_server_run(silcd);
129 /* Stop the server. This probably has been done already but it
130 doesn't hurt to do it here again. */
131 silc_server_stop(silcd);
132 silc_server_free(silcd);