static void libev_ctx_del(void *ctx, const verto_ev *ev, void *evpriv) { switch (verto_get_type(ev)) { case VERTO_EV_TYPE_IO: ev_io_stop(ctx, evpriv); break; case VERTO_EV_TYPE_TIMEOUT: ev_timer_stop(ctx, evpriv); break; case VERTO_EV_TYPE_IDLE: ev_idle_stop(ctx, evpriv); break; case VERTO_EV_TYPE_SIGNAL: ev_signal_stop(ctx, evpriv); break; case VERTO_EV_TYPE_CHILD: ev_child_stop(ctx, evpriv); break; default: break; } free(evpriv); }
static void mon_child_cb(struct ev_loop* loop, ev_child* w, int revents V_UNUSED) { dmn_assert(loop); dmn_assert(w); dmn_assert(revents == EV_CHILD); ev_child_stop(loop, w); // always single-shot mon_t* this_mon = w->data; ev_timer_stop(loop, this_mon->cmd_timeout); this_mon->cmd_pid = 0; bool failed = true; int status = w->rstatus; if(WIFEXITED(status)) { if(!WEXITSTATUS(status)) failed = false; } else { if(WIFSIGNALED(status)) dmn_log_warn("Monitor child process for '%s' terminated by signal %u", this_mon->cmd->desc, WTERMSIG(status)); else dmn_log_warn("Monitor child process for '%s' terminated abnormally...", this_mon->cmd->desc); } // If timeout already sent a failure, don't double-send // here when we reap the SIGKILL'd child if(this_mon->result_pending) { if(!killed_by) { sendq_enq(emc_encode_mon(this_mon->cmd->idx, failed)); ev_io_start(loop, plugin_write_watcher); } if (num_proc > 0) { num_proc--; } this_mon->result_pending = false; } }
// Report that a child has exited void child_cb(EV_P_ ev_child *w, int revents) { char str[100]; char format[] = "{\"processTerminated\" : " " {\"pid\" : %d, \"returnCode\" : %d, \"bySignal\" : %d, \"endTime\" : %ld }}"; struct timeval tp; gettimeofday(&tp, NULL); long int time = (long int) tp.tv_sec * 1000 + tp.tv_usec; sprintf(str, format, w->rpid, WEXITSTATUS(w->rstatus), WSTOPSIG(w->rstatus), time); socket_t *s = w->data; ev_child_stop (EV_A_ w); frame_t *frame = malloc(sizeof(frame_t)); frame->fin = 1; frame->opcode = WS_OP_BIN; frame->len = strlen(str); frame->payload = str; int fr_len; char *fr_str = write_frame(frame, &fr_len); socket_write(s, fr_str, fr_len); free(frame); free(fr_str); ilist_remove(processes, w->rpid); }
static void child_cb(EV_P_ ev_child *w, int revents) { ev_child_stop(EV_A_ w); if (WIFEXITED(w->rstatus)) { exit(WEXITSTATUS(w->rstatus)); } else { exit(WTERMSIG(w->rstatus) + 128); } }
/** * Stops the child so it won't be called by the specified event loop. * * Usage: * child:stop(loop) * * [+0, -0, e] */ static int child_stop(lua_State *L) { ev_child* child = check_child(L, 1); struct ev_loop* loop = *check_loop_and_init(L, 2); loop_stop_watcher(L, loop, GET_WATCHER_DATA(child), 1); ev_child_stop(loop, child); return 0; }
static int signal_child_unwatch(lua_State *T) { if (signal_child_active()) { ev_ref(LEM); ev_child_stop(LEM_ &signal_child_watcher); } lua_pushboolean(T, 1); return 1; }
/* * Handler which will be called when we get a SIGCHLD for the nagbar, meaning * it exited (or could not be started, depending on the exit code). * */ static void nagbar_exited(EV_P_ ev_child *watcher, int revents) { ev_child_stop(EV_A_ watcher); if (!WIFEXITED(watcher->rstatus)) { ELOG("ERROR: i3-nagbar did not exit normally.\n"); return; } int exitcode = WEXITSTATUS(watcher->rstatus); DLOG("i3-nagbar process exited with status %d\n", exitcode); if (exitcode == 2) { ELOG("ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n"); } *((pid_t *)watcher->data) = -1; }
static void event_child_cb(struct ev_loop *loop, ev_child *w, int revents) { liEventChild *child = LI_CONTAINER_OF(w, liEventChild, libevmess.child); liEventLoop *my_loop = child->base.link_watchers.data; UNUSED(revents); LI_FORCE_ASSERT(NULL != my_loop); LI_FORCE_ASSERT(loop == my_loop->loop); if (ev_is_active(w)) { if (!child->base.keep_loop_alive) ev_ref(loop); ev_child_stop(loop, w); } child->base.active = 0; child->base.callback(&child->base, LI_EV_WAKEUP); }
static void worker_exited_cb(EV_P_ ev_child *w, int revents) { struct worker *worker = CONTAINER_OF(w, struct worker, child_watcher); LOGF(3, "=== %d: worker ended, status=%d\n", worker_pid(worker), w->rstatus); ev_child_stop(EV_A_ w); worker->f_alive = false; if (worker->session == NULL) { printf("WARNING: worker without session!\n"); return; } session_on_worker_exited_cb(EV_A_ worker->session, w->rstatus); }
static void child_died(struct ev_loop *loop, ev_child *w, int revents) { child *c = (child*) w->data; UNUSED(revents); ev_child_stop(loop, w); c->d->running--; c->pid = -1; if (c->d->shutdown) return; if (ev_now(c->d->loop) - c->last_spawn > (opts.retry_timeout_ms / (ev_tstamp) 1000)) { g_printerr("Child[%i] died, respawn\n", c->id); c->tries = 0; } else { g_printerr("Spawning child[%i] failed, next try\n", c->id); } spawn(c); }
void child_proc_cb(EV_P_ ev_child *watcher, int revents) { ev_child_stop(EV_A_ watcher); process_t *process = watcher->data; struct proc_data *procdata = process->data; pn_proc_exited(process, watcher->rstatus); printf("process %s[%d] - ", pn_proc_program(process)->name, pn_proc_pid(process)); pn_proc_print(stdout, process, 0, 0); //publish_proc_event(process, "exited"); if (procdata->running_state_timer != NULL) { ev_timer_stop(EV_A_ (ev_timer *)procdata->running_state_timer); free(procdata->running_state_timer); //running_state_timer_cb(EV_A_ procdata->running_state_timer, 0); } restart_child(process, 2.0); /* We allocate a new watcher for each pid, so this one is done. */ free(watcher); } /* child_proc_cb */
static void uv__chld(EV_P_ ev_child* watcher, int revents) { int status = watcher->rstatus; int exit_status = 0; int term_signal = 0; uv_process_t *process = watcher->data; assert(&process->child_watcher == watcher); assert(revents & EV_CHILD); ev_child_stop(EV_A_ &process->child_watcher); if (WIFEXITED(status)) { exit_status = WEXITSTATUS(status); } if (WIFSIGNALED(status)) { term_signal = WTERMSIG(status); } if (process->exit_cb) { process->exit_cb((uv_handle_t *)process, exit_status, term_signal); } }
void worker_stop(EV_P_ struct worker *worker) { LOGF(3, "=== %d: worker stopped\n", worker_pid(worker)); if (worker->f_alive) { LOGF(1, "=== %d: worker still alive - sending SIGKILL\n", worker_pid(worker)); kill(worker_pid(worker), SIGKILL); } writeq_uninit(&worker->stdin_writeq); writeq_uninit(&worker->msgin_writeq); if (ev_is_active(&worker->child_watcher)) { ev_child_stop(EV_A_ &worker->child_watcher); } if (ev_is_active(&worker->stdin_w)) { ev_io_stop(EV_A_ &worker->stdin_w); } if (ev_is_active(&worker->stdout_w)) { ev_io_stop(EV_A_ &worker->stdout_w); } if (ev_is_active(&worker->stderr_w)) { ev_io_stop(EV_A_ &worker->stderr_w); } if (ev_is_active(&worker->msgin_w)) { ev_io_stop(EV_A_ &worker->msgin_w); } if (ev_is_active(&worker->msgout_w)) { ev_io_stop(EV_A_ &worker->msgout_w); } close(worker->stdin_w.fd); close(worker->stdout_w.fd); close(worker->stderr_w.fd); close(worker->msgin_w.fd); close(worker->msgout_w.fd); free(worker); }
void exit_cb(struct ev_loop* loop, struct ev_child* cwatcher, int status) { struct worker_s* worker = container_of(cwatcher, struct worker_s, cwatcher); ev_child_stop(loop, cwatcher); err("worker[pid:%d] exit with status:%d, stop_moniter:%d", worker->pid, cwatcher->rstatus, worker->listener->stop_moniter); struct timeval tv; gettimeofday(&tv, 0); if (worker->listener->stop_moniter || 2 > ((int)tv.tv_sec - worker->starttime)) { return; } worker->pid = spawn_worker(worker); if (-1 == worker->pid) { err("spawn worker failed, worker_id:%d", worker->worker_id); exit(EXIT_FAILURE); } err("worker %d restart, new pid: %d", worker->worker_id, worker->pid); ev_child_set(cwatcher, worker->pid, 0); ev_child_start(loop, cwatcher); }
static void child_cb (EV_P_ ev_child *w, int revents) { ev_child_stop (EV_A_ w); printf ("Process %d changed status to %x\n", w->rpid, w->rstatus); }
static void child_cb (EV_P_ ev_child *w, int revents) { ev_child_stop (EV_A_ w); printf ("process %d exited with status %x\n", w->rpid, w->rstatus); }
static void child_stop (void *impl, flux_watcher_t *w) { assert (w->signature == CHILD_SIG); ev_child_stop (w->r->loop, (ev_child *)impl); }
void uv__process_close(uv_process_t* handle) { ev_child_stop(handle->loop->ev, &handle->child_watcher); }
void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { uv_async_t* async; uv_stream_t* stream; uv_process_t* process; handle->close_cb = close_cb; switch (handle->type) { case UV_NAMED_PIPE: uv_pipe_cleanup((uv_pipe_t*)handle); /* Fall through. */ case UV_TTY: case UV_TCP: stream = (uv_stream_t*)handle; uv_read_stop(stream); ev_io_stop(stream->loop->ev, &stream->write_watcher); uv__close(stream->fd); stream->fd = -1; if (stream->accepted_fd >= 0) { uv__close(stream->accepted_fd); stream->accepted_fd = -1; } assert(!ev_is_active(&stream->read_watcher)); assert(!ev_is_active(&stream->write_watcher)); break; case UV_UDP: uv__udp_start_close((uv_udp_t*)handle); break; case UV_PREPARE: uv_prepare_stop((uv_prepare_t*) handle); break; case UV_CHECK: uv_check_stop((uv_check_t*) handle); break; case UV_IDLE: uv_idle_stop((uv_idle_t*) handle); break; case UV_ASYNC: async = (uv_async_t*)handle; ev_async_stop(async->loop->ev, &async->async_watcher); ev_ref(async->loop->ev); break; case UV_TIMER: uv_timer_stop((uv_timer_t*)handle); break; case UV_PROCESS: process = (uv_process_t*)handle; ev_child_stop(process->loop->ev, &process->child_watcher); break; case UV_FS_EVENT: uv__fs_event_destroy((uv_fs_event_t*)handle); break; default: assert(0); } handle->flags |= UV_CLOSING; /* This is used to call the on_close callback in the next loop. */ ev_idle_start(handle->loop->ev, &handle->next_watcher); ev_feed_event(handle->loop->ev, &handle->next_watcher, EV_IDLE); assert(ev_is_pending(&handle->next_watcher)); }
void feng_stop_child_watcher(struct feng *srv) { ev_child_stop (srv->loop, &cw); }