Commit e13b69c0 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Read configuration from a config file.

(param): New variable, holding (almost) all configuration.
(main): Only accept -d and name of config file as arguments.
parent e546bd35
/*
* $Id: ramkomd.c,v 0.43 1993/11/22 19:06:35 ceder Exp $
* $Id: ramkomd.c,v 0.44 1994/01/12 01:44:21 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -31,7 +31,7 @@
* It has grown! /ceder
*/
static char *rcsid = "$Id: ramkomd.c,v 0.43 1993/11/22 19:06:35 ceder Exp $";
static char *rcsid = "$Id: ramkomd.c,v 0.44 1994/01/12 01:44:21 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -80,19 +80,56 @@ USE(rcsid);
#include "internal-services.h"
#include "server/smalloc.h"
#include "kom-memory.h"
Kom_err kom_errno;
unsigned long err_stat;
Bool send_async_messages = TRUE;
#include "conf-file.h"
#include "param.h"
#include "admin.h"
struct kom_par param;
Kom_err kom_errno = KOM_NO_ERROR;
unsigned long err_stat = 0;
static Bool false = FALSE;
static Bool true = TRUE;
static Conf_no c1 = 1;
static Conf_no c2 = 2;
static Conf_no c3 = 3;
static Conf_no c4 = 4;
static Text_no t0 = 0;
static const struct parameter parameters[] = {
{"Locale",
assign_string, 0, 1, NULL, &param.use_locale},
{"Database directory",
assign_string, 0, 1, NULL, &param.dbase_dir},
{"Send async",
assign_bool, 0, 1, &true, &param.send_async_messages},
{"Client port",
assign_string, 1, 1, NULL, &param.ip_client_port},
{"Mux port",
assign_string, 1, 1, NULL, &param.ip_mux_port},
{"Presentation of conferences",
assign_conf_no, 0, 1, &c1, &kom_info.conf_pres_conf},
{"Presentation of persons",
assign_conf_no, 0, 1, &c2, &kom_info.pers_pres_conf},
{"Motd-conference",
assign_conf_no, 0, 1, &c3, &kom_info.motd_conf},
{"News-conference",
assign_conf_no, 0, 1, &c4, &kom_info.kom_news_conf},
{"Message of the day",
assign_text_no, 0, 1, &t0, &kom_info.motd_of_lyskom},
#ifdef DEBUG
int buglevel = 0;
Bool never_save = FALSE;
{"Never save",
assign_bool, 0, 1, &false, &param.never_save},
#endif
#ifdef LOGACCESSES
char *logaccess_file = NULL;
{"Log accesses",
assign_string, 0, 1, NULL, &param.logaccess_file},
#endif
{NULL, NULL, NULL, FALSE, NULL}}; /* end marker */
#ifdef DEBUG
int buglevel = 0;
#endif
EXPORT char datafilename[BUFSIZ]; /* Full pathname to the database file */
......@@ -102,21 +139,13 @@ EXPORT char statisticfile[BUFSIZ]; /* Dito to statistics file. */
EXPORT char pidfile[BUFSIZ]; /* Dito pid-file. */
INTERNAL char memusefile[BUFSIZ]; /* Memory usage file. */
static char ip_client_port[80]; /* Port to listen to for clients */
static char ip_mux_port[80]; /* Port to listen to for mux:es */
int num_ip_client_port=0; /* Numeric representation of the above. */
int num_ip_mux_port=0; /* -"- */
static IscSession *listen_client = NULL; /* ISC listen identifier */
static IscSession *listen_mux = NULL; /* -"- */
static void
dump_exit_statistics(void);
static void dump_exit_statistics(void);
static void
server_init( char * client_port, char * mux_port)
server_init (char * client_port, char * mux_port)
{
IscConfig config;
IscAddress *isc_adr = NULL;
......@@ -149,7 +178,7 @@ server_init( char * client_port, char * mux_port)
if (isc_adr == NULL)
restart_kom("server_init(): can't isc_getladdress (listen_client)\n");
num_ip_client_port = isc_getportnum (isc_adr);
param.num_ip_client_port = isc_getportnum (isc_adr);
isc_freeaddress (isc_adr);
listen_mux = isc_listentcp (kom_server_mcb, NULL, mux_port);
......@@ -160,11 +189,11 @@ server_init( char * client_port, char * mux_port)
if (isc_adr == NULL)
restart_kom("server_init(): can't isc_getladdress (listen_mux)\n");
num_ip_mux_port = isc_getportnum (isc_adr);
param.num_ip_mux_port = isc_getportnum (isc_adr);
isc_freeaddress (isc_adr);
log("Listening for clients on %d and muxes on %d.\n",
num_ip_client_port, num_ip_mux_port);
param.num_ip_client_port, param.num_ip_mux_port);
/*
* Ignore SIGPIPE, which the server gets if it tries to write to a
......@@ -273,45 +302,73 @@ save_pid(void)
if ( (fp = fopen(pidfile, "w")) == NULL )
return;
fprintf(fp, "%d\n", getpid());
fprintf(fp, "%ld\n", (long)getpid());
fclose(fp);
}
void
initialize(const char *config_file)
{
read_config(config_file, parameters);
#ifdef HAVE_LOCALE_H
if (param.use_locale != NULL)
if (setlocale(LC_CTYPE, param.use_locale) == NULL)
{
fprintf(stderr, "setlocale: ");
perror(param.use_locale);
exit(1);
}
#else
if (param.use_locale != NULL)
{
fprintf(stderr, "locale not supported in your environment.\n");
exit(1);
}
#endif
server_init(param.ip_client_port, param.ip_mux_port);
init_data_base(param.dbase_dir);
}
/* Stop complaint from gcc 2.0 about "no previous prototype for `main'". */
int main(int argc, char **argv);
int
main (int argc,
char **argv)
{
int i;
char *dbase_dir = NULL;
char *use_locale = NULL;
char *default_config_file;
char *config_file;
log("*** Version %d (process %d) started.\n",
#include "version.incl"
, getpid());
/* Find out how many connections we can handle. */
#if defined (HAVE_SYSCONF)
MAX_NO_OF_CONNECTIONS = sysconf(_SC_OPEN_MAX) - PROTECTED_FDS;
#else
# ifdef HAVE_GETDTABLESIZE
MAX_NO_OF_CONNECTIONS = getdtablesize() - PROTECTED_FDS;
# else
/* If we don't have getdtablesize or sysconf, MAX_NO_OF_CONNECTIONS is
set at compile time. */
# endif
#endif
/* If we don't have getdtablesize MAX_NO_OF_CONNECTIONS is
set at compile time. */
#ifdef ENCRYPT_PASSWORDS
/* Seed the random number generator. */
srand(time(NULL) + getpid());
#endif
s_set_storage_management(string_malloc, string_realloc, string_free);
strcpy(ip_client_port, DEFAULT_CLIENT_SERVICE);
strcpy(ip_mux_port, DEFAULT_MUX_SERVICE);
/* Initialize the string handling package. */
s_set_storage_management(string_malloc, string_realloc, string_free);
/* Parse command line arguments. */
for (i = 1; i < argc && argv[i][0] == '-'; i++)
switch (argv[i][1])
{
......@@ -319,71 +376,32 @@ main (int argc,
buglevel++;
break;
case 'q':
never_save = TRUE;
break;
case 'D': /* Database directory */
dbase_dir = argv[i]+2;
break;
case 'p': /* TCP/IP port number for clients */
strcpy(ip_client_port, argv[i]+2);
break;
case 'P': /* TCP/IP port number for MUXes */
strcpy(ip_mux_port, argv[i]+2);
break;
case 'a':
send_async_messages = FALSE;
break;
default:
restart_kom("usage: %s [-d ...] [config-file]\n", argv[0]);
}
case 'l':
use_locale = argv[i]+2;
break;
#ifdef LOGACCESSES
case 'L':
logaccess_file = argv[i] + 2;
break;
#endif
/* Read in the configuration file. */
default:
#ifdef LOGACCESSES
restart_kom("usage: %s [-d] [-q] [-Ddir] [-pport] [-Pmuxport] [-a] [-llocale] [-Ldb_trace_file]\n", argv[0]);
#else
restart_kom("usage: %s [-d] [-q] [-Ddir] [-pport] [-Pmuxport] [-a] [-llocale]\n", argv[0]);
#endif
}
default_config_file = smalloc(sizeof(DEFAULT_DBASE_DIR) +
sizeof(CONFIG_FILE) + 2);
sprintf(default_config_file, "%s/%s", DEFAULT_DBASE_DIR, CONFIG_FILE);
if (i < argc)
{
restart_kom("usage: %s [-d] [-q] [-Ddir] [-pport] [-Pmuxport] [-a] [-llocale]\n", argv[0]);
}
config_file = argv[i++];
else
config_file = default_config_file;
#ifdef HAVE_LOCALE_H
if (setlocale(LC_CTYPE, use_locale) == NULL)
{
fprintf(stderr, "setlocale: ");
perror(use_locale);
exit(1);
}
#else
if (use_locale != NULL)
{
fprintf(stderr, "locale not supported in your environment.\n");
exit(1);
}
#endif
if (i < argc)
restart_kom("usage: %s [-d ...] [config-file]\n", argv[0]);
signal(SIGHUP, sighandler_hup);
signal(SIGQUIT, sighandler_quit);
signal(SIGUSR1, sighandler_usr1);
signal(SIGUSR2, sighandler_usr2);
server_init(ip_client_port, ip_mux_port);
init_data_base(dbase_dir);
initialize(config_file); /* Read config, listen, and start db */
sfree(default_config_file);
save_pid();
toploop();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment