From 37f5bef63c0db4892d8ffa3c38a04c7998e10f83 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 5 Apr 2010 03:18:40 +0200 Subject: libbb: split update_utmp from login/getty in preparation to use it for telnetd function old new delta update_utent - 339 +339 login_main 1498 1128 -370 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 339/-370) Total: -31 bytes function old new delta update_utmp 246 337 +91 login_main 1128 1140 +12 getty_main 1908 1918 +10 ... update_utent 339 - -339 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 5/6 up/down: 119/-368) Total: -249 bytes Signed-off-by: Denys Vlasenko --- loginutils/getty.c | 61 ++---------------------------------------------------- 1 file changed, 2 insertions(+), 59 deletions(-) (limited to 'loginutils/getty.c') diff --git a/loginutils/getty.c b/loginutils/getty.c index 20411b04c..8d1d5254e 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c @@ -19,7 +19,7 @@ #include #if ENABLE_FEATURE_UTMP -#include /* updwtmp() */ +#include /* LOGIN_PROCESS */ #endif #ifndef IUCLC @@ -575,61 +575,6 @@ static void termios_final(struct options *op, struct termios *tp, struct chardat ioctl_or_perror_and_die(0, TCSETS, tp, "%s: TCSETS", op->tty); } -#if ENABLE_FEATURE_UTMP -static void touch(const char *filename) -{ - if (access(filename, R_OK | W_OK) == -1) - close(open(filename, O_WRONLY | O_CREAT, 0664)); -} - -/* update_utmp - update our utmp entry */ -static NOINLINE void update_utmp(const char *line, char *fakehost) -{ - struct utmp ut; - struct utmp *utp; - int mypid = getpid(); - - /* In case we won't find an entry below... */ - memset(&ut, 0, sizeof(ut)); - safe_strncpy(ut.ut_id, line + 3, sizeof(ut.ut_id)); - - /* - * The utmp file holds miscellaneous information about things started by - * /sbin/init and other system-related events. Our purpose is to update - * the utmp entry for the current process, in particular the process type - * and the tty line we are listening to. Return successfully only if the - * utmp file can be opened for update, and if we are able to find our - * entry in the utmp file. - */ - touch(_PATH_UTMP); - - utmpname(_PATH_UTMP); - setutent(); - while ((utp = getutent()) != NULL) { - if (utp->ut_type == INIT_PROCESS && utp->ut_pid == mypid) { - memcpy(&ut, utp, sizeof(ut)); - break; - } - } - - strcpy(ut.ut_user, "LOGIN"); - safe_strncpy(ut.ut_line, line, sizeof(ut.ut_line)); - if (fakehost) - safe_strncpy(ut.ut_host, fakehost, sizeof(ut.ut_host)); - ut.ut_tv.tv_sec = time(NULL); - ut.ut_type = LOGIN_PROCESS; - ut.ut_pid = mypid; - - pututline(&ut); - endutent(); - -#if ENABLE_FEATURE_WTMP - touch(bb_path_wtmp_file); - updwtmp(bb_path_wtmp_file, &ut); -#endif -} -#endif /* CONFIG_FEATURE_UTMP */ - int getty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int getty_main(int argc UNUSED_PARAM, char **argv) { @@ -715,10 +660,8 @@ int getty_main(int argc UNUSED_PARAM, char **argv) tcsetpgrp(0, getpid()); #endif -#if ENABLE_FEATURE_UTMP /* Update the utmp file. This tty is ours now! */ - update_utmp(options.tty, fakehost); -#endif + update_utmp(LOGIN_PROCESS, options.tty, "LOGIN", fakehost); /* Initialize the termios settings (raw mode, eight-bit, blocking i/o). */ debug("calling termios_init\n"); -- cgit v1.2.3