Revision: 2782
          http://tmux.svn.sourceforge.net/tmux/?rev=2782&view=rev
Author:   tcunha
Date:     2012-04-24 16:24:03 +0000 (Tue, 24 Apr 2012)
Log Message:
-----------
Sync OpenBSD patchset 1100:

Use an enum for client exit reasons, from George Nachman.

Modified Paths:
--------------
    trunk/client.c

Modified: trunk/client.c
===================================================================
--- trunk/client.c      2012-04-24 16:22:28 UTC (rev 2781)
+++ trunk/client.c      2012-04-24 16:24:03 UTC (rev 2782)
@@ -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 @@
        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 @@
         * 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);
@@ -225,8 +260,8 @@
 
        /* 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)
@@ -325,12 +360,12 @@
        } 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;
@@ -382,7 +417,7 @@
        return;
 
 lost_server:
-       client_exitmsg = "lost server";
+       client_exitreason = CLIENT_EXIT_LOST_SERVER;
        client_exitval = 1;
        event_loopexit(NULL);
 }
@@ -479,9 +514,9 @@
 
                        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:
@@ -490,7 +525,7 @@
                                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)
@@ -503,7 +538,7 @@
                                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:

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
tmux-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to