Update of /cvsroot/tmux/tmux
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv22104

Modified Files:
        client.c cmd-load-buffer.c cmd-save-buffer.c server-client.c 
        tmux.c tmux.h 
Log Message:
Sync OpenBSD patchset 731:

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


Index: server-client.c
===================================================================
RCS file: /cvsroot/tmux/tmux/server-client.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- server-client.c     6 Jun 2010 00:30:34 -0000       1.33
+++ server-client.c     2 Jul 2010 02:52:13 -0000       1.34
@@ -68,6 +68,10 @@
 
        ARRAY_INIT(&c->prompt_hdata);
 
+       c->stdin_file = NULL;
+       c->stdout_file = NULL;
+       c->stderr_file = NULL;
+
        c->tty.fd = -1;
        c->title = NULL;
 
@@ -117,6 +121,13 @@
        if (c->flags & CLIENT_TERMINAL)
                tty_free(&c->tty);
 
+       if (c->stdin_file != NULL)
+               fclose(c->stdin_file);
+       if (c->stdout_file != NULL)
+               fclose(c->stdout_file);
+       if (c->stderr_file != NULL)
+               fclose(c->stderr_file);
+
        screen_free(&c->status);
        job_tree_free(&c->status_jobs);
 
@@ -554,8 +565,31 @@
                                fatalx("MSG_IDENTIFY missing fd");
                        memcpy(&identifydata, imsg.data, sizeof identifydata);
 
+                       c->stdin_file = fdopen(imsg.fd, "r");
+                       if (c->stdin_file == NULL)
+                               fatal("fdopen(stdin) failed");
                        server_client_msg_identify(c, &identifydata, imsg.fd);
                        break;
+               case MSG_STDOUT:
+                       if (datalen != 0)
+                               fatalx("bad MSG_STDOUT size");
+                       if (imsg.fd == -1)
+                               fatalx("MSG_STDOUT missing fd");
+
+                       c->stdout_file = fdopen(imsg.fd, "w");
+                       if (c->stdout_file == NULL)
+                               fatal("fdopen(stdout) failed");
+                       break;
+               case MSG_STDERR:
+                       if (datalen != 0)
+                               fatalx("bad MSG_STDERR size");
+                       if (imsg.fd == -1)
+                               fatalx("MSG_STDERR missing fd");
+
+                       c->stderr_file = fdopen(imsg.fd, "w");
+                       if (c->stderr_file == NULL)
+                               fatal("fdopen(stderr) failed");
+                       break;
                case MSG_RESIZE:
                        if (datalen != 0)
                                fatalx("bad MSG_RESIZE size");
@@ -621,45 +655,45 @@
 void printflike2
 server_client_msg_error(struct cmd_ctx *ctx, const char *fmt, ...)
 {
-       struct msg_print_data   data;
-       va_list                 ap;
+       va_list ap;
 
        va_start(ap, fmt);
-       xvsnprintf(data.msg, sizeof data.msg, fmt, ap);
+       vfprintf(ctx->cmdclient->stderr_file, fmt, ap);
        va_end(ap);
 
-       server_write_client(ctx->cmdclient, MSG_ERROR, &data, sizeof data);
+       fputc('\n', ctx->cmdclient->stderr_file);
+       fflush(ctx->cmdclient->stderr_file);
 }
 
 /* Callback to send print message to client. */
 void printflike2
 server_client_msg_print(struct cmd_ctx *ctx, const char *fmt, ...)
 {
-       struct msg_print_data   data;
-       va_list                 ap;
+       va_list ap;
 
        va_start(ap, fmt);
-       xvsnprintf(data.msg, sizeof data.msg, fmt, ap);
+       vfprintf(ctx->cmdclient->stdout_file, fmt, ap);
        va_end(ap);
 
-       server_write_client(ctx->cmdclient, MSG_PRINT, &data, sizeof data);
+       fputc('\n', ctx->cmdclient->stdout_file);
+       fflush(ctx->cmdclient->stdout_file);
 }
 
 /* Callback to send print message to client, if not quiet. */
 void printflike2
 server_client_msg_info(struct cmd_ctx *ctx, const char *fmt, ...)
 {
-       struct msg_print_data   data;
-       va_list                 ap;
+       va_list ap;
 
        if (options_get_number(&global_options, "quiet"))
                return;
 
        va_start(ap, fmt);
-       xvsnprintf(data.msg, sizeof data.msg, fmt, ap);
+       vfprintf(ctx->cmdclient->stdout_file, fmt, ap);
        va_end(ap);
 
-       server_write_client(ctx->cmdclient, MSG_PRINT, &data, sizeof data);
+       fputc('\n', ctx->cmdclient->stderr_file);
+       fflush(ctx->cmdclient->stdout_file);
 }
 
 /* Handle command message. */
