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

(parameters): New config: "Core directory".

(add_prefix, param_name, check_abs_path): New static functions.
(read_configuration): Check that all path names are complete paths.
parent f337d788
/*
* $Id: server-config.c,v 0.33 1994/10/24 00:38:57 ceder Exp $
* $Id: server-config.c,v 0.34 1995/09/05 19:15:12 ceder Exp $
* Copyright (C) 1991, 1992, 1993, 1994 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -31,7 +31,7 @@
* Compile with -DDEFAULT_PREFIX='"/usr/lyskom"' or something similar.
*/
static char *rcsid = "$Id: server-config.c,v 0.33 1994/10/24 00:38:57 ceder Exp $";
static char *rcsid = "$Id: server-config.c,v 0.34 1995/09/05 19:15:12 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -40,7 +40,9 @@ USE(rcsid);
#include <sys/types.h>
#include <time.h>
#include <stdarg.h>
#include <assert.h>
#include "smalloc.h"
#include "config.h"
#include "server-config.h"
#include "misc-types.h"
......@@ -112,6 +114,9 @@ static const struct parameter parameters[] = {
assign_string, 0, 1, "etc/pid", &param.pid_name},
{"Memory usage file",
assign_string, 0, 1, "etc/memory-usage", &param.memuse_name},
/* Where to dump core. */
{"Core directory",
assign_string, 0, 1, "cores", &param.core_dir},
/* Performance tuning parameters (milliseconds) */
{"Idle timeout",
assign_int, 0, 1, "120000", &param.timeout},
......@@ -288,11 +293,95 @@ ident_param(const char *val, const struct parameter *par)
return OK;
}
static void
add_prefix(char **name)
{
char *s;
if (**name == '/')
return; /* Don't alter full paths. */
s = smalloc(2 + strlen(param.dbase_dir) + strlen(*name));
sprintf(s, "%s/%s", param.dbase_dir, *name);
sfree(*name);
*name = s;
}
const char *
param_name(void *value)
{
int ix;
for (ix = 0; parameters[ix].name != NULL; ix++)
if (parameters[ix].value == value)
return parameters[ix].name;
restart_kom("Internal error: non-existing config param in param_name.\n");
}
static Bool
check_abs_path(char **path)
{
if (**path == '/')
return FALSE;
log("Parameter '%s' must be an absolute path when 'Prefix' is empty.\n",
param_name(path));
return TRUE;
}
void
read_configuration(const char *conf_file)
{
Bool err = FALSE;
read_config(conf_file, parameters);
assert(param.dbase_dir != NULL);
assert(param.datafile_name != NULL);
assert(param.backupfile_name != NULL);
assert(param.textfile_name != NULL);
assert(param.textbackupfile_name != NULL);
assert(param.statistic_name != NULL);
assert(param.pid_name != NULL);
assert(param.memuse_name != NULL);
assert(param.logfile_name != NULL);
assert(param.core_dir != NULL);
if (strlen(param.dbase_dir) > 0)
{
if (param.dbase_dir[0] != '/')
{
log("The 'Prefix' parameter must be an absolute path.\n");
err = TRUE;
}
add_prefix(&param.datafile_name);
add_prefix(&param.backupfile_name);
add_prefix(&param.textfile_name);
add_prefix(&param.textbackupfile_name);
add_prefix(&param.statistic_name);
add_prefix(&param.pid_name);
add_prefix(&param.memuse_name);
add_prefix(&param.logfile_name);
add_prefix(&param.core_dir);
}
else
{
err |= check_abs_path(&param.datafile_name);
err |= check_abs_path(&param.backupfile_name);
err |= check_abs_path(&param.textfile_name);
err |= check_abs_path(&param.textbackupfile_name);
err |= check_abs_path(&param.statistic_name);
err |= check_abs_path(&param.pid_name);
err |= check_abs_path(&param.memuse_name);
err |= check_abs_path(&param.logfile_name);
err |= check_abs_path(&param.core_dir);
}
/* FIXME///+++ Check config parameters for sanity */
if (err)
restart_kom("Please fix the above configuration errors.\n");
}
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