mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-17 02:57:33 -05:00
Whitespace rationalisation of entire code base.
The number of people has been steadily increasing who read our source code with an editor that thinks tab stops are 4 spaces apart, as opposed to the traditional tty-derived 8 that the PuTTY code expects. So I've been wondering for ages about just fixing it, and switching to a spaces-only policy throughout the code. And I recently found out about 'git blame -w', which should make this change not too disruptive for the purposes of source-control archaeology; so perhaps now is the time. While I'm at it, I've also taken the opportunity to remove all the trailing spaces from source lines (on the basis that git dislikes them, and is the only thing that seems to have a strong opinion one way or the other). Apologies to anyone downstream of this code who has complicated patch sets to rebase past this change. I don't intend it to be needed again.
This commit is contained in:
418
unix/uxpty.c
418
unix/uxpty.c
@ -106,9 +106,9 @@ static int ptyfd_compare(void *av, void *bv)
|
||||
PtyFd *b = (PtyFd *)bv;
|
||||
|
||||
if (a->fd < b->fd)
|
||||
return -1;
|
||||
return -1;
|
||||
else if (a->fd > b->fd)
|
||||
return +1;
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -118,9 +118,9 @@ static int ptyfd_find(void *av, void *bv)
|
||||
PtyFd *b = (PtyFd *)bv;
|
||||
|
||||
if (a < b->fd)
|
||||
return -1;
|
||||
return -1;
|
||||
else if (a > b->fd)
|
||||
return +1;
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -138,9 +138,9 @@ static int pty_compare_by_pid(void *av, void *bv)
|
||||
Pty *b = (Pty *)bv;
|
||||
|
||||
if (a->child_pid < b->child_pid)
|
||||
return -1;
|
||||
return -1;
|
||||
else if (a->child_pid > b->child_pid)
|
||||
return +1;
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -150,9 +150,9 @@ static int pty_find_by_pid(void *av, void *bv)
|
||||
Pty *b = (Pty *)bv;
|
||||
|
||||
if (a < b->child_pid)
|
||||
return -1;
|
||||
return -1;
|
||||
else if (a > b->child_pid)
|
||||
return +1;
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -163,12 +163,12 @@ static tree234 *ptys_by_pid = NULL;
|
||||
* allocated a pty structure, which we must then return from
|
||||
* pty_init() rather than allocating a new one. Here we store that
|
||||
* structure between allocation and use.
|
||||
*
|
||||
*
|
||||
* Note that although most of this module is entirely capable of
|
||||
* handling multiple ptys in a single process, pty_pre_init() is
|
||||
* fundamentally _dependent_ on there being at most one pty per
|
||||
* process, so the normal static-data constraints don't apply.
|
||||
*
|
||||
*
|
||||
* Likewise, since utmp is only used via pty_pre_init, it too must
|
||||
* be single-instance, so we can declare utmp-related variables
|
||||
* here.
|
||||
@ -240,9 +240,9 @@ static void setup_utmp(char *ttyname, char *location)
|
||||
strncpy(lastlog_entry.ll_host, location, lenof(lastlog_entry.ll_host));
|
||||
time(&lastlog_entry.ll_time);
|
||||
if ((lastlog = fopen(LASTLOG_FILE, "r+")) != NULL) {
|
||||
fseek(lastlog, sizeof(lastlog_entry) * getuid(), SEEK_SET);
|
||||
fwrite(&lastlog_entry, 1, sizeof(lastlog_entry), lastlog);
|
||||
fclose(lastlog);
|
||||
fseek(lastlog, sizeof(lastlog_entry) * getuid(), SEEK_SET);
|
||||
fwrite(&lastlog_entry, 1, sizeof(lastlog_entry), lastlog);
|
||||
fclose(lastlog);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -255,7 +255,7 @@ static void cleanup_utmp(void)
|
||||
struct timeval tv;
|
||||
|
||||
if (!pty_stamped_utmp)
|
||||
return;
|
||||
return;
|
||||
|
||||
utmp_entry.ut_type = DEAD_PROCESS;
|
||||
memset(utmp_entry.ut_user, 0, lenof(utmp_entry.ut_user));
|
||||
@ -280,7 +280,7 @@ static void cleanup_utmp(void)
|
||||
static void sigchld_handler(int signum)
|
||||
{
|
||||
if (write(pty_signal_pipe[1], "x", 1) <= 0)
|
||||
/* not much we can do about it */;
|
||||
/* not much we can do about it */;
|
||||
}
|
||||
|
||||
static void pty_setup_sigchld_handler(void)
|
||||
@ -304,7 +304,7 @@ static void fatal_sig_handler(int signum)
|
||||
static int pty_open_slave(Pty *pty)
|
||||
{
|
||||
if (pty->slave_fd < 0) {
|
||||
pty->slave_fd = open(pty->name, O_RDWR);
|
||||
pty->slave_fd = open(pty->name, O_RDWR);
|
||||
cloexec(pty->slave_fd);
|
||||
}
|
||||
|
||||
@ -321,34 +321,34 @@ static void pty_open_master(Pty *pty)
|
||||
struct group *gp;
|
||||
|
||||
for (p1 = chars1; *p1; p1++)
|
||||
for (p2 = chars2; *p2; p2++) {
|
||||
sprintf(master_name, "/dev/pty%c%c", *p1, *p2);
|
||||
pty->master_fd = open(master_name, O_RDWR);
|
||||
if (pty->master_fd >= 0) {
|
||||
if (geteuid() == 0 ||
|
||||
access(master_name, R_OK | W_OK) == 0) {
|
||||
/*
|
||||
* We must also check at this point that we are
|
||||
* able to open the slave side of the pty. We
|
||||
* wouldn't want to allocate the wrong master,
|
||||
* get all the way down to forking, and _then_
|
||||
* find we're unable to open the slave.
|
||||
*/
|
||||
strcpy(pty->name, master_name);
|
||||
pty->name[5] = 't'; /* /dev/ptyXX -> /dev/ttyXX */
|
||||
for (p2 = chars2; *p2; p2++) {
|
||||
sprintf(master_name, "/dev/pty%c%c", *p1, *p2);
|
||||
pty->master_fd = open(master_name, O_RDWR);
|
||||
if (pty->master_fd >= 0) {
|
||||
if (geteuid() == 0 ||
|
||||
access(master_name, R_OK | W_OK) == 0) {
|
||||
/*
|
||||
* We must also check at this point that we are
|
||||
* able to open the slave side of the pty. We
|
||||
* wouldn't want to allocate the wrong master,
|
||||
* get all the way down to forking, and _then_
|
||||
* find we're unable to open the slave.
|
||||
*/
|
||||
strcpy(pty->name, master_name);
|
||||
pty->name[5] = 't'; /* /dev/ptyXX -> /dev/ttyXX */
|
||||
|
||||
cloexec(pty->master_fd);
|
||||
|
||||
if (pty_open_slave(pty) >= 0 &&
|
||||
access(pty->name, R_OK | W_OK) == 0)
|
||||
goto got_one;
|
||||
if (pty->slave_fd > 0)
|
||||
close(pty->slave_fd);
|
||||
pty->slave_fd = -1;
|
||||
}
|
||||
close(pty->master_fd);
|
||||
}
|
||||
}
|
||||
if (pty_open_slave(pty) >= 0 &&
|
||||
access(pty->name, R_OK | W_OK) == 0)
|
||||
goto got_one;
|
||||
if (pty->slave_fd > 0)
|
||||
close(pty->slave_fd);
|
||||
pty->slave_fd = -1;
|
||||
}
|
||||
close(pty->master_fd);
|
||||
}
|
||||
}
|
||||
|
||||
/* If we get here, we couldn't get a tty at all. */
|
||||
fprintf(stderr, "pterm: unable to open a pseudo-terminal device\n");
|
||||
@ -383,26 +383,26 @@ static void pty_open_master(Pty *pty)
|
||||
#endif
|
||||
|
||||
if (pty->master_fd < 0) {
|
||||
perror("posix_openpt");
|
||||
exit(1);
|
||||
perror("posix_openpt");
|
||||
exit(1);
|
||||
}
|
||||
#else
|
||||
pty->master_fd = open("/dev/ptmx", flags);
|
||||
|
||||
if (pty->master_fd < 0) {
|
||||
perror("/dev/ptmx: open");
|
||||
exit(1);
|
||||
perror("/dev/ptmx: open");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (grantpt(pty->master_fd) < 0) {
|
||||
perror("grantpt");
|
||||
exit(1);
|
||||
perror("grantpt");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
if (unlockpt(pty->master_fd) < 0) {
|
||||
perror("unlockpt");
|
||||
exit(1);
|
||||
perror("unlockpt");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cloexec(pty->master_fd);
|
||||
@ -460,7 +460,7 @@ void pty_pre_init(void)
|
||||
#endif
|
||||
|
||||
if (geteuid() != getuid() || getegid() != getgid()) {
|
||||
pty_open_master(pty);
|
||||
pty_open_master(pty);
|
||||
|
||||
#ifndef OMIT_UTMP
|
||||
/*
|
||||
@ -489,7 +489,7 @@ void pty_pre_init(void)
|
||||
|
||||
dlen = 0;
|
||||
while (1) {
|
||||
|
||||
|
||||
ret = read(pipefd[0], buffer, lenof(buffer));
|
||||
if (ret <= 0) {
|
||||
cleanup_utmp();
|
||||
@ -565,23 +565,23 @@ void pty_pre_init(void)
|
||||
/* Drop privs. */
|
||||
{
|
||||
#ifndef HAVE_NO_SETRESUID
|
||||
int gid = getgid(), uid = getuid();
|
||||
int setresgid(gid_t, gid_t, gid_t);
|
||||
int setresuid(uid_t, uid_t, uid_t);
|
||||
if (setresgid(gid, gid, gid) < 0) {
|
||||
int gid = getgid(), uid = getuid();
|
||||
int setresgid(gid_t, gid_t, gid_t);
|
||||
int setresuid(uid_t, uid_t, uid_t);
|
||||
if (setresgid(gid, gid, gid) < 0) {
|
||||
perror("setresgid");
|
||||
exit(1);
|
||||
}
|
||||
if (setresuid(uid, uid, uid) < 0) {
|
||||
if (setresuid(uid, uid, uid) < 0) {
|
||||
perror("setresuid");
|
||||
exit(1);
|
||||
}
|
||||
#else
|
||||
if (setgid(getgid()) < 0) {
|
||||
if (setgid(getgid()) < 0) {
|
||||
perror("setgid");
|
||||
exit(1);
|
||||
}
|
||||
if (setuid(getuid()) < 0) {
|
||||
if (setuid(getuid()) < 0) {
|
||||
perror("setuid");
|
||||
exit(1);
|
||||
}
|
||||
@ -601,13 +601,13 @@ static void pty_real_select_result(Pty *pty, int fd, int event, int status)
|
||||
bool finished = false;
|
||||
|
||||
if (event < 0) {
|
||||
/*
|
||||
* We've been called because our child process did
|
||||
* something. `status' tells us what.
|
||||
*/
|
||||
if ((WIFEXITED(status) || WIFSIGNALED(status))) {
|
||||
/*
|
||||
* The primary child process died.
|
||||
/*
|
||||
* We've been called because our child process did
|
||||
* something. `status' tells us what.
|
||||
*/
|
||||
if ((WIFEXITED(status) || WIFSIGNALED(status))) {
|
||||
/*
|
||||
* The primary child process died.
|
||||
*/
|
||||
pty->child_dead = true;
|
||||
del234(ptys_by_pid, pty);
|
||||
@ -615,24 +615,24 @@ static void pty_real_select_result(Pty *pty, int fd, int event, int status)
|
||||
|
||||
/*
|
||||
* If this is an ordinary pty session, this is also the
|
||||
* moment to terminate the whole backend.
|
||||
* moment to terminate the whole backend.
|
||||
*
|
||||
* We _could_ instead keep the terminal open for remaining
|
||||
* subprocesses to output to, but conventional wisdom
|
||||
* seems to feel that that's the Wrong Thing for an
|
||||
* xterm-alike, so we bail out now (though we don't
|
||||
* necessarily _close_ the window, depending on the state
|
||||
* of Close On Exit). This would be easy enough to change
|
||||
* or make configurable if necessary.
|
||||
*/
|
||||
* subprocesses to output to, but conventional wisdom
|
||||
* seems to feel that that's the Wrong Thing for an
|
||||
* xterm-alike, so we bail out now (though we don't
|
||||
* necessarily _close_ the window, depending on the state
|
||||
* of Close On Exit). This would be easy enough to change
|
||||
* or make configurable if necessary.
|
||||
*/
|
||||
if (pty->master_fd >= 0)
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (event == SELECT_R) {
|
||||
if (event == SELECT_R) {
|
||||
bool is_stdout = (fd == pty->master_o);
|
||||
|
||||
ret = read(fd, buf, sizeof(buf));
|
||||
ret = read(fd, buf, sizeof(buf));
|
||||
|
||||
/*
|
||||
* Treat EIO on a pty master as equivalent to EOF (because
|
||||
@ -643,7 +643,7 @@ static void pty_real_select_result(Pty *pty, int fd, int event, int status)
|
||||
if (fd == pty->master_fd && ret < 0 && errno == EIO)
|
||||
ret = 0;
|
||||
|
||||
if (ret == 0) {
|
||||
if (ret == 0) {
|
||||
/*
|
||||
* EOF on this input fd, so to begin with, we may as
|
||||
* well close it, and remove all references to it in
|
||||
@ -673,13 +673,13 @@ static void pty_real_select_result(Pty *pty, int fd, int event, int status)
|
||||
if (!pty->child_dead)
|
||||
pty->exit_code = 0;
|
||||
}
|
||||
} else if (ret < 0) {
|
||||
perror("read pty master");
|
||||
exit(1);
|
||||
} else if (ret > 0) {
|
||||
seat_output(pty->seat, !is_stdout, buf, ret);
|
||||
}
|
||||
} else if (event == SELECT_W) {
|
||||
} else if (ret < 0) {
|
||||
perror("read pty master");
|
||||
exit(1);
|
||||
} else if (ret > 0) {
|
||||
seat_output(pty->seat, !is_stdout, buf, ret);
|
||||
}
|
||||
} else if (event == SELECT_W) {
|
||||
/*
|
||||
* Attempt to send data down the pty.
|
||||
*/
|
||||
@ -688,7 +688,7 @@ static void pty_real_select_result(Pty *pty, int fd, int event, int status)
|
||||
}
|
||||
|
||||
if (finished && !pty->finished) {
|
||||
int close_on_exit;
|
||||
int close_on_exit;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
@ -697,29 +697,29 @@ static void pty_real_select_result(Pty *pty, int fd, int event, int status)
|
||||
|
||||
pty_close(pty);
|
||||
|
||||
pty->finished = true;
|
||||
pty->finished = true;
|
||||
|
||||
/*
|
||||
* This is a slight layering-violation sort of hack: only
|
||||
* if we're not closing on exit (COE is set to Never, or to
|
||||
* Only On Clean and it wasn't a clean exit) do we output a
|
||||
* `terminated' message.
|
||||
*/
|
||||
close_on_exit = conf_get_int(pty->conf, CONF_close_on_exit);
|
||||
if (close_on_exit == FORCE_OFF ||
|
||||
(close_on_exit == AUTO && pty->exit_code != 0)) {
|
||||
char *message;
|
||||
/*
|
||||
* This is a slight layering-violation sort of hack: only
|
||||
* if we're not closing on exit (COE is set to Never, or to
|
||||
* Only On Clean and it wasn't a clean exit) do we output a
|
||||
* `terminated' message.
|
||||
*/
|
||||
close_on_exit = conf_get_int(pty->conf, CONF_close_on_exit);
|
||||
if (close_on_exit == FORCE_OFF ||
|
||||
(close_on_exit == AUTO && pty->exit_code != 0)) {
|
||||
char *message;
|
||||
if (WIFEXITED(pty->exit_code)) {
|
||||
message = dupprintf(
|
||||
message = dupprintf(
|
||||
"\r\n[pterm: process terminated with exit code %d]\r\n",
|
||||
WEXITSTATUS(pty->exit_code));
|
||||
} else if (WIFSIGNALED(pty->exit_code)) {
|
||||
#ifdef HAVE_NO_STRSIGNAL
|
||||
message = dupprintf(
|
||||
message = dupprintf(
|
||||
"\r\n[pterm: process terminated on signal %d]\r\n",
|
||||
WTERMSIG(pty->exit_code));
|
||||
#else
|
||||
message = dupprintf(
|
||||
message = dupprintf(
|
||||
"\r\n[pterm: process terminated on signal %d (%s)]\r\n",
|
||||
WTERMSIG(pty->exit_code),
|
||||
strsignal(WTERMSIG(pty->exit_code)));
|
||||
@ -729,12 +729,12 @@ static void pty_real_select_result(Pty *pty, int fd, int event, int status)
|
||||
* is better than no message at all */
|
||||
message = dupprintf("\r\n[pterm: process terminated]\r\n");
|
||||
}
|
||||
seat_stdout_pl(pty->seat, ptrlen_from_asciz(message));
|
||||
seat_stdout_pl(pty->seat, ptrlen_from_asciz(message));
|
||||
sfree(message);
|
||||
}
|
||||
}
|
||||
|
||||
seat_eof(pty->seat);
|
||||
seat_notify_remote_exit(pty->seat);
|
||||
seat_notify_remote_exit(pty->seat);
|
||||
}
|
||||
}
|
||||
|
||||
@ -757,18 +757,18 @@ static void pty_try_wait(void)
|
||||
void pty_select_result(int fd, int event)
|
||||
{
|
||||
if (fd == pty_signal_pipe[0]) {
|
||||
char c[1];
|
||||
char c[1];
|
||||
|
||||
if (read(pty_signal_pipe[0], c, 1) <= 0)
|
||||
/* ignore error */;
|
||||
/* ignore its value; it'll be `x' */
|
||||
if (read(pty_signal_pipe[0], c, 1) <= 0)
|
||||
/* ignore error */;
|
||||
/* ignore its value; it'll be `x' */
|
||||
|
||||
pty_try_wait();
|
||||
} else {
|
||||
PtyFd *ptyfd = find234(ptyfds, &fd, ptyfd_find);
|
||||
|
||||
if (ptyfd)
|
||||
pty_real_select_result(ptyfd->pty, fd, event, 0);
|
||||
if (ptyfd)
|
||||
pty_real_select_result(ptyfd->pty, fd, event, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -862,7 +862,7 @@ Backend *pty_backend_create(
|
||||
{
|
||||
int slavefd;
|
||||
pid_t pid, pgrp;
|
||||
#ifndef NOT_X_WINDOWS /* for Mac OS X native compilation */
|
||||
#ifndef NOT_X_WINDOWS /* for Mac OS X native compilation */
|
||||
bool got_windowid;
|
||||
long windowid;
|
||||
#endif
|
||||
@ -873,13 +873,13 @@ Backend *pty_backend_create(
|
||||
seat_set_trust_status(seat, false);
|
||||
|
||||
if (single_pty) {
|
||||
pty = single_pty;
|
||||
pty = single_pty;
|
||||
assert(pty->conf == NULL);
|
||||
} else {
|
||||
pty = new_pty_struct();
|
||||
pty->master_fd = pty->slave_fd = -1;
|
||||
pty = new_pty_struct();
|
||||
pty->master_fd = pty->slave_fd = -1;
|
||||
#ifndef OMIT_UTMP
|
||||
pty_stamped_utmp = false;
|
||||
pty_stamped_utmp = false;
|
||||
#endif
|
||||
}
|
||||
for (i = 0; i < 6; i++)
|
||||
@ -968,7 +968,7 @@ Backend *pty_backend_create(
|
||||
add234(ptyfds, &pty->fds[0]);
|
||||
}
|
||||
|
||||
#ifndef NOT_X_WINDOWS /* for Mac OS X native compilation */
|
||||
#ifndef NOT_X_WINDOWS /* for Mac OS X native compilation */
|
||||
got_windowid = seat_get_windowid(pty->seat, &windowid);
|
||||
#endif
|
||||
|
||||
@ -983,16 +983,16 @@ Backend *pty_backend_create(
|
||||
*/
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
perror("fork");
|
||||
exit(1);
|
||||
perror("fork");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
struct termios attrs;
|
||||
|
||||
/*
|
||||
* We are the child.
|
||||
*/
|
||||
/*
|
||||
* We are the child.
|
||||
*/
|
||||
|
||||
if (pty_osx_envrestore_prefix) {
|
||||
int plen = strlen(pty_osx_envrestore_prefix);
|
||||
@ -1082,34 +1082,34 @@ Backend *pty_backend_create(
|
||||
}
|
||||
}
|
||||
|
||||
setpgid(pgrp, pgrp);
|
||||
setpgid(pgrp, pgrp);
|
||||
if (!pipes_instead) {
|
||||
int ptyfd = open(pty->name, O_WRONLY, 0);
|
||||
if (ptyfd >= 0)
|
||||
close(ptyfd);
|
||||
}
|
||||
setpgid(pgrp, pgrp);
|
||||
setpgid(pgrp, pgrp);
|
||||
|
||||
if (env_vars_to_unset)
|
||||
for (const char *const *p = env_vars_to_unset; *p; p++)
|
||||
unsetenv(*p);
|
||||
|
||||
if (!pipes_instead) {
|
||||
char *term_env_var = dupprintf("TERM=%s",
|
||||
conf_get_str(conf, CONF_termtype));
|
||||
putenv(term_env_var);
|
||||
/* We mustn't free term_env_var, as putenv links it into the
|
||||
* environment in place.
|
||||
*/
|
||||
}
|
||||
#ifndef NOT_X_WINDOWS /* for Mac OS X native compilation */
|
||||
if (got_windowid) {
|
||||
char *windowid_env_var = dupprintf("WINDOWID=%ld", windowid);
|
||||
putenv(windowid_env_var);
|
||||
/* We mustn't free windowid_env_var, as putenv links it into the
|
||||
* environment in place.
|
||||
*/
|
||||
}
|
||||
if (!pipes_instead) {
|
||||
char *term_env_var = dupprintf("TERM=%s",
|
||||
conf_get_str(conf, CONF_termtype));
|
||||
putenv(term_env_var);
|
||||
/* We mustn't free term_env_var, as putenv links it into the
|
||||
* environment in place.
|
||||
*/
|
||||
}
|
||||
#ifndef NOT_X_WINDOWS /* for Mac OS X native compilation */
|
||||
if (got_windowid) {
|
||||
char *windowid_env_var = dupprintf("WINDOWID=%ld", windowid);
|
||||
putenv(windowid_env_var);
|
||||
/* We mustn't free windowid_env_var, as putenv links it into the
|
||||
* environment in place.
|
||||
*/
|
||||
}
|
||||
{
|
||||
/*
|
||||
* In case we were invoked with a --display argument that
|
||||
@ -1128,22 +1128,22 @@ Backend *pty_backend_create(
|
||||
}
|
||||
}
|
||||
#endif
|
||||
{
|
||||
char *key, *val;
|
||||
{
|
||||
char *key, *val;
|
||||
|
||||
for (val = conf_get_str_strs(conf, CONF_environmt, NULL, &key);
|
||||
val != NULL;
|
||||
val = conf_get_str_strs(conf, CONF_environmt, key, &key)) {
|
||||
char *varval = dupcat(key, "=", val, NULL);
|
||||
putenv(varval);
|
||||
/*
|
||||
* We must not free varval, since putenv links it
|
||||
* into the environment _in place_. Weird, but
|
||||
* there we go. Memory usage will be rationalised
|
||||
* as soon as we exec anyway.
|
||||
*/
|
||||
}
|
||||
}
|
||||
for (val = conf_get_str_strs(conf, CONF_environmt, NULL, &key);
|
||||
val != NULL;
|
||||
val = conf_get_str_strs(conf, CONF_environmt, key, &key)) {
|
||||
char *varval = dupcat(key, "=", val, NULL);
|
||||
putenv(varval);
|
||||
/*
|
||||
* We must not free varval, since putenv links it
|
||||
* into the environment _in place_. Weird, but
|
||||
* there we go. Memory usage will be rationalised
|
||||
* as soon as we exec anyway.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
if (dir) {
|
||||
if (chdir(dir) < 0) {
|
||||
@ -1152,18 +1152,18 @@ Backend *pty_backend_create(
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* SIGINT, SIGQUIT and SIGPIPE may have been set to ignored by
|
||||
* our parent, particularly by things like sh -c 'pterm &' and
|
||||
* some window or session managers. SIGPIPE was also
|
||||
* (potentially) blocked by us during startup. Reverse all
|
||||
* this for our child process.
|
||||
*/
|
||||
putty_signal(SIGINT, SIG_DFL);
|
||||
putty_signal(SIGQUIT, SIG_DFL);
|
||||
putty_signal(SIGPIPE, SIG_DFL);
|
||||
block_signal(SIGPIPE, false);
|
||||
if (argv || cmd) {
|
||||
/*
|
||||
* SIGINT, SIGQUIT and SIGPIPE may have been set to ignored by
|
||||
* our parent, particularly by things like sh -c 'pterm &' and
|
||||
* some window or session managers. SIGPIPE was also
|
||||
* (potentially) blocked by us during startup. Reverse all
|
||||
* this for our child process.
|
||||
*/
|
||||
putty_signal(SIGINT, SIG_DFL);
|
||||
putty_signal(SIGQUIT, SIG_DFL);
|
||||
putty_signal(SIGPIPE, SIG_DFL);
|
||||
block_signal(SIGPIPE, false);
|
||||
if (argv || cmd) {
|
||||
/*
|
||||
* If we were given a separated argument list, try to exec
|
||||
* it.
|
||||
@ -1207,31 +1207,31 @@ Backend *pty_backend_create(
|
||||
execl(shell, shell, "-c", cmd, (void *)NULL);
|
||||
}
|
||||
} else {
|
||||
char *shell = getenv("SHELL");
|
||||
char *shellname;
|
||||
if (conf_get_bool(conf, CONF_login_shell)) {
|
||||
char *p = strrchr(shell, '/');
|
||||
shellname = snewn(2+strlen(shell), char);
|
||||
p = p ? p+1 : shell;
|
||||
sprintf(shellname, "-%s", p);
|
||||
} else
|
||||
shellname = shell;
|
||||
execl(getenv("SHELL"), shellname, (void *)NULL);
|
||||
}
|
||||
char *shell = getenv("SHELL");
|
||||
char *shellname;
|
||||
if (conf_get_bool(conf, CONF_login_shell)) {
|
||||
char *p = strrchr(shell, '/');
|
||||
shellname = snewn(2+strlen(shell), char);
|
||||
p = p ? p+1 : shell;
|
||||
sprintf(shellname, "-%s", p);
|
||||
} else
|
||||
shellname = shell;
|
||||
execl(getenv("SHELL"), shellname, (void *)NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we're here, exec has gone badly foom.
|
||||
*/
|
||||
perror("exec");
|
||||
_exit(127);
|
||||
/*
|
||||
* If we're here, exec has gone badly foom.
|
||||
*/
|
||||
perror("exec");
|
||||
_exit(127);
|
||||
} else {
|
||||
pty->child_pid = pid;
|
||||
pty->child_dead = false;
|
||||
pty->finished = false;
|
||||
if (pty->slave_fd > 0)
|
||||
close(pty->slave_fd);
|
||||
if (!ptys_by_pid)
|
||||
ptys_by_pid = newtree234(pty_compare_by_pid);
|
||||
pty->child_pid = pid;
|
||||
pty->child_dead = false;
|
||||
pty->finished = false;
|
||||
if (pty->slave_fd > 0)
|
||||
close(pty->slave_fd);
|
||||
if (!ptys_by_pid)
|
||||
ptys_by_pid = newtree234(pty_compare_by_pid);
|
||||
if (pty->pipefds[0] >= 0) {
|
||||
close(pty->pipefds[0]);
|
||||
pty->pipefds[0] = -1;
|
||||
@ -1244,16 +1244,16 @@ Backend *pty_backend_create(
|
||||
close(pty->pipefds[5]);
|
||||
pty->pipefds[5] = -1;
|
||||
}
|
||||
add234(ptys_by_pid, pty);
|
||||
add234(ptys_by_pid, pty);
|
||||
}
|
||||
|
||||
if (pty_signal_pipe[0] < 0) {
|
||||
if (pipe(pty_signal_pipe) < 0) {
|
||||
perror("pipe");
|
||||
exit(1);
|
||||
}
|
||||
cloexec(pty_signal_pipe[0]);
|
||||
cloexec(pty_signal_pipe[1]);
|
||||
if (pipe(pty_signal_pipe) < 0) {
|
||||
perror("pipe");
|
||||
exit(1);
|
||||
}
|
||||
cloexec(pty_signal_pipe[0]);
|
||||
cloexec(pty_signal_pipe[1]);
|
||||
}
|
||||
pty_uxsel_setup(pty);
|
||||
|
||||
@ -1336,7 +1336,7 @@ static void pty_try_write(Pty *pty)
|
||||
|
||||
while (bufchain_size(&pty->output_data) > 0) {
|
||||
ptrlen data = bufchain_prefix(&pty->output_data);
|
||||
ret = write(pty->master_i, data.ptr, data.len);
|
||||
ret = write(pty->master_i, data.ptr, data.len);
|
||||
|
||||
if (ret < 0 && (errno == EWOULDBLOCK)) {
|
||||
/*
|
||||
@ -1344,11 +1344,11 @@ static void pty_try_write(Pty *pty)
|
||||
*/
|
||||
break;
|
||||
}
|
||||
if (ret < 0) {
|
||||
perror("write pty master");
|
||||
exit(1);
|
||||
}
|
||||
bufchain_consume(&pty->output_data, ret);
|
||||
if (ret < 0) {
|
||||
perror("write pty master");
|
||||
exit(1);
|
||||
}
|
||||
bufchain_consume(&pty->output_data, ret);
|
||||
}
|
||||
|
||||
if (pty->pending_eof && bufchain_size(&pty->output_data) == 0) {
|
||||
@ -1373,7 +1373,7 @@ static size_t pty_send(Backend *be, const char *buf, size_t len)
|
||||
Pty *pty = container_of(be, Pty, backend);
|
||||
|
||||
if (pty->master_i < 0 || pty->pending_eof)
|
||||
return 0; /* ignore all writes if fd closed */
|
||||
return 0; /* ignore all writes if fd closed */
|
||||
|
||||
bufchain_add(&pty->output_data, buf, len);
|
||||
pty_try_write(pty);
|
||||
@ -1393,8 +1393,8 @@ static void pty_close(Pty *pty)
|
||||
uxsel_del(pty->master_i);
|
||||
|
||||
if (pty->master_fd >= 0) {
|
||||
close(pty->master_fd);
|
||||
pty->master_fd = -1;
|
||||
close(pty->master_fd);
|
||||
pty->master_fd = -1;
|
||||
}
|
||||
for (i = 0; i < 6; i++) {
|
||||
if (pty->pipefds[i] >= 0)
|
||||
@ -1404,8 +1404,8 @@ static void pty_close(Pty *pty)
|
||||
pty->master_i = pty->master_o = pty->master_e = -1;
|
||||
#ifndef OMIT_UTMP
|
||||
if (pty_utmp_helper_pipe >= 0) {
|
||||
close(pty_utmp_helper_pipe); /* this causes utmp to be cleaned up */
|
||||
pty_utmp_helper_pipe = -1;
|
||||
close(pty_utmp_helper_pipe); /* this causes utmp to be cleaned up */
|
||||
pty_utmp_helper_pipe = -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1536,7 +1536,7 @@ static int pty_exitcode(Backend *be)
|
||||
{
|
||||
Pty *pty = container_of(be, Pty, backend);
|
||||
if (!pty->finished)
|
||||
return -1; /* not dead yet */
|
||||
return -1; /* not dead yet */
|
||||
else if (WIFSIGNALED(pty->exit_code))
|
||||
return 128 + WTERMSIG(pty->exit_code);
|
||||
else
|
||||
@ -1548,7 +1548,7 @@ int pty_backend_exit_signum(Backend *be)
|
||||
Pty *pty = container_of(be, Pty, backend);
|
||||
|
||||
if (!pty->finished || !WIFSIGNALED(pty->exit_code))
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
return WTERMSIG(pty->exit_code);
|
||||
}
|
||||
@ -1559,7 +1559,7 @@ ptrlen pty_backend_exit_signame(Backend *be, char **aux_msg)
|
||||
|
||||
int sig = pty_backend_exit_signum(be);
|
||||
if (sig < 0)
|
||||
return PTRLEN_LITERAL("");
|
||||
return PTRLEN_LITERAL("");
|
||||
|
||||
#define TRANSLATE_SIGNAL(s) do \
|
||||
{ \
|
||||
|
Reference in New Issue
Block a user