tmux  3.2a
About: tmux is a terminal multiplexer that lets you switch easily between several programs in one terminal.
  Fossies Dox: tmux-3.2a.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

client.c
Go to the documentation of this file.
1 /* $OpenBSD$ */
2 
3 /*
4  * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <sys/uio.h>
22 #include <sys/un.h>
23 #include <sys/wait.h>
24 #include <sys/file.h>
25 
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <signal.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <unistd.h>
32 
33 #include "tmux.h"
34 
35 static struct tmuxproc *client_proc;
36 static struct tmuxpeer *client_peer;
37 static uint64_t client_flags;
38 static int client_suspended;
39 static enum {
50 static int client_exitflag;
51 static int client_exitval;
52 static enum msgtype client_exittype;
53 static const char *client_exitsession;
54 static char *client_exitmessage;
55 static const char *client_execshell;
56 static const char *client_execcmd;
57 static int client_attached;
58 static struct client_files client_files = RB_INITIALIZER(&client_files);
59 
60 static __dead void client_exec(const char *,const char *);
61 static int client_get_lock(char *);
62 static int client_connect(struct event_base *, const char *,
63  uint64_t);
64 static void client_send_identify(const char *, const char *,
65  char **, u_int, const char *, int);
66 static void client_signal(int);
67 static void client_dispatch(struct imsg *, void *);
68 static void client_dispatch_attached(struct imsg *);
69 static void client_dispatch_wait(struct imsg *);
70 static const char *client_exit_message(void);
71 
72 /*
73  * Get server create lock. If already held then server start is happening in
74  * another client, so block until the lock is released and return -2 to
75  * retry. Return -1 on failure to continue and start the server anyway.
76  */
77 static int
78 client_get_lock(char *lockfile)
79 {
80  int lockfd;
81 
82  log_debug("lock file is %s", lockfile);
83 
84  if ((lockfd = open(lockfile, O_WRONLY|O_CREAT, 0600)) == -1) {
85  log_debug("open failed: %s", strerror(errno));
86  return (-1);
87  }
88 
89  if (flock(lockfd, LOCK_EX|LOCK_NB) == -1) {
90  log_debug("flock failed: %s", strerror(errno));
91  if (errno != EAGAIN)
92  return (lockfd);
93  while (flock(lockfd, LOCK_EX) == -1 && errno == EINTR)
94  /* nothing */;
95  close(lockfd);
96  return (-2);
97  }
98  log_debug("flock succeeded");
99 
100  return (lockfd);
101 }
102 
103 /* Connect client to server. */
104 static int
105 client_connect(struct event_base *base, const char *path, uint64_t flags)
106 {
107  struct sockaddr_un sa;
108  size_t size;
109  int fd, lockfd = -1, locked = 0;
110  char *lockfile = NULL;
111 
112  memset(&sa, 0, sizeof sa);
113  sa.sun_family = AF_UNIX;
114  size = strlcpy(sa.sun_path, path, sizeof sa.sun_path);
115  if (size >= sizeof sa.sun_path) {
116  errno = ENAMETOOLONG;
117  return (-1);
118  }
119  log_debug("socket is %s", path);
120 
121 retry:
122  if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
123  return (-1);
124 
125  log_debug("trying connect");
126  if (connect(fd, (struct sockaddr *)&sa, sizeof sa) == -1) {
127  log_debug("connect failed: %s", strerror(errno));
128  if (errno != ECONNREFUSED && errno != ENOENT)
129  goto failed;
130  if (flags & CLIENT_NOSTARTSERVER)
131  goto failed;
132  if (~flags & CLIENT_STARTSERVER)
133  goto failed;
134  close(fd);
135 
136  if (!locked) {
137  xasprintf(&lockfile, "%s.lock", path);
138  if ((lockfd = client_get_lock(lockfile)) < 0) {
139  log_debug("didn't get lock (%d)", lockfd);
140 
141  free(lockfile);
142  lockfile = NULL;
143 
144  if (lockfd == -2)
145  goto retry;
146  }
147  log_debug("got lock (%d)", lockfd);
148 
149  /*
150  * Always retry at least once, even if we got the lock,
151  * because another client could have taken the lock,
152  * started the server and released the lock between our
153  * connect() and flock().
154  */
155  locked = 1;
156  goto retry;
157  }
158 
159  if (lockfd >= 0 && unlink(path) != 0 && errno != ENOENT) {
160  free(lockfile);
161  close(lockfd);
162  return (-1);
163  }
164  fd = server_start(client_proc, flags, base, lockfd, lockfile);
165  }
166 
167  if (locked && lockfd >= 0) {
168  free(lockfile);
169  close(lockfd);
170  }
171  setblocking(fd, 0);
172  return (fd);
173 
174 failed:
175  if (locked) {
176  free(lockfile);
177  close(lockfd);
178  }
179  close(fd);
180  return (-1);
181 }
182 
183 /* Get exit string from reason number. */
184 const char *
186 {
187  static char msg[256];
188 
189  switch (client_exitreason) {
190  case CLIENT_EXIT_NONE:
191  break;
193  if (client_exitsession != NULL) {
194  xsnprintf(msg, sizeof msg, "detached "
195  "(from session %s)", client_exitsession);
196  return (msg);
197  }
198  return ("detached");
200  if (client_exitsession != NULL) {
201  xsnprintf(msg, sizeof msg, "detached and SIGHUP "
202  "(from session %s)", client_exitsession);
203  return (msg);
204  }
205  return ("detached and SIGHUP");
207  return ("lost tty");
209  return ("terminated");
211  return ("server exited unexpectedly");
212  case CLIENT_EXIT_EXITED:
213  return ("exited");
215  return ("server exited");
217  return (client_exitmessage);
218  }
219  return ("unknown reason");
220 }
221 
222 /* Exit if all streams flushed. */
223 static void
225 {
228 }
229 
230 /* Client main loop. */
231 int
232 client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
233  int feat)
234 {
235  struct cmd_parse_result *pr;
236  struct msg_command *data;
237  int fd, i;
238  const char *ttynam, *termname, *cwd;
239  pid_t ppid;
240  enum msgtype msg;
241  struct termios tio, saved_tio;
242  size_t size, linesize = 0;
243  ssize_t linelen;
244  char *line = NULL, **caps = NULL, *cause;
245  u_int ncaps = 0;
246 
247  /* Ignore SIGCHLD now or daemon() in the server will leave a zombie. */
248  signal(SIGCHLD, SIG_IGN);
249 
250  /* Set up the initial command. */
251  if (shell_command != NULL) {
252  msg = MSG_SHELL;
253  flags |= CLIENT_STARTSERVER;
254  } else if (argc == 0) {
255  msg = MSG_COMMAND;
256  flags |= CLIENT_STARTSERVER;
257  } else {
258  msg = MSG_COMMAND;
259 
260  /*
261  * It sucks parsing the command string twice (in client and
262  * later in server) but it is necessary to get the start server
263  * flag.
264  */
265  pr = cmd_parse_from_arguments(argc, argv, NULL);
266  if (pr->status == CMD_PARSE_SUCCESS) {
268  flags |= CLIENT_STARTSERVER;
269  cmd_list_free(pr->cmdlist);
270  } else
271  free(pr->error);
272  }
273 
274  /* Create client process structure (starts logging). */
275  client_proc = proc_start("client");
277 
278  /* Save the flags. */
279  client_flags = flags;
280  log_debug("flags are %#llx", (unsigned long long)client_flags);
281 
282  /* Initialize the client socket and start the server. */
284  if (fd == -1) {
285  if (errno == ECONNREFUSED) {
286  fprintf(stderr, "no server running on %s\n",
287  socket_path);
288  } else {
289  fprintf(stderr, "error connecting to %s (%s)\n",
290  socket_path, strerror(errno));
291  }
292  return (1);
293  }
295 
296  /* Save these before pledge(). */
297  if ((cwd = find_cwd()) == NULL && (cwd = find_home()) == NULL)
298  cwd = "/";
299  if ((ttynam = ttyname(STDIN_FILENO)) == NULL)
300  ttynam = "";
301  if ((termname = getenv("TERM")) == NULL)
302  termname = "";
303 
304  /*
305  * Drop privileges for client. "proc exec" is needed for -c and for
306  * locking (which uses system(3)).
307  *
308  * "tty" is needed to restore termios(4) and also for some reason -CC
309  * does not work properly without it (input is not recognised).
310  *
311  * "sendfd" is dropped later in client_dispatch_wait().
312  */
313  if (pledge(
314  "stdio rpath wpath cpath unix sendfd proc exec tty",
315  NULL) != 0)
316  fatal("pledge failed");
317 
318  /* Load terminfo entry if any. */
319  if (isatty(STDIN_FILENO) &&
320  *termname != '\0' &&
321  tty_term_read_list(termname, STDIN_FILENO, &caps, &ncaps,
322  &cause) != 0) {
323  fprintf(stderr, "%s\n", cause);
324  free(cause);
325  return (1);
326  }
327 
328  /* Free stuff that is not used in the client. */
329  if (ptm_fd != -1)
330  close(ptm_fd);
335 
336  /* Set up control mode. */
338  if (tcgetattr(STDIN_FILENO, &saved_tio) != 0) {
339  fprintf(stderr, "tcgetattr failed: %s\n",
340  strerror(errno));
341  return (1);
342  }
343  cfmakeraw(&tio);
344  tio.c_iflag = ICRNL|IXANY;
345  tio.c_oflag = OPOST|ONLCR;
346 #ifdef NOKERNINFO
347  tio.c_lflag = NOKERNINFO;
348 #endif
349  tio.c_cflag = CREAD|CS8|HUPCL;
350  tio.c_cc[VMIN] = 1;
351  tio.c_cc[VTIME] = 0;
352  cfsetispeed(&tio, cfgetispeed(&saved_tio));
353  cfsetospeed(&tio, cfgetospeed(&saved_tio));
354  tcsetattr(STDIN_FILENO, TCSANOW, &tio);
355  }
356 
357  /* Send identify messages. */
358  client_send_identify(ttynam, termname, caps, ncaps, cwd, feat);
359  tty_term_free_list(caps, ncaps);
360 
361  /* Send first command. */
362  if (msg == MSG_COMMAND) {
363  /* How big is the command? */
364  size = 0;
365  for (i = 0; i < argc; i++)
366  size += strlen(argv[i]) + 1;
367  if (size > MAX_IMSGSIZE - (sizeof *data)) {
368  fprintf(stderr, "command too long\n");
369  return (1);
370  }
371  data = xmalloc((sizeof *data) + size);
372 
373  /* Prepare command for server. */
374  data->argc = argc;
375  if (cmd_pack_argv(argc, argv, (char *)(data + 1), size) != 0) {
376  fprintf(stderr, "command too long\n");
377  free(data);
378  return (1);
379  }
380  size += sizeof *data;
381 
382  /* Send the command. */
383  if (proc_send(client_peer, msg, -1, data, size) != 0) {
384  fprintf(stderr, "failed to send command\n");
385  free(data);
386  return (1);
387  }
388  free(data);
389  } else if (msg == MSG_SHELL)
390  proc_send(client_peer, msg, -1, NULL, 0);
391 
392  /* Start main loop. */
393  proc_loop(client_proc, NULL);
394 
395  /* Run command if user requested exec, instead of exiting. */
396  if (client_exittype == MSG_EXEC) {
398  tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
400  }
401 
402  /* Restore streams to blocking. */
403  setblocking(STDIN_FILENO, 1);
404  setblocking(STDOUT_FILENO, 1);
405  setblocking(STDERR_FILENO, 1);
406 
407  /* Print the exit message, if any, and exit. */
408  if (client_attached) {
410  printf("[%s]\n", client_exit_message());
411 
412  ppid = getppid();
413  if (client_exittype == MSG_DETACHKILL && ppid > 1)
414  kill(ppid, SIGHUP);
415  } else if (client_flags & CLIENT_CONTROL) {
417  printf("%%exit %s\n", client_exit_message());
418  else
419  printf("%%exit\n");
420  fflush(stdout);
422  setvbuf(stdin, NULL, _IOLBF, 0);
423  for (;;) {
424  linelen = getline(&line, &linesize, stdin);
425  if (linelen <= 1)
426  break;
427  }
428  free(line);
429  }
431  printf("\033\\");
432  fflush(stdout);
433  tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
434  }
435  } else if (client_exitreason != CLIENT_EXIT_NONE)
436  fprintf(stderr, "%s\n", client_exit_message());
437  return (client_exitval);
438 }
439 
440 /* Send identify messages to server. */
441 static void
442 client_send_identify(const char *ttynam, const char *termname, char **caps,
443  u_int ncaps, const char *cwd, int feat)
444 {
445  char **ss;
446  size_t sslen;
447  int fd, flags = client_flags;
448  pid_t pid;
449  u_int i;
450 
451  proc_send(client_peer, MSG_IDENTIFY_FLAGS, -1, &flags, sizeof flags);
453  sizeof client_flags);
454 
455  proc_send(client_peer, MSG_IDENTIFY_TERM, -1, termname,
456  strlen(termname) + 1);
457  proc_send(client_peer, MSG_IDENTIFY_FEATURES, -1, &feat, sizeof feat);
458 
460  strlen(ttynam) + 1);
461  proc_send(client_peer, MSG_IDENTIFY_CWD, -1, cwd, strlen(cwd) + 1);
462 
463  for (i = 0; i < ncaps; i++) {
465  caps[i], strlen(caps[i]) + 1);
466  }
467 
468  if ((fd = dup(STDIN_FILENO)) == -1)
469  fatal("dup failed");
471  if ((fd = dup(STDOUT_FILENO)) == -1)
472  fatal("dup failed");
474 
475  pid = getpid();
476  proc_send(client_peer, MSG_IDENTIFY_CLIENTPID, -1, &pid, sizeof pid);
477 
478  for (ss = environ; *ss != NULL; ss++) {
479  sslen = strlen(*ss) + 1;
480  if (sslen > MAX_IMSGSIZE - IMSG_HEADER_SIZE)
481  continue;
482  proc_send(client_peer, MSG_IDENTIFY_ENVIRON, -1, *ss, sslen);
483  }
484 
485  proc_send(client_peer, MSG_IDENTIFY_DONE, -1, NULL, 0);
486 }
487 
488 /* Run command in shell; used for -c. */
489 static __dead void
490 client_exec(const char *shell, const char *shellcmd)
491 {
492  const char *name, *ptr;
493  char *argv0;
494 
495  log_debug("shell %s, command %s", shell, shellcmd);
496 
497  ptr = strrchr(shell, '/');
498  if (ptr != NULL && *(ptr + 1) != '\0')
499  name = ptr + 1;
500  else
501  name = shell;
503  xasprintf(&argv0, "-%s", name);
504  else
505  xasprintf(&argv0, "%s", name);
506  setenv("SHELL", shell, 1);
507 
509 
510  setblocking(STDIN_FILENO, 1);
511  setblocking(STDOUT_FILENO, 1);
512  setblocking(STDERR_FILENO, 1);
513  closefrom(STDERR_FILENO + 1);
514 
515  execl(shell, argv0, "-c", shellcmd, (char *) NULL);
516  fatal("execl failed");
517 }
518 
519 /* Callback to handle signals in the client. */
520 static void
522 {
523  struct sigaction sigact;
524  int status;
525 
526  log_debug("%s: %s", __func__, strsignal(sig));
527  if (sig == SIGCHLD)
528  waitpid(WAIT_ANY, &status, WNOHANG);
529  else if (!client_attached) {
530  if (sig == SIGTERM)
532  } else {
533  switch (sig) {
534  case SIGHUP:
536  client_exitval = 1;
537  proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
538  break;
539  case SIGTERM:
540  if (!client_suspended)
542  client_exitval = 1;
543  proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
544  break;
545  case SIGWINCH:
546  proc_send(client_peer, MSG_RESIZE, -1, NULL, 0);
547  break;
548  case SIGCONT:
549  memset(&sigact, 0, sizeof sigact);
550  sigemptyset(&sigact.sa_mask);
551  sigact.sa_flags = SA_RESTART;
552  sigact.sa_handler = SIG_IGN;
553  if (sigaction(SIGTSTP, &sigact, NULL) != 0)
554  fatal("sigaction failed");
555  proc_send(client_peer, MSG_WAKEUP, -1, NULL, 0);
556  client_suspended = 0;
557  break;
558  }
559  }
560 }
561 
562 /* Callback for file write error or close. */
563 static void
564 client_file_check_cb(__unused struct client *c, __unused const char *path,
565  __unused int error, __unused int closed, __unused struct evbuffer *buffer,
566  __unused void *data)
567 {
568  if (client_exitflag)
569  client_exit();
570 }
571 
572 /* Callback for client read events. */
573 static void
574 client_dispatch(struct imsg *imsg, __unused void *arg)
575 {
576  if (imsg == NULL) {
577  if (!client_exitflag) {
579  client_exitval = 1;
580  }
582  return;
583  }
584 
585  if (client_attached)
587  else
588  client_dispatch_wait(imsg);
589 }
590 
591 /* Process an exit message. */
592 static void
593 client_dispatch_exit_message(char *data, size_t datalen)
594 {
595  int retval;
596 
597  if (datalen < sizeof retval && datalen != 0)
598  fatalx("bad MSG_EXIT size");
599 
600  if (datalen >= sizeof retval) {
601  memcpy(&retval, data, sizeof retval);
602  client_exitval = retval;
603  }
604 
605  if (datalen > sizeof retval) {
606  datalen -= sizeof retval;
607  data += sizeof retval;
608 
609  client_exitmessage = xmalloc(datalen);
610  memcpy(client_exitmessage, data, datalen);
611  client_exitmessage[datalen - 1] = '\0';
612 
614  }
615 }
616 
617 /* Dispatch imsgs when in wait state (before MSG_READY). */
618 static void
619 client_dispatch_wait(struct imsg *imsg)
620 {
621  char *data;
622  ssize_t datalen;
623  static int pledge_applied;
624 
625  /*
626  * "sendfd" is no longer required once all of the identify messages
627  * have been sent. We know the server won't send us anything until that
628  * point (because we don't ask it to), so we can drop "sendfd" once we
629  * get the first message from the server.
630  */
631  if (!pledge_applied) {
632  if (pledge(
633  "stdio rpath wpath cpath unix proc exec tty",
634  NULL) != 0)
635  fatal("pledge failed");
636  pledge_applied = 1;
637  }
638 
639  data = imsg->data;
640  datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
641 
642  switch (imsg->hdr.type) {
643  case MSG_EXIT:
644  case MSG_SHUTDOWN:
645  client_dispatch_exit_message(data, datalen);
646  client_exitflag = 1;
647  client_exit();
648  break;
649  case MSG_READY:
650  if (datalen != 0)
651  fatalx("bad MSG_READY size");
652 
653  client_attached = 1;
654  proc_send(client_peer, MSG_RESIZE, -1, NULL, 0);
655  break;
656  case MSG_VERSION:
657  if (datalen != 0)
658  fatalx("bad MSG_VERSION size");
659 
660  fprintf(stderr, "protocol version mismatch "
661  "(client %d, server %u)\n", PROTOCOL_VERSION,
662  imsg->hdr.peerid & 0xff);
663  client_exitval = 1;
665  break;
666  case MSG_FLAGS:
667  if (datalen != sizeof client_flags)
668  fatalx("bad MSG_FLAGS string");
669 
670  memcpy(&client_flags, data, sizeof client_flags);
671  log_debug("new flags are %#llx",
672  (unsigned long long)client_flags);
673  break;
674  case MSG_SHELL:
675  if (datalen == 0 || data[datalen - 1] != '\0')
676  fatalx("bad MSG_SHELL string");
677 
678  client_exec(data, shell_command);
679  /* NOTREACHED */
680  case MSG_DETACH:
681  case MSG_DETACHKILL:
682  proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
683  break;
684  case MSG_EXITED:
686  break;
687  case MSG_READ_OPEN:
690  NULL);
691  break;
692  case MSG_WRITE_OPEN:
695  NULL);
696  break;
697  case MSG_WRITE:
699  break;
700  case MSG_WRITE_CLOSE:
702  break;
703  case MSG_OLDSTDERR:
704  case MSG_OLDSTDIN:
705  case MSG_OLDSTDOUT:
706  fprintf(stderr, "server version is too old for client\n");
708  break;
709  }
710 }
711 
712 /* Dispatch imsgs in attached state (after MSG_READY). */
713 static void
714 client_dispatch_attached(struct imsg *imsg)
715 {
716  struct sigaction sigact;
717  char *data;
718  ssize_t datalen;
719 
720  data = imsg->data;
721  datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
722 
723  switch (imsg->hdr.type) {
724  case MSG_FLAGS:
725  if (datalen != sizeof client_flags)
726  fatalx("bad MSG_FLAGS string");
727 
728  memcpy(&client_flags, data, sizeof client_flags);
729  log_debug("new flags are %#llx",
730  (unsigned long long)client_flags);
731  break;
732  case MSG_DETACH:
733  case MSG_DETACHKILL:
734  if (datalen == 0 || data[datalen - 1] != '\0')
735  fatalx("bad MSG_DETACH string");
736 
737  client_exitsession = xstrdup(data);
738  client_exittype = imsg->hdr.type;
739  if (imsg->hdr.type == MSG_DETACHKILL)
741  else
743  proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
744  break;
745  case MSG_EXEC:
746  if (datalen == 0 || data[datalen - 1] != '\0' ||
747  strlen(data) + 1 == (size_t)datalen)
748  fatalx("bad MSG_EXEC string");
749  client_execcmd = xstrdup(data);
750  client_execshell = xstrdup(data + strlen(data) + 1);
751 
752  client_exittype = imsg->hdr.type;
753  proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
754  break;
755  case MSG_EXIT:
756  client_dispatch_exit_message(data, datalen);
759  proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
760  break;
761  case MSG_EXITED:
762  if (datalen != 0)
763  fatalx("bad MSG_EXITED size");
764 
766  break;
767  case MSG_SHUTDOWN:
768  if (datalen != 0)
769  fatalx("bad MSG_SHUTDOWN size");
770 
771  proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
773  client_exitval = 1;
774  break;
775  case MSG_SUSPEND:
776  if (datalen != 0)
777  fatalx("bad MSG_SUSPEND size");
778 
779  memset(&sigact, 0, sizeof sigact);
780  sigemptyset(&sigact.sa_mask);
781  sigact.sa_flags = SA_RESTART;
782  sigact.sa_handler = SIG_DFL;
783  if (sigaction(SIGTSTP, &sigact, NULL) != 0)
784  fatal("sigaction failed");
785  client_suspended = 1;
786  kill(getpid(), SIGTSTP);
787  break;
788  case MSG_LOCK:
789  if (datalen == 0 || data[datalen - 1] != '\0')
790  fatalx("bad MSG_LOCK string");
791 
792  system(data);
793  proc_send(client_peer, MSG_UNLOCK, -1, NULL, 0);
794  break;
795  }
796 }
@ CLIENT_EXIT_LOST_TTY
Definition: client.c:43
@ CLIENT_EXIT_MESSAGE_PROVIDED
Definition: client.c:48
@ CLIENT_EXIT_NONE
Definition: client.c:40
@ CLIENT_EXIT_DETACHED
Definition: client.c:41
@ CLIENT_EXIT_TERMINATED
Definition: client.c:44
@ CLIENT_EXIT_SERVER_EXITED
Definition: client.c:47
@ CLIENT_EXIT_EXITED
Definition: client.c:46
@ CLIENT_EXIT_LOST_SERVER
Definition: client.c:45
@ CLIENT_EXIT_DETACHED_HUP
Definition: client.c:42
static struct client_files client_files
Definition: client.c:58
static enum msgtype client_exittype
Definition: client.c:52
static void client_dispatch_wait(struct imsg *)
Definition: client.c:619
static enum @0 client_exitreason
static struct tmuxpeer * client_peer
Definition: client.c:36
static void client_exec(const char *, const char *)
Definition: client.c:490
static void client_dispatch_exit_message(char *data, size_t datalen)
Definition: client.c:593
static void client_dispatch(struct imsg *, void *)
Definition: client.c:574
static int client_connect(struct event_base *, const char *, uint64_t)
Definition: client.c:105
static int client_attached
Definition: client.c:57
int client_main(struct event_base *base, int argc, char **argv, uint64_t flags, int feat)
Definition: client.c:232
static char * client_exitmessage
Definition: client.c:54
static void client_send_identify(const char *, const char *, char **, u_int, const char *, int)
Definition: client.c:442
static void client_exit(void)
Definition: client.c:224
static uint64_t client_flags
Definition: client.c:37
static int client_suspended
Definition: client.c:38
static const char * client_execshell
Definition: client.c:55
static int client_get_lock(char *)
Definition: client.c:78
static void client_file_check_cb(struct client *c, const char *path, int error, int closed, struct evbuffer *buffer, void *data)
Definition: client.c:564
static const char * client_exit_message(void)
Definition: client.c:185
static void client_dispatch_attached(struct imsg *)
Definition: client.c:714
static int client_exitflag
Definition: client.c:50
static void client_signal(int)
Definition: client.c:521
static struct tmuxproc * client_proc
Definition: client.c:35
static int client_exitval
Definition: client.c:51
static const char * client_execcmd
Definition: client.c:56
static const char * client_exitsession
Definition: client.c:53
struct cmd_parse_result * cmd_parse_from_arguments(int argc, char **argv, struct cmd_parse_input *pi)
Definition: cmd-parse.c:697
int cmd_list_any_have(struct cmd_list *cmdlist, int flag)
Definition: cmd.c:690
void cmd_list_free(struct cmd_list *cmdlist)
Definition: cmd.c:606
int cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
Definition: cmd.c:275
#define __unused
Definition: compat.h:60
#define LOCK_NB
Definition: compat.h:278
#define pledge(s, p)
Definition: compat.h:126
int setenv(const char *, const char *, int)
#define flock(fd, op)
Definition: compat.h:279
#define LOCK_EX
Definition: compat.h:277
size_t strlcpy(char *, const char *, size_t)
ssize_t getline(char **, size_t *, FILE *)
void closefrom(int)
void cfmakeraw(struct termios *)
#define WAIT_ANY
Definition: compat.h:222
#define __dead
Definition: compat.h:63
void environ_free(struct environ *env)
Definition: environ.c:56
void file_read_open(struct client_files *files, struct tmuxpeer *peer, struct imsg *imsg, int allow_streams, int close_received, client_file_cb cb, void *cbdata)
Definition: file.c:696
void file_write_data(struct client_files *files, struct imsg *imsg)
Definition: file.c:599
void file_write_close(struct client_files *files, struct imsg *imsg)
Definition: file.c:619
int file_write_left(struct client_files *files)
Definition: file.c:479
void file_write_open(struct client_files *files, struct tmuxpeer *peer, struct imsg *imsg, int allow_streams, int close_received, client_file_cb cb, void *cbdata)
Definition: file.c:537
const char * name
Definition: layout-set.c:38
void fatal(const char *msg,...)
Definition: log.c:144
void fatalx(const char *msg,...)
Definition: log.c:159
void log_debug(const char *msg,...)
Definition: log.c:130
void options_free(struct options *oo)
Definition: options.c:182
void proc_loop(struct tmuxproc *tp, int(*loopcb)(void))
Definition: proc.c:216
void proc_clear_signals(struct tmuxproc *tp, int defaults)
Definition: proc.c:272
struct tmuxpeer * proc_add_peer(struct tmuxproc *tp, int fd, void(*dispatchcb)(struct imsg *, void *), void *arg)
Definition: proc.c:307
int proc_send(struct tmuxpeer *peer, enum msgtype type, int fd, const void *buf, size_t len)
Definition: proc.c:162
struct tmuxproc * proc_start(const char *name)
Definition: proc.c:181
void proc_set_signals(struct tmuxproc *tp, void(*signalcb)(int))
Definition: proc.c:236
void proc_exit(struct tmuxproc *tp)
Definition: proc.c:226
int server_start(struct tmuxproc *client, int flags, struct event_base *base, int lockfd, char *lockfile)
Definition: server.c:173
Definition: tmux.h:1608
enum cmd_parse_status status
Definition: tmux.h:1489
char * error
Definition: tmux.h:1491
struct cmd_list * cmdlist
Definition: tmux.h:1490
int argc
Definition: tmux.h:557
Definition: proc.c:54
Definition: proc.c:36
int ptm_fd
Definition: tmux.c:43
const char * find_home(void)
Definition: tmux.c:299
struct environ * global_environ
Definition: tmux.c:39
struct options * global_s_options
Definition: tmux.c:37
const char * find_cwd(void)
Definition: tmux.c:274
const char * socket_path
Definition: tmux.c:42
struct options * global_w_options
Definition: tmux.c:38
const char * shell_command
Definition: tmux.c:44
void setblocking(int fd, int state)
Definition: tmux.c:233
struct options * global_options
Definition: tmux.c:36
#define CMD_STARTSERVER
Definition: tmux.h:1539
#define PROTOCOL_VERSION
Definition: tmux.h:69
#define CLIENT_STARTSERVER
Definition: tmux.h:1682
msgtype
Definition: tmux.h:505
@ MSG_IDENTIFY_TERMINFO
Definition: tmux.h:520
@ MSG_OLDSTDIN
Definition: tmux.h:534
@ MSG_DETACH
Definition: tmux.h:523
@ MSG_VERSION
Definition: tmux.h:506
@ MSG_WRITE_OPEN
Definition: tmux.h:545
@ MSG_RESIZE
Definition: tmux.h:530
@ MSG_IDENTIFY_FEATURES
Definition: tmux.h:517
@ MSG_READY
Definition: tmux.h:529
@ MSG_IDENTIFY_CLIENTPID
Definition: tmux.h:515
@ MSG_EXIT
Definition: tmux.h:525
@ MSG_IDENTIFY_STDIN
Definition: tmux.h:512
@ MSG_IDENTIFY_STDOUT
Definition: tmux.h:518
@ MSG_SUSPEND
Definition: tmux.h:536
@ MSG_IDENTIFY_LONGFLAGS
Definition: tmux.h:519
@ MSG_SHUTDOWN
Definition: tmux.h:532
@ MSG_IDENTIFY_DONE
Definition: tmux.h:514
@ MSG_LOCK
Definition: tmux.h:528
@ MSG_WRITE
Definition: tmux.h:546
@ MSG_WAKEUP
Definition: tmux.h:538
@ MSG_UNLOCK
Definition: tmux.h:537
@ MSG_EXITING
Definition: tmux.h:527
@ MSG_COMMAND
Definition: tmux.h:522
@ MSG_DETACHKILL
Definition: tmux.h:524
@ MSG_EXITED
Definition: tmux.h:526
@ MSG_SHELL
Definition: tmux.h:531
@ MSG_OLDSTDOUT
Definition: tmux.h:535
@ MSG_READ_OPEN
Definition: tmux.h:542
@ MSG_IDENTIFY_TERM
Definition: tmux.h:509
@ MSG_IDENTIFY_FLAGS
Definition: tmux.h:508
@ MSG_EXEC
Definition: tmux.h:539
@ MSG_OLDSTDERR
Definition: tmux.h:533
@ MSG_IDENTIFY_TTYNAME
Definition: tmux.h:510
@ MSG_IDENTIFY_CWD
Definition: tmux.h:516
@ MSG_IDENTIFY_ENVIRON
Definition: tmux.h:513
@ MSG_FLAGS
Definition: tmux.h:540
@ MSG_WRITE_CLOSE
Definition: tmux.h:548
void tty_term_free_list(char **, u_int)
Definition: tty-term.c:736
@ CMD_PARSE_SUCCESS
Definition: tmux.h:1486
#define CLIENT_CONTROL_WAITEXIT
Definition: tmux.h:1687
#define CLIENT_NOSTARTSERVER
Definition: tmux.h:1666
#define CLIENT_CONTROL
Definition: tmux.h:1667
char ** environ
#define CLIENT_CONTROLCONTROL
Definition: tmux.h:1668
#define CLIENT_LOGIN
Definition: tmux.h:1655
int tty_term_read_list(const char *, int, char ***, u_int *, char **)
Definition: tty-term.c:664
void * xmalloc(size_t size)
Definition: xmalloc.c:27
int xsnprintf(char *str, size_t len, const char *fmt,...)
Definition: xmalloc.c:135
int xasprintf(char **ret, const char *fmt,...)
Definition: xmalloc.c:109
char * xstrdup(const char *str)
Definition: xmalloc.c:89