/* called when check runs into timeout */ void check_alarm_handler(int sig) { pid_t pid; gm_log( GM_LOG_TRACE, "check_alarm_handler(%i)\n", sig ); pid = getpid(); if(current_job != NULL && mod_gm_opt->fork_on_exec == GM_DISABLED) { /* create a useful log message*/ if ( !strcmp( current_job->type, "service" ) ) { gm_log( GM_LOG_INFO, "timeout (%is) hit for servicecheck: %s - %s\n", current_job->timeout, current_job->host_name, current_job->service_description); } else if ( !strcmp( current_job->type, "host" ) ) { gm_log( GM_LOG_INFO, "timeout (%is) hit for hostcheck: %s\n", current_job->timeout, current_job->host_name); } else if ( !strcmp( current_job->type, "eventhandler" ) ) { gm_log( GM_LOG_INFO, "timeout (%is) hit for eventhandler: %s\n", current_job->timeout, current_job->command_line); } send_timeout_result(current_job); gearman_job_send_complete(current_gearman_job, NULL, 0); } if(current_child_pid > 0) { kill_child_checks(); } else { signal(SIGINT, SIG_IGN); gm_log( GM_LOG_TRACE, "send SIGINT to %d\n", pid); kill(-pid, SIGINT); signal(SIGINT, SIG_DFL); sleep(1); gm_log( GM_LOG_TRACE, "send SIGKILL to %d\n", pid); kill(-pid, SIGKILL); } return; }
/* do a clean exit */ void clean_worker_exit(int sig) { int *shm; /* give us 30 seconds to stop */ signal(SIGALRM, exit_sighandler); alarm(30); gm_log( GM_LOG_TRACE, "clean_worker_exit(%d)\n", sig); /* clear gearmans job, otherwise it would be retried and retried */ if(current_gearman_job != NULL) { if(sig == SIGINT) { /* if worker stopped with sigint, let the job retry */ } else { send_failed_result(current_job, sig); gearman_job_send_complete(current_gearman_job, NULL, 0); } /* make sure no processes are left over */ kill_child_checks(); } gm_log( GM_LOG_TRACE, "cleaning worker\n"); gearman_worker_unregister_all(&worker); gearman_job_free_all( &worker ); gm_log( GM_LOG_TRACE, "cleaning client\n"); gearman_client_free( &client ); mod_gm_free_opt(mod_gm_opt); #ifdef EMBEDDEDPERL deinit_embedded_perl(0); #endif if(worker_run_mode == GM_WORKER_STANDALONE) exit( EXIT_SUCCESS ); /* Now we attach the segment to our data space. */ if((shm = shmat(shmid, NULL, 0)) == (int *) -1) { perror("shmat"); gm_log( GM_LOG_TRACE, "worker finished: %d\n", getpid() ); _exit( EXIT_FAILURE ); } /* clean our pid from worker list */ if( shm[shm_index] == current_pid || shm[shm_index] == -current_pid ) { shm[shm_index] = -1; } /* detach from shared memory */ if(shmdt(shm) < 0) perror("shmdt"); _exit( EXIT_SUCCESS ); }