1 | /* Copyright 1996 by the Massachusetts Institute of Technology. |
---|
2 | * |
---|
3 | * Permission to use, copy, modify, and distribute this |
---|
4 | * software and its documentation for any purpose and without |
---|
5 | * fee is hereby granted, provided that the above copyright |
---|
6 | * notice appear in all copies and that both that copyright |
---|
7 | * notice and this permission notice appear in supporting |
---|
8 | * documentation, and that the name of M.I.T. not be used in |
---|
9 | * advertising or publicity pertaining to distribution of the |
---|
10 | * software without specific, written prior permission. |
---|
11 | * M.I.T. makes no representations about the suitability of |
---|
12 | * this software for any purpose. It is provided "as is" |
---|
13 | * without express or implied warranty. |
---|
14 | */ |
---|
15 | |
---|
16 | static const char rcsid[] = "$Id: access_off.c,v 1.6 1997-04-11 20:48:49 ghudson Exp $"; |
---|
17 | |
---|
18 | #include <stdio.h> |
---|
19 | #include <signal.h> |
---|
20 | #include <errno.h> |
---|
21 | #include <string.h> |
---|
22 | |
---|
23 | int main(int argc, char **argv) |
---|
24 | { |
---|
25 | FILE *pidfile; |
---|
26 | int pid, status, signo; |
---|
27 | char *progname; |
---|
28 | |
---|
29 | pidfile = fopen("/var/athena/inetd.pid", "r"); |
---|
30 | if (!pidfile) |
---|
31 | { |
---|
32 | printf("cannot read process id file--daemon probably not running\n"); |
---|
33 | return 1; |
---|
34 | } |
---|
35 | if (fscanf(pidfile, "%d", &pid) != 1) |
---|
36 | { |
---|
37 | printf("error reading process id file\n"); |
---|
38 | return 1; |
---|
39 | } |
---|
40 | fclose(pidfile); |
---|
41 | |
---|
42 | progname = strrchr(argv[0], '/'); |
---|
43 | progname = (progname) ? progname + 1 : argv[0]; |
---|
44 | signo = (strcmp(progname, "access_off") == 0) ? SIGUSR2 : SIGUSR1; |
---|
45 | |
---|
46 | if (kill(pid, signo) < 0) |
---|
47 | { |
---|
48 | if (errno != ESRCH) |
---|
49 | perror("error killing daemon"); |
---|
50 | return 1; |
---|
51 | } |
---|
52 | |
---|
53 | return 0; |
---|
54 | } |
---|