static int compat_freebsd_modcmd(modcmd_t cmd, void *arg) { int error; switch (cmd) { case MODULE_CMD_INIT: freebsd_sysctl_init(); error = exec_add(freebsd_execsw, __arraycount(freebsd_execsw)); if (error != 0) freebsd_sysctl_fini(); return error; case MODULE_CMD_FINI: error = exec_remove(freebsd_execsw, __arraycount(freebsd_execsw)); if (error == 0) freebsd_sysctl_fini(); return error; default: return ENOTTY; } }
static int compat_sunos_modcmd(modcmd_t cmd, void *arg) { switch (cmd) { case MODULE_CMD_INIT: return exec_add(&sunos_execsw, 1); case MODULE_CMD_FINI: return exec_remove(&sunos_execsw, 1); default: return ENOTTY; } }
static int exec_command(memcached_st *mcd, int n_cmds, char * const cmds[]) { int retval = 1; if (strcmp(cmds[0], "get") == 0 && n_cmds == 2) retval = exec_get(mcd, cmds[1]); else if (strcmp(cmds[0], "add") == 0 && (n_cmds >= 3 && n_cmds <= 5)) retval = exec_add(mcd, cmds[1], cmds[2], n_cmds > 3 ? atol(cmds[3]) : 0, n_cmds > 4 ? atol(cmds[4]) : 0); else if (strcmp(cmds[0], "set") == 0 && (n_cmds >= 3 && n_cmds <= 5)) retval = exec_set(mcd, cmds[1], cmds[2], n_cmds > 3 ? atol(cmds[3]) : 0, n_cmds > 4 ? atol(cmds[4]) : 0); else if (strcmp(cmds[0], "replace") == 0 && (n_cmds >= 3 && n_cmds <= 5)) retval = exec_replace(mcd, cmds[1], cmds[2], n_cmds > 3 ? atol(cmds[3]) : 0, n_cmds > 4 ? atol(cmds[4]) : 0); else if (strcmp(cmds[0], "append") == 0 && (n_cmds >= 3 && n_cmds <= 5)) retval = exec_append(mcd, cmds[1], cmds[2], n_cmds > 3 ? atol(cmds[3]) : 0, n_cmds > 4 ? atol(cmds[4]) : 0); else if (strcmp(cmds[0], "prepend") == 0 && (n_cmds >= 3 && n_cmds <= 5)) retval = exec_prepend(mcd, cmds[1], cmds[2], n_cmds > 3 ? atol(cmds[3]) : 0, n_cmds > 4 ? atol(cmds[4]) : 0); else if (strcmp(cmds[0], "cas") == 0 && (n_cmds >= 4 && n_cmds <= 6)) retval = exec_cas(mcd, cmds[1], cmds[2], atol(cmds[3]), n_cmds > 4 ? atol(cmds[4]) : 0, n_cmds > 5 ? atol(cmds[5]) : 0); else if (strcmp(cmds[0], "delete") == 0 && (n_cmds >= 2 && n_cmds <= 3)) retval = exec_delete(mcd, cmds[1], n_cmds > 2 ? atol(cmds[2]) : 0); else if (strcmp(cmds[0], "incr") == 0 && n_cmds == 2) retval = exec_incr(mcd, cmds[1]); else if (strcmp(cmds[0], "decr") == 0 && n_cmds == 2) retval = exec_decr(mcd, cmds[1]); else if (strcmp(cmds[0], "flush") == 0 && (n_cmds >= 1 && n_cmds <=2)) retval = exec_flush(mcd, n_cmds > 1 ? atol(cmds[1]) : 0); else if (strcmp(cmds[0], "simple_bench") == 0 && (n_cmds >= 1 && n_cmds <=2)) retval = exec_simple_bench(mcd, n_cmds > 1 ? atof(cmds[1]) : 100.0); return retval; }
static int exec_elf32_modcmd(modcmd_t cmd, void *arg) { switch (cmd) { case MODULE_CMD_INIT: return exec_add(exec_elf32_execsw, __arraycount(exec_elf32_execsw)); case MODULE_CMD_FINI: return exec_remove(exec_elf32_execsw, __arraycount(exec_elf32_execsw)); default: return ENOTTY; } }
static int exec_elf32_modcmd(modcmd_t cmd, void *arg) { #if ARCH_ELFSIZE == 64 /* * If we are on a 64bit system, we don't want the 32bit execsw[] to be * added in the global array, because the exec_elf32 module only works * on 32bit systems. * * However, we need the exec_elf32 module, because it will make the 32bit * functions available for netbsd32 and linux32. * * Therefore, allow this module on 64bit systems, but make it dormant. */ (void)exec_elf32_execsw; /* unused */ switch (cmd) { case MODULE_CMD_INIT: case MODULE_CMD_FINI: return 0; default: return ENOTTY; } #else /* ARCH_ELFSIZE == 64 */ switch (cmd) { case MODULE_CMD_INIT: return exec_add(exec_elf32_execsw, __arraycount(exec_elf32_execsw)); case MODULE_CMD_FINI: return exec_remove(exec_elf32_execsw, __arraycount(exec_elf32_execsw)); default: return ENOTTY; } #endif /* ARCH_ELFSIZE == 64 */ }
static int compat_svr4_modcmd(modcmd_t cmd, void *arg) { int error; switch (cmd) { case MODULE_CMD_INIT: svr4_md_init(); error = exec_add(svr4_execsw, __arraycount(svr4_execsw)); if (error != 0) svr4_md_fini(); return error; case MODULE_CMD_FINI: error = exec_remove(svr4_execsw, __arraycount(svr4_execsw)); if (error == 0) svr4_md_fini(); return error; default: return ENOTTY; } }
int exec_command_run (struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol, int start_arg) { char str_buffer[512]; struct t_exec_cmd *new_exec_cmd; struct t_exec_cmd_options cmd_options; struct t_hashtable *process_options; struct t_infolist *ptr_infolist; struct t_gui_buffer *ptr_new_buffer; /* parse command options */ cmd_options.command_index = -1; cmd_options.use_shell = 0; cmd_options.detached = 0; cmd_options.pipe_stdin = 0; cmd_options.timeout = 0; cmd_options.ptr_buffer_name = NULL; cmd_options.ptr_buffer = buffer; cmd_options.output_to_buffer = 0; cmd_options.new_buffer = 0; cmd_options.new_buffer_clear = 0; cmd_options.switch_to_buffer = 1; cmd_options.line_numbers = -1; cmd_options.flush = 1; cmd_options.color = EXEC_COLOR_AUTO; cmd_options.display_rc = 1; cmd_options.ptr_command_name = NULL; cmd_options.pipe_command = NULL; cmd_options.hsignal = NULL; /* parse default options */ if (!exec_command_parse_options (&cmd_options, exec_config_cmd_num_options, exec_config_cmd_options, 0, 0)) { weechat_printf (NULL, _("%s%s: invalid options in option " "exec.command.default_options"), weechat_prefix ("error"), EXEC_PLUGIN_NAME); return WEECHAT_RC_ERROR; } if (!exec_command_parse_options (&cmd_options, argc, argv, start_arg, 1)) return WEECHAT_RC_ERROR; /* options "-bg" and "-o"/"-n" are incompatible */ if (cmd_options.detached && (cmd_options.output_to_buffer || cmd_options.new_buffer)) return WEECHAT_RC_ERROR; /* options "-pipe" and "-bg"/"-o"/"-n" are incompatible */ if (cmd_options.pipe_command && (cmd_options.detached || cmd_options.output_to_buffer || cmd_options.new_buffer)) return WEECHAT_RC_ERROR; /* command not found? */ if (cmd_options.command_index < 0) return WEECHAT_RC_ERROR; new_exec_cmd = exec_add (); if (!new_exec_cmd) return WEECHAT_RC_ERROR; /* create hashtable for weechat_hook_process_hashtable() */ process_options = weechat_hashtable_new (32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, NULL, NULL); if (!process_options) { exec_free (new_exec_cmd); return WEECHAT_RC_ERROR; } /* automatically disable shell if we are downloading an URL */ if (strncmp (argv_eol[cmd_options.command_index], "url:", 4) == 0) cmd_options.use_shell = 0; if (cmd_options.use_shell) { /* command will be: sh -c "command arguments..." */ weechat_hashtable_set (process_options, "arg1", "-c"); weechat_hashtable_set (process_options, "arg2", argv_eol[cmd_options.command_index]); } if (cmd_options.pipe_stdin) weechat_hashtable_set (process_options, "stdin", "1"); if (cmd_options.detached) weechat_hashtable_set (process_options, "detached", "1"); if (cmd_options.flush) weechat_hashtable_set (process_options, "buffer_flush", "1"); /* set variables in new command (before running the command) */ new_exec_cmd->name = (cmd_options.ptr_command_name) ? strdup (cmd_options.ptr_command_name) : NULL; new_exec_cmd->command = strdup (argv_eol[cmd_options.command_index]); new_exec_cmd->detached = cmd_options.detached; if (!cmd_options.detached && !cmd_options.pipe_command && !cmd_options.hsignal) { if (cmd_options.ptr_buffer_name && !cmd_options.ptr_buffer) { /* output in a new buffer using given name */ new_exec_cmd->output_to_buffer = 0; snprintf (str_buffer, sizeof (str_buffer), "exec.%s", cmd_options.ptr_buffer_name); ptr_new_buffer = exec_buffer_new (str_buffer, (cmd_options.new_buffer == 2), cmd_options.new_buffer_clear, cmd_options.switch_to_buffer); if (ptr_new_buffer) { new_exec_cmd->buffer_full_name = strdup (weechat_buffer_get_string (ptr_new_buffer, "full_name")); } } else if (cmd_options.new_buffer) { /* output in a new buffer using automatic name */ if (new_exec_cmd->name) { snprintf (str_buffer, sizeof (str_buffer), "exec.%s", new_exec_cmd->name); } else { snprintf (str_buffer, sizeof (str_buffer), "exec.%d", new_exec_cmd->number); } ptr_new_buffer = exec_buffer_new (str_buffer, (cmd_options.new_buffer == 2), cmd_options.new_buffer_clear, cmd_options.switch_to_buffer); if (ptr_new_buffer) { new_exec_cmd->buffer_full_name = strdup (weechat_buffer_get_string (ptr_new_buffer, "full_name")); } } else if (cmd_options.ptr_buffer) { new_exec_cmd->buffer_full_name = strdup (weechat_buffer_get_string (cmd_options.ptr_buffer, "full_name")); if (cmd_options.switch_to_buffer) weechat_buffer_set (cmd_options.ptr_buffer, "display", "1"); } if (cmd_options.ptr_buffer && (strcmp (weechat_buffer_get_string (cmd_options.ptr_buffer, "plugin"), EXEC_PLUGIN_NAME) == 0)) { cmd_options.output_to_buffer = 0; cmd_options.new_buffer = 1; } } new_exec_cmd->output_to_buffer = cmd_options.output_to_buffer; new_exec_cmd->line_numbers = (cmd_options.line_numbers < 0) ? cmd_options.new_buffer : cmd_options.line_numbers; new_exec_cmd->color = cmd_options.color; new_exec_cmd->display_rc = cmd_options.display_rc; new_exec_cmd->pipe_command = cmd_options.pipe_command; new_exec_cmd->hsignal = cmd_options.hsignal; /* execute the command */ if (weechat_exec_plugin->debug >= 1) { weechat_printf (NULL, "%s: executing command: \"%s%s%s\"", EXEC_PLUGIN_NAME, (cmd_options.use_shell) ? "" : "sh -c '", argv_eol[cmd_options.command_index], (cmd_options.use_shell) ? "" : "'"); } new_exec_cmd->hook = weechat_hook_process_hashtable ( (cmd_options.use_shell) ? "sh" : argv_eol[cmd_options.command_index], process_options, cmd_options.timeout * 1000, &exec_process_cb, new_exec_cmd); if (new_exec_cmd->hook) { /* get PID of command */ ptr_infolist = weechat_infolist_get ("hook", new_exec_cmd->hook, NULL); if (ptr_infolist) { if (weechat_infolist_next (ptr_infolist)) { new_exec_cmd->pid = weechat_infolist_integer (ptr_infolist, "child_pid"); } weechat_infolist_free (ptr_infolist); } } else { exec_free (new_exec_cmd); weechat_printf (NULL, _("%s%s: failed to run command \"%s\""), weechat_prefix ("error"), EXEC_PLUGIN_NAME, argv_eol[cmd_options.command_index]); } weechat_hashtable_free (process_options); return WEECHAT_RC_OK; }
int execute_work_queue (void) { union op *op; int errors; Bool update_map = False; int dosync; if (verbose) { printf ("!\n"); printf ("! executing work queue\n"); printf ("!\n"); } errors = 0; dosync = 0; for (op = work_queue.head; op; op = op->generic.next) { if (verbose) print_opcode (op); /* check to see if we have to update the keyboard mapping */ if (dosync && (dosync < 0 || op->generic.type != doKeycode || !op->keycode.target_keycode)) { XSync (dpy, 0); while (XEventsQueued (dpy, QueuedAlready) > 0) { XEvent event; XNextEvent (dpy, &event); if (event.type == MappingNotify) { /* read all MappingNotify events */ while (XCheckTypedEvent (dpy, MappingNotify, &event)) ; XRefreshKeyboardMapping (&event.xmapping); } else { fprintf (stderr, "%s: unknown event %ld\n", ProgramName, (long) event.type); } } } dosync = 0; switch (op->generic.type) { case doKeycode: if (exec_keycode (&op->keycode) < 0) errors++; if (op->keycode.target_keycode) dosync = 1; else dosync = -1; break; case doAddModifier: if (exec_add (&op->addmodifier) < 0) errors++; else update_map = True; break; case doRemoveModifier: if (exec_remove (&op->removemodifier) < 0) errors++; else update_map = True; break; case doClearModifier: if (exec_clear (&op->clearmodifier) < 0) errors++; else update_map = True; break; case doPointer: if (exec_pointer (&op->pointer) < 0) errors++; break; default: fprintf (stderr, "%s: unknown opcode %d\n", ProgramName, op->generic.type); break; } } if (update_map) { if (UpdateModifierMapping (map) < 0) errors++; } return (errors > 0 ? -1 : 0); }