summaryrefslogtreecommitdiffstats
path: root/control.c
diff options
context:
space:
mode:
authornicm <nicm>2019-12-12 11:39:56 +0000
committernicm <nicm>2019-12-12 11:39:56 +0000
commitc284ebe0ade7cc85ad6c3fe5ce7ed5108119222d (patch)
tree52fa29b04da1e5468bdce23cce61bf0370923c2e /control.c
parent64fb7e472a9e627ee486707ab9d30b607d76478a (diff)
Rewrite the code for reading and writing files. Now, if the client is
not attached, the server process asks it to open the file, similar to how works for stdin, stdout, stderr. This makes special files like /dev/fd/X work (used by some shells). stdin, stdout and stderr and control mode are now just special cases of the same mechanism. This will also make it easier to use for other commands that read files such as source-file.
Diffstat (limited to 'control.c')
-rw-r--r--control.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/control.c b/control.c
index c4cf5338..b8a16e73 100644
--- a/control.c
+++ b/control.c
@@ -30,23 +30,12 @@
void
control_write(struct client *c, const char *fmt, ...)
{
- va_list ap;
+ va_list ap;
va_start(ap, fmt);
- evbuffer_add_vprintf(c->stdout_data, fmt, ap);
+ file_vprint(c, fmt, ap);
+ file_print(c, "\n");
va_end(ap);
-
- evbuffer_add(c->stdout_data, "\n", 1);
- server_client_push_stdout(c);
-}
-
-/* Write a buffer, adding a terminal newline. Empties buffer. */
-void
-control_write_buffer(struct client *c, struct evbuffer *buffer)
-{
- evbuffer_add_buffer(c->stdout_data, buffer);
- evbuffer_add(c->stdout_data, "\n", 1);
- server_client_push_stdout(c);
}
/* Control error callback. */
@@ -65,20 +54,22 @@ control_error(struct cmdq_item *item, void *data)
}
/* Control input callback. Read lines and fire commands. */
-void
-control_callback(struct client *c, int closed, __unused void *data)
+static void
+control_callback(__unused struct client *c, __unused const char *path,
+ int error, int closed, struct evbuffer *buffer, __unused void *data)
{
char *line;
struct cmdq_item *item;
struct cmd_parse_result *pr;
- if (closed)
+ if (closed || error != 0)
c->flags |= CLIENT_EXIT;
for (;;) {
- line = evbuffer_readln(c->stdin_data, NULL, EVBUFFER_EOL_LF);
+ line = evbuffer_readln(buffer, NULL, EVBUFFER_EOL_LF);
if (line == NULL)
break;
+ log_debug("%s: %s", __func__, line);
if (*line == '\0') { /* empty line exit */
free(line);
c->flags |= CLIENT_EXIT;
@@ -104,3 +95,12 @@ control_callback(struct client *c, int closed, __unused void *data)
free(line);
}
}
+
+void
+control_start(struct client *c)
+{
+ file_read(c, "-", control_callback, c);
+
+ if (c->flags & CLIENT_CONTROLCONTROL)
+ file_print(c, "\033P1000p");
+}