Line 0
Link Here
|
|
|
1 |
--- orig/nrpe-2.0/src/Makefile.in Tue Aug 5 07:01:53 2003 |
2 |
+++ src/Makefile.in Tue May 17 00:25:33 2005 |
3 |
@@ -9,7 +9,7 @@ |
4 |
SRC_COMMON=../common |
5 |
|
6 |
CC=@CC@ |
7 |
-CFLAGS=@CFLAGS@ @DEFS@ |
8 |
+CFLAGS=@CFLAGS@ @DEFS@ -DPID_DIR=\"/var/run/\" |
9 |
LDFLAGS=@LDFLAGS@ @LIBS@ |
10 |
SOCKETLIBS=@SOCKETLIBS@ |
11 |
|
12 |
--- orig/nrpe-2.0/src/nrpe.c Tue Sep 9 04:52:37 2003 |
13 |
+++ src/nrpe.c Tue May 17 00:24:29 2005 |
14 |
@@ -23,6 +23,7 @@ |
15 |
#include "nrpe.h" |
16 |
#include "utils.h" |
17 |
|
18 |
+ |
19 |
#ifdef HAVE_SSL |
20 |
#include "dh.h" |
21 |
#endif |
22 |
@@ -83,7 +84,6 @@ |
23 |
#endif |
24 |
|
25 |
|
26 |
- |
27 |
int main(int argc, char **argv){ |
28 |
int result=OK; |
29 |
int x; |
30 |
@@ -219,7 +219,45 @@ |
31 |
|
32 |
/* else daemonize and start listening for requests... */ |
33 |
else if(fork()==0){ |
34 |
- |
35 |
+#ifdef PID_DIR |
36 |
+ int fd; |
37 |
+ int pid_written = 0; |
38 |
+ char *pid_fname; |
39 |
+ char pbuf[16]; |
40 |
+ char *bname = strrchr(argv[0], '/'); /* basename from XPG4.2 would be nice */ |
41 |
+ |
42 |
+ bname = !bname ? argv[0] : ++bname; |
43 |
+ pid_fname = malloc(strlen(PID_DIR) + strlen(bname) + sizeof(".pid")); |
44 |
+ strcpy(pid_fname, PID_DIR); |
45 |
+ strcat(pid_fname, bname); strcat(pid_fname, ".pid"); |
46 |
+ if ((fd = open (pid_fname, O_RDONLY)) >= 0) { |
47 |
+ int status = read (fd, pbuf, (sizeof pbuf) - 1); |
48 |
+ close (fd); |
49 |
+ if (status > 0) { |
50 |
+ int pid; |
51 |
+ pbuf [status] = 0; |
52 |
+ pid = atoi (pbuf); |
53 |
+ /* If the previous server process is not still running, |
54 |
+ write a new pid file immediately. */ |
55 |
+ if (pid && (pid == getpid() || kill (pid, 0) < 0)) { |
56 |
+ unlink (pid_fname); |
57 |
+ } else { |
58 |
+ syslog(LOG_ERR,"There's already a nrpe server running."); |
59 |
+ free(pid_fname); |
60 |
+ return STATE_CRITICAL; |
61 |
+ } |
62 |
+ } |
63 |
+ } |
64 |
+ if ((fd = open (pid_fname, O_WRONLY | O_CREAT, 0644)) >= 0) { |
65 |
+ sprintf (pbuf, "%d\n", (int)getpid ()); |
66 |
+ write (fd, pbuf, strlen (pbuf)); |
67 |
+ close (fd); |
68 |
+ } else { |
69 |
+ syslog(LOG_ERR,"Can not write the pidfile(%s).", pid_fname); |
70 |
+ } |
71 |
+ free(pid_fname); |
72 |
+#endif |
73 |
+ |
74 |
/* we're a daemon - set up a new process group */ |
75 |
setsid(); |
76 |
|