summaryrefslogtreecommitdiffstats
path: root/cmd-run-shell.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2009-11-08 22:56:04 +0000
committerTiago Cunha <tcunha@gmx.com>2009-11-08 22:56:04 +0000
commit53ef4c2babc3d4bf8df16ba6bbd596d0b9a8240b (patch)
tree286476b1c81ce35d95e0cedce4dee1a728bfa5fb /cmd-run-shell.c
parent5116aaa51a6059904a6b8ae75bffa77c95ceb41a (diff)
Sync OpenBSD patchset 493:
Switch jobs over to use a bufferevent.
Diffstat (limited to 'cmd-run-shell.c')
-rw-r--r--cmd-run-shell.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/cmd-run-shell.c b/cmd-run-shell.c
index 15d117e4..986706ea 100644
--- a/cmd-run-shell.c
+++ b/cmd-run-shell.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-run-shell.c,v 1.4 2009-11-02 21:38:26 tcunha Exp $ */
+/* $Id: cmd-run-shell.c,v 1.5 2009-11-08 22:56:04 tcunha Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -77,31 +77,33 @@ cmd_run_shell_callback(struct job *job)
{
struct cmd_run_shell_data *cdata = job->data;
struct cmd_ctx *ctx = &cdata->ctx;
- char *cmd, *msg, *line, *buf;
- size_t off, len, llen;
+ char *cmd, *msg, *line;
+ size_t size;
int retcode;
+ u_int lines;
- buf = BUFFER_OUT(job->out);
- len = BUFFER_USED(job->out);
+ lines = 0;
+ do {
+ if ((line = evbuffer_readline(job->event->input)) != NULL) {
+ ctx->print(ctx, "%s", line);
+ lines++;
+ }
+ } while (line != NULL);
- cmd = cdata->cmd;
+ size = EVBUFFER_LENGTH(job->event->input);
+ if (size != 0) {
+ line = xmalloc(size + 1);
+ memcpy(line, EVBUFFER_DATA(job->event->input), size);
+ line[size] = '\0';
- if (len != 0) {
- line = buf;
- for (off = 0; off < len; off++) {
- if (buf[off] == '\n') {
- llen = buf + off - line;
- if (llen > INT_MAX)
- break;
- ctx->print(ctx, "%.*s", (int) llen, line);
- line = buf + off + 1;
- }
- }
- llen = buf + len - line;
- if (llen > 0 && llen < INT_MAX)
- ctx->print(ctx, "%.*s", (int) llen, line);
+ ctx->print(ctx, "%s", line);
+ lines++;
+
+ xfree(line);
}
+ cmd = cdata->cmd;
+
msg = NULL;
if (WIFEXITED(job->status)) {
if ((retcode = WEXITSTATUS(job->status)) != 0)
@@ -111,7 +113,7 @@ cmd_run_shell_callback(struct job *job)
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
}
if (msg != NULL) {
- if (len != 0)
+ if (lines != 0)
ctx->print(ctx, "%s", msg);
else
ctx->info(ctx, "%s", msg);