@@ -716,13 +750,19 @@
 server_client_msg_identify(
     struct client *c, struct msg_identify_data *data, int fd)
 {
+       int     tty_fd;
+
        c->cwd = NULL;
        data->cwd[(sizeof data->cwd) - 1] = '\0';
        if (*data->cwd != '\0')
                c->cwd = xstrdup(data->cwd);
 
+       if (!isatty(fd))
+           return;
+       if ((tty_fd = dup(fd)) == -1)
+               fatal("dup failed");
        data->term[(sizeof data->term) - 1] = '\0';
-       tty_init(&c->tty, fd, data->term);
+       tty_init(&c->tty, tty_fd, data->term);
        if (data->flags & IDENTIFY_UTF8)
                c->tty.flags |= TTY_UTF8;
        if (data->flags & IDENTIFY_256COLOURS)

Index: cmd-save-buffer.c
===================================================================
RCS file: /cvsroot/tmux/tmux/cmd-save-buffer.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- cmd-save-buffer.c   14 Nov 2009 17:56:39 -0000      1.10
+++ cmd-save-buffer.c   2 Jul 2010 02:52:13 -0000       1.11
@@ -48,7 +48,7 @@
        struct session          *s;
        struct paste_buffer     *pb;
        mode_t                  mask;
-       FILE                    *f;
+       FILE                    *f, *close_f;
 
        if ((s = cmd_find_session(ctx, data->target)) == NULL)
                return (-1);
@@ -65,15 +65,25 @@
                }
        }
 
-       mask = umask(S_IRWXG | S_IRWXO);
-       if (cmd_check_flag(data->chflags, 'a'))
-               f = fopen(data->arg, "ab");
-       else
-               f = fopen(data->arg, "wb");
-       umask(mask);
-       if (f == NULL) {
-               ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
-               return (-1);
+       if (strcmp(data->arg, "-") == 0) {
+               if (ctx->cmdclient == NULL) {
+                       ctx->error(ctx, "%s: can't write to stdout", data->arg);
+                       return (-1);
+               }
+               f = ctx->cmdclient->stdout_file;
+               close_f = NULL;
+       } else {
+               mask = umask(S_IRWXG | S_IRWXO);
+               if (cmd_check_flag(data->chflags, 'a'))
+                       f = fopen(data->arg, "ab");
+               else
+                       f = fopen(data->arg, "wb");
+               umask(mask);
+               if (f == NULL) {
+                       ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
+                       return (-1);
+               }
+               close_f = f;
        }
 
        if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
@@ -82,7 +92,8 @@
                return (-1);
        }
 
-       fclose(f);
+       if (close_f != NULL)
+               fclose(close_f);
 
        return (0);
 }

Index: cmd-load-buffer.c
===================================================================
RCS file: /cvsroot/tmux/tmux/cmd-load-buffer.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- cmd-load-buffer.c   26 Feb 2010 13:30:07 -0000      1.15
+++ cmd-load-buffer.c   2 Jul 2010 02:52:13 -0000       1.16
@@ -16,10 +16,13 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include <sys/types.h>
+
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "tmux.h"
 
