libbb: code shrink by factoring out common update_utmp_DEAD_PROCESS
authorDenys Vlasenko <vda.linux@googlemail.com>
Mon, 5 Jan 2015 14:37:58 +0000 (15:37 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 5 Jan 2015 14:37:58 +0000 (15:37 +0100)
function                                             old     new   delta
update_utmp_DEAD_PROCESS                               -      17     +17
telnetd_main                                        1685    1674     -11
mark_terminated                                       56      45     -11
handle_sigchld                                        74      63     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
include/libbb.h
init/init.c
libbb/utmp.c
loginutils/login.c
networking/telnetd.c

index 68a7cf002fdd964f38b58182641d3479564ce3ac..be792d6b277b372b7c35b8c0a76892ceeeb0fd01 100644 (file)
@@ -921,9 +921,11 @@ void die_if_bad_username(const char* name) FAST_FUNC;
 #if ENABLE_FEATURE_UTMP
 void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname);
 void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname);
+void FAST_FUNC update_utmp_DEAD_PROCESS(pid_t pid);
 #else
 # define write_new_utmp(pid, new_type, tty_name, username, hostname) ((void)0)
 # define update_utmp(pid, new_type, tty_name, username, hostname) ((void)0)
+# define update_utmp_DEAD_PROCESS(pid) ((void)0)
 #endif
 
 
index d99d68ce446f115af49eae744db03216095a1b55..b2fe85635eb2275569edecc1187b81a63576cfb5 100644 (file)
@@ -538,11 +538,7 @@ static struct init_action *mark_terminated(pid_t pid)
        struct init_action *a;
 
        if (pid > 0) {
-               update_utmp(pid, DEAD_PROCESS,
-                               /*tty_name:*/ NULL,
-                               /*username:*/ NULL,
-                               /*hostname:*/ NULL
-               );
+               update_utmp_DEAD_PROCESS(pid);
                for (a = init_action_list; a; a = a->next) {
                        if (a->pid == pid) {
                                a->pid = 0;
index 09443fb6c42b1b58232176ed3250e1a487f93d8c..8ad9ba27ef74726cb2b1312384fb1d32a8156bce 100644 (file)
@@ -130,3 +130,17 @@ void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const
        updwtmp(bb_path_wtmp_file, &utent);
 #endif
 }
+
+/* man utmp:
+ * When init(8) finds that a process has exited, it locates its utmp entry
+ * by ut_pid, sets ut_type to DEAD_PROCESS, and clears ut_user, ut_host
+ * and ut_time with null bytes.
+ * [same applies to other processes which maintain utmp entries, like telnetd]
+ *
+ * We do not bother actually clearing fields:
+ * it might be interesting to know who was logged in and from where
+ */
+void FAST_FUNC update_utmp_DEAD_PROCESS(pid_t pid)
+{
+       update_utmp(pid, DEAD_PROCESS, NULL, NULL, NULL);
+}
index a4b19ccfc3d2ab44f07354e999ddaed2c78cde57..b9d910331e0a97bae3e91cc77f9cc1006730ee79 100644 (file)
@@ -454,7 +454,7 @@ int login_main(int argc UNUSED_PARAM, char **argv)
                else {
                        if (safe_waitpid(child_pid, NULL, 0) == -1)
                                bb_perror_msg("waitpid");
-                       update_utmp(child_pid, DEAD_PROCESS, NULL, NULL, NULL);
+                       update_utmp_DEAD_PROCESS(child_pid);
                }
                IF_PAM(login_pam_end(pamh);)
                return 0;
index 9e7a84cce200c2bfa2cf62d1493bed60cf1d2732..6aee95871d8f0bee95cda9b4c722688efd9cd8ab 100644 (file)
@@ -462,15 +462,7 @@ static void handle_sigchld(int sig UNUSED_PARAM)
                while (ts) {
                        if (ts->shell_pid == pid) {
                                ts->shell_pid = -1;
-// man utmp:
-// When init(8) finds that a process has exited, it locates its utmp entry
-// by ut_pid, sets ut_type to DEAD_PROCESS, and clears ut_user, ut_host
-// and ut_time with null bytes.
-// [same applies to other processes which maintain utmp entries, like telnetd]
-//
-// We do not bother actually clearing fields:
-// it might be interesting to know who was logged in and from where
-                               update_utmp(pid, DEAD_PROCESS, /*tty_name:*/ NULL, /*username:*/ NULL, /*hostname:*/ NULL);
+                               update_utmp_DEAD_PROCESS(pid);
                                break;
                        }
                        ts = ts->next;
@@ -739,7 +731,7 @@ int telnetd_main(int argc UNUSED_PARAM, char **argv)
                continue;
  kill_session:
                if (ts->shell_pid > 0)
-                       update_utmp(ts->shell_pid, DEAD_PROCESS, /*tty_name:*/ NULL, /*username:*/ NULL, /*hostname:*/ NULL);
+                       update_utmp_DEAD_PROCESS(ts->shell_pid);
                free_session(ts);
                ts = next;
        }