Annotation of src/usr.bin/tmux/client-fn.c, Revision 1.5
1.5 ! nicm 1: /* $OpenBSD: client-fn.c,v 1.4 2009/07/30 16:32:12 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: {
1.5 ! nicm 69: imsg_compose(&cctx->ibuf, type, PROTOCOL_VERSION, -1, -1, buf, len);
1.4 nicm 70: }
71:
72: void
73: client_suspend(void)
74: {
75: struct sigaction act;
76:
77: memset(&act, 0, sizeof act);
78: sigemptyset(&act.sa_mask);
79: act.sa_flags = SA_RESTART;
80:
81: act.sa_handler = SIG_DFL;
82: if (sigaction(SIGTSTP, &act, NULL) != 0)
83: fatal("sigaction failed");
84:
85: act.sa_handler = sighandler;
86: if (sigaction(SIGCONT, &act, NULL) != 0)
87: fatal("sigaction failed");
88:
89: kill(getpid(), SIGTSTP);
1.1 nicm 90: }