aboutsummaryrefslogtreecommitdiffstats
path: root/main/arpwatch/21_all_arpwatch-2.1a15-pid-filename.patch
blob: af4d6ca51c75172e4f171a078a607a0ef4dca542 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
--- ./arpwatch.8.orig	2007-03-27 22:06:16.000000000 +0400
+++ ./arpwatch.8	2007-03-27 22:08:41.000000000 +0400
@@ -88,6 +88,12 @@
 .br
 .ti +9
 [
+.B -P
+.I pid_path
+]
+.br
+.ti +9
+[
 .B -a
 ]
 .br
@@ -204,6 +210,10 @@
 YMMV. (This feature comes from Debian).
 .LP
 The
+.B -P
+flag is used to specify pid filename. Default is set to /var/run/arpwatch.pid.
+.LP
+The
 .B -a
 flag tells
 .B arpwatch
--- ./arpwatch.h.orig	2007-03-27 21:36:50.000000000 +0400
+++ ./arpwatch.h	2007-03-27 21:37:17.000000000 +0400
@@ -1,6 +1,7 @@
 /* @(#) $Id: arpwatch.h,v 1.29 2000/09/30 23:40:49 leres Exp $ (LBL) */
 
 #define ARPFILE "arp.dat"
+#define PIDFILENAME "/var/run/arpwatch.pid"
 /*#define ETHERCODES "ethercodes.dat" */
 #define CHECKPOINT (15*60)		/* Checkpoint time in seconds */
 
--- ./arpwatch.c.orig	2007-03-27 21:31:18.000000000 +0400
+++ ./arpwatch.c	2007-03-27 22:04:15.000000000 +0400
@@ -108,6 +108,8 @@
 
 char *prog;
 char *path_sendmail = PATH_SENDMAIL;
+char *pidname = PIDFILENAME;
+int nofork = 0;
 
 int can_checkpoint;
 int swapped;
@@ -179,7 +181,6 @@
 	struct bpf_program code;
 	char errbuf[PCAP_ERRBUF_SIZE];
 	char* username = NULL;
-	int nofork = 0;
 	int restart = 0;
 	int restarting_loop = 0;
 	char options[] =
@@ -194,6 +195,7 @@
 		"m:"
 		"s:"
 		"p"
+		"P:"
 		"a"
 		"u:"
 		"R:"
@@ -202,6 +204,7 @@
 		"z:"
 	;
 	char *tmpptr;
+	FILE *pidfile;
 
 	if (argv[0] == NULL)
 		prog = "arpwatch";
@@ -274,6 +277,10 @@
 			++nopromisc;
 			break;
 
+		case 'P':
+			pidname = optarg;
+			break;
+
 		case 'a':
 			++allsubnets;
 			break;
@@ -342,6 +349,15 @@
 					exit(1);
 				} else if (pid != 0)
 					exit(0);
+				pidfile = fopen(pidname, "w");
+				if(pidfile) {
+					int pid = (int)getpid();
+					fprintf(pidfile, "%d\n", pid);
+					fclose(pidfile);
+					syslog(LOG_INFO, "Wrote pid %d to %s", pid, pidname);
+				}
+				else
+					fprintf(stderr, "Couldn't write pid file\n");
 			}
 			(void)close(fileno(stdin));
 			(void)close(fileno(stdout));
@@ -870,6 +886,9 @@
 {
 
 	syslog(LOG_DEBUG, "exiting");
+	if (!debug && !nofork)
+		if(!unlink(pidname))
+			syslog(LOG_DEBUG, "unable to remove pid file %s", pidname);
 	checkpoint(0);
 	exit(1);
 }