| ︙ | | |
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
-
+
|
/*
* The pty_signal_pipe, along with the SIGCHLD handler, must be
* process-global rather than session-specific.
*/
static int pty_signal_pipe[2] = { -1, -1 }; /* obviously bogus initial val */
struct pty_tag {
Config cfg;
Conf *conf;
int master_fd, slave_fd;
void *frontend;
char name[FILENAME_MAX];
pid_t child_pid;
int term_width, term_height;
int child_dead, finished;
int exit_code;
|
| ︙ | | |
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
|
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
|
+
+
+
-
-
+
+
|
* Attempt to send data down the pty.
*/
pty_try_write(pty);
}
}
if (finished && !pty->finished) {
int close_on_exit;
uxsel_del(pty->master_fd);
pty_close(pty);
pty->master_fd = -1;
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 (pty->cfg.close_on_exit == FORCE_OFF ||
(pty->cfg.close_on_exit == AUTO && pty->exit_code != 0)) {
if (close_on_exit == FORCE_OFF ||
(close_on_exit == AUTO && pty->exit_code != 0)) {
char message[512];
if (WIFEXITED(pty->exit_code))
sprintf(message, "\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
sprintf(message, "\r\n[pterm: process terminated on signal"
|
| ︙ | | |
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
|
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
|
-
+
|
* Called to set up the pty.
*
* Returns an error message, or NULL on success.
*
* Also places the canonical host name into `realhost'. It must be
* freed by the caller.
*/
static const char *pty_init(void *frontend, void **backend_handle, Config *cfg,
static const char *pty_init(void *frontend, void **backend_handle, Conf *conf,
char *host, int port, char **realhost, int nodelay,
int keepalive)
{
int slavefd;
pid_t pid, pgrp;
#ifndef NOT_X_WINDOWS /* for Mac OS X native compilation */
long windowid;
|
| ︙ | | |
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
|
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
|
-
-
-
+
+
+
+
-
+
-
+
|
pty_stamped_utmp = FALSE;
#endif
}
pty->frontend = frontend;
*backend_handle = NULL; /* we can't sensibly use this, sadly */
pty->cfg = *cfg; /* structure copy */
pty->term_width = cfg->width;
pty->term_height = cfg->height;
pty->conf = conf_copy(conf);
pty->term_width = conf_get_int(conf, CONF_width);
pty->term_height = conf_get_int(conf, CONF_height);
if (pty->master_fd < 0)
pty_open_master(pty);
/*
* Set the backspace character to be whichever of ^H and ^? is
* specified by bksp_is_delete.
*/
{
struct termios attrs;
tcgetattr(pty->master_fd, &attrs);
attrs.c_cc[VERASE] = conf_get_int(conf, CONF_bksp_is_delete)
attrs.c_cc[VERASE] = cfg->bksp_is_delete ? '\177' : '\010';
? '\177' : '\010';
tcsetattr(pty->master_fd, TCSANOW, &attrs);
}
#ifndef OMIT_UTMP
/*
* Stamp utmp (that is, tell the utmp helper process to do so),
* or not.
*/
if (!cfg->stamp_utmp) {
if (!conf_get_int(conf, CONF_stamp_utmp)) {
close(pty_utmp_helper_pipe); /* just let the child process die */
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) {
int ret = write(pty_utmp_helper_pipe, location+pos, len - pos);
|
| ︙ | | |
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
|
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
|
-
+
+
-
-
-
+
+
+
-
-
-
-
-
+
-
-
-
-
+
+
|
#endif
pgrp = getpid();
tcsetpgrp(0, pgrp);
setpgid(pgrp, pgrp);
close(open(pty->name, O_WRONLY, 0));
setpgid(pgrp, pgrp);
{
char *term_env_var = dupprintf("TERM=%s", cfg->termtype);
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 */
{
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.
*/
}
#endif
{
char *e = cfg->environmt;
char *var, *varend, *val, *varval;
while (*e) {
char *key, *val;
for (val = conf_get_str_strs(conf, CONF_environmt, NULL, &key);
var = e;
while (*e && *e != '\t') e++;
varend = e;
if (*e == '\t') e++;
val = e;
val != NULL;
while (*e) e++;
e++;
varval = dupprintf("%.*s=%s", varend-var, var, val);
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.
*/
|
| ︙ | | |
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
|
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
|
-
+
|
putty_signal(SIGPIPE, SIG_DFL);
block_signal(SIGCHLD, 0);
if (pty_argv)
execvp(pty_argv[0], pty_argv);
else {
char *shell = getenv("SHELL");
char *shellname;
if (cfg->login_shell) {
if (conf_get_int(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);
|
| ︙ | | |
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
|
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
|
-
+
-
+
|
*backend_handle = pty;
*realhost = dupprintf("\0");
return NULL;
}
static void pty_reconfig(void *handle, Config *cfg)
static void pty_reconfig(void *handle, Conf *conf)
{
Pty pty = (Pty)handle;
/*
* 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 */
conf_copy_into(pty->conf, conf);
}
/*
* Stub routine (never called in pterm).
*/
static void pty_free(void *handle)
{
|
| ︙ | | |