+void done_with_pty(struct gui_data *inst)
+{
+ extern void pty_close(void);
+
+ if (inst->master_fd >= 0) {
+ pty_close();
+ inst->master_fd = -1;
+ gtk_input_remove(inst->master_func_id);
+ }
+
+ if (!inst->exited && back->exitcode() >= 0) {
+ int exitcode = back->exitcode();
+ int clean;
+
+ clean = WIFEXITED(exitcode) && (WEXITSTATUS(exitcode) == 0);
+
+ /*
+ * Terminate now, if the Close On Exit setting is
+ * appropriate.
+ */
+ if (cfg.close_on_exit == COE_ALWAYS ||
+ (cfg.close_on_exit == COE_NORMAL && clean))
+ exit(0);
+
+ /*
+ * Otherwise, output an indication that the session has
+ * closed.
+ */
+ {
+ char message[512];
+ if (WIFEXITED(exitcode))
+ sprintf(message, "\r\n[pterm: process terminated with exit"
+ " code %d]\r\n", WEXITSTATUS(exitcode));
+ else if (WIFSIGNALED(exitcode))
+#ifdef HAVE_NO_STRSIGNAL
+ sprintf(message, "\r\n[pterm: process terminated on signal"
+ " %d]\r\n", WTERMSIG(exitcode));
+#else
+ sprintf(message, "\r\n[pterm: process terminated on signal"
+ " %d (%.400s)]\r\n", WTERMSIG(exitcode),
+ strsignal(WTERMSIG(exitcode)));
+#endif
+ from_backend((void *)term, 0, message, strlen(message));
+ }
+ inst->exited = 1;
+ }
+}
+
+void frontend_keypress(void)
+{
+ /*
+ * If our child process has exited but not closed, terminate on
+ * any keypress.
+ */
+ if (inst->exited)
+ exit(0);
+}
+