summaryrefslogtreecommitdiffstats
path: root/client.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2019-12-13 08:01:24 +0000
committerThomas Adam <thomas@xteddy.org>2019-12-13 08:01:24 +0000
commite24e9867ece878572c7cca0a4ff7455b5facd2d6 (patch)
treef2e0d423aeedd2fffa424018349d5470cfa358a2 /client.c
parent58908b045b48b224063ce04d3db63741d32d0898 (diff)
parent6ce943f4d979423290662f691e3d8a3cded79a42 (diff)
Merge branch 'obsd-master'
Diffstat (limited to 'client.c')
-rw-r--r--client.c54
1 files changed, 30 insertions, 24 deletions
diff --git a/client.c b/client.c
index 5bbd4a42..3cf4acee 100644
--- a/client.c
+++ b/client.c
@@ -45,6 +45,7 @@ static enum {
CLIENT_EXIT_EXITED,
CLIENT_EXIT_SERVER_EXITED,
} client_exitreason = CLIENT_EXIT_NONE;
+static int client_exitflag;
static int client_exitval;
static enum msgtype client_exittype;
static const char *client_exitsession;
@@ -209,6 +210,27 @@ client_exit_message(void)
return ("unknown reason");
}
+/* Exit if all streams flushed. */
+static void
+client_exit(void)
+{
+ struct client_file *cf;
+ size_t left;
+ int waiting = 0;
+
+ RB_FOREACH (cf, client_files, &client_files) {
+ if (cf->event == NULL)
+ continue;
+ left = EVBUFFER_LENGTH(cf->event->output);
+ if (left != 0) {
+ waiting++;
+ log_debug("file %u %zu bytes left", cf->stream, left);
+ }
+ }
+ if (waiting == 0)
+ proc_exit(client_proc);
+}
+
/* Client main loop. */
int
client_main(struct event_base *base, int argc, char **argv, int flags)
@@ -439,6 +461,9 @@ client_write_error_callback(__unused struct bufferevent *bev,
close(cf->fd);
cf->fd = -1;
+
+ if (client_exitflag)
+ client_exit();
}
/* File write callback. */
@@ -453,6 +478,9 @@ client_write_callback(__unused struct bufferevent *bev, void *arg)
RB_REMOVE(client_files, &client_files, cf);
file_free(cf);
}
+
+ if (client_exitflag)
+ client_exit();
}
/* Open write file. */
@@ -726,29 +754,6 @@ client_signal(int sig)
}
}
-/* Exit if all streams flushed. */
-static void
-client_exit(__unused int fd, __unused short events, __unused void *arg)
-{
- struct client_file *cf;
- size_t left;
- int waiting = 0;
-
- RB_FOREACH (cf, client_files, &client_files) {
- if (cf->event == NULL)
- continue;
- left = EVBUFFER_LENGTH(cf->event->output);
- if (left != 0) {
- waiting++;
- log_debug("file %u %zu bytes left", cf->stream, left);
- }
- }
- if (waiting == 0)
- proc_exit(client_proc);
- else
- event_once(-1, EV_TIMEOUT, client_exit, NULL, NULL);
-}
-
/* Callback for client read events. */
static void
client_dispatch(struct imsg *imsg, __unused void *arg)
@@ -801,7 +806,8 @@ client_dispatch_wait(struct imsg *imsg)
memcpy(&retval, data, sizeof retval);
client_exitval = retval;
}
- event_once(-1, EV_TIMEOUT, client_exit, NULL, NULL);
+ client_exitflag = 1;
+ client_exit();
break;
case MSG_READY:
if (datalen != 0)