diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2013-03-25 11:43:33 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2013-03-25 11:43:33 +0000 |
commit | 599dd2a56009300df999c54c73aa9e83268809e8 (patch) | |
tree | d651a1c49f228d4b756a25695d0192c19b2750cd /window-copy.c | |
parent | d28a39d01de47786a703e630a4f8930485cba7a1 (diff) |
Create a new context when copying instead of using the input
context. The input context may not exist yet. Fixes crash when copying
from config file errors.
Diffstat (limited to 'window-copy.c')
-rw-r--r-- | window-copy.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/window-copy.c b/window-copy.c index 61fa382a..f5f78cf2 100644 --- a/window-copy.c +++ b/window-copy.c @@ -54,7 +54,8 @@ void window_copy_start_selection(struct window_pane *); int window_copy_update_selection(struct window_pane *); void *window_copy_get_selection(struct window_pane *, size_t *); void window_copy_copy_buffer(struct window_pane *, int, void *, size_t); -void window_copy_copy_pipe(struct window_pane *, int, const char *); +void window_copy_copy_pipe( + struct window_pane *, struct session *, int, const char *); void window_copy_copy_selection(struct window_pane *, int); void window_copy_clear_selection(struct window_pane *); void window_copy_copy_line( @@ -539,7 +540,7 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key) break; case MODEKEYCOPY_COPYPIPE: if (sess != NULL) { - window_copy_copy_pipe(wp, data->numprefix, arg); + window_copy_copy_pipe(wp, sess, data->numprefix, arg); window_pane_reset_mode(wp); return; } @@ -1384,10 +1385,14 @@ window_copy_get_selection(struct window_pane *wp, size_t *len) void window_copy_copy_buffer(struct window_pane *wp, int idx, void *buf, size_t len) { - u_int limit; + u_int limit; + struct screen_write_ctx ctx; - if (options_get_number(&global_options, "set-clipboard")) - screen_write_setselection(&wp->ictx.ctx, buf, len); + if (options_get_number(&global_options, "set-clipboard")) { + screen_write_start(&ctx, wp, NULL); + screen_write_setselection(&ctx, buf, len); + screen_write_stop(&ctx); + } if (idx == -1) { limit = options_get_number(&global_options, "buffer-limit"); @@ -1397,21 +1402,20 @@ window_copy_copy_buffer(struct window_pane *wp, int idx, void *buf, size_t len) } void -window_copy_copy_pipe(struct window_pane *wp, int idx, const char *arg) +window_copy_copy_pipe( + struct window_pane *wp, struct session *sess, int idx, const char *arg) { - void* buf; - size_t len; - FILE* f; + void *buf; + size_t len; + struct job *job; + buf = window_copy_get_selection(wp, &len); if (buf == NULL) return; - f = popen(arg, "w"); - if (f != NULL) { - fwrite(buf, 1, len, f); - pclose(f); - } + job = job_run(arg, sess, NULL, NULL, NULL); + bufferevent_write(job->event, buf, len); window_copy_copy_buffer(wp, idx, buf, len); } |