#define _PATH_LOGIN "/bin/login"
-#ifdef linux
+ /* If USE_SYSLOG is undefined all diagnostics go directly to /dev/console. */
+#ifdef CONFIG_SYSLOGD
#include <sys/param.h>
#define USE_SYSLOG
-#endif
-
-extern void updwtmp(const char *filename, const struct utmp *ut);
-
- /* If USE_SYSLOG is undefined all diagnostics go directly to /dev/console. */
-#ifdef USE_SYSLOG
#include <syslog.h>
#endif
#ifdef LOGIN_PROCESS /* defined in System V utmp.h */
#define SYSV_STYLE /* select System V style getty */
+#ifdef CONFIG_FEATURE_U_W_TMP
+extern void updwtmp(const char *filename, const struct utmp *ut);
#endif
+#endif /* LOGIN_PROCESS */
/*
* Things you may want to modify.
#include <time.h>
#endif
-#define LOGIN " login: " /* login prompt */
-
/* Some shorthands for control characters. */
#define CTL(x) (x ^ 0100) /* Assumes ASCII dialect */
0, /* no capslock */
};
+#if 0
struct Speedtab {
long speed;
int code;
#endif
{0, 0},
};
+#endif
static void parse_args(int argc, char **argv, struct options *op);
static void parse_speeds(struct options *op, char *arg);
-static void update_utmp(char *line);
static void open_tty(char *tty, struct termio *tp, int local);
static void termio_init(struct termio *tp, int speed, struct options *op);
static void auto_baud(struct termio *tp);
static int bcode(const char *s);
static void error(const char *fmt, ...) __attribute__ ((noreturn));
+#ifdef CONFIG_FEATURE_U_W_TMP
+static void update_utmp(char *line);
+#endif
+
/* The following is used for understandable diagnostics. */
/* Fake hostname for ut_host specified on command line. */
};
#ifdef DEBUGGING
- dbf = xfopen(DEBUGTERM, "w");
+ dbf = bb_xfopen(DEBUGTERM, "w");
{
int i;
/* Update the utmp file. */
+
#ifdef SYSV_STYLE
+#ifdef CONFIG_FEATURE_U_W_TMP
update_utmp(options.tty);
+#endif
#endif
debug("calling open_tty\n");
switch (c) {
case 'I':
if (!(op->initstring = strdup(optarg)))
- error("can't malloc initstring");
+ error(bb_msg_memory_exhausted);
{
- char ch, *p, *q;
- int i;
+ const char *p;
+ char *q;
/* copy optarg into op->initstring decoding \ddd
octal codes into chars */
q = op->initstring;
p = optarg;
while (*p) {
- if (*p == '\\') { /* know \\ means \ */
+ if (*p == '\\') {
p++;
- if (*p == '\\') {
- ch = '\\';
- p++;
- } else { /* handle \000 - \177 */
- ch = 0;
- for (i = 1; i <= 3; i++) {
- if (*p >= '0' && *p <= '7') {
- ch <<= 3;
- ch += *p - '0';
- p++;
- } else
- break;
- }
- }
- *q++ = ch;
+ *q++ = bb_process_escape_sequence(&p);
} else {
*q++ = *p++;
}
op->flags |= F_WAITCRLF;
break;
default:
- show_usage();
+ bb_show_usage();
}
}
debug("after getopt loop\n");
if (argc < optind + 2) /* check parameter count */
- show_usage();
+ bb_show_usage();
/* we loosen up a bit and accept both "baudrate tty" and "tty baudrate" */
if ('0' <= argv[optind][0] && argv[optind][0] <= '9') {
}
#ifdef SYSV_STYLE
+#ifdef CONFIG_FEATURE_U_W_TMP
/* update_utmp - update our utmp entry */
static void update_utmp(char *line)
}
}
-#endif
+#endif /* CONFIG_FEATURE_U_W_TMP */
+#endif /* SYSV_STYLE */
/* open_tty - set up tty as standard { input, output, error } */
static void open_tty(char *tty, struct termio *tp, int local)
/* do_prompt - show login prompt, optionally preceded by /etc/issue contents */
static void do_prompt(struct options *op, struct termio *tp)
{
-#ifdef ISSUE
- FILE *fd;
- int oflag;
- int c;
- struct utsname uts;
-
- (void) uname(&uts);
-#endif
-
- (void) write(1, "\r\n", 2); /* start a new line */
#ifdef ISSUE /* optional: show /etc/issue */
- if ((op->flags & F_ISSUE) && (fd = fopen(op->issue, "r"))) {
- oflag = tp->c_oflag; /* save current setting */
- tp->c_oflag |= (ONLCR | OPOST); /* map NL in output to CR-NL */
- (void) ioctl(0, TCSETAW, tp);
-
-
- while ((c = getc(fd)) != EOF) {
- if (c == '\\') {
- c = getc(fd);
-
- switch (c) {
- case 's':
- (void) printf("%s", uts.sysname);
- break;
-
- case 'n':
- (void) printf("%s", uts.nodename);
- break;
-
- case 'r':
- (void) printf("%s", uts.release);
- break;
-
- case 'v':
- (void) printf("%s", uts.version);
- break;
-
- case 'm':
- (void) printf("%s", uts.machine);
- break;
-
- case 'o':
- {
- char domainname[256];
-
- getdomainname(domainname, sizeof(domainname));
- domainname[sizeof(domainname) - 1] = '\0';
- printf("%s", domainname);
- }
- break;
-
- case 'd':
- case 't':
- {
- char *weekday[] = { "Sun", "Mon", "Tue", "Wed", "Thu",
- "Fri", "Sat"
- };
- char *month[] = { "Jan", "Feb", "Mar", "Apr", "May",
- "Jun", "Jul", "Aug", "Sep", "Oct",
- "Nov", "Dec"
- };
- time_t now;
- struct tm *tm;
-
- (void) time(&now);
- tm = localtime(&now);
-
- if (c == 'd')
- (void) printf("%s %s %d %d",
- weekday[tm->tm_wday],
- month[tm->tm_mon], tm->tm_mday,
- tm->tm_year <
- 70 ? tm->tm_year +
- 2000 : tm->tm_year + 1900);
- else
- (void) printf("%02d:%02d:%02d", tm->tm_hour,
- tm->tm_min, tm->tm_sec);
-
- break;
- }
-
- case 'l':
- (void) printf("%s", op->tty);
- break;
-
- case 'b':
- {
- int i;
-
- for (i = 0; speedtab[i].speed; i++) {
- if (speedtab[i].code == (tp->c_cflag & CBAUD)) {
- printf("%ld", speedtab[i].speed);
- break;
- }
- }
- break;
- }
- case 'u':
- case 'U':
- {
- int users = 0;
- struct utmp *ut;
-
- setutent();
- while ((ut = getutent()))
- if (ut->ut_type == USER_PROCESS)
- users++;
- endutent();
- printf("%d ", users);
- if (c == 'U')
- printf((users == 1) ? "user" : "users");
- break;
- }
- default:
- (void) putchar(c);
- }
- } else
- (void) putchar(c);
- }
- fflush(stdout);
-
- tp->c_oflag = oflag; /* restore settings */
- (void) ioctl(0, TCSETAW, tp); /* wait till output is gone */
- (void) fclose(fd);
- }
+ print_login_issue(op->issue, op->tty);
#endif
-#ifdef __linux__
- {
- char hn[MAXHOSTNAMELEN + 1];
-
- (void) gethostname(hn, MAXHOSTNAMELEN);
- write(1, hn, strlen(hn));
- }
-#endif
- (void) write(1, LOGIN, sizeof(LOGIN) - 1); /* always show login prompt */
+ print_login_prompt();
}
/* next_speed - select next baud rate */
tp->c_cc[VQUIT] = DEF_QUIT; /* default quit */
tp->c_cc[VEOF] = DEF_EOF; /* default EOF character */
tp->c_cc[VEOL] = DEF_EOL;
-#ifdef __linux__
tp->c_cc[VSWTC] = DEF_SWITCH; /* default switch character */
-#else
- tp->c_cc[VSWTCH] = DEF_SWITCH; /* default switch character */
-#endif
/* Account for special characters seen in input. */
/* bcode - convert speed string to speed code; return 0 on failure */
static int bcode(const char *s)
{
+#if 0
struct Speedtab *sp;
long speed = atol(s);
if (sp->speed == speed)
return (sp->code);
return (0);
+#else
+ int r;
+
+ if ((r = bb_value_to_baud(atol(s))) > 0) {
+ return r;
+ }
+ return 0;
+#endif
}
/* error - report errors to console or syslog; only understands %s and %m */
buf[0] = '\0';
bp = buf;
#else
- strncpy(buf, applet_name, 256);
+ strncpy(buf, bb_applet_name, 256);
strncat(buf, ": ", 256);
buf[255] = 0;
bp = buf + strlen(buf);