| ︙ | | |
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
|
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
|
-
+
-
-
+
+
-
+
-
+
|
* 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 char *pty_init(void *frontend, void **backend_handle,
static char *pty_init(void *frontend, void **backend_handle, Config *cfg,
char *host, int port, char **realhost, int nodelay)
{
int slavefd;
pid_t pid, pgrp;
pty_frontend = frontend;
*backend_handle = NULL; /* we can't sensibly use this, sadly */
pty_term_width = cfg.width;
pty_term_height = cfg.height;
pty_term_width = cfg->width;
pty_term_height = cfg->height;
if (pty_master_fd < 0)
pty_open_master();
/*
* 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] = cfg.bksp_is_delete ? '\177' : '\010';
attrs.c_cc[VERASE] = cfg->bksp_is_delete ? '\177' : '\010';
tcsetattr(pty_master_fd, TCSANOW, &attrs);
}
/*
* 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 {
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);
if (ret < 0) {
|
| ︙ | | |
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
|
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
|
-
-
+
+
-
+
|
setpgrp();
close(open(pty_name, O_WRONLY, 0));
setpgrp();
/* Close everything _else_, for tidiness. */
for (i = 3; i < 1024; i++)
close(i);
{
char term_env_var[10 + sizeof(cfg.termtype)];
sprintf(term_env_var, "TERM=%s", cfg.termtype);
char term_env_var[10 + sizeof(cfg->termtype)];
sprintf(term_env_var, "TERM=%s", cfg->termtype);
putenv(term_env_var);
}
/*
* SIGINT and SIGQUIT may have been set to ignored by our
* parent, particularly by things like sh -c 'pterm &' and
* some window managers. Reverse this for our child process.
*/
putty_signal(SIGINT, SIG_DFL);
putty_signal(SIGQUIT, SIG_DFL);
if (pty_argv)
execvp(pty_argv[0], pty_argv);
else {
char *shell = getenv("SHELL");
char *shellname;
if (cfg.login_shell) {
if (cfg->login_shell) {
char *p = strrchr(shell, '/');
shellname = smalloc(2+strlen(shell));
p = p ? p+1 : shell;
sprintf(shellname, "-%s", p);
} else
shellname = shell;
execl(getenv("SHELL"), shellname, NULL);
|
| ︙ | | |
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
|
+
+
+
+
+
+
+
|
} else {
pty_child_pid = pid;
pty_child_dead = FALSE;
}
return NULL;
}
/*
* Stub routine (we don't have any need to reconfigure this backend).
*/
static void pty_reconfig(void *handle, Config *cfg)
{
}
/*
* Called to send data down the pty.
*/
static int pty_send(void *handle, char *buf, int len)
{
if (pty_master_fd < 0)
|
| ︙ | | |
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
|
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
|
+
|
return -1; /* not dead yet */
else
return pty_exit_code;
}
Backend pty_backend = {
pty_init,
pty_reconfig,
pty_send,
pty_sendbuffer,
pty_size,
pty_special,
pty_socket,
pty_exitcode,
pty_sendok,
pty_ldisc,
pty_provide_ldisc,
pty_provide_logctx,
pty_unthrottle,
1
};
|