{
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;
#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;
}
int
telnetd_main(int argc, char **argv)
{
-#ifndef CONFIG_FEATURE_TELNETD_INETD
- sockaddr_type sa;
- int master_fd;
-#endif /* CONFIG_FEATURE_TELNETD_INETD */
+ unsigned opt;
fd_set rdfdset, wrfdset;
int selret;
#ifndef CONFIG_FEATURE_TELNETD_INETD
+ sockaddr_type sa;
+ int master_fd;
int on = 1;
- int portnbr = 23;
+ unsigned portnbr = 23;
struct in_addr bind_addr = { .s_addr = 0x0 };
-#endif /* CONFIG_FEATURE_TELNETD_INETD */
- int c;
- static const char options[] =
-#ifdef CONFIG_FEATURE_TELNETD_INETD
- "f:l:";
-#else /* CONFIG_EATURE_TELNETD_INETD */
- "f:l:p:b:";
+ char *opt_portnbr, *opt_bindaddr;
#endif /* CONFIG_FEATURE_TELNETD_INETD */
int maxlen, w, r;
* 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;
- for (;;) {
- c = getopt( argc, argv, options);
- if (c == EOF) break;
- switch (c) {
- case 'f':
- issuefile = optarg;
- break;
- case 'l':
- loginpath = optarg;
- break;
+ 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
- case 'p':
- portnbr = atoi(optarg);
- break;
- case 'b':
- if (inet_aton(optarg, &bind_addr) == 0)
- bb_show_usage();
- break;
+ 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 */
- default:
- bb_show_usage();
- }
- }
if (access(loginpath, X_OK) < 0) {
bb_error_msg_and_die("'%s' unavailable", loginpath);
maxfd = master_fd;
#endif /* CONFIG_FEATURE_TELNETD_INETD */
- do {
+ while(1) {
struct tsession *ts;
FD_ZERO(&rdfdset);
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
}
#endif /* CONFIG_FEATURE_TELNETD_INETD */
- } while (1);
+ } /* while(1) */
return 0;
}