Add assertions that kill() is never accidentally passed a non-positive
authorMartin Pool <mbp@samba.org>
Wed, 20 Mar 2002 06:57:03 +0000 (06:57 +0000)
committerMartin Pool <mbp@samba.org>
Wed, 20 Mar 2002 06:57:03 +0000 (06:57 +0000)
pid.  This follows a bug in rsync where it would accidentally
kill(-1), removing all the user's processes.  I can't see any way this
would directly happen in Samba, but having the assertions seems
beneficial.

http://cvs.samba.org/cgi-bin/cvsweb/rsync/util.c.diff?r1=1.108&r2=1.109&f=h

source/lib/messages.c
source/lib/util.c
source/nmbd/asyncdns.c
source/web/startstop.c

index 642caafac416ea0c2b9dcbb138a88f57f5c3c147..b745cbaf8bde3880ba0b0d1a181af22ae40c7b80 100644 (file)
@@ -144,6 +144,9 @@ static TDB_DATA message_key_pid(pid_t pid)
 
 static BOOL message_notify(pid_t pid)
 {
+       /* Doing kill with a non-positive pid causes messages to be
+        * sent to places we don't want. */
+       SMB_ASSERT(pid > 0);
        if (kill(pid, SIGUSR1) == -1) {
                if (errno == ESRCH) {
                        DEBUG(2,("pid %d doesn't exist - deleting messages record\n", (int)pid));
@@ -174,6 +177,10 @@ BOOL message_send_pid(pid_t pid, int msg_type, const void *buf, size_t len,
        rec.src = sys_getpid();
        rec.len = len;
 
+       /* Doing kill with a non-positive pid causes messages to be
+        * sent to places we don't want. */
+       SMB_ASSERT(pid > 0);
+
        kbuf = message_key_pid(pid);
 
        /* lock the record for the destination */
index 8867d37d57f76ba57ee3b3ff6af4ffa55663fd75..a2f8c086e84b91f1a6e8e99fe1f6b3fcc7c0d6b5 100644 (file)
@@ -1034,6 +1034,9 @@ check if a process exists. Does this work on all unixes?
 
 BOOL process_exists(pid_t pid)
 {
+       /* Doing kill with a non-positive pid causes messages to be
+        * sent to places we don't want. */
+       SMB_ASSERT(pid > 0);
        return(kill(pid,0) == 0 || errno != ESRCH);
 }
 
index c5ff718836c0b90af7e6ad53e09780fd7cd7ce5e..6c2f8de3b181e52658b126433f20ae411e791ba8 100644 (file)
@@ -120,8 +120,9 @@ static void sig_term(int sig)
 
 void kill_async_dns_child(void)
 {
-  if(child_pid != 0 && child_pid != -1)
-    kill(child_pid, SIGTERM);
+       if (child_pid > 0) {
+               kill(child_pid, SIGTERM);
+       }
 }
 
 /***************************************************************************
index 27ee7dd96e083cc881c564e6633b03c33655fe98..c56320c962ba7593202f6bca5a75701b6fe1cb4d 100644 (file)
@@ -75,7 +75,7 @@ void stop_smbd(void)
 
        if (geteuid() != 0) return;
 
-       if (pid == 0) return;
+       if (pid <= 0) return;
 
        kill(pid, SIGTERM);
 }
@@ -87,7 +87,7 @@ void stop_nmbd(void)
 
        if (geteuid() != 0) return;
 
-       if (pid == 0) return;
+       if (pid <= 0) return;
 
        kill(pid, SIGTERM);
 }