}
}
- num_totty = totty - ptr0;
+ num_totty = totty - ptr0;
*pnum_totty = num_totty;
/* the difference between ptr and totty is number of iacs
we removed from the stream. Adjust buf1 accordingly. */
#if ENABLE_FEATURE_TELNETD_STANDALONE
ts->sockfd_read = sock;
ndelay_on(sock);
- if (!sock) /* We are called with fd 0 - we are in inetd mode */
- sock++;
+ if (!sock) { /* We are called with fd 0 - we are in inetd mode */
+ sock++; /* so use fd 1 for output */
+ ndelay_on(sock);
+ }
ts->sockfd_write = sock;
- ndelay_on(sock);
if (sock > maxfd)
maxfd = sock;
#else
if (pid < 0) {
free(ts);
close(fd);
- /* sock_r and sock_w will be closed by caller */
+ /* sock will be closed by caller */
bb_perror_msg("vfork");
return NULL;
}
_exit(1); /*bb_perror_msg_and_die("execv %s", loginpath);*/
}
+/* Must match getopt32 string */
+enum {
+ OPT_WATCHCHILD = (1 << 2), /* -K */
+ OPT_INETD = (1 << 3) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -i */
+ OPT_PORT = (1 << 4) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -p */
+ OPT_FOREGROUND = (1 << 6) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -F */
+};
+
#if ENABLE_FEATURE_TELNETD_STANDALONE
static void
{
struct tsession *t = sessions;
+ if (option_mask32 & OPT_INETD)
+ exit(0);
+
/* Unlink this telnet session from the session list */
if (t == ts)
sessions = ts->next;
close(ts->sockfd_read);
/* We do not need to close(ts->sockfd_write), it's the same
* as sockfd_read unless we are in inetd mode. But in inetd mode
- * we do not free_session(), ever */
+ * we do not reach this */
free(ts);
/* Scan all sessions and find new maxfd */
#else /* !FEATURE_TELNETD_STANDALONE */
-/* Never actually called */
-void free_session(struct tsession *ts);
+/* Used in main() only, thus exits. */
+#define free_session(ts) return 0
#endif
portnbr = 23,
};
#endif
- enum {
- OPT_WATCHCHILD = (1 << 2), /* -K */
- OPT_INETD = (1 << 3) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -i */
- OPT_PORT = (1 << 4) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -p */
- OPT_FOREGROUND = (1 << 6) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -F */
- };
-
/* Even if !STANDALONE, we accept (and ignore) -i, thus people
* don't need to guess whether it's ok to pass -i to us */
opt = getopt32(argv, "f:l:Ki" USE_FEATURE_TELNETD_STANDALONE("p:b:F"),
while (ts) {
struct tsession *next = ts->next; /* in case we free ts. */
if (ts->shell_pid == -1) {
+ /* Child died ad we detected that */
free_session(ts);
} else {
if (ts->size1 > 0) /* can write to pty */
if (count < 0) {
if (errno == EAGAIN)
goto skip1;
- if (IS_INETD)
- return 0;
goto kill_session;
}
ts->size1 -= count;
if (count < 0) {
if (errno == EAGAIN)
goto skip2;
- if (IS_INETD)
- return 0;
goto kill_session;
}
ts->size2 -= count;
if (count <= 0) {
if (count < 0 && errno == EAGAIN)
goto skip3;
- if (IS_INETD)
- return 0;
goto kill_session;
}
/* Ignore trailing NUL if it is there */
if (count <= 0) {
if (count < 0 && errno == EAGAIN)
goto skip4;
- if (IS_INETD)
- return 0;
goto kill_session;
}
ts->size2 += count;