@@ -45,7 +48,7 @@
 {
        struct cmd_buffer_data  *data = self->data;
        struct session          *s;
-       FILE                    *f;
+       FILE                    *f, *close_f;
        char                    *pdata, *new_pdata;
        size_t                   psize;
        u_int                    limit;
@@ -54,9 +57,23 @@
        if ((s = cmd_find_session(ctx, data->target)) == NULL)
                return (-1);
 
-       if ((f = fopen(data->arg, "rb")) == NULL) {
-               ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
-               return (-1);
+       if (strcmp(data->arg, "-") == 0 ) {
+               if (ctx->cmdclient == NULL) {
+                       ctx->error(ctx, "%s: can't read from stdin", data->arg);
+                       return (-1);
+               }
+               f = ctx->cmdclient->stdin_file;
+               if (isatty(fileno(ctx->cmdclient->stdin_file))) {
+                       ctx->error(ctx, "%s: stdin is a tty", data->arg);
+                       return (-1);
+               }
+               close_f = NULL;
+       } else {
+               if ((f = fopen(data->arg, "rb")) == NULL) {
+                       ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
+                       return (-1);
+               }
+               close_f = f;
        }
 
        pdata = NULL;
@@ -77,7 +94,8 @@
        if (pdata != NULL)
                pdata[psize] = '\0';
 
-       fclose(f);
+       if (close_f != NULL)
+               fclose(close_f);
 
        limit = options_get_number(&s->options, "buffer-limit");
        if (data->buffer == -1) {
@@ -94,6 +112,7 @@
 error:
        if (pdata != NULL)
                xfree(pdata);
-       fclose(f);
+       if (close_f != NULL)
+               fclose(close_f);
        return (-1);
 }

Index: tmux.c
===================================================================
RCS file: /cvsroot/tmux/tmux/tmux.c,v
retrieving revision 1.212
retrieving revision 1.213
diff -u -d -r1.212 -r1.213
--- tmux.c      2 Jul 2010 02:49:19 -0000       1.212
+++ tmux.c      2 Jul 2010 02:52:13 -0000       1.213
@@ -613,7 +613,6 @@
 {
        struct imsg             imsg;
        ssize_t                 n, datalen;
-       struct msg_print_data   printdata;
        struct msg_shell_data   shelldata;
 
        if ((n = imsg_read(main_ibuf)) == -1 || n == 0)
@@ -633,17 +632,6 @@
                                fatalx("bad MSG_EXIT size");
 
                        exit(main_exitval);
-               case MSG_ERROR:
-               case MSG_PRINT:
-                       if (datalen != sizeof printdata)
-                               fatalx("bad MSG_PRINT size");
-                       memcpy(&printdata, imsg.data, sizeof printdata);
-                       printdata.msg[(sizeof printdata.msg) - 1] = '\0';
-
-                       log_info("%s", printdata.msg);
-                       if (imsg.hdr.type == MSG_ERROR)
-                               main_exitval = 1;
-                       break;
                case MSG_READY:
                        if (datalen != 0)
                                fatalx("bad MSG_READY size");

Index: client.c
===================================================================
RCS file: /cvsroot/tmux/tmux/client.c,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -d -r1.94 -r1.95
--- client.c    6 Jun 2010 00:30:34 -0000       1.94
+++ client.c    2 Jul 2010 02:52:13 -0000       1.95
@@ -100,8 +100,7 @@
 
        if (cmdflags & CMD_SENDENVIRON)
                client_send_environ();
-       if (isatty(STDIN_FILENO))
-               client_send_identify(flags);
+       client_send_identify(flags);
 
        return (&client_ibuf);
 
@@ -135,6 +134,14 @@
                fatal("dup failed");
        imsg_compose(&client_ibuf,
            MSG_IDENTIFY, PROTOCOL_VERSION, -1, fd, &data, sizeof data);
+
+       if ((fd = dup(STDOUT_FILENO)) == -1)
+               fatal("dup failed");
+       imsg_compose(&client_ibuf, MSG_STDOUT, PROTOCOL_VERSION, -1, fd, NULL, 
0);
+
+       if ((fd = dup(STDERR_FILENO)) == -1)
+               fatal("dup failed");
+       imsg_compose(&client_ibuf, MSG_STDERR, PROTOCOL_VERSION, -1, fd, NULL, 
0);
 }
 
 void

Index: tmux.h
===================================================================
RCS file: /cvsroot/tmux/tmux/tmux.h,v
retrieving revision 1.566
retrieving revision 1.567
diff -u -d -r1.566 -r1.567
--- tmux.h      2 Jul 2010 02:49:19 -0000       1.566
+++ tmux.h      2 Jul 2010 02:52:13 -0000       1.567
@@ -21,7 +21,7 @@
 
 #include "config.h"
 
-#define PROTOCOL_VERSION 5
+#define PROTOCOL_VERSION 6
 
 #include <sys/param.h>
 #include <sys/time.h>
@@ -67,7 +67,6 @@
  */
 #define COMMAND_LENGTH 2048    /* packed argv size */
 #define TERMINAL_LENGTH 128    /* length of TERM environment variable */
-#define PRINT_LENGTH 512       /* printed error/message size */
 #define ENVIRON_LENGTH 1024    /* environment variable length */
 
 /*
@@ -372,7 +371,9 @@
        MSG_ENVIRON,
        MSG_UNLOCK,
        MSG_LOCK,
-       MSG_SHELL
+       MSG_SHELL,
+       MSG_STDERR,
+       MSG_STDOUT,
 };
 
 /*
@@ -380,10 +381,6 @@
  *
  * Don't forget to bump PROTOCOL_VERSION if any of these change!
  */
-struct msg_print_data {
-       char            msg[PRINT_LENGTH];
-};
-
 struct msg_command_data {
        pid_t           pid;                    /* pid from $TMUX or -1 */
        u_int           idx;                    /* index from $TMUX */
@@ -1079,6 +1076,10 @@
        char            *cwd;
 
        struct tty       tty;
+       FILE            *stdin_file;
+       FILE            *stdout_file;
+       FILE            *stderr_file;
+
        struct event     repeat_timer;
 
        struct timeval   status_timer;


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
tmux-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to