=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-load-buffer.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- src/usr.bin/tmux/cmd-load-buffer.c 2012/07/11 07:10:15 1.22 +++ src/usr.bin/tmux/cmd-load-buffer.c 2013/03/24 09:54:10 1.23 @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-load-buffer.c,v 1.22 2012/07/11 07:10:15 nicm Exp $ */ +/* $OpenBSD: cmd-load-buffer.c,v 1.23 2013/03/24 09:54:10 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha @@ -30,7 +30,7 @@ * Loads a paste buffer from a file. */ -enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmd_q *); void cmd_load_buffer_callback(struct client *, int, void *); const struct cmd_entry cmd_load_buffer_entry = { @@ -44,10 +44,10 @@ }; enum cmd_retval -cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) +cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; - struct client *c = ctx->cmdclient; + struct client *c = cmdq->client; struct session *s; FILE *f; const char *path, *newpath, *wd; @@ -61,7 +61,7 @@ else { buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause); if (cause != NULL) { - ctx->error(ctx, "buffer %s", cause); + cmdq_error(cmdq, "buffer %s", cause); free(cause); return (CMD_RETURN_ERROR); } @@ -75,16 +75,16 @@ error = server_set_stdin_callback (c, cmd_load_buffer_callback, buffer_ptr, &cause); if (error != 0) { - ctx->error(ctx, "%s: %s", path, cause); + cmdq_error(cmdq, "%s: %s", path, cause); free(cause); return (CMD_RETURN_ERROR); } - return (CMD_RETURN_YIELD); + return (CMD_RETURN_WAIT); } if (c != NULL) wd = c->cwd; - else if ((s = cmd_current_session(ctx, 0)) != NULL) { + else if ((s = cmd_current_session(cmdq, 0)) != NULL) { wd = options_get_string(&s->options, "default-path"); if (*wd == '\0') wd = s->cwd; @@ -96,7 +96,7 @@ path = newpath; } if ((f = fopen(path, "rb")) == NULL) { - ctx->error(ctx, "%s: %s", path, strerror(errno)); + cmdq_error(cmdq, "%s: %s", path, strerror(errno)); return (CMD_RETURN_ERROR); } @@ -105,14 +105,14 @@ while ((ch = getc(f)) != EOF) { /* Do not let the server die due to memory exhaustion. */ if ((new_pdata = realloc(pdata, psize + 2)) == NULL) { - ctx->error(ctx, "realloc error: %s", strerror(errno)); + cmdq_error(cmdq, "realloc error: %s", strerror(errno)); goto error; } pdata = new_pdata; pdata[psize++] = ch; } if (ferror(f)) { - ctx->error(ctx, "%s: read error", path); + cmdq_error(cmdq, "%s: read error", path); goto error; } if (pdata != NULL) @@ -126,7 +126,7 @@ return (CMD_RETURN_NORMAL); } if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) { - ctx->error(ctx, "no buffer %d", buffer); + cmdq_error(cmdq, "no buffer %d", buffer); free(pdata); return (CMD_RETURN_ERROR); } @@ -153,12 +153,13 @@ c->stdin_callback = NULL; c->references--; - c->flags |= CLIENT_EXIT; + if (c->flags & CLIENT_DEAD) + return; psize = EVBUFFER_LENGTH(c->stdin_data); if (psize == 0 || (pdata = malloc(psize + 1)) == NULL) { free(data); - return; + goto out; } memcpy(pdata, EVBUFFER_DATA(c->stdin_data), psize); pdata[psize] = '\0'; @@ -174,4 +175,7 @@ } free(data); + +out: + cmdq_continue(c->cmdq); }