summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Pool <mbp@samba.org>2002-03-20 06:57:03 +0000
committerMartin Pool <mbp@samba.org>2002-03-20 06:57:03 +0000
commit098905bea29c7d5b886809d431294ddf2fc1e152 (patch)
tree5b99b8876978459673bfb690193365a51bc66d77
parentb1b7ae8bcfafc92c2d475908f4220f3f1ff941a1 (diff)
downloadsamba-098905bea29c7d5b886809d431294ddf2fc1e152.tar.gz
samba-098905bea29c7d5b886809d431294ddf2fc1e152.tar.xz
samba-098905bea29c7d5b886809d431294ddf2fc1e152.zip
Add assertions that kill() is never accidentally passed a non-positive
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
-rw-r--r--source/lib/messages.c7
-rw-r--r--source/lib/util.c3
-rw-r--r--source/nmbd/asyncdns.c5
-rw-r--r--source/web/startstop.c4
4 files changed, 15 insertions, 4 deletions
diff --git a/source/lib/messages.c b/source/lib/messages.c
index 642caafac41..b745cbaf8bd 100644
--- a/source/lib/messages.c
+++ b/source/lib/messages.c
@@ -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 */
diff --git a/source/lib/util.c b/source/lib/util.c
index 8867d37d57f..a2f8c086e84 100644
--- a/source/lib/util.c
+++ b/source/lib/util.c
@@ -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);
}
diff --git a/source/nmbd/asyncdns.c b/source/nmbd/asyncdns.c
index c5ff718836c..6c2f8de3b18 100644
--- a/source/nmbd/asyncdns.c
+++ b/source/nmbd/asyncdns.c
@@ -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);
+ }
}
/***************************************************************************
diff --git a/source/web/startstop.c b/source/web/startstop.c
index 27ee7dd96e0..c56320c962b 100644
--- a/source/web/startstop.c
+++ b/source/web/startstop.c
@@ -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);
}