[Pkg-nagios-changes] [pkg-mod-gearman] 33/48: removed waitpid bullshit again

Stig Sandbeck Mathisen ssm at debian.org
Sun Nov 24 22:38:11 UTC 2013


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository pkg-mod-gearman.

commit 004726efc9c42c6db39cf1f5ffc19e97c1aec298
Author: Sven Nierlein <Sven.Nierlein at consol.de>
Date:   Fri Nov 1 18:22:21 2013 +0100

    removed waitpid bullshit again
---
 common/check_utils.c |  2 +-
 common/utils.c       | 15 +--------------
 include/utils.h      |  3 +--
 t/02-full.c          | 21 +++++++++++++++------
 worker/worker.c      |  4 ++--
 5 files changed, 20 insertions(+), 25 deletions(-)

diff --git a/common/check_utils.c b/common/check_utils.c
index a178d05..fdc4fcf 100644
--- a/common/check_utils.c
+++ b/common/check_utils.c
@@ -450,7 +450,7 @@ void kill_child_checks(void) {
             signal(SIGINT, SIG_DFL);
             return;
         }
-        if(pid_alive(current_child_pid, TRUE)) {
+        if(pid_alive(current_child_pid)) {
             gm_log( GM_LOG_TRACE, "kill_child_checks(): send SIGKILL to %d\n", current_child_pid);
             kill(current_child_pid, SIGKILL);
         }
diff --git a/common/utils.c b/common/utils.c
index 3276cd1..767a2d5 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -1213,7 +1213,7 @@ int free_job(gm_job_t *job) {
 }
 
 /* verify if a pid is alive */
-int pid_alive(int pid, int with_child_check) {
+int pid_alive(int pid) {
     int status;
 
     if(pid < 0) { pid = -pid; }
@@ -1224,19 +1224,6 @@ int pid_alive(int pid, int with_child_check) {
 
     /* send kill 0 to verify the process still exists */
     if(kill(pid, 0) == 0) {
-        // waitpid is only available for child processes
-        if(with_child_check) {
-            if(waitpid(pid, &status, WNOHANG) == -1) {
-                perror("waitpid");
-            }
-            if(WIFEXITED(status)) {
-                return FALSE;
-            }
-            if(WIFSIGNALED(status) && (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGQUIT)) {
-                return FALSE;
-            }
-        }
-
         return TRUE;
     }
 
diff --git a/include/utils.h b/include/utils.h
index e4ab491..aeb76f9 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -314,11 +314,10 @@ int free_job(gm_job_t *job);
  * check if a pid is alive
  *
  * @param[in] pid - pid to check
- * @param[in] with_child_check - check child by waitpid too
  *
  * @return true if pid is alive
  */
-int pid_alive(int pid, int with_child_check);
+int pid_alive(int pid);
 
 /**
  * escapestring
diff --git a/t/02-full.c b/t/02-full.c
index 3ea29c7..6b3e814 100644
--- a/t/02-full.c
+++ b/t/02-full.c
@@ -214,7 +214,7 @@ void do_result_work(int nr) {
     int x = 0;
     for(x=0;x<nr;x++) {
         ret = gearman_worker_work( &worker );
-        //ok(ret == GEARMAN_SUCCESS, 'got valid job' );
+        ok(ret == GEARMAN_SUCCESS, "got valid job from result queue" );
     }
     return;
 }
@@ -360,7 +360,7 @@ void check_no_worker_running(char* worker_logfile) {
 int main (int argc, char **argv, char **env) {
     argc = argc; argv = argv; env  = env;
     int status, chld, rc;
-    int tests = 110;
+    int tests = 127;
     int rrc;
     char cmd[150];
     char *result, *error, *message, *output;
@@ -402,7 +402,7 @@ int main (int argc, char **argv, char **env) {
         diag("make sure gearmand is in your PATH. Common locations are /usr/sbin or /usr/local/sbin");
         exit( EXIT_FAILURE );
     }
-    if(!ok(pid_alive(gearmand_pid, FALSE) == TRUE, "gearmand alive")) {
+    if(!ok(pid_alive(gearmand_pid) == TRUE, "gearmand alive")) {
         check_logfile("/tmp/gearmand.log", 3);
         kill(gearmand_pid, SIGTERM);
         kill(worker_pid, SIGTERM);
@@ -410,7 +410,7 @@ int main (int argc, char **argv, char **env) {
     }
     if(!ok(worker_pid > 0, "worker started with pid: %d", worker_pid))
         diag("could not start worker");
-    if(!ok(pid_alive(worker_pid, FALSE) == TRUE, "worker alive")) {
+    if(!ok(pid_alive(worker_pid) == TRUE, "worker alive")) {
         check_logfile(worker_logfile, 3);
         kill(gearmand_pid, SIGTERM);
         kill(worker_pid, SIGTERM);
@@ -428,6 +428,9 @@ int main (int argc, char **argv, char **env) {
     /* send big job */
     send_big_jobs(GM_ENCODE_ONLY);
     do_result_work(1);
+    wait_for_empty_queue("eventhandler", 20);
+    wait_for_empty_queue("service", 5);
+    wait_for_empty_queue(GM_DEFAULT_RESULT_QUEUE, 5);
 
     /*****************************************
      * test check
@@ -436,6 +439,9 @@ int main (int argc, char **argv, char **env) {
     do_result_work(1);
     like(last_result, "test plugin CRITICAL", "stdout output from ./t/crit.pl");
     like(last_result, "some errors on stderr", "stderr output from ./t/crit.pl");
+    wait_for_empty_queue("eventhandler", 20);
+    wait_for_empty_queue("service", 5);
+    wait_for_empty_queue(GM_DEFAULT_RESULT_QUEUE, 5);
 
     /*****************************************
      * test check2
@@ -444,6 +450,9 @@ int main (int argc, char **argv, char **env) {
     do_result_work(1);
     like(last_result, "stdout output", "stdout output from ./t/both");
     like(last_result, "stderr output", "stderr output from ./t/both");
+    wait_for_empty_queue("eventhandler", 20);
+    wait_for_empty_queue("service", 5);
+    wait_for_empty_queue(GM_DEFAULT_RESULT_QUEUE, 5);
 
     /* try to send some data with base64 only */
     test_eventhandler(GM_ENCODE_ONLY);
@@ -540,7 +549,7 @@ int main (int argc, char **argv, char **env) {
     /* wait 5 seconds to shutdown */
     for(i=0;i<=5;i++) {
         waitpid(gearmand_pid, &status, WNOHANG);
-        if(pid_alive(gearmand_pid, FALSE) == FALSE) {
+        if(pid_alive(gearmand_pid) == FALSE) {
             todo();
             ok(status == 0, "gearmand (%d) exited with: %d", gearmand_pid, real_exit_code(status));
             endtodo;
@@ -549,7 +558,7 @@ int main (int argc, char **argv, char **env) {
         sleep(1);
     }
 
-    if(pid_alive(gearmand_pid, FALSE) == TRUE) {
+    if(pid_alive(gearmand_pid) == TRUE) {
         /* kill it the hard way */
         kill(gearmand_pid, SIGTERM);
         waitpid(gearmand_pid, &status, 0);
diff --git a/worker/worker.c b/worker/worker.c
index 43e0276..532126a 100644
--- a/worker/worker.c
+++ b/worker/worker.c
@@ -202,7 +202,7 @@ void count_current_worker(int restart) {
      */
 
     /* check if status worker died */
-    if( shm[SHM_STATUS_WORKER_PID] != -1 && pid_alive(shm[SHM_STATUS_WORKER_PID], TRUE) == FALSE ) {
+    if( shm[SHM_STATUS_WORKER_PID] != -1 && pid_alive(shm[SHM_STATUS_WORKER_PID]) == FALSE ) {
         gm_log( GM_LOG_TRACE, "removed stale status worker, old pid: %d\n", shm[SHM_STATUS_WORKER_PID] );
         shm[SHM_STATUS_WORKER_PID] = -1;
     }
@@ -214,7 +214,7 @@ void count_current_worker(int restart) {
     for(x=SHM_SHIFT; x < mod_gm_opt->max_worker+SHM_SHIFT; x++) {
         /* verify worker is alive */
         gm_log( GM_LOG_TRACE3, "worker slot:   shm[%d] = %d\n", x, shm[x]);
-        if( shm[x] != -1 && pid_alive(shm[x], TRUE) == FALSE ) {
+        if( shm[x] != -1 && pid_alive(shm[x]) == FALSE ) {
             gm_log( GM_LOG_TRACE, "removed stale worker %d, old pid: %d\n", x, shm[x]);
             shm[x] = -1;
             /* immediately start new worker, otherwise the fork rate cannot be guaranteed */

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-nagios/pkg-mod-gearman



More information about the Pkg-nagios-changes mailing list