Commit 95b8bdfc authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(usage): New function.

(checkstatus): Use parameters "Normal shutdown time", "Mail after
	downtime" and "Mail until downtime" instead of using
	hard-coded values.  Use "mail" instead of "Mail" to send the mail.
(main): Read the configuration file.  Use parameters "Pid file",
	"Status file" and "lyskomd path" instead of hard-coded values.
parent 44901677
/*
* $Id: updateLysKOM.c,v 1.9 1999/04/17 00:16:46 ceder Exp $
* $Id: updateLysKOM.c,v 1.10 1999/04/17 22:02:18 ceder Exp $
* Copyright (C) 1994, 1995 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -52,6 +52,21 @@
#include "ldifftime.h"
#include "pidfile.h"
#include "kom-types.h"
#include "s-string.h"
#include "string-malloc.h"
#include "server/smalloc.h"
#include "kom-config.h"
#include "server-config.h"
#include "param.h"
static void
usage(const char *arg0)
{
fprintf(stderr, "usage: %s [-c config-file] [ -v ] [ -V ]\n",
arg0);
exit(1);
}
static void
checkstatus(FILE *fp,
......@@ -82,24 +97,29 @@ checkstatus(FILE *fp,
else
{
/* The signal got through... */
/* cron 10 minutes */
if (ldifftime(time(NULL), sbuf.st_mtime) > 1260)
if (ldifftime(time(NULL), sbuf.st_mtime) >
60 * param.normal_shutdown_time)
{
/* ...more than once. Strange. */
fprintf(stderr, "%s: Told lyskomd to shut down. Twice.",
/* It takes very long for lyskomd to shut down. Strange. */
fprintf(stderr,
"%s: Warning: it takes lyskomd a long time to die.\n"
"Consider increasing ``Normal shutdown time'' "
"in the config file if you get this message often.\n",
progname);
exit(1);
}
}
}
if (ldifftime(time(NULL), sbuf.st_mtime) < 3600)
if (ldifftime(time(NULL), sbuf.st_mtime) < 60 * param.downtime_mail_start)
{
/* NOP */
}
else if (ldifftime(time(NULL), sbuf.st_mtime) < 2*3600)
else if (ldifftime(time(NULL), sbuf.st_mtime)
< 60 * param.downtime_mail_end)
{
/* Send mail to creator of file, the first line in the file. */
/* The first line of the file should be a mail addres to send
a reminder to. */
if (fgets(lbuf, 80, fp) == NULL)
{
......@@ -109,7 +129,7 @@ checkstatus(FILE *fp,
}
if (strchr(lbuf, '\n'))
*strchr(lbuf, '\n') = '\0';
sprintf(buf2, "echo 'Reminder: LysKOM is still not running.'|Mail %s",
sprintf(buf2, "echo 'Reminder: LysKOM is still not running.'|mail %s",
lbuf);
if (system(buf2) != 0)
{
......@@ -145,6 +165,8 @@ main (int argc,
int i;
FILE *fp;
long pid;
char *default_config_file = NULL;
char *config_file = NULL;
if (getuid() == 0 || geteuid() == 0)
{
......@@ -153,29 +175,63 @@ main (int argc,
exit(1);
}
/* 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++)
{
if (argv[i][1] == '\0' || argv[i][2] != '\0')
usage(argv[0]);
switch (argv[i][1])
{
case 'c':
if (config_file != NULL)
{
fprintf(stderr, "%s: -c may only be used once\n", argv[0]);
exit(1);
}
if (++i >= argc)
usage(argv[0]);
config_file = argv[i];
break;
case 'V':
case 'v':
fprintf(stderr, "updateLysKOM %d $Revision: 1.9 $\n",
fprintf(stderr, "updateLysKOM %d $Revision: 1.10 $\n",
#include "version.incl"
);
exit(0);
default:
fprintf(stderr, "usage: %s [-V]\n", argv[0]);
usage(argv[0]);
}
}
if (i < argc)
usage(argv[0]);
/* Read in the configuration file. */
if (config_file == NULL)
{
default_config_file = smalloc(strlen(DEFAULT_DBASE_DIR) +
strlen(CONFIG_FILE) + 2);
sprintf(default_config_file, "%s/%s", DEFAULT_DBASE_DIR, CONFIG_FILE);
config_file = default_config_file;
}
read_configuration(config_file);
pid = read_pid_file(DEFAULT_PREFIX "/etc/pid", argv[0]);
pid = read_pid_file(param.pid_name, argv[0]);
if (pid == 1)
{
fprintf(stderr, "%s: got pid %ld.\n", argv[0], pid);
exit(1);
}
fp = fopen(DEFAULT_PREFIX "/etc/status", "r");
fp = fopen(param.status_file, "r");
if (fp != NULL)
{
checkstatus(fp, pid, argv[0]);
......@@ -194,7 +250,7 @@ main (int argc,
savecore();
execl(DEFAULT_PREFIX "/bin/lyskomd", "lyskomd", (char *)0);
execl(param.lyskomd_path, "lyskomd", (char *)0);
fprintf(stderr, "%s: execl() failed: ", argv[0]);
perror("");
exit(1);
......
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