diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-07-30 16:53:51 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-07-30 16:53:51 +0000 |
| commit | 7767041c2cb4f7739881cb8433a8ce7f9ef6d08c (patch) | |
| tree | 13f811fc65504a974491068e5a60c48247cedccd /input.c | |
| parent | changelog: use <section>.<option> syntax (diff) | |
config: tokenize key bindings' pipe command when loading the configuration
This allows us to detect syntax errors early on, and is also more
efficient since we don't have to re-tokenize the command line every
time the binding is executed.
Diffstat (limited to 'input.c')
| -rw-r--r-- | input.c | 24 |
1 files changed, 6 insertions, 18 deletions
@@ -76,7 +76,7 @@ pipe_closed: static void execute_binding(struct seat *seat, struct terminal *term, - enum bind_action_normal action, const char *pipe_cmd, + enum bind_action_normal action, char *const *pipe_argv, uint32_t serial) { switch (action) { @@ -146,7 +146,7 @@ execute_binding(struct seat *seat, struct terminal *term, case BIND_ACTION_PIPE_SCROLLBACK: case BIND_ACTION_PIPE_VIEW: { - if (pipe_cmd == NULL) + if (pipe_argv == NULL) break; struct pipe_context *ctx = NULL; @@ -158,12 +158,6 @@ execute_binding(struct seat *seat, struct terminal *term, char *text = NULL; size_t len = 0; - char *cmd = strdup(pipe_cmd); - char **argv = NULL; - - if (!tokenize_cmdline(cmd, &argv)) - goto pipe_err; - if (pipe(pipe_fd) < 0) { LOG_ERRNO("failed to create pipe"); goto pipe_err; @@ -207,13 +201,9 @@ execute_binding(struct seat *seat, struct terminal *term, } } - if (!spawn(term->reaper, NULL, argv, pipe_fd[0], stdout_fd, stderr_fd)) + if (!spawn(term->reaper, NULL, pipe_argv, pipe_fd[0], stdout_fd, stderr_fd)) goto pipe_err; - /* Not needed anymore */ - free(argv); argv = NULL; - free(cmd); cmd = NULL; - /* Close read end */ close(pipe_fd[0]); @@ -239,8 +229,6 @@ execute_binding(struct seat *seat, struct terminal *term, if (pipe_fd[1] >= 0) close(pipe_fd[1]); free(text); - free(argv); - free(cmd); free(ctx); break; } @@ -426,7 +414,7 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, ((struct key_binding_normal){ .bind = it2->item, .action = it->item.action, - .pipe_cmd = it->item.pipe_cmd})); + .pipe_argv = it->item.pipe.argv})); } tll_free(bindings); } @@ -743,14 +731,14 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, /* Match symbol */ if (it->item.bind.sym == sym) { - execute_binding(seat, term, it->item.action, it->item.pipe_cmd, serial); + execute_binding(seat, term, it->item.action, it->item.pipe_argv, serial); goto maybe_repeat; } /* Match raw key code */ tll_foreach(it->item.bind.key_codes, code) { if (code->item == key) { - execute_binding(seat, term, it->item.action, it->item.pipe_cmd, serial); + execute_binding(seat, term, it->item.action, it->item.pipe_argv, serial); goto maybe_repeat; } } |
