|
|
1 | // This file is part of libptytty. Do not make local modifications. |
|
|
2 | // http://software.schmorp.de/pkg/libptytty |
|
|
3 | |
1 | /*--------------------------------*-C-*---------------------------------* |
4 | /*----------------------------------------------------------------------* |
2 | * File: ptytty.C |
5 | * File: ptytty.C |
3 | *----------------------------------------------------------------------* |
6 | *----------------------------------------------------------------------* |
4 | * |
7 | * |
5 | * All portions of code are copyright by their respective author/s. |
8 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com> |
9 | * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com> |
… | |
… | |
19 | * You should have received a copy of the GNU General Public License |
22 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
23 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
22 | *---------------------------------------------------------------------*/ |
25 | *---------------------------------------------------------------------*/ |
23 | |
26 | |
24 | #include "../config.h" /* NECESSARY */ |
27 | #include "../config.h" |
25 | |
28 | |
26 | #include "fdpass.h" |
29 | #include "fdpass.h" |
27 | #include "ptytty.h" |
30 | #include "ptytty.h" |
28 | |
31 | |
29 | #include <cstdlib> |
32 | #include <cstdlib> |
… | |
… | |
384 | bool login_shell; |
387 | bool login_shell; |
385 | int cmd_pid; |
388 | int cmd_pid; |
386 | char hostname[512]; // arbitrary, but should be plenty |
389 | char hostname[512]; // arbitrary, but should be plenty |
387 | }; |
390 | }; |
388 | |
391 | |
389 | struct ptytty_proxy : zero_initialized, ptytty |
392 | struct ptytty_proxy : ptytty |
390 | { |
393 | { |
391 | ptytty *id; |
394 | ptytty *id; |
|
|
395 | |
|
|
396 | ptytty_proxy () |
|
|
397 | : id(0) |
|
|
398 | { |
|
|
399 | } |
392 | |
400 | |
393 | ~ptytty_proxy (); |
401 | ~ptytty_proxy (); |
394 | |
402 | |
395 | bool get (); |
403 | bool get (); |
396 | void login (int cmd_pid, bool login_shell, const char *hostname); |
404 | void login (int cmd_pid, bool login_shell, const char *hostname); |
… | |
… | |
432 | write (sock_fd, &cmd, sizeof (cmd)); |
440 | write (sock_fd, &cmd, sizeof (cmd)); |
433 | } |
441 | } |
434 | |
442 | |
435 | ptytty_proxy::~ptytty_proxy () |
443 | ptytty_proxy::~ptytty_proxy () |
436 | { |
444 | { |
|
|
445 | if (id) |
|
|
446 | { |
437 | command cmd; |
447 | command cmd; |
438 | |
448 | |
439 | cmd.type = command::destroy; |
449 | cmd.type = command::destroy; |
440 | cmd.id = id; |
450 | cmd.id = id; |
441 | |
451 | |
442 | write (sock_fd, &cmd, sizeof (cmd)); |
452 | write (sock_fd, &cmd, sizeof (cmd)); |
|
|
453 | } |
443 | } |
454 | } |
444 | |
455 | |
445 | static |
456 | static |
446 | void serve () |
457 | void serve () |
447 | { |
458 | { |
… | |
… | |
511 | if (pid < 0) |
522 | if (pid < 0) |
512 | fatal ("could not create pty/sessiondb helper process, aborting.\n"); |
523 | fatal ("could not create pty/sessiondb helper process, aborting.\n"); |
513 | |
524 | |
514 | if (pid) |
525 | if (pid) |
515 | { |
526 | { |
516 | // client, urxvt |
527 | // client, process |
517 | sock_fd = sv[0]; |
528 | sock_fd = sv[0]; |
518 | close (sv[1]); |
529 | close (sv[1]); |
519 | fcntl (sock_fd, F_SETFD, FD_CLOEXEC); |
530 | fcntl (sock_fd, F_SETFD, FD_CLOEXEC); |
520 | } |
531 | } |
521 | else |
532 | else |