diff options
Diffstat (limited to 'monkey')
-rw-r--r-- | monkey/dispatch.c | 9 | ||||
-rw-r--r-- | monkey/dispatch.h | 2 | ||||
-rw-r--r-- | monkey/main.c | 25 | ||||
-rw-r--r-- | monkey/utils.c | 5 |
4 files changed, 30 insertions, 11 deletions
diff --git a/monkey/dispatch.c b/monkey/dispatch.c index 9d022560c..c70070d4e 100644 --- a/monkey/dispatch.c +++ b/monkey/dispatch.c @@ -35,15 +35,18 @@ typedef struct cmdhandler { static monkey_cmdhandler_t *handler_ring = NULL; -void +nserror monkey_register_handler(const char *cmd, handle_command_fn fn) { monkey_cmdhandler_t *ret = calloc(sizeof(*ret), 1); - if (ret == NULL) - die("Unable to allocate handler"); + if (ret == NULL) { + LOG(("Unable to allocate handler")); + return NSERROR_NOMEM; + } ret->cmd = strdup(cmd); ret->fn = fn; RING_INSERT(handler_ring, ret); + return NSERROR_OK; } void diff --git a/monkey/dispatch.h b/monkey/dispatch.h index fe8f4e2f8..dc6e50a0b 100644 --- a/monkey/dispatch.h +++ b/monkey/dispatch.h @@ -21,7 +21,7 @@ typedef void (*handle_command_fn)(int argc, char **argv); -void monkey_register_handler(const char *cmd, handle_command_fn fn); +nserror monkey_register_handler(const char *cmd, handle_command_fn fn); void monkey_process_command(void); diff --git a/monkey/main.c b/monkey/main.c index 77ef831b1..289017d94 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -42,6 +42,19 @@ char **respaths; /** resource search path vector */ static bool monkey_done = false; +/** + * Cause an abnormal program termination. + * + * \note This never returns and is intended to terminate without any cleanup. + * + * \param error The message to display to the user. + */ +static void die(const char * const error) +{ + fprintf(stderr, "DIE %s\n", error); + exit(EXIT_FAILURE); +} + /* Stolen from gtk/gui.c */ static char ** nsmonkey_init_resource(const char *resource_path) @@ -174,8 +187,16 @@ main(int argc, char **argv) urldb_load_cookies(nsoption_charp(cookie_file)); monkey_prepare_input(); - monkey_register_handler("QUIT", quit_handler); - monkey_register_handler("WINDOW", monkey_window_handle_command); + + ret = monkey_register_handler("QUIT", quit_handler); + if (ret != NSERROR_OK) { + die("quit handler failed to register"); + } + + ret = monkey_register_handler("WINDOW", monkey_window_handle_command); + if (ret != NSERROR_OK) { + die("window handler fialed to register"); + } fprintf(stdout, "GENERIC STARTED\n"); diff --git a/monkey/utils.c b/monkey/utils.c index e1a702f2f..102f8ac01 100644 --- a/monkey/utils.c +++ b/monkey/utils.c @@ -28,8 +28,3 @@ void warn_user(const char *warning, const char *detail) fprintf(stderr, "WARN %s %s\n", warning, detail); } -void die(const char * const error) -{ - fprintf(stderr, "DIE %s\n", error); - exit(EXIT_FAILURE); -} |