cmd-detach-client.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* $OpenBSD$ */
  2. /*
  3. * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
  14. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  15. * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <sys/types.h>
  18. #include <string.h>
  19. #include "tmux.h"
  20. /*
  21. * Detach a client.
  22. */
  23. enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_q *);
  24. const struct cmd_entry cmd_detach_client_entry = {
  25. .name = "detach-client",
  26. .alias = "detach",
  27. .args = { "as:t:P", 0, 0 },
  28. .usage = "[-P] [-a] [-s target-session] " CMD_TARGET_CLIENT_USAGE,
  29. .sflag = CMD_SESSION,
  30. .tflag = CMD_CLIENT,
  31. .flags = CMD_READONLY,
  32. .exec = cmd_detach_client_exec
  33. };
  34. const struct cmd_entry cmd_suspend_client_entry = {
  35. .name = "suspend-client",
  36. .alias = "suspendc",
  37. .args = { "t:", 0, 0 },
  38. .usage = CMD_TARGET_CLIENT_USAGE,
  39. .tflag = CMD_CLIENT,
  40. .flags = 0,
  41. .exec = cmd_detach_client_exec
  42. };
  43. enum cmd_retval
  44. cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
  45. {
  46. struct args *args = self->args;
  47. struct client *c = cmdq->state.c, *cloop;
  48. struct session *s;
  49. enum msgtype msgtype;
  50. if (self->entry == &cmd_suspend_client_entry) {
  51. tty_stop_tty(&c->tty);
  52. c->flags |= CLIENT_SUSPENDED;
  53. proc_send(c->peer, MSG_SUSPEND, -1, NULL, 0);
  54. return (CMD_RETURN_NORMAL);
  55. }
  56. if (args_has(args, 'P'))
  57. msgtype = MSG_DETACHKILL;
  58. else
  59. msgtype = MSG_DETACH;
  60. if (args_has(args, 's')) {
  61. s = cmdq->state.sflag.s;
  62. TAILQ_FOREACH(cloop, &clients, entry) {
  63. if (cloop->session == s)
  64. server_client_detach(cloop, msgtype);
  65. }
  66. return (CMD_RETURN_STOP);
  67. }
  68. if (args_has(args, 'a')) {
  69. TAILQ_FOREACH(cloop, &clients, entry) {
  70. if (cloop->session != NULL && cloop != c)
  71. server_client_detach(cloop, msgtype);
  72. }
  73. return (CMD_RETURN_NORMAL);
  74. }
  75. server_client_detach(c, msgtype);
  76. return (CMD_RETURN_STOP);
  77. }