Commit 9fa8cfb8 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Don't close all files (lyskomd is a proper daemon now).

Kill lyskomd if etc/status exists.
Use ldifftime(), not difftime().
parent 9552886e
/*
* $Id: updateLysKOM.c,v 1.1 1994/03/06 19:59:55 ceder Exp $
* $Id: updateLysKOM.c,v 1.2 1994/04/04 18:30:16 ceder Exp $
* Copyright (C) 1994 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -45,12 +45,12 @@
#include <time.h>
#include <unistd.h>
#ifndef HAVE_DIFFTIME
# include "tmp-difftime.h"
#endif
#include "ldifftime.h"
void
checkstatus(FILE *fp)
checkstatus(FILE *fp,
long pid,
char *progname)
{
char lbuf[80];
char buf2[300];
......@@ -62,11 +62,32 @@ checkstatus(FILE *fp)
exit(1);
}
if (difftime(time(NULL), sbuf.st_mtime) < 3600)
if (kill(pid, SIGHUP) != 0)
{
if (errno != ESRCH)
{
fprintf(stderr, "%s: kill(%ld, SIGHUP) failed", progname, pid);
perror("");
exit(1);
}
}
else
{
/* The signal got through... */
if (ldifftime(time(NULL), sbuf.st_mtime) > 1260) /* cron 10 minutes */
{
/* ...more than once. Strange. */
fprintf(stderr, "%s: Told lyskomd to shut down. Twice.",
progname);
exit(1);
}
}
if (ldifftime(time(NULL), sbuf.st_mtime) < 3600)
{
/* NOP */
}
else if (difftime(time(NULL), sbuf.st_mtime) < 2*3600)
else if (ldifftime(time(NULL), sbuf.st_mtime) < 2*3600)
{
/* Send mail to creator of file, the first line in the file. */
......@@ -102,6 +123,7 @@ main (int argc,
{
int i;
FILE *fp;
long pid;
if (getuid() == 0 || geteuid() == 0)
{
......@@ -116,37 +138,38 @@ main (int argc,
{
case 'V':
case 'v':
fprintf(stderr, "updateLysKOM $Revision: 1.1 $\n");
fprintf(stderr, "updateLysKOM %d $Revision: 1.2 $\n",
#include "version.incl"
);
exit(0);
default:
fprintf(stderr, "usage: %s [-V]\n", argv[0]);
}
fp = fopen(DEFAULT_PREFIX "/etc/pid", "r");
if (fp == NULL)
{
fprintf(stderr, "%s: %s: ", argv[0], DEFAULT_PREFIX "/etc/pid");
perror("");
exit(1);
}
pid = 0;
fscanf(fp, "%lu", &pid);
if (pid < 2)
{
fprintf(stderr, "%s: got pid %ld.\n", argv[0], pid);
exit(1);
}
fp = fopen(DEFAULT_PREFIX "/etc/status", "r");
if (fp != NULL)
{
checkstatus(fp);
checkstatus(fp, pid, argv[0]);
}
else
{
long pid;
fp = fopen(DEFAULT_PREFIX "/etc/pid", "r");
if (fp == NULL)
{
fprintf(stderr, "%s: %s: ", argv[0], DEFAULT_PREFIX "/etc/pid");
perror("");
exit(1);
}
pid = 0;
fscanf(fp, "%lu", &pid);
if (pid == 0 || pid == 1)
{
fprintf(stderr, "%s: got pid %ld.\n", argv[0], pid);
exit(1);
}
if (kill(pid, SIGUSR1) != 0)
{
if (errno != ESRCH)
......@@ -155,18 +178,6 @@ main (int argc,
perror("");
exit(1);
}
close(0);
close(1);
close(2);
if (0 != open("/dev/null", O_RDONLY)
|| 1 != open(DEFAULT_PREFIX "etc/stdout.log",
O_WRONLY|O_APPEND|O_CREAT, 0666)
|| 2 != open(DEFAULT_PREFIX "etc/stdout.log",
O_WRONLY|O_APPEND|O_CREAT, 0666))
{
fprintf(stderr, "%s: open", argv[0]);
perror("");
}
execl(DEFAULT_PREFIX "/bin/lyskomd", "lyskomd", (char *)0);
fprintf(stderr, "%s: execl() failed: ", argv[0]);
perror("");
......
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