diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-04-23 23:18:44 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-04-23 23:18:44 +0000 |
commit | fce0b1915a307571065b64591db5ad466c294443 (patch) | |
tree | cfd7e580a598753fe192e5ae7254c659936842e9 | |
parent | 0022b7f54a0278b74c142c960510e45ae974dc58 (diff) |
Use an enum for client exit reasons, from George Nachman.
-rw-r--r-- | usr.bin/tmux/client.c | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c index fc10a08ca7c..15d652cf76a 100644 --- a/usr.bin/tmux/client.c +++ b/usr.bin/tmux/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.51 2012/03/24 11:23:19 nicm Exp $ */ +/* $OpenBSD: client.c,v 1.52 2012/04/23 23:18:43 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -35,7 +35,16 @@ struct imsgbuf client_ibuf; struct event client_event; -const char *client_exitmsg; +enum { + CLIENT_EXIT_NONE, + CLIENT_EXIT_DETACHED, + CLIENT_EXIT_DETACHED_HUP, + CLIENT_EXIT_LOST_TTY, + CLIENT_EXIT_TERMINATED, + CLIENT_EXIT_LOST_SERVER, + CLIENT_EXIT_EXITED, + CLIENT_EXIT_SERVER_EXITED, +} client_exitreason = CLIENT_EXIT_NONE; int client_exitval; enum msgtype client_exittype; int client_attached; @@ -121,6 +130,31 @@ failed: return (-1); } +/* Get exit string from reason number. */ +const char * +client_exit_message(void) +{ + switch (client_exitreason) { + case CLIENT_EXIT_NONE: + break; + case CLIENT_EXIT_DETACHED: + return ("detached"); + case CLIENT_EXIT_DETACHED_HUP: + return ("detached and SIGHUP"); + case CLIENT_EXIT_LOST_TTY: + return ("lost tty"); + case CLIENT_EXIT_TERMINATED: + return ("terminated"); + case CLIENT_EXIT_LOST_SERVER: + return ("lost server"); + case CLIENT_EXIT_EXITED: + return ("exited"); + case CLIENT_EXIT_SERVER_EXITED: + return ("server exited"); + } + return ("unknown reason"); +} + /* Client main loop. */ int client_main(int argc, char **argv, int flags) @@ -170,7 +204,8 @@ client_main(int argc, char **argv, int flags) * if the socket path matches $TMUX, this is probably the same server. */ if (shell_cmd == NULL && environ_path != NULL && - cmdflags & CMD_CANTNEST && strcmp(socket_path, environ_path) == 0) { + (cmdflags & CMD_CANTNEST) && + strcmp(socket_path, environ_path) == 0) { log_warnx("sessions should be nested with care. " "unset $TMUX to force."); return (1); @@ -223,8 +258,8 @@ client_main(int argc, char **argv, int flags) /* Print the exit message, if any, and exit. */ if (client_attached) { - if (client_exitmsg != NULL && !login_shell) - printf("[%s]\n", client_exitmsg); + if (client_exitreason != CLIENT_EXIT_NONE && !login_shell) + printf("[%s]\n", client_exit_message()); ppid = getppid(); if (client_exittype == MSG_DETACHKILL && ppid > 1) @@ -323,12 +358,12 @@ client_signal(int sig, unused short events, unused void *data) } else { switch (sig) { case SIGHUP: - client_exitmsg = "lost tty"; + client_exitreason = CLIENT_EXIT_LOST_TTY; client_exitval = 1; client_write_server(MSG_EXITING, NULL, 0); break; case SIGTERM: - client_exitmsg = "terminated"; + client_exitreason = CLIENT_EXIT_TERMINATED; client_exitval = 1; client_write_server(MSG_EXITING, NULL, 0); break; @@ -380,7 +415,7 @@ client_callback(unused int fd, short events, void *data) return; lost_server: - client_exitmsg = "lost server"; + client_exitreason = CLIENT_EXIT_LOST_SERVER; client_exitval = 1; event_loopexit(NULL); } @@ -477,9 +512,9 @@ client_dispatch_attached(void) client_exittype = imsg.hdr.type; if (imsg.hdr.type == MSG_DETACHKILL) - client_exitmsg = "detached and SIGHUP"; + client_exitreason = CLIENT_EXIT_DETACHED_HUP; else - client_exitmsg = "detached"; + client_exitreason = CLIENT_EXIT_DETACHED; client_write_server(MSG_EXITING, NULL, 0); break; case MSG_EXIT: @@ -488,7 +523,7 @@ client_dispatch_attached(void) fatalx("bad MSG_EXIT size"); client_write_server(MSG_EXITING, NULL, 0); - client_exitmsg = "exited"; + client_exitreason = CLIENT_EXIT_EXITED; break; case MSG_EXITED: if (datalen != 0) @@ -501,7 +536,7 @@ client_dispatch_attached(void) fatalx("bad MSG_SHUTDOWN size"); client_write_server(MSG_EXITING, NULL, 0); - client_exitmsg = "server exited"; + client_exitreason = CLIENT_EXIT_SERVER_EXITED; client_exitval = 1; break; case MSG_SUSPEND: |