/* Standard reboot/shutdown utilities talk to init using /dev/initctl. * We should check if the fifo was recreated and reopen it. */ static void parse(void *UNUSED(arg), int fd, int UNUSED(events)) { struct init_request rq; _d("Receiving request on %s...", FINIT_FIFO); while (1) { ssize_t len = read(fd, &rq, sizeof(rq)); if (len <= 0) { if (-1 == len) { if (EINTR == errno) continue; if (EAGAIN == errno) break; _e("Failed reading initctl request, error %d: %s", errno, strerror(errno)); } break; } if (rq.magic != INIT_MAGIC || len != sizeof(rq)) { _e("Invalid initctl request."); break; } _d("Magic OK..."); if (rq.cmd == INIT_CMD_RUNLVL) { switch (rq.runlevel) { case '0': _d("Halting system (SIGUSR2)"); do_shutdown(SIGUSR2); break; case 's': case 'S': rq.runlevel = '1'; /* Fall through to regular processing */ case '1'...'5': _d("Setting new runlevel %c ...", rq.runlevel); svc_runlevel(rq.runlevel - '0'); break; case '6': _d("Rebooting system (SIGUSR1)"); do_shutdown(SIGUSR1); break; default: _d("Unsupported runlevel: %d", rq.runlevel); break; } } else if (rq.cmd == INIT_CMD_DEBUG) { debug = !debug; } else { _d("Unsupported cmd: %d", rq.cmd); } }
/* ************************************************************************************************************ * * function * * name : * * parmeters : standby_mode: 0, 普通模式,需要检测电源状态 * * 1, 测试模式,强制进入standby模式,不论电源状态 * * return : * * note : probe power and other condition * * * ************************************************************************************************************ */ void board_status_probe(int standby_mode) { int ret; //清除power按键 axp_probe_key(); //启动条件判断,第一阶段,检测电源电压状态 if(!standby_mode) { ret = board_probe_power_level(); //负数:关机;0:进入系统;正数:待机 debug("stage1 resule %d\n", ret); if(ret < 0) { do_shutdown(NULL, 0, 1, NULL); } else if(!ret) { return ; } //启动条件判断,第二阶段,检测开机原因 ret = board_probe_poweron_cause(); //负数,0:进入系统;正数:待机或者直接关机 debug("stage2 resule %d\n", ret); if(ret <= 0) { return ; } else if(ret == AXP_VBUS_DCIN_NOT_EXIST) //当前一次为boot standby状态,但是启动时检查无外部电源,直接关机 { do_shutdown(NULL, 0, 1, NULL); } } //启动条件判断,第三阶段,检测电池存在 //负数:关机;0:进入系统;正数:待机 ret = board_probe_bat_status(standby_mode); debug("stage3 resule %d\n", ret); if(ret < 0) { do_shutdown(NULL, 0, 1, NULL); } else if(!ret) { return ; } //启动条件判断,第四阶段,进入boot待机 //负数:关机,其它:进入系统 ret = board_standby_status(ret); debug("stage4 resule %d\n", ret); if(ret < 0) { do_shutdown(NULL, 0, 1, NULL); } return ; }
/** * abort task to run on test timed out * * @param cls NULL * @param tc the task context */ static void do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting\n"); abort_task = NULL; do_shutdown (cls, tc); }
static uint_t ds1287_issue_shutdown(caddr_t arg) { struct ds1287 *softsp = (struct ds1287 *)arg; DPRINTF("ds1287_issue_shutdown\n"); mutex_enter(&softsp->ds1287_mutex); softsp->events |= PB_BUTTON_PRESS; if (softsp->monitor_on != 0) { mutex_exit(&softsp->ds1287_mutex); pollwakeup(&softsp->pollhd, POLLRDNORM); pollwakeup(&softsp->pollhd, POLLIN); return (DDI_INTR_CLAIMED); } if (!softsp->shutdown_pending) { cmn_err(CE_WARN, "Power button is pressed, powering down " "the system!"); softsp->shutdown_pending = 1; do_shutdown(); /* * Wait a while for "do_shutdown()" to shut down the system * before logging an error message. */ (void) timeout((void(*)(void *))ds1287_log_message, NULL, 100 * hz); } mutex_exit(&softsp->ds1287_mutex); return (DDI_INTR_CLAIMED); }
// this just wraps ALL the code in total catch block int Kernel::run(int argc, const char* argv[], const std::string& appName) { m_argc = argc; m_argv = argv; m_appName = appName; int switches_status = do_switches(); if (switches_status) return switches_status; int startup_status = do_startup(); if (startup_status) return startup_status; int execution_status = do_execution(); // note we will try to shutdown cleanly even if we got an error condition // in the execution phase int shutdown_status = do_shutdown(); if (execution_status) return execution_status; return shutdown_status; }
/* * Shut down on INT USR1 USR2 */ static void shutdown_handler(int sig, siginfo_t *info, void *UNUSED(ctx)) { _d("Rebooting on signal %d from %s (PID %d)", sig, pid_get_name(info->si_pid, NULL, 0), info->si_pid); do_shutdown(sig); }
/** * abort task to run on test timed out * * @param cls NULL * @param tc the task context */ static void do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); abort_task = GNUNET_SCHEDULER_NO_TASK; do_shutdown (cls, tc); }
/** * abort task to run on test timed out * * @param cls NULL * @param tc the task context */ static void do_abort (void *cls) { LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); abort_task = NULL; do_shutdown (cls); }
static void ctrl_c_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { ctrl_c_task_id = NULL; do_shutdown (); GNUNET_break (0); global_ret = 1; }
static void do_deferred_shutdown (DskWebsocket *websocket) { if (websocket->outgoing.size == 0) do_shutdown (websocket); else websocket->is_deferred_shutdown = DSK_TRUE; }
/** * Shutdown nicely * * @param cls * @param tc the task context */ static void do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n"); abort_task_id = GNUNET_SCHEDULER_NO_TASK; result = TEST_FAIL; do_shutdown (cls, tc); }
/* * Main program. * Write a wtmp entry and reboot cq. halt. */ int main(int argc, char **argv) { int do_sync = 1; int do_hard = 0; int do_ifdown = 0; int c; /* * Get flags */ while((c = getopt(argc, argv, ":ifn:")) != EOF) { switch(c) { case 'n': do_sync = 0; break; case 'f': do_hard = 1; break; case 'i': do_ifdown = 1; break; default: usage(); } } if (argc == optind) usage(); if (geteuid() != 0) { fprintf(stderr, "%s: must be superuser.\n", progname); exit(1); } (void)chdir("/"); if (!do_hard ) { /* * See if we are in runlevel 0 or 6. */ c = get_runlevel(); if (c != '0' && c != '6') do_shutdown(argv[optind]); } if (do_sync) { sync(); sleep(2); } if (do_ifdown) (void)ifdown(); (void)hdflush(); syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, argv[optind]); return 0; }
void dialog_ok(GtkWidget *widget, gpointer data) { const gchar *title = (const gchar *)data; if(!g_strcasecmp(title, item_labels[2])) do_reboot(); else if(!g_strcasecmp(title, item_labels[3])) do_shutdown(); }
int main (int argc, char *argv[]) { if (0 != GNUNET_TESTING_peer_run ("test-fs-namespace-list-updateable", "test_fs_namespace_data.conf", &run, NULL)) return 1; do_shutdown (); return err; }
static void do_stop(struct cardstate *cs) { unsigned long flags; spin_lock_irqsave(&cs->lock, flags); cs->connected = 0; spin_unlock_irqrestore(&cs->lock, flags); do_shutdown(cs); }
int main(int argc, char **argv) { int status; wrapper_argc = argc; wrapper_argv = argv; --argc; ++argv; init(argc, argv); struct sigaction sa; memset(&sa, 0, sizeof(struct sigaction)); sa.sa_handler = &signal_handler; sigaction(SIGUSR2, &sa, NULL); sigaction(SIGHUP, &sa, NULL); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); if (getenv(REEXEC_FLAG) != NULL) { /* We are being re-executed: restart HAProxy gracefully */ int i; char **pid_strv = NULL; int nb_pid = read_pids(&pid_strv); unsetenv(REEXEC_FLAG); spawn_haproxy(pid_strv, nb_pid); for (i = 0; i < nb_pid; ++i) free(pid_strv[i]); free(pid_strv); } else { /* Start a fresh copy of HAProxy */ spawn_haproxy(NULL, 0); } status = -1; while (caught_signal || wait(&status) != -1 || errno == EINTR) { int sig = caught_signal; if (caught_signal == SIGUSR2 || caught_signal == SIGHUP) { caught_signal = 0; do_restart(sig); } else if (caught_signal == SIGINT || caught_signal == SIGTERM) { caught_signal = 0; do_shutdown(sig); } } fprintf(stderr, SD_NOTICE "haproxy-systemd-wrapper: exit, haproxy RC=%d\n", status); return status; }
static void desslify(struct context *ctx, int cur) { if (ctx->cbufo && ctx->cbufo->length - ctx->cbufo->offset) control2socket(ctx, cur); if (ctx->cbufo && ctx->cbufo->length - ctx->cbufo->offset) io_set_cb_o(ctx->io, cur, (void *) do_shutdown); else { io_clr_i(ctx->io, cur); io_clr_o(ctx->io, cur); do_shutdown(ctx, cur); } }
/*===========================================================================* * sef_cb_signal_handler * *===========================================================================*/ PRIVATE void sef_cb_signal_handler(int signo) { /* Check for known signals, ignore anything else. */ switch(signo) { case SIGCHLD: do_sigchld(); break; case SIGTERM: do_shutdown(NULL); break; } }
/*===========================================================================* * sig_handler * *===========================================================================*/ PRIVATE void sig_handler() { sigset_t sigset; int sig; /* Try to obtain signal set from PM. */ if (getsigset(&sigset) != 0) return; /* Check for known signals. */ if (sigismember(&sigset, SIGCHLD)) do_exit(NULL); if (sigismember(&sigset, SIGTERM)) do_shutdown(NULL); }
/** * Task run for shutdown. * * @param cls closure, NULL if we need to self-restart * @param tc context */ static void shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct ServiceList *pos; struct ServiceList *nxt; struct ServiceListeningInfo *sli; if (GNUNET_SCHEDULER_NO_TASK != child_restart_task) { GNUNET_SCHEDULER_cancel (child_restart_task); child_restart_task = GNUNET_SCHEDULER_NO_TASK; } in_shutdown = GNUNET_YES; /* first, stop listening */ for (pos = running_head; NULL != pos; pos = pos->next) { while (NULL != (sli = pos->listen_head)) { GNUNET_CONTAINER_DLL_remove (pos->listen_head, pos->listen_tail, sli); if (sli->accept_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (sli->accept_task); sli->accept_task = GNUNET_SCHEDULER_NO_TASK; } GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sli->listen_socket)); GNUNET_free (sli->service_addr); GNUNET_free (sli); } } /* then, shutdown all existing service processes */ nxt = running_head; while (NULL != (pos = nxt)) { nxt = pos->next; if (pos->proc != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping service `%s'\n", pos->name); pos->killed_at = GNUNET_TIME_absolute_get (); if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); } else { free_service (pos); } } /* finally, should all service processes be already gone, terminate for real */ if (running_head == NULL) do_shutdown (); }
/** * Something went wrong and timed out. Kill everything and set error flag */ static void do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: ABORT\n"); if (0 != test_task) { GNUNET_SCHEDULER_cancel (test_task); } result = GNUNET_SYSERR; abort_task = 0; do_shutdown (cls, tc); }
/** * abort task to run on test timed out * * @param cls NULL * @param tc the task context */ static void do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); abort_task = NULL; if (NULL != delayed_connect_task) { GNUNET_SCHEDULER_cancel (delayed_connect_task); delayed_connect_task = NULL; } do_shutdown (cls, tc); }
/** * Something went wrong and timed out. Kill everything and set error flag */ static void do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ABORT\n"); result = GNUNET_SYSERR; abort_task = NULL; if (NULL != shutdown_task) { GNUNET_SCHEDULER_cancel (shutdown_task); shutdown_task = NULL; } do_shutdown (cls, tc); }
struct cmdline_config init_config(int argc, char **argv) { struct cmdline_config config = { .daemonize = true, .create_basedir = true, .configfile = CONFIGFILE, }; read_cmdline(argc, argv, &config); if (config.test_config) exit(EXIT_SUCCESS); if (optind < argc) exit_usage(1); plugin_init_ctx(); if (configure_collectd(&config) != 0) exit(EXIT_FAILURE); return config; } int run_loop(bool test_readall) { int exit_status = 0; if (do_init() != 0) { ERROR("Error: one or more plugin init callbacks failed."); exit_status = 1; } if (test_readall) { if (plugin_read_all_once() != 0) { ERROR("Error: one or more plugin read callbacks failed."); exit_status = 1; } } else { INFO("Initialization complete, entering read-loop."); do_loop(); } /* close syslog */ INFO("Exiting normally."); if (do_shutdown() != 0) { ERROR("Error: one or more plugin shutdown callbacks failed."); exit_status = 1; } return exit_status; } /* int run_loop */
bool winsock2_streambuf::shutdown() { if (!is_open()) return false; // try flush if (sync() == -1) return false; #ifdef EXT_ENABLE_OPENSSL // try stop ssl if (!stop_ssl()) return false; #endif //EXT_ENABLE_OPENSSL // делаем shutdown return do_shutdown(); }
void quit(const char *fmt, ...) { static int done; va_list args; va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); if (!done) { done = 1; do_shutdown(); } exit(1); }
/*-------------------------------------------------------------------*/ static void sigterm_handler (int signo) { // logmsg ("impl.c: sigterm handler entered for thread %lu\n",/*debug*/ // thread_id()); /*debug*/ UNREFERENCED(signo); signal(SIGTERM, sigterm_handler); /* Ignore signal unless presented on main program (impl) thread */ if ( !equal_threads( thread_id(), sysblk.impltid ) ) return; /* Initiate system shutdown */ do_shutdown(); return; } /* end function sigterm_handler */
void quit(const char *fmt, ...) { static int done; va_list args; va_start(args, fmt); if (is_daemon) vsyslog(LOG_ERR, fmt, args); else vfprintf(stderr, fmt, args); va_end(args); if (!done) { done = 1; do_shutdown(); } exit(1); }
/*-------------------------------------------------------------------*/ static void delayed_exit (int exit_code) { UNREFERENCED(exit_code); /* Delay exiting is to give the system * time to display the error message. */ #if defined( _MSVC_ ) SetConsoleCtrlHandler( NULL, FALSE); // disable Ctrl-C intercept #endif sysblk.shutimmed = TRUE; fflush(stderr); fflush(stdout); usleep(100000); do_shutdown(); fflush(stderr); fflush(stdout); usleep(100000); return; }
void item_press(GtkWidget *widget, GdkEventButton *event, gpointer data) { ITEM_IMG *item_img = (ITEM_IMG *)data; gint index = item_img->index; switch(index) { case REBOOT: do_reboot(); break; case STANDBY: standby(); break; case SHUTDOWN: do_shutdown(); break; case CANCEL: cancel(); break; } }