cmd-kill-session.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 "tmux.h"
  19. /*
  20. * Destroy session, detaching all clients attached to it and destroying any
  21. * windows linked only to this session.
  22. *
  23. * Note this deliberately has no alias to make it hard to hit by accident.
  24. */
  25. enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmd_q *);
  26. const struct cmd_entry cmd_kill_session_entry = {
  27. .name = "kill-session",
  28. .alias = NULL,
  29. .args = { "aCt:", 0, 0 },
  30. .usage = "[-aC] " CMD_TARGET_SESSION_USAGE,
  31. .tflag = CMD_SESSION,
  32. .flags = 0,
  33. .exec = cmd_kill_session_exec
  34. };
  35. enum cmd_retval
  36. cmd_kill_session_exec(struct cmd *self, struct cmd_q *cmdq)
  37. {
  38. struct args *args = self->args;
  39. struct session *s, *sloop, *stmp;
  40. struct winlink *wl;
  41. s = cmdq->state.tflag.s;
  42. if (args_has(args, 'C')) {
  43. RB_FOREACH(wl, winlinks, &s->windows) {
  44. wl->window->flags &= ~WINDOW_ALERTFLAGS;
  45. wl->flags &= ~WINLINK_ALERTFLAGS;
  46. }
  47. server_redraw_session(s);
  48. } else if (args_has(args, 'a')) {
  49. RB_FOREACH_SAFE(sloop, sessions, &sessions, stmp) {
  50. if (sloop != s) {
  51. server_destroy_session(sloop);
  52. session_destroy(sloop);
  53. }
  54. }
  55. } else {
  56. server_destroy_session(s);
  57. session_destroy(s);
  58. }
  59. return (CMD_RETURN_NORMAL);
  60. }