close pid files as early as possible in psadwatchd
authorMichael Rash <mbr@cipherdyne.org>
Sat, 8 Feb 2014 14:47:39 +0000 (09:47 -0500)
committerMichael Rash <mbr@cipherdyne.org>
Sat, 8 Feb 2014 14:47:39 +0000 (09:47 -0500)
psadwatchd.c

index ea9810f..ecb399e 100644 (file)
@@ -229,18 +229,19 @@ static void check_process(
             fprintf(stderr, "[-] Could not read the pid file: %s\n",
                 pid_file);
 #endif
+            fclose(pidfile_ptr);
+
             /* see if we need to give up */
             incr_syscall_ctr(pid_name, max_retries);
-            fclose(pidfile_ptr);
             return;
         }
 
-        /* convert the pid_line into an integer */
-        pid = atoi(pid_line);
-
         /* close the pid_file now that we have read it */
         fclose(pidfile_ptr);
 
+        /* convert the pid_line into an integer */
+        pid = atoi(pid_line);
+
         if (kill(pid, 0) != 0) {
             /* the process is not running so start it */
             restart = 1;