This enables plugins called via hooks/notifiers triggered
[mpls-ppp.git] / NeXT / Examples / pppkill.c
blob932eaca2c879c3cc981946f4b29774d3f50f7122
1 Many thanks to:
2 shess@winternet.com (Scott Hess)
3 andrew_abernathy@wire.seanet.com (Andrew Abernathy)
4 michal@ellpspace.math.ualberta.ca (Michal Jaegermann)
6 for contributing programs that can take the place
7 of the pppdown script. I have included Scott Hess's
8 (now modified) here. If you would like to see the other program, please
9 mail Andrew.
11 ======================================================================
13 From shess@winternet.com Mon Jan 9 02:45 EST 1995
14 Date: Mon, 9 Jan 95 01:45 CST
15 From: shess@winternet.com (Scott Hess)
16 Reply-To: shess@winternet.com (Scott Hess)
17 To: Steve Perkins <perkins@cps.msu.edu>
18 Subject: Bringing down ppp.
20 [munch]
22 In any case, having to run pppdown as root has been annoying,
23 because I don't like to run things as root more than necessary.
24 In other words, more than about once a week is too often :-). So,
25 I wrote the following quick&dirty hack. Basic operation is to read
26 the pppd pid from a file where it's stored and send a SIGINT to
27 that process. Since there's not a shell script in sight, this
28 should be a reasonably safe program to make setuid root. [I'll
29 have to think on what someone can do if they crack it or /etc/ppp
30 and can send SIGINT to just anyone. Perhaps it should check to
31 see if the process is really a pppd? Oh, well.]
33 howard:/tmp> ls -l /usr/local/ppp/bin/killppp
35 -rwsr-sr-x 1 root 1464 Jan 7 12:41 /usr/local/ppp/bin/killppp*
36 howard:/tmp> cat /usr/local/ppp/src/killppp.c
39 * Originally written by Scott Hess <shess@winternet.com>
40 * and later modified by Michal Jaegermann <michal@ellpspace.math.ualberta.ca>
43 #include <libc.h>
44 #include <stdio.h>
47 #include <libc.h>
48 #include <stdio.h>
50 #define PIDF "/etc/ppp/ppp0.pid"
52 int
53 main( void)
55 FILE *ff;
56 int pid;
59 if( NULL == (ff = fopen( PIDF, "r"))) {
60 perror( "opening " PIDF
61 "\nppp0 link does not seem to be active" );
62 exit(1);
66 if( fscanf( ff, "%d", &pid)<1) {
67 fprintf( stderr, "Cannot read pid from" PIDF "\n");
68 exit(1);
72 fclose( ff);
73 if( kill( pid, SIGINT)==-1) {
74 perror( "killing pppd");
75 fprintf( stderr, "removing stale" PIDF "file\n");
76 if (0 != unlink( PIDF)) {
77 perror("cannot remove" PIDF);
79 exit(1);
81 return 0;
84 Later,
85 ---
86 scott hess <shess@winternet.com> (WWW to "http://www.winternet.com/~shess/")
87 Home: 12901 Upton Avenue South, #326 Burnsville, MN 55337 (612) 895-1208
88 Office: 101 W. Burnsville Pkwy, Suite 108E, Burnsville, MN 55337 890-1332
89 <?If you haven't the time to design, where will you find the time to debug?>