wget: add TODO
[oweals/busybox.git] / networking / telnetd.c
index 808d4be51271acef32a25bf80e33ad9f49ff8e41..da7911fcc88156807f4ff5a5c0e61d02006b70e2 100644 (file)
@@ -188,12 +188,18 @@ getpty(char *line)
 {
        int p;
 #ifdef CONFIG_FEATURE_DEVPTS
-       p = open("/dev/ptmx", 2);
+       p = open("/dev/ptmx", O_RDWR);
        if (p > 0) {
+               const char *name;
                grantpt(p);
                unlockpt(p);
-               strcpy(line, ptsname(p));
-               return(p);
+               name = ptsname(p);
+               if (!name) {
+                       bb_perror_msg("ptsname error (is /dev/pts mounted?)");
+                       return -1;
+               }
+               strcpy(line, name);
+               return p;
        }
 #else
        struct stat stb;
@@ -213,7 +219,8 @@ getpty(char *line)
 #ifdef DEBUG
                        fprintf(stderr, "Trying to open device: %s\n", line);
 #endif
-                       if ((p = open(line, O_RDWR | O_NOCTTY)) >= 0) {
+                       p = open(line, O_RDWR | O_NOCTTY);
+                       if (p >= 0) {
                                line[5] = 't';
                                return p;
                        }
@@ -369,7 +376,7 @@ telnetd_main(int argc, char **argv)
        sockaddr_type sa;
        int master_fd;
        int on = 1;
-       int portnbr = 23;
+       unsigned portnbr = 23;
        struct in_addr bind_addr = { .s_addr = 0x0 };
        char *opt_portnbr, *opt_bindaddr;
 #endif /* CONFIG_FEATURE_TELNETD_INETD */
@@ -384,16 +391,16 @@ telnetd_main(int argc, char **argv)
         * look into syslog for all errors, even early ones.
         * Direct all output to syslog at once.
         */
-       openlog(bb_applet_name, 0, LOG_USER);
+       openlog(applet_name, 0, LOG_USER);
        logmode = LOGMODE_SYSLOG;
 
-       opt = getopt32(argc, argv, "f:l:" USE_FEATURE_TELNETD_INETD("p:b:"),
+       opt = getopt32(argc, argv, "f:l:" SKIP_FEATURE_TELNETD_INETD("p:b:"),
                        &issuefile, &loginpath
                        SKIP_FEATURE_TELNETD_INETD(, &opt_portnbr, &opt_bindaddr));
        //if (opt & 1) // -f
        //if (opt & 2) // -l
 #ifndef CONFIG_FEATURE_TELNETD_INETD
-       if (opt & 4) portnbr = atoi(opt_portnbr); // -p
+       if (opt & 4) portnbr = xatou16(opt_portnbr); // -p
        if (opt & 8) // -b
                if (inet_aton(opt_bindaddr, &bind_addr) == 0) bb_show_usage();
 #endif /* CONFIG_FEATURE_TELNETD_INETD */
@@ -435,7 +442,7 @@ telnetd_main(int argc, char **argv)
        maxfd = master_fd;
 #endif /* CONFIG_FEATURE_TELNETD_INETD */
 
-       do {
+       while(1) {
                struct tsession *ts;
 
                FD_ZERO(&rdfdset);
@@ -493,8 +500,8 @@ telnetd_main(int argc, char **argv)
                        socklen_t salen;
 
                        salen = sizeof(sa);
-                       if ((fd = accept(master_fd, (struct sockaddr *)&sa,
-                                               &salen)) < 0) {
+                       fd = accept(master_fd, (struct sockaddr *)&sa, &salen);
+                       if (fd < 0) {
                                continue;
                        } else {
                                /* Create a new session and link it into
@@ -632,7 +639,7 @@ telnetd_main(int argc, char **argv)
                }
 #endif /* CONFIG_FEATURE_TELNETD_INETD */
 
-       } while (1);
+       } /* while(1) */
 
        return 0;
 }