Skip to content
Snippets Groups Projects
Commit 9c2b9171 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Survive non-existing pid file.

parent 9798ab00
No related branches found
No related tags found
No related merge requests found
/* /*
* $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. * Copyright (C) 1994 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -61,28 +61,32 @@ checkstatus(FILE *fp, ...@@ -61,28 +61,32 @@ checkstatus(FILE *fp,
perror("updateLysKOM: stat failed"); perror("updateLysKOM: stat failed");
exit(1); 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); if (errno != ESRCH)
perror(""); {
exit(1); fprintf(stderr, "%s: kill(%ld, SIGHUP) failed", progname, pid);
perror("");
exit(1);
}
} }
} else
else
{
/* The signal got through... */
if (ldifftime(time(NULL), sbuf.st_mtime) > 1260) /* cron 10 minutes */
{ {
/* ...more than once. Strange. */ /* The signal got through... */
fprintf(stderr, "%s: Told lyskomd to shut down. Twice.", /* cron 10 minutes */
progname); if (ldifftime(time(NULL), sbuf.st_mtime) > 1260)
exit(1); {
/* ...more than once. Strange. */
fprintf(stderr, "%s: Told lyskomd to shut down. Twice.",
progname);
exit(1);
}
} }
} }
if (ldifftime(time(NULL), sbuf.st_mtime) < 3600) if (ldifftime(time(NULL), sbuf.st_mtime) < 3600)
{ {
/* NOP */ /* NOP */
...@@ -93,8 +97,9 @@ checkstatus(FILE *fp, ...@@ -93,8 +97,9 @@ checkstatus(FILE *fp,
if (fgets(lbuf, 80, fp) == NULL) if (fgets(lbuf, 80, fp) == NULL)
{ {
perror("updateLysKOM: fgets failed"); fprintf(stderr,
exit(1); "updateLysKOM: LysKOM has been down for a short while\n");
exit(2);
} }
if (strchr(lbuf, '\n')) if (strchr(lbuf, '\n'))
*strchr(lbuf, '\n') = '\0'; *strchr(lbuf, '\n') = '\0';
...@@ -136,7 +141,7 @@ main (int argc, ...@@ -136,7 +141,7 @@ main (int argc,
{ {
case 'V': case 'V':
case 'v': case 'v':
fprintf(stderr, "updateLysKOM %d $Revision: 1.3 $\n", fprintf(stderr, "updateLysKOM %d $Revision: 1.4 $\n",
#include "version.incl" #include "version.incl"
); );
exit(0); exit(0);
...@@ -148,17 +153,20 @@ main (int argc, ...@@ -148,17 +153,20 @@ main (int argc,
fp = fopen(DEFAULT_PREFIX "/etc/pid", "r"); fp = fopen(DEFAULT_PREFIX "/etc/pid", "r");
if (fp == NULL) 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(""); perror("");
exit(1); pid = 0;
} }
else
pid = 0;
fscanf(fp, "%lu", &pid);
if (pid < 2)
{ {
fprintf(stderr, "%s: got pid %ld.\n", argv[0], pid); pid = 0;
exit(1); 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"); fp = fopen(DEFAULT_PREFIX "/etc/status", "r");
...@@ -168,7 +176,8 @@ main (int argc, ...@@ -168,7 +176,8 @@ main (int argc,
} }
else else
{ {
if (kill(pid, SIGUSR1) != 0) errno = ESRCH; /* Set sane default if pid==0. */
if (pid == 0 || kill(pid, SIGUSR1) != 0)
{ {
if (errno != ESRCH) if (errno != ESRCH)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment