[Snort-devel] patch to add option to specify location for pid file

Adam Bernau Abernau at ...1853...
Tue Mar 11 04:59:19 EST 2003


On machines with multiple copies of snort running on the same interface, the location to store the pid file does not work correctly. The test says to first try the /var/run directory, then /var/log, then the logging directory. To save mangling this logic, I have added a -j option (all the good letters were taken) to specify the location of the pid file as a file name. This is a patch against 1.9.1.

    Adam

PS. The patch may or may not be line wrapped correctly by this horrible excuse for a mail interface.


diff -ru snort-1.9.1/src/snort.c snort-1.9.1-j/src/snort.c
--- snort-1.9.1/src/snort.c     Fri Feb 21 10:32:16 2003
+++ snort-1.9.1-j/src/snort.c   Tue Mar 11 13:15:39 2003
@@ -656,6 +656,7 @@
     fputs("        -G <mode>  Add reference ids back into alert msgs (modes: basic, url)\n", stderr);
     fputs("        -h <hn>    Home network = <hn>\n", stderr);
     fputs("        -i <if>    Listen on interface <if>\n", stderr);
+    fputs("        -j <file>  Use <file> as pid file\n", stderr);
     fputs("        -I         Add Interface name to alert output\n", stderr);
     fputs("        -l <ld>    Log to directory <ld>\n", stderr);
     fputs("        -m <umask> Set umask = <umask>\n", stderr);
@@ -755,10 +756,10 @@
 
 #ifndef WIN32
     valid_options = "R:B:fk:TXL:IOCqS:pNA:m:F:DM:br:xeh:l:dc:n:P:"
-        "i:G:vV?ao6u:g:s:t:Uwyz";
+        "i:G:vV?ao6u:g:s:t:Uwyzj:";
 #else
     valid_options = "R:B:fk:TXL:IOCqS:pNA:m:F:DM:br:xeh:l:dc:n:P:"
-        "i:G:vV?ao6u:g:s:t:UwyzEW";
+        "i:G:vV?ao6u:g:s:t:UwyzEWj:";
 #endif
 
     /* loop through each command line var and process it */
@@ -993,6 +994,10 @@
 
             case 'I':       /* add interface name to alert string */
                 pv.alert_interface_flag = 1;
+                break;
+
+           case 'j':  /* specify pidfile to use */
+                strlcpy(pv.pid_filename, optarg, STD_BUF);
                 break;
 
             case 'k':  /* set checksum mode */
diff -ru snort-1.9.1/src/util.c snort-1.9.1-j/src/util.c
--- snort-1.9.1/src/util.c      Tue Feb  4 03:31:06 2003
+++ snort-1.9.1-j/src/util.c    Tue Mar 11 13:33:04 2003
@@ -682,7 +682,8 @@
     char dir[STD_BUF + 1];
 #endif
 
-    if (!pv.readmode_flag) 
+    /* pid_filename can be specified on the command line */
+    if (!pv.readmode_flag && !strlen(pv.pid_filename))
     {
         if(!pv.quiet_flag)
         {
@@ -728,16 +729,19 @@
         }
     }
 
-    if(intf == NULL || pv.pid_path == NULL)
-    {
-        /* pv.pid_path should have some value by now
-         *          * so let us just be sane.
-         *                   */
-        FatalError("ERROR: CreatePidFile() failed to lookup interface or pid_path is unknown!\n");
-    }
+    /* filename could have been passed to us already from the command line */
+    if(!strlen(pv.pid_filename)) {
+        if(intf == NULL || pv.pid_path == NULL)
+        {
+            /* pv.pid_path should have some value by now
+             *          * so let us just be sane.
+             *                   */
+            FatalError("ERROR: CreatePidFile() failed to lookup interface or pid_path is unknown!\n");
+        }
 
-    snprintf(pv.pid_filename, STD_BUF,  "%s/snort_%s%s.pid", pv.pid_path, intf,
+        snprintf(pv.pid_filename, STD_BUF,  "%s/snort_%s%s.pid", pv.pid_path, intf,
                    pv.pidfile_suffix);
+    }
 
     pid_file = fopen(pv.pid_filename, "w");
 





More information about the Snort-devel mailing list