static struct utmp utmp_entry;
#endif
char **pty_argv;
+int use_pty_argv = TRUE;
static void pty_close(void);
#endif
struct passwd *pw;
FILE *wtmp;
+ time_t uttime;
pw = getpwuid(getuid());
memset(&utmp_entry, 0, sizeof(utmp_entry));
strncpy(utmp_entry.ut_id, ttyname+8, lenof(utmp_entry.ut_id));
strncpy(utmp_entry.ut_user, pw->pw_name, lenof(utmp_entry.ut_user));
strncpy(utmp_entry.ut_host, location, lenof(utmp_entry.ut_host));
- time(&utmp_entry.ut_time);
+ /* Apparently there are some architectures where (struct utmp).ut_time
+ * is not essentially time_t (e.g. Linux amd64). Hence the temporary. */
+ time(&uttime);
+ utmp_entry.ut_time = uttime; /* may truncate */
#if defined HAVE_PUTUTLINE
utmpname(UTMP_FILE);
{
#ifndef OMIT_UTMP
FILE *wtmp;
+ time_t uttime;
if (!pty_stamped_utmp)
return;
utmp_entry.ut_type = DEAD_PROCESS;
memset(utmp_entry.ut_user, 0, lenof(utmp_entry.ut_user));
- time(&utmp_entry.ut_time);
+ time(&uttime);
+ utmp_entry.ut_time = uttime;
if ((wtmp = fopen(WTMP_FILE, "a")) != NULL) {
fwrite(&utmp_entry, 1, sizeof(utmp_entry), wtmp);
* Also places the canonical host name into `realhost'. It must be
* freed by the caller.
*/
-static char *pty_init(void *frontend, void **backend_handle, Config *cfg,
- char *host, int port, char **realhost, int nodelay)
+static const char *pty_init(void *frontend, void **backend_handle, Config *cfg,
+ char *host, int port, char **realhost, int nodelay,
+ int keepalive)
{
int slavefd;
pid_t pid, pgrp;
* Stamp utmp (that is, tell the utmp helper process to do so),
* or not.
*/
- if (!cfg->stamp_utmp)
+ if (!cfg->stamp_utmp) {
close(pty_utmp_helper_pipe); /* just let the child process die */
- else {
+ pty_utmp_helper_pipe = -1;
+ } else {
char *location = get_x_display(pty_frontend);
int len = strlen(location)+1, pos = 0; /* +1 to include NUL */
while (pos < len) {
if (ret < 0) {
perror("pterm: writing to utmp helper process");
close(pty_utmp_helper_pipe); /* arrgh, just give up */
+ pty_utmp_helper_pipe = -1;
break;
}
pos += ret;
sprintf(windowid_env_var, "WINDOWID=%ld", windowid);
putenv(windowid_env_var);
}
+ {
+ char *e = cfg->environmt;
+ char *var, *varend, *val, *varval;
+ while (*e) {
+ var = e;
+ while (*e && *e != '\t') e++;
+ varend = e;
+ if (*e == '\t') e++;
+ val = e;
+ while (*e) e++;
+ e++;
+
+ varval = dupprintf("%.*s=%s", varend-var, var, val);
+ 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.
+ */
+ }
+ }
+
/*
* SIGINT and SIGQUIT may have been set to ignored by our
* parent, particularly by things like sh -c 'pterm &' and
return NULL;
}
-/*
- * Stub routine (we don't have any need to reconfigure this backend).
- */
static void pty_reconfig(void *handle, Config *cfg)
{
+ /*
+ * We don't have much need to reconfigure this backend, but
+ * unfortunately we do need to pick up the setting of Close On
+ * Exit so we know whether to give a `terminated' message.
+ */
+ pty_cfg = *cfg; /* structure copy */
}
/*
- * Stub routine (never called in pterm
+ * Stub routine (never called in pterm).
*/
static void pty_free(void *handle)
{
}
-
/*
* Called to send data down the pty.
*/
close(pty_master_fd);
pty_master_fd = -1;
}
- close(pty_utmp_helper_pipe); /* this causes utmp to be cleaned up */
+ if (pty_utmp_helper_pipe >= 0) {
+ close(pty_utmp_helper_pipe); /* this causes utmp to be cleaned up */
+ pty_utmp_helper_pipe = -1;
+ }
}
/*
return;
}
+/*
+ * Return a list of the special codes that make sense in this
+ * protocol.
+ */
+static const struct telnet_special *pty_get_specials(void *handle)
+{
+ /*
+ * Hmm. When I get round to having this actually usable, it
+ * might be quite nice to have the ability to deliver a few
+ * well chosen signals to the child process - SIGINT, SIGTERM,
+ * SIGKILL at least.
+ */
+ return NULL;
+}
+
static Socket pty_socket(void *handle)
{
return NULL; /* shouldn't ever be needed */
pty_sendbuffer,
pty_size,
pty_special,
+ pty_get_specials,
pty_socket,
pty_exitcode,
pty_sendok,