/** * Signal handler for SIGINT / SIGQUIT * * @param sig signal number */ static void signal_handler(int sig) { /* if a process receives a shutdown signal, it will clear all ipc resourcses (in case of normal shutdown only chstat would do this) */ ipc_shutdown(); exit(EXIT_SUCCESS); }
/* * Restart i3 in-place * appends -a to argument list to disable autostart * */ void i3_restart(bool forget_layout) { char *restart_filename = forget_layout ? NULL : store_restart_layout(); kill_nagbar(&config_error_nagbar_pid, true); kill_nagbar(&command_error_nagbar_pid, true); restore_geometry(); ipc_shutdown(); LOG("restarting \"%s\"...\n", start_argv[0]); /* make sure -a is in the argument list or append it */ start_argv = append_argument(start_argv, "-a"); /* replace -r <file> so that the layout is restored */ if (restart_filename != NULL) { /* create the new argv */ int num_args; for (num_args = 0; start_argv[num_args] != NULL; num_args++) ; char **new_argv = scalloc((num_args + 3) * sizeof(char *)); /* copy the arguments, but skip the ones we'll replace */ int write_index = 0; bool skip_next = false; for (int i = 0; i < num_args; ++i) { if (skip_next) skip_next = false; else if (!strcmp(start_argv[i], "-r") || !strcmp(start_argv[i], "--restart")) skip_next = true; else new_argv[write_index++] = start_argv[i]; } /* add the arguments we'll replace */ new_argv[write_index++] = "--restart"; new_argv[write_index] = restart_filename; /* swap the argvs */ start_argv = new_argv; } execvp(start_argv[0], start_argv); /* not reached */ }
u32 _main(void *base) { FRESULT fres; int res; u32 vector; (void)base; gecko_init(); gecko_printf("mini %s loading\n", git_version); gecko_printf("Initializing exceptions...\n"); exception_initialize(); gecko_printf("Configuring caches and MMU...\n"); mem_initialize(); gecko_printf("IOSflags: %08x %08x %08x\n", read32(0xffffff00), read32(0xffffff04), read32(0xffffff08)); gecko_printf(" %08x %08x %08x\n", read32(0xffffff0c), read32(0xffffff10), read32(0xffffff14)); irq_initialize(); irq_enable(IRQ_TIMER); // irq_enable(IRQ_GPIO1B); irq_enable(IRQ_GPIO1); irq_enable(IRQ_RESET); gecko_timer_initialize(); gecko_printf("Interrupts initialized\n"); crypto_initialize(); gecko_printf("crypto support initialized\n"); nand_initialize(); gecko_printf("NAND initialized.\n"); boot2_init(); gecko_printf("Initializing IPC...\n"); ipc_initialize(); gecko_printf("Initializing SDHC...\n"); sdhc_init(); gecko_printf("Mounting SD...\n"); fres = f_mount(0, &fatfs); //if (read32(0x0d800190) & 2) //{ // gecko_printf("GameCube compatibility mode detected...\n"); vector = boot2_run(1, 2); // goto shutdown; //} //if(fres != FR_OK) //{ // gecko_printf("Error %d while trying to mount SD\n", fres); // panic2(0, PANIC_MOUNT); //} //gecko_printf("Trying to boot:" PPC_BOOT_FILE "\n"); //res = powerpc_boot_file(PPC_BOOT_FILE); //if(res < 0) { // gecko_printf("Failed to boot PPC: %d\n", res); // gecko_printf("Continuing anyway\n"); //} //gecko_printf("Going into IPC mainloop...\n"); //vector = ipc_process_slow(); //gecko_printf("IPC mainloop done!\n"); gecko_printf("Shutting down IPC...\n"); ipc_shutdown(); shutdown: gecko_printf("Shutting down interrupts...\n"); irq_shutdown(); gecko_printf("Shutting down caches and MMU...\n"); mem_shutdown(); gecko_printf("Vectoring to 0x%08x...\n", vector); return vector; }
/** * Main entry point * * @param argc argument counter * @param argv argument array * * @return EXIT_SUCCESS on success, EXIT_FAILURE otherwise */ int main(int argc, char **argv) { struct sigaction s; /* We only catch INT and QUIT (allthough we could catch TERM as well) */ const int signals[] = { SIGINT, SIGQUIT }; parse_args(argc, argv); s.sa_handler = signal_handler; s.sa_flags = SA_RESTART; /* Block all signals here ... */ if(sigfillset(&s.sa_mask) < 0) { bail_out(EXIT_FAILURE, "Error creating Signal Block Mask"); } /* ... unblock signals and set handler */ for(int i = 0; i < 2; ++i) { if(sigaction(signals[i], &s, NULL) < 0) { bail_out(EXIT_FAILURE, "Failed to sigaction for signale %d", signals[i]); } } /* Init ipc variables */ ipc_init(); #ifdef _BUILD_READIN { /* readin reads stdin line wise (max MAX_BUF_SIZE - 1 chars) */ char buf[MAX_BUF_SIZE]; while(fgets(buf, MAX_BUF_SIZE, stdin) != NULL) { /* ... and writes them to shm */ if(ipc_write(buf) == -1) { /* Write has failed, propably ipc channels have been removed by other process */ bail_out(EXIT_FAILURE, "Error writing to shared memory"); } } if(ipc_write(NULL) == -1) { /* This signals waiting read processed an EOF */ bail_out(EXIT_FAILURE, "Error writing to shared memory"); } shm_detach(); /* Normal shutdown for readin */ } #else { int c = 0; /* chstat keeps on listening */ while(1) { /* wait for read queue to open up, generate statistic */ c = ipc_process(); if(c == -1) { /* Error reading from shmem, probably ipc channels have been removed by other process */ bail_out(EXIT_FAILURE, "Error reading from shared memory"); } else if(c == 0) { /* EOF */ print_stat(); break; } else if(opt_v == 1) { /* If called with -v */ print_stat(); } } ipc_shutdown(); /* Normal shutdown for chstat */ } #endif return 0; }
int main(int argc, char *argv[]) { char path[PATH_MAX + 128], buf[PATH_MAX]; FILE *log; int fd; const char *log_file_dir = NULL; const char *hostname_str = NULL; #ifdef HAVE_SYS_RESOURCE_H setpriority(PRIO_PROCESS, 0, 19); #elif _WIN32 SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS); #endif if (!eina_init()) return 1; efreetd_mp_stat = eina_mempool_add("chained_mempool", "struct stat", NULL, sizeof(struct stat), 10); if (!efreetd_mp_stat) return 1; if (!ecore_init()) goto ecore_error; ecore_app_args_set(argc, (const char **)argv); if (!ecore_file_init()) goto ecore_file_error; if (!ipc_init()) goto ipc_error; if (!cache_init()) goto cache_error; log_file_dir = eina_environment_tmp_get(); if (gethostname(buf, sizeof(buf)) < 0) hostname_str = ""; else hostname_str = buf; snprintf(path, sizeof(path), "%s/efreetd_%s_XXXXXX.log", log_file_dir, hostname_str); fd = eina_file_mkstemp(path, NULL); if (fd < 0) { ERR("Can't create log file '%s'\b", path); goto tmp_error; } log = fdopen(fd, "wb"); if (!log) goto tmp_error; eina_log_print_cb_set(eina_log_print_cb_file, log); efreetd_log_dom = eina_log_domain_register("efreetd", EFREETD_DEFAULT_LOG_COLOR); if (efreetd_log_dom < 0) { EINA_LOG_ERR("Efreet: Could not create a log domain for efreetd."); goto tmp_error; } ecore_main_loop_begin(); eina_mempool_del(efreetd_mp_stat); cache_shutdown(); ipc_shutdown(); ecore_file_shutdown(); ecore_shutdown(); eina_log_domain_unregister(efreetd_log_dom); efreetd_log_dom = -1; eina_shutdown(); return 0; tmp_error: cache_shutdown(); cache_error: ipc_shutdown(); ipc_error: ecore_file_shutdown(); ecore_file_error: ecore_shutdown(); ecore_error: if (efreetd_log_dom >= 0) eina_log_domain_unregister(efreetd_log_dom); efreetd_log_dom = -1; eina_shutdown(); return 1; }