int main(int argc, char *argv[]) { char *conffile = NULL; int request_kill = 0, show_message = 0; if (!read_parameters(argc, argv, &conffile, &request_kill, &show_message)) { print_usage(argv[0]); return 1; } /* read the config file; conffile = NULL means use the default. */ if (!read_config(conffile)) return 1; /* error reading the config file */ setup_defaults(); if (request_kill) { kill_server(); return 0; } if (show_message) { signal_message(); return 0; } setup_signals(); /* Init files and directories. * Start logging last, so that the log is only created if startup succeeds. */ if (!init_workdir() || !init_database() || !check_database() || !begin_logging()) return 1; if (!settings.nodaemon) { if (daemon(0, 0) == -1) { settings.nodaemon = TRUE; log_msg("could not detach from terminal: %s", strerror(errno)); return 1; } if (!create_pidfile()) return 1; } /* give this process and its children their own process group id for kill() */ setpgid(0, 0); report_startup(); runserver(); /* shutdown */ remove_pidfile(); end_logging(); close_database(); remove_unix_socket(); free_config(); return 0; }
int error_processing(stack_t* _this, int errnum) { if (!errnum) return 0; stack_Dump(_this); end_logging(); fprintf(stderr, "%s", ERRDESCRIP[errnum - STARTERRORS]); }
void accel_data_handler(AccelData *data, uint32_t num_samples) { DictionaryIterator *iter; app_message_outbox_begin(&iter); for (int x = 0; x < (int)num_samples; x++) { AccelData *d = malloc(sizeof(AccelData)); *(AccelData *)d = *(data+x); add_item(AccelLogging, d, -1); } end_logging(); }
void exit_client(const char *err) { const char *msg = err ? err : ""; json_t *exit_obj; if (err) log_msg("Client error: %s. Exit.", err); if (outfd != -1) { exit_obj = json_object(); json_object_set_new(exit_obj, "error", err ? json_true() : json_false()); json_object_set_new(exit_obj, "message", json_string(msg)); if (can_send_msg) client_msg("server_error", exit_obj); else json_decref(exit_obj); usleep(100); /* try to make sure the server process handles write() before close(). */ close(infd); close(outfd); infd = outfd = -1; } termination_flag = 3; /* make sure the command loop exits if nh_exit_game jumps there */ if (!sigsegv_flag) nh_exit_game(EXIT_FORCE_SAVE); /* might not return here */ nh_lib_exit(); close_database(); if (user_info.username) free(user_info.username); free_config(); reset_cached_diplaydata(); end_logging(); exit(err != NULL); }
int cpu_end(cpu_t* _this) { ISNOTNULL(_this); end_logging(); return 0; }