aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeebs <seebs@seebs.net>2016-11-23 16:39:41 -0600
committerSeebs <seebs@seebs.net>2016-11-23 16:39:41 -0600
commitd6eb2df3fe63b765f35d62332add4d0e4e9c6a39 (patch)
tree50ac70acdf1e3eaf352f55cb7075238ad72488b0
parent11b74aee8d35fd224d03804a07ce82c332b6630c (diff)
downloadpseudo-d6eb2df3fe63b765f35d62332add4d0e4e9c6a39.tar.gz
pseudo-d6eb2df3fe63b765f35d62332add4d0e4e9c6a39.tar.bz2
pseudo-d6eb2df3fe63b765f35d62332add4d0e4e9c6a39.zip
Make pseudo -S cmd wait for server
If you're running pseudo in docker, a script that creates a pseudo daemon can exit, causing docker to kill pseudo before it's done writing the database. Since the client sending the shutdown request doesn't have its socket closed explicitly by the server, we can just read from the socket in the client to create a delay until the actual exit, which can take a while if there's an in-memory DB. Signed-off-by: Seebs <seebs@seebs.net>
-rw-r--r--ChangeLog.txt3
-rw-r--r--pseudo.c4
-rw-r--r--pseudo_client.c17
-rw-r--r--pseudo_client.h2
4 files changed, 17 insertions, 9 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt
index 411229f..e05572c 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -1,3 +1,6 @@
+2016-11-23:
+ * (seebs) actually wait on server shutdown for pseudo -S [cmd]
+
2016-11-04:
* (seebs) clarify usage message on missing --prefix
diff --git a/pseudo.c b/pseudo.c
index db1c400..a3bc7fa 100644
--- a/pseudo.c
+++ b/pseudo.c
@@ -334,7 +334,7 @@ main(int argc, char *argv[]) {
/* If you didn't specify a command, opt_S shuts down here. */
if (opt_S && argc <= optind) {
- return pseudo_client_shutdown();
+ return pseudo_client_shutdown(0);
}
if (opt_d && opt_f) {
@@ -409,7 +409,7 @@ main(int argc, char *argv[]) {
* the server.
*/
if (opt_S) {
- pseudo_client_shutdown();
+ pseudo_client_shutdown(1);
}
if (WIFEXITED(rc)) {
return WEXITSTATUS(rc);
diff --git a/pseudo_client.c b/pseudo_client.c
index b1a00fa..2a4c106 100644
--- a/pseudo_client.c
+++ b/pseudo_client.c
@@ -1357,7 +1357,7 @@ pseudo_client_request(pseudo_msg_t *msg, size_t len, const char *path) {
}
int
-pseudo_client_shutdown(void) {
+pseudo_client_shutdown(int wait_on_socket) {
pseudo_msg_t msg;
pseudo_msg_t *ack;
char *pseudo_path;
@@ -1428,12 +1428,17 @@ pseudo_client_shutdown(void) {
pseudo_diag("server did not respond to shutdown query.\n");
return 1;
}
- if (ack->type == PSEUDO_MSG_ACK) {
- return 0;
+ if (ack->type != PSEUDO_MSG_ACK) {
+ pseudo_diag("Server refused shutdown. Remaining client fds: %d\n", ack->fd);
+ pseudo_diag("Client pids: %s\n", ack->path);
+ pseudo_diag("Server will shut down after all clients exit.\n");
+ }
+ if (wait_on_socket) {
+ /* try to receive a message the server won't send;
+ * this should abort/error-out when the server actually
+ * shuts down. */
+ ack = pseudo_msg_receive(connect_fd);
}
- pseudo_diag("Server refused shutdown. Remaining client fds: %d\n", ack->fd);
- pseudo_diag("Client pids: %s\n", ack->path);
- pseudo_diag("Server will shut down after all clients exit.\n");
return 0;
}
diff --git a/pseudo_client.h b/pseudo_client.h
index 68e5160..28b23dc 100644
--- a/pseudo_client.h
+++ b/pseudo_client.h
@@ -34,7 +34,7 @@ extern void pseudo_magic(void);
extern void pseudo_client_touchuid(void);
extern void pseudo_client_touchgid(void);
extern char *pseudo_client_fdpath(int fd);
-extern int pseudo_client_shutdown(void);
+extern int pseudo_client_shutdown(int);
extern int pseudo_fd(int fd, int how);
#define MOVE_FD 0
#define COPY_FD 1