1 /* vi: set sw=4 ts=4: */
4 * Bjorn Wesen, Axis Communications AB (bjornw@axis.com)
6 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 * ---------------------------------------------------------------------------
9 * (C) Copyright 2000, Axis Communications AB, LUND, SWEDEN
10 ****************************************************************************
12 * The telnetd manpage says it all:
14 * Telnetd operates by allocating a pseudo-terminal device (see pty(4)) for
15 * a client, then creating a login process which has the slave side of the
16 * pseudo-terminal as stdin, stdout, and stderr. Telnetd manipulates the
17 * master side of the pseudo-terminal, implementing the telnet protocol and
18 * passing characters between the remote client and the login process.
20 * Vladimir Oleynik <dzo@simtreas.ru> 2001
21 * Set process group corrections, initial busybox port
24 //usage:#define telnetd_trivial_usage
26 //usage:#define telnetd_full_usage "\n\n"
27 //usage: "Handle incoming telnet connections"
28 //usage: IF_NOT_FEATURE_TELNETD_STANDALONE(" via inetd") "\n"
29 //usage: "\n -l LOGIN Exec LOGIN on connect"
30 //usage: "\n -f ISSUE_FILE Display ISSUE_FILE instead of /etc/issue"
31 //usage: "\n -K Close connection as soon as login exits"
32 //usage: "\n (normally wait until all programs close slave pty)"
33 //usage: IF_FEATURE_TELNETD_STANDALONE(
34 //usage: "\n -p PORT Port to listen on"
35 //usage: "\n -b ADDR[:PORT] Address to bind to"
36 //usage: "\n -F Run in foreground"
37 //usage: "\n -i Inetd mode"
38 //usage: IF_FEATURE_TELNETD_INETD_WAIT(
39 //usage: "\n -w SEC Inetd 'wait' mode, linger time SEC"
40 //usage: "\n -S Log to syslog (implied by -i or without -F and -w)"
47 #include "common_bufsiz.h"
54 #include <arpa/telnet.h>
58 struct tsession *next;
63 smallint buffered_IAC_for_pty;
65 /* two circular buffers */
66 /*char *buf1, *buf2;*/
67 /*#define TS_BUF1(ts) ts->buf1*/
68 /*#define TS_BUF2(ts) TS_BUF2(ts)*/
69 #define TS_BUF1(ts) ((unsigned char*)(ts + 1))
70 #define TS_BUF2(ts) (((unsigned char*)(ts + 1)) + BUFSIZE)
71 int rdidx1, wridx1, size1;
72 int rdidx2, wridx2, size2;
75 /* Two buffers are directly after tsession in malloced memory.
76 * Make whole thing fit in 4k */
77 enum { BUFSIZE = (4 * 1024 - sizeof(struct tsession)) / 2 };
82 struct tsession *sessions;
83 const char *loginpath;
84 const char *issuefile;
87 #define G (*(struct globals*)bb_common_bufsiz1)
88 #define INIT_G() do { \
89 setup_common_bufsiz(); \
90 G.loginpath = "/bin/login"; \
91 G.issuefile = "/etc/issue.net"; \
95 /* Write some buf1 data to pty, processing IACs.
96 * Update wridx1 and size1. Return < 0 on error.
97 * Buggy if IAC is present but incomplete: skips them.
100 safe_write_to_pty_decode_iac(struct tsession *ts)
105 unsigned char *found;
107 buf = TS_BUF1(ts) + ts->wridx1;
108 wr = MIN(BUFSIZE - ts->wridx1, ts->size1);
109 /* wr is at least 1 here */
111 if (ts->buffered_IAC_for_pty) {
112 /* Last time we stopped on a "dangling" IAC byte.
113 * We removed it from the buffer back then.
114 * Now pretend it's still there, and jump to IAC processing.
116 ts->buffered_IAC_for_pty = 0;
119 buf--; /* Yes, this can point before the buffer. It's ok */
124 found = memchr(buf, IAC, wr);
126 /* There is a "prefix" of non-IAC chars.
127 * Write only them, and return.
132 /* We map \r\n ==> \r for pragmatic reasons:
133 * many client implementations send \r\n when
134 * the user hits the CarriageReturn key.
135 * See RFC 1123 3.3.1 Telnet End-of-Line Convention.
138 found = memchr(buf, '\r', wr);
140 rc = found - buf + 1;
141 rc = safe_write(ts->ptyfd, buf, rc);
144 if (rc < wr /* don't look past available data */
145 && buf[rc-1] == '\r' /* need this: imagine that write was _short_ */
146 && (buf[rc] == '\n' || buf[rc] == '\0')
150 goto update_and_return;
153 /* buf starts with IAC char. Process that sequence.
154 * Example: we get this from our own (bbox) telnet client:
155 * read(5, "\377\374\1""\377\373\37""\377\372\37\0\262\0@\377\360""\377\375\1""\377\375\3"):
156 * IAC WONT ECHO, IAC WILL NAWS, IAC SB NAWS <cols> <rows> IAC SE, IAC DO SGA
157 * Another example (telnet-0.17 from old-netkit):
158 * read(4, "\377\375\3""\377\373\30""\377\373\37""\377\373 ""\377\373!""\377\373\"""\377\373'"
159 * "\377\375\5""\377\373#""\377\374\1""\377\372\37\0\257\0I\377\360""\377\375\1"):
160 * IAC DO SGA, IAC WILL TTYPE, IAC WILL NAWS, IAC WILL TSPEED, IAC WILL LFLOW, IAC WILL LINEMODE, IAC WILL NEW_ENVIRON,
161 * IAC DO STATUS, IAC WILL XDISPLOC, IAC WONT ECHO, IAC SB NAWS <cols> <rows> IAC SE, IAC DO ECHO
164 /* Only the single IAC byte is in the buffer, eat it
165 * and set a flag "process the rest of the sequence
166 * next time we are here".
168 //bb_error_msg("dangling IAC!");
169 ts->buffered_IAC_for_pty = 1;
171 goto update_and_return;
175 /* 2-byte commands (240..250 and 255):
176 * IAC IAC (255) Literal 255. Supported.
177 * IAC SE (240) End of subnegotiation. Treated as NOP.
178 * IAC NOP (241) NOP. Supported.
179 * IAC BRK (243) Break. Like serial line break. TODO via tcsendbreak()?
180 * IAC AYT (246) Are you there. Send back evidence that AYT was seen. TODO (send NOP back)?
181 * These don't look useful:
182 * IAC DM (242) Data mark. What is this?
183 * IAC IP (244) Suspend, interrupt or abort the process. (Ancient cousin of ^C).
184 * IAC AO (245) Abort output. "You can continue running, but do not send me the output".
185 * IAC EC (247) Erase character. The receiver should delete the last received char.
186 * IAC EL (248) Erase line. The receiver should delete everything up tp last newline.
187 * IAC GA (249) Go ahead. For half-duplex lines: "now you talk".
188 * Implemented only as part of NAWS:
189 * IAC SB (250) Subnegotiation of an option follows.
192 /* Literal 255 (emacs M-DEL) */
193 //bb_error_msg("255!");
194 rc = safe_write(ts->ptyfd, &buf[1], 1);
198 goto update_and_return;
200 if (buf[1] >= 240 && buf[1] <= 249) {
201 /* NOP (241). Ignore (putty keepalive, etc) */
202 /* All other 2-byte commands also treated as NOPs here */
204 goto update_and_return;
208 /* BUG: only 2 bytes of the IAC is in the buffer, we just eat them.
209 * This is not a practical problem since >2 byte IACs are seen only
210 * in initial negotiation, when buffer is empty
213 goto update_and_return;
217 if (buf[2] == TELOPT_NAWS) {
218 /* IAC SB, TELOPT_NAWS, 4-byte, IAC SE */
221 /* BUG: incomplete, can't process */
223 goto update_and_return;
225 memset(&ws, 0, sizeof(ws)); /* pixel sizes are set to 0 */
226 ws.ws_col = (buf[3] << 8) | buf[4];
227 ws.ws_row = (buf[5] << 8) | buf[6];
228 ioctl(ts->ptyfd, TIOCSWINSZ, (char *)&ws);
230 /* trailing IAC SE will be eaten separately, as 2-byte NOP */
231 goto update_and_return;
233 /* else: other subnegs not supported yet */
236 /* Assume it is a 3-byte WILL/WONT/DO/DONT 251..254 command and skip it */
238 fprintf(stderr, "Ignoring IAC %s,%s\n",
239 TELCMD(buf[1]), TELOPT(buf[2]));
245 if (ts->wridx1 >= BUFSIZE) /* actually == BUFSIZE */
249 * Hack. We cannot process IACs which wrap around buffer's end.
250 * Since properly fixing it requires writing bigger code,
251 * we rely instead on this code making it virtually impossible
252 * to have wrapped IAC (people don't type at 2k/second).
253 * It also allows for bigger reads in common case.
255 if (ts->size1 == 0) { /* very typical */
256 //bb_error_msg("zero size1");
262 if (wr != 0 && wr < ts->rdidx1) {
263 /* Buffer is not wrapped yet.
264 * We can easily move it to the beginning.
266 //bb_error_msg("moved %d", wr);
267 memmove(TS_BUF1(ts), TS_BUF1(ts) + wr, ts->size1);
275 * Converting single IAC into double on output
277 static size_t safe_write_double_iac(int fd, const char *buf, size_t count)
280 size_t wr, rc, total;
286 if (*buf == (char)IAC) {
287 static const char IACIAC[] ALIGN1 = { IAC, IAC };
288 rc = safe_write(fd, IACIAC, 2);
289 /* BUG: if partial write was only 1 byte long, we end up emitting just one IAC */
297 /* count != 0, *buf != IAC */
298 IACptr = memchr(buf, IAC, count);
302 rc = safe_write(fd, buf, wr);
309 /* here: rc - result of last short write */
310 if ((ssize_t)rc < 0) { /* error? */
318 /* Must match getopt32 string */
320 OPT_WATCHCHILD = (1 << 2), /* -K */
321 OPT_INETD = (1 << 3) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -i */
322 OPT_PORT = (1 << 4) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -p PORT */
323 OPT_FOREGROUND = (1 << 6) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -F */
324 OPT_SYSLOG = (1 << 7) * ENABLE_FEATURE_TELNETD_INETD_WAIT, /* -S */
325 OPT_WAIT = (1 << 8) * ENABLE_FEATURE_TELNETD_INETD_WAIT, /* -w SEC */
328 static struct tsession *
330 IF_FEATURE_TELNETD_STANDALONE(int sock)
331 IF_NOT_FEATURE_TELNETD_STANDALONE(void)
333 #if !ENABLE_FEATURE_TELNETD_STANDALONE
336 const char *login_argv[2];
337 struct termios termbuf;
339 char tty_name[GETPTY_BUFSIZE];
340 struct tsession *ts = xzalloc(sizeof(struct tsession) + BUFSIZE * 2);
342 /*ts->buf1 = (char *)(ts + 1);*/
343 /*ts->buf2 = ts->buf1 + BUFSIZE;*/
345 /* Got a new connection, set up a tty */
346 fd = xgetpty(tty_name);
351 close_on_exec_on(fd);
353 /* SO_KEEPALIVE by popular demand */
354 setsockopt_keepalive(sock);
355 #if ENABLE_FEATURE_TELNETD_STANDALONE
356 ts->sockfd_read = sock;
358 if (sock == 0) { /* We are called with fd 0 - we are in inetd mode */
359 sock++; /* so use fd 1 for output */
362 ts->sockfd_write = sock;
366 /* ts->sockfd_read = 0; - done by xzalloc */
367 ts->sockfd_write = 1;
372 /* Make the telnet client understand we will echo characters so it
373 * should not do it locally. We don't tell the client to run linemode,
374 * because we want to handle line editing and tab completion and other
375 * stuff that requires char-by-char support. */
377 static const char iacs_to_send[] ALIGN1 = {
378 IAC, DO, TELOPT_ECHO,
379 IAC, DO, TELOPT_NAWS,
380 /* This requires telnetd.ctrlSQ.patch (incomplete) */
381 /*IAC, DO, TELOPT_LFLOW,*/
382 IAC, WILL, TELOPT_ECHO,
383 IAC, WILL, TELOPT_SGA
385 /* This confuses safe_write_double_iac(), it will try to duplicate
387 //memcpy(TS_BUF2(ts), iacs_to_send, sizeof(iacs_to_send));
388 //ts->rdidx2 = sizeof(iacs_to_send);
389 //ts->size2 = sizeof(iacs_to_send);
390 /* So just stuff it into TCP stream! (no error check...) */
391 #if ENABLE_FEATURE_TELNETD_STANDALONE
392 safe_write(sock, iacs_to_send, sizeof(iacs_to_send));
394 safe_write(1, iacs_to_send, sizeof(iacs_to_send));
396 /*ts->rdidx2 = 0; - xzalloc did it */
401 pid = vfork(); /* NOMMU-friendly */
405 /* sock will be closed by caller */
406 bb_perror_msg("vfork");
416 /* Careful - we are after vfork! */
418 /* Restore default signal handling ASAP */
419 bb_signals((1 << SIGCHLD) + (1 << SIGPIPE), SIG_DFL);
423 if (ENABLE_FEATURE_UTMP) {
424 len_and_sockaddr *lsa = get_peer_lsa(sock);
425 char *hostname = NULL;
427 hostname = xmalloc_sockaddr2dotted(&lsa->u.sa);
430 write_new_utmp(pid, LOGIN_PROCESS, tty_name, /*username:*/ "LOGIN", hostname);
434 /* Make new session and process group */
437 /* Open the child's side of the tty */
438 /* NB: setsid() disconnects from any previous ctty's. Therefore
439 * we must open child's side of the tty AFTER setsid! */
441 xopen(tty_name, O_RDWR); /* becomes our ctty */
444 tcsetpgrp(0, pid); /* switch this tty's process group to us */
446 /* The pseudo-terminal allocated to the client is configured to operate
447 * in cooked mode, and with XTABS CRMOD enabled (see tty(4)) */
448 tcgetattr(0, &termbuf);
449 termbuf.c_lflag |= ECHO; /* if we use readline we dont want this */
450 termbuf.c_oflag |= ONLCR | XTABS;
451 termbuf.c_iflag |= ICRNL;
452 termbuf.c_iflag &= ~IXOFF;
453 /*termbuf.c_lflag &= ~ICANON;*/
454 tcsetattr_stdin_TCSANOW(&termbuf);
456 /* Uses FILE-based I/O to stdout, but does fflush_all(),
457 * so should be safe with vfork.
458 * I fear, though, that some users will have ridiculously big
459 * issue files, and they may block writing to fd 1,
460 * (parent is supposed to read it, but parent waits
461 * for vforked child to exec!) */
462 print_login_issue(G.issuefile, tty_name);
464 /* Exec shell / login / whatever */
465 login_argv[0] = G.loginpath;
466 login_argv[1] = NULL;
467 /* exec busybox applet (if PREFER_APPLETS=y), if that fails,
468 * exec external program.
469 * NB: sock is either 0 or has CLOEXEC set on it.
470 * fd has CLOEXEC set on it too. These two fds will be closed here.
472 BB_EXECVP(G.loginpath, (char **)login_argv);
473 /* _exit is safer with vfork, and we shouldn't send message
474 * to remote clients anyway */
475 _exit(EXIT_FAILURE); /*bb_perror_msg_and_die("execv %s", G.loginpath);*/
478 #if ENABLE_FEATURE_TELNETD_STANDALONE
481 free_session(struct tsession *ts)
485 if (option_mask32 & OPT_INETD)
488 /* Unlink this telnet session from the session list */
491 G.sessions = ts->next;
493 while (t->next != ts)
499 /* It was said that "normal" telnetd just closes ptyfd,
500 * doesn't send SIGKILL. When we close ptyfd,
501 * kernel sends SIGHUP to processes having slave side opened. */
502 kill(ts->shell_pid, SIGKILL);
503 waitpid(ts->shell_pid, NULL, 0);
506 close(ts->sockfd_read);
507 /* We do not need to close(ts->sockfd_write), it's the same
508 * as sockfd_read unless we are in inetd mode. But in inetd mode
509 * we do not reach this */
512 /* Scan all sessions and find new maxfd */
516 if (G.maxfd < ts->ptyfd)
518 if (G.maxfd < ts->sockfd_read)
519 G.maxfd = ts->sockfd_read;
521 /* Again, sockfd_write == sockfd_read here */
522 if (G.maxfd < ts->sockfd_write)
523 G.maxfd = ts->sockfd_write;
529 #else /* !FEATURE_TELNETD_STANDALONE */
531 /* Used in main() only, thus "return 0" actually is exit(EXIT_SUCCESS). */
532 #define free_session(ts) return 0
536 static void handle_sigchld(int sig UNUSED_PARAM)
540 int save_errno = errno;
542 /* Looping: more than one child may have exited */
544 pid = wait_any_nohang(NULL);
549 if (ts->shell_pid == pid) {
551 update_utmp_DEAD_PROCESS(pid);
561 int telnetd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
562 int telnetd_main(int argc UNUSED_PARAM, char **argv)
564 fd_set rdfdset, wrfdset;
568 #if ENABLE_FEATURE_TELNETD_STANDALONE
569 #define IS_INETD (opt & OPT_INETD)
570 int master_fd = master_fd; /* for compiler */
571 int sec_linger = sec_linger;
572 char *opt_bindaddr = NULL;
582 /* -w NUM, and implies -F. -w and -i don't mix */
583 IF_FEATURE_TELNETD_INETD_WAIT(opt_complementary = "wF:i--w:w--i";)
584 /* Even if !STANDALONE, we accept (and ignore) -i, thus people
585 * don't need to guess whether it's ok to pass -i to us */
586 opt = getopt32(argv, "f:l:Ki"
587 IF_FEATURE_TELNETD_STANDALONE("p:b:F")
588 IF_FEATURE_TELNETD_INETD_WAIT("Sw:+"),
589 &G.issuefile, &G.loginpath
590 IF_FEATURE_TELNETD_STANDALONE(, &opt_portnbr, &opt_bindaddr)
591 IF_FEATURE_TELNETD_INETD_WAIT(, &sec_linger)
593 if (!IS_INETD /*&& !re_execed*/) {
594 /* inform that we start in standalone mode?
595 * May be useful when people forget to give -i */
596 /*bb_error_msg("listening for connections");*/
597 if (!(opt & OPT_FOREGROUND)) {
598 /* DAEMON_CHDIR_ROOT was giving inconsistent
599 * behavior with/without -F, -i */
600 bb_daemonize_or_rexec(0 /*was DAEMON_CHDIR_ROOT*/, argv);
603 /* Redirect log to syslog early, if needed */
604 if (IS_INETD || (opt & OPT_SYSLOG) || !(opt & OPT_FOREGROUND)) {
605 openlog(applet_name, LOG_PID, LOG_DAEMON);
606 logmode = LOGMODE_SYSLOG;
608 #if ENABLE_FEATURE_TELNETD_STANDALONE
610 G.sessions = make_new_session(0);
611 if (!G.sessions) /* pty opening or vfork problem, exit */
612 return 1; /* make_new_session printed error message */
615 if (!(opt & OPT_WAIT)) {
616 unsigned portnbr = 23;
618 portnbr = xatou16(opt_portnbr);
619 master_fd = create_and_bind_stream_or_die(opt_bindaddr, portnbr);
620 xlisten(master_fd, 1);
622 close_on_exec_on(master_fd);
625 G.sessions = make_new_session();
626 if (!G.sessions) /* pty opening or vfork problem, exit */
627 return 1; /* make_new_session printed error message */
630 /* We don't want to die if just one session is broken */
631 signal(SIGPIPE, SIG_IGN);
633 if (opt & OPT_WATCHCHILD)
634 signal(SIGCHLD, handle_sigchld);
635 else /* prevent dead children from becoming zombies */
636 signal(SIGCHLD, SIG_IGN);
639 This is how the buffers are used. The arrows indicate data flow.
641 +-------+ wridx1++ +------+ rdidx1++ +----------+
642 | | <-------------- | buf1 | <-------------- | |
643 | | size1-- +------+ size1++ | |
645 | | rdidx2++ +------+ wridx2++ | |
646 | | --------------> | buf2 | --------------> | |
647 +-------+ size2++ +------+ size2-- +----------+
649 size1: "how many bytes are buffered for pty between rdidx1 and wridx1?"
650 size2: "how many bytes are buffered for socket between rdidx2 and wridx2?"
652 Each session has got two buffers. Buffers are circular. If sizeN == 0,
653 buffer is empty. If sizeN == BUFSIZE, buffer is full. In both these cases
660 /* Select on the master socket, all telnet sockets and their
661 * ptys if there is room in their session buffers.
662 * NB: scalability problem: we recalculate entire bitmap
663 * before each select. Can be a problem with 500+ connections. */
666 struct tsession *next = ts->next; /* in case we free ts */
667 if (ts->shell_pid == -1) {
668 /* Child died and we detected that */
671 if (ts->size1 > 0) /* can write to pty */
672 FD_SET(ts->ptyfd, &wrfdset);
673 if (ts->size1 < BUFSIZE) /* can read from socket */
674 FD_SET(ts->sockfd_read, &rdfdset);
675 if (ts->size2 > 0) /* can write to socket */
676 FD_SET(ts->sockfd_write, &wrfdset);
677 if (ts->size2 < BUFSIZE) /* can read from pty */
678 FD_SET(ts->ptyfd, &rdfdset);
683 FD_SET(master_fd, &rdfdset);
684 /* This is needed because free_session() does not
685 * take master_fd into account when it finds new
686 * maxfd among remaining fd's */
687 if (master_fd > G.maxfd)
692 struct timeval *tv_ptr = NULL;
693 #if ENABLE_FEATURE_TELNETD_INETD_WAIT
695 if ((opt & OPT_WAIT) && !G.sessions) {
696 tv.tv_sec = sec_linger;
701 count = select(G.maxfd + 1, &rdfdset, &wrfdset, NULL, tv_ptr);
703 if (count == 0) /* "telnetd -w SEC" timed out */
706 goto again; /* EINTR or ENOMEM */
708 #if ENABLE_FEATURE_TELNETD_STANDALONE
709 /* Check for and accept new sessions */
710 if (!IS_INETD && FD_ISSET(master_fd, &rdfdset)) {
712 struct tsession *new_ts;
714 fd = accept(master_fd, NULL, NULL);
717 close_on_exec_on(fd);
719 /* Create a new session and link it into active list */
720 new_ts = make_new_session(fd);
722 new_ts->next = G.sessions;
730 /* Then check for data tunneling */
732 while (ts) { /* For all sessions... */
733 struct tsession *next = ts->next; /* in case we free ts */
735 if (/*ts->size1 &&*/ FD_ISSET(ts->ptyfd, &wrfdset)) {
736 /* Write to pty from buffer 1 */
737 count = safe_write_to_pty_decode_iac(ts);
745 if (/*ts->size2 &&*/ FD_ISSET(ts->sockfd_write, &wrfdset)) {
746 /* Write to socket from buffer 2 */
747 count = MIN(BUFSIZE - ts->wridx2, ts->size2);
748 count = safe_write_double_iac(ts->sockfd_write, (void*)(TS_BUF2(ts) + ts->wridx2), count);
755 if (ts->wridx2 >= BUFSIZE) /* actually == BUFSIZE */
758 if (ts->size2 == 0) {
765 if (/*ts->size1 < BUFSIZE &&*/ FD_ISSET(ts->sockfd_read, &rdfdset)) {
766 /* Read from socket to buffer 1 */
767 count = MIN(BUFSIZE - ts->rdidx1, BUFSIZE - ts->size1);
768 count = safe_read(ts->sockfd_read, TS_BUF1(ts) + ts->rdidx1, count);
770 if (count < 0 && errno == EAGAIN)
774 /* Ignore trailing NUL if it is there */
775 if (!TS_BUF1(ts)[ts->rdidx1 + count - 1]) {
780 if (ts->rdidx1 >= BUFSIZE) /* actually == BUFSIZE */
784 if (/*ts->size2 < BUFSIZE &&*/ FD_ISSET(ts->ptyfd, &rdfdset)) {
785 /* Read from pty to buffer 2 */
786 count = MIN(BUFSIZE - ts->rdidx2, BUFSIZE - ts->size2);
787 count = safe_read(ts->ptyfd, TS_BUF2(ts) + ts->rdidx2, count);
789 if (count < 0 && errno == EAGAIN)
795 if (ts->rdidx2 >= BUFSIZE) /* actually == BUFSIZE */
802 if (ts->shell_pid > 0)
803 update_utmp_DEAD_PROCESS(ts->shell_pid);