Annotation of src/usr.bin/tmux/client-fn.c, Revision 1.4
1.4 ! nicm 1: /* $OpenBSD: client-fn.c,v 1.3 2009/07/29 14:17:26 nicm Exp $ */
1.1 nicm 2:
3: /*
4: * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
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:
21: #include <stdlib.h>
22: #include <string.h>
1.4 ! nicm 23: #include <unistd.h>
1.1 nicm 24:
25: #include "tmux.h"
26:
27: void
28: client_fill_session(struct msg_command_data *data)
29: {
30: char *env, *ptr1, *ptr2, buf[256];
31: size_t len;
32: const char *errstr;
33: long long ll;
34:
35: data->pid = -1;
36: if ((env = getenv("TMUX")) == NULL)
37: return;
38:
39: if ((ptr2 = strrchr(env, ',')) == NULL || ptr2 == env)
40: return;
41: for (ptr1 = ptr2 - 1; ptr1 > env && *ptr1 != ','; ptr1--)
42: ;
43: if (*ptr1 != ',')
44: return;
45: ptr1++;
46: ptr2++;
47:
48: len = ptr2 - ptr1 - 1;
49: if (len > (sizeof buf) - 1)
50: return;
51: memcpy(buf, ptr1, len);
52: buf[len] = '\0';
53:
54: ll = strtonum(buf, 0, LONG_MAX, &errstr);
55: if (errstr != NULL)
56: return;
57: data->pid = ll;
58:
59: ll = strtonum(ptr2, 0, UINT_MAX, &errstr);
60: if (errstr != NULL)
61: return;
62: data->idx = ll;
63: }
64:
65: void
66: client_write_server(
1.3 nicm 67: struct client_ctx *cctx, enum msgtype type, void *buf, size_t len)
1.1 nicm 68: {
69: struct hdr hdr;
70:
71: hdr.type = type;
72: hdr.size = len;
73: buffer_write(cctx->srv_out, &hdr, sizeof hdr);
74:
75: if (buf != NULL && len > 0)
76: buffer_write(cctx->srv_out, buf, len);
1.4 ! nicm 77: }
! 78:
! 79: void
! 80: client_suspend(void)
! 81: {
! 82: struct sigaction act;
! 83:
! 84: memset(&act, 0, sizeof act);
! 85: sigemptyset(&act.sa_mask);
! 86: act.sa_flags = SA_RESTART;
! 87:
! 88: act.sa_handler = SIG_DFL;
! 89: if (sigaction(SIGTSTP, &act, NULL) != 0)
! 90: fatal("sigaction failed");
! 91:
! 92: act.sa_handler = sighandler;
! 93: if (sigaction(SIGCONT, &act, NULL) != 0)
! 94: fatal("sigaction failed");
! 95:
! 96: kill(getpid(), SIGTSTP);
1.1 nicm 97: }