[BACK]Return to client.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/client.c between version 1.134 and 1.135

version 1.134, 2019/12/13 07:00:22 version 1.135, 2019/12/16 15:48:50
Line 486 
Line 486 
 client_write_open(void *data, size_t datalen)  client_write_open(void *data, size_t datalen)
 {  {
         struct msg_write_open   *msg = data;          struct msg_write_open   *msg = data;
           const char              *path;
         struct msg_write_ready   reply;          struct msg_write_ready   reply;
         struct client_file       find, *cf;          struct client_file       find, *cf;
         const int                flags = O_NONBLOCK|O_WRONLY|O_CREAT;          const int                flags = O_NONBLOCK|O_WRONLY|O_CREAT;
         int                      error = 0;          int                      error = 0;
   
         if (datalen != sizeof *msg)          if (datalen < sizeof *msg)
                 fatalx("bad MSG_WRITE_OPEN size");                  fatalx("bad MSG_WRITE_OPEN size");
         log_debug("open write file %d %s", msg->stream, msg->path);          if (datalen == sizeof *msg)
                   path = "-";
           else
                   path = (const char *)(msg + 1);
           log_debug("open write file %d %s", msg->stream, path);
   
         find.stream = msg->stream;          find.stream = msg->stream;
         if ((cf = RB_FIND(client_files, &client_files, &find)) == NULL) {          if ((cf = RB_FIND(client_files, &client_files, &find)) == NULL) {
Line 510 
Line 515 
   
         cf->fd = -1;          cf->fd = -1;
         if (msg->fd == -1)          if (msg->fd == -1)
                 cf->fd = open(msg->path, msg->flags|flags, 0644);                  cf->fd = open(path, msg->flags|flags, 0644);
         else {          else {
                 if (msg->fd != STDOUT_FILENO && msg->fd != STDERR_FILENO)                  if (msg->fd != STDOUT_FILENO && msg->fd != STDERR_FILENO)
                         errno = EBADF;                          errno = EBADF;
Line 542 
Line 547 
 {  {
         struct msg_write_data   *msg = data;          struct msg_write_data   *msg = data;
         struct client_file       find, *cf;          struct client_file       find, *cf;
           size_t                   size = datalen - sizeof *msg;
   
         if (datalen != sizeof *msg)          if (datalen < sizeof *msg)
                 fatalx("bad MSG_WRITE size");                  fatalx("bad MSG_WRITE size");
         find.stream = msg->stream;          find.stream = msg->stream;
         if ((cf = RB_FIND(client_files, &client_files, &find)) == NULL)          if ((cf = RB_FIND(client_files, &client_files, &find)) == NULL)
                 fatalx("unknown stream number");                  fatalx("unknown stream number");
         log_debug("write %zu to file %d", msg->size, cf->stream);          log_debug("write %zu to file %d", size, cf->stream);
   
         if (cf->event != NULL)          if (cf->event != NULL)
                 bufferevent_write(cf->event, msg->data, msg->size);                  bufferevent_write(cf->event, msg + 1, size);
 }  }
   
 /* Close client file. */  /* Close client file. */
Line 585 
Line 591 
         struct client_file      *cf = arg;          struct client_file      *cf = arg;
         void                    *bdata;          void                    *bdata;
         size_t                   bsize;          size_t                   bsize;
         struct msg_read_data     msg;          struct msg_read_data    *msg;
           size_t                   msglen;
   
           msg = xmalloc(sizeof *msg);
         for (;;) {          for (;;) {
                 bdata = EVBUFFER_DATA(cf->event->input);                  bdata = EVBUFFER_DATA(cf->event->input);
                 bsize = EVBUFFER_LENGTH(cf->event->input);                  bsize = EVBUFFER_LENGTH(cf->event->input);
   
                 if (bsize == 0)                  if (bsize == 0)
                         break;                          break;
                 if (bsize > sizeof msg.data)                  if (bsize > MAX_IMSGSIZE - IMSG_HEADER_SIZE)
                         bsize = sizeof msg.data;                          bsize = MAX_IMSGSIZE - IMSG_HEADER_SIZE;
                 log_debug("read %zu from file %d", bsize, cf->stream);                  log_debug("read %zu from file %d", bsize, cf->stream);
   
                 memcpy(msg.data, bdata, bsize);                  msglen = (sizeof *msg) + bsize;
                 msg.size = bsize;                  msg = xrealloc(msg, msglen);
                   msg->stream = cf->stream;
                   memcpy(msg + 1, bdata, bsize);
                   proc_send(client_peer, MSG_READ, -1, msg, msglen);
   
                 msg.stream = cf->stream;  
                 proc_send(client_peer, MSG_READ, -1, &msg, sizeof msg);  
   
                 evbuffer_drain(cf->event->input, bsize);                  evbuffer_drain(cf->event->input, bsize);
         }          }
           free(msg);
 }  }
   
 /* File read error callback. */  /* File read error callback. */
Line 632 
Line 641 
 client_read_open(void *data, size_t datalen)  client_read_open(void *data, size_t datalen)
 {  {
         struct msg_read_open    *msg = data;          struct msg_read_open    *msg = data;
           const char              *path;
         struct msg_read_done     reply;          struct msg_read_done     reply;
         struct client_file       find, *cf;          struct client_file       find, *cf;
         const int                flags = O_NONBLOCK|O_RDONLY;          const int                flags = O_NONBLOCK|O_RDONLY;
         int                      error = 0;          int                      error = 0;
   
         if (datalen != sizeof *msg)          if (datalen < sizeof *msg)
                 fatalx("bad MSG_READ_OPEN size");                  fatalx("bad MSG_READ_OPEN size");
         log_debug("open read file %d %s", msg->stream, msg->path);          if (datalen == sizeof *msg)
                   path = "-";
           else
                   path = (const char *)(msg + 1);
           log_debug("open read file %d %s", msg->stream, path);
   
         find.stream = msg->stream;          find.stream = msg->stream;
         if ((cf = RB_FIND(client_files, &client_files, &find)) == NULL) {          if ((cf = RB_FIND(client_files, &client_files, &find)) == NULL) {
Line 656 
Line 670 
   
         cf->fd = -1;          cf->fd = -1;
         if (msg->fd == -1)          if (msg->fd == -1)
                 cf->fd = open(msg->path, flags);                  cf->fd = open(path, flags);
         else {          else {
                 if (msg->fd != STDIN_FILENO)                  if (msg->fd != STDIN_FILENO)
                         errno = EBADF;                          errno = EBADF;

Legend:
Removed from v.1.134  
changed lines
  Added in v.1.135