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

Survive non-existing pid file.

parent 9798ab00
/*
* $Id: updateLysKOM.c,v 1.3 1994/04/04 18:58:26 ceder Exp $
* $Id: updateLysKOM.c,v 1.4 1994/04/05 20:30:00 ceder Exp $
* Copyright (C) 1994 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -61,28 +61,32 @@ checkstatus(FILE *fp,
perror("updateLysKOM: stat failed");
exit(1);
}
if (kill(pid, SIGHUP) != 0)
if (pid != 0)
{
if (errno != ESRCH)
if (kill(pid, SIGHUP) != 0)
{
fprintf(stderr, "%s: kill(%ld, SIGHUP) failed", progname, pid);
perror("");
exit(1);
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 */
else
{
/* ...more than once. Strange. */
fprintf(stderr, "%s: Told lyskomd to shut down. Twice.",
progname);
exit(1);
/* The signal got through... */
/* cron 10 minutes */
if (ldifftime(time(NULL), sbuf.st_mtime) > 1260)
{
/* ...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 */
......@@ -93,8 +97,9 @@ checkstatus(FILE *fp,
if (fgets(lbuf, 80, fp) == NULL)
{
perror("updateLysKOM: fgets failed");
exit(1);
fprintf(stderr,
"updateLysKOM: LysKOM has been down for a short while\n");
exit(2);
}
if (strchr(lbuf, '\n'))
*strchr(lbuf, '\n') = '\0';
......@@ -136,7 +141,7 @@ main (int argc,
{
case 'V':
case 'v':
fprintf(stderr, "updateLysKOM %d $Revision: 1.3 $\n",
fprintf(stderr, "updateLysKOM %d $Revision: 1.4 $\n",
#include "version.incl"
);
exit(0);
......@@ -148,17 +153,20 @@ main (int argc,
fp = fopen(DEFAULT_PREFIX "/etc/pid", "r");
if (fp == NULL)
{
fprintf(stderr, "%s: %s: ", argv[0], DEFAULT_PREFIX "/etc/pid");
fprintf(stderr, "%s: warning: %s: ", argv[0],
DEFAULT_PREFIX "/etc/pid");
perror("");
exit(1);
pid = 0;
}
pid = 0;
fscanf(fp, "%lu", &pid);
if (pid < 2)
else
{
fprintf(stderr, "%s: got pid %ld.\n", argv[0], pid);
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");
......@@ -168,7 +176,8 @@ main (int argc,
}
else
{
if (kill(pid, SIGUSR1) != 0)
errno = ESRCH; /* Set sane default if pid==0. */
if (pid == 0 || kill(pid, SIGUSR1) != 0)
{
if (errno != ESRCH)
{
......
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