2009-08-14 21:04:04 +00:00
|
|
|
/* $Id: client-fn.c,v 1.10 2009-08-14 21:04:04 tcunha Exp $ */
|
2007-10-03 10:18:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-07-30 20:57:39 +00:00
|
|
|
#include <unistd.h>
|
2007-10-03 10:18:32 +00:00
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
void
|
2007-10-23 10:48:23 +00:00
|
|
|
client_fill_session(struct msg_command_data *data)
|
2007-10-03 10:18:32 +00:00
|
|
|
{
|
2009-03-04 17:24:07 +00:00
|
|
|
char *env, *ptr1, *ptr2, buf[256];
|
|
|
|
size_t len;
|
2007-10-03 10:18:32 +00:00
|
|
|
const char *errstr;
|
|
|
|
long long ll;
|
|
|
|
|
2007-10-23 10:48:23 +00:00
|
|
|
data->pid = -1;
|
2007-10-03 10:18:32 +00:00
|
|
|
if ((env = getenv("TMUX")) == NULL)
|
|
|
|
return;
|
2009-03-04 17:24:07 +00:00
|
|
|
|
|
|
|
if ((ptr2 = strrchr(env, ',')) == NULL || ptr2 == env)
|
2007-10-03 10:18:32 +00:00
|
|
|
return;
|
2009-03-04 17:24:07 +00:00
|
|
|
for (ptr1 = ptr2 - 1; ptr1 > env && *ptr1 != ','; ptr1--)
|
|
|
|
;
|
|
|
|
if (*ptr1 != ',')
|
2007-10-03 10:18:32 +00:00
|
|
|
return;
|
2009-03-04 17:24:07 +00:00
|
|
|
ptr1++;
|
|
|
|
ptr2++;
|
2007-10-03 10:18:32 +00:00
|
|
|
|
2009-03-04 17:24:07 +00:00
|
|
|
len = ptr2 - ptr1 - 1;
|
|
|
|
if (len > (sizeof buf) - 1)
|
2007-10-03 10:18:32 +00:00
|
|
|
return;
|
2009-03-04 17:24:07 +00:00
|
|
|
memcpy(buf, ptr1, len);
|
|
|
|
buf[len] = '\0';
|
2007-10-03 10:18:32 +00:00
|
|
|
|
2008-07-01 20:35:16 +00:00
|
|
|
ll = strtonum(buf, 0, LONG_MAX, &errstr);
|
2007-10-03 10:18:32 +00:00
|
|
|
if (errstr != NULL)
|
|
|
|
return;
|
2007-10-23 10:48:23 +00:00
|
|
|
data->pid = ll;
|
2009-03-04 17:24:07 +00:00
|
|
|
|
|
|
|
ll = strtonum(ptr2, 0, UINT_MAX, &errstr);
|
|
|
|
if (errstr != NULL)
|
|
|
|
return;
|
|
|
|
data->idx = ll;
|
2007-10-03 10:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_write_server(
|
2009-07-30 20:21:55 +00:00
|
|
|
struct client_ctx *cctx, enum msgtype type, void *buf, size_t len)
|
2007-10-03 10:18:32 +00:00
|
|
|
{
|
2009-08-14 21:04:04 +00:00
|
|
|
imsg_compose(&cctx->ibuf, type, PROTOCOL_VERSION, -1, -1, buf, len);
|
2007-10-03 10:18:32 +00:00
|
|
|
}
|
2009-07-30 20:57:39 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
client_suspend(void)
|
|
|
|
{
|
|
|
|
struct sigaction act;
|
|
|
|
|
|
|
|
memset(&act, 0, sizeof act);
|
|
|
|
sigemptyset(&act.sa_mask);
|
|
|
|
act.sa_flags = SA_RESTART;
|
|
|
|
|
|
|
|
act.sa_handler = SIG_DFL;
|
|
|
|
if (sigaction(SIGTSTP, &act, NULL) != 0)
|
|
|
|
fatal("sigaction failed");
|
|
|
|
|
|
|
|
act.sa_handler = sighandler;
|
|
|
|
if (sigaction(SIGCONT, &act, NULL) != 0)
|
|
|
|
fatal("sigaction failed");
|
|
|
|
|
|
|
|
kill(getpid(), SIGTSTP);
|
|
|
|
}
|