diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-01-05 15:37:58 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-01-05 15:37:58 +0100 |
commit | da9212667c99f2f2121747c4715d067deb7c155b (patch) | |
tree | 66a670e6d78ca899a454a42228abbbc2740fad0d | |
parent | 08b90a9d10f2f712c6e16c118328d85930762b92 (diff) | |
download | busybox-w32-da9212667c99f2f2121747c4715d067deb7c155b.tar.gz busybox-w32-da9212667c99f2f2121747c4715d067deb7c155b.tar.bz2 busybox-w32-da9212667c99f2f2121747c4715d067deb7c155b.zip |
libbb: code shrink by factoring out common update_utmp_DEAD_PROCESS
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>
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | init/init.c | 6 | ||||
-rw-r--r-- | libbb/utmp.c | 14 | ||||
-rw-r--r-- | loginutils/login.c | 2 | ||||
-rw-r--r-- | networking/telnetd.c | 12 |
5 files changed, 20 insertions, 16 deletions
diff --git a/include/libbb.h b/include/libbb.h index 68a7cf002..be792d6b2 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -921,9 +921,11 @@ void die_if_bad_username(const char* name) FAST_FUNC; | |||
921 | #if ENABLE_FEATURE_UTMP | 921 | #if ENABLE_FEATURE_UTMP |
922 | void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname); | 922 | void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname); |
923 | void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname); | 923 | void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname); |
924 | void FAST_FUNC update_utmp_DEAD_PROCESS(pid_t pid); | ||
924 | #else | 925 | #else |
925 | # define write_new_utmp(pid, new_type, tty_name, username, hostname) ((void)0) | 926 | # define write_new_utmp(pid, new_type, tty_name, username, hostname) ((void)0) |
926 | # define update_utmp(pid, new_type, tty_name, username, hostname) ((void)0) | 927 | # define update_utmp(pid, new_type, tty_name, username, hostname) ((void)0) |
928 | # define update_utmp_DEAD_PROCESS(pid) ((void)0) | ||
927 | #endif | 929 | #endif |
928 | 930 | ||
929 | 931 | ||
diff --git a/init/init.c b/init/init.c index d99d68ce4..b2fe85635 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -538,11 +538,7 @@ static struct init_action *mark_terminated(pid_t pid) | |||
538 | struct init_action *a; | 538 | struct init_action *a; |
539 | 539 | ||
540 | if (pid > 0) { | 540 | if (pid > 0) { |
541 | update_utmp(pid, DEAD_PROCESS, | 541 | update_utmp_DEAD_PROCESS(pid); |
542 | /*tty_name:*/ NULL, | ||
543 | /*username:*/ NULL, | ||
544 | /*hostname:*/ NULL | ||
545 | ); | ||
546 | for (a = init_action_list; a; a = a->next) { | 542 | for (a = init_action_list; a; a = a->next) { |
547 | if (a->pid == pid) { | 543 | if (a->pid == pid) { |
548 | a->pid = 0; | 544 | a->pid = 0; |
diff --git a/libbb/utmp.c b/libbb/utmp.c index 09443fb6c..8ad9ba27e 100644 --- a/libbb/utmp.c +++ b/libbb/utmp.c | |||
@@ -130,3 +130,17 @@ void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const | |||
130 | updwtmp(bb_path_wtmp_file, &utent); | 130 | updwtmp(bb_path_wtmp_file, &utent); |
131 | #endif | 131 | #endif |
132 | } | 132 | } |
133 | |||
134 | /* man utmp: | ||
135 | * When init(8) finds that a process has exited, it locates its utmp entry | ||
136 | * by ut_pid, sets ut_type to DEAD_PROCESS, and clears ut_user, ut_host | ||
137 | * and ut_time with null bytes. | ||
138 | * [same applies to other processes which maintain utmp entries, like telnetd] | ||
139 | * | ||
140 | * We do not bother actually clearing fields: | ||
141 | * it might be interesting to know who was logged in and from where | ||
142 | */ | ||
143 | void FAST_FUNC update_utmp_DEAD_PROCESS(pid_t pid) | ||
144 | { | ||
145 | update_utmp(pid, DEAD_PROCESS, NULL, NULL, NULL); | ||
146 | } | ||
diff --git a/loginutils/login.c b/loginutils/login.c index a4b19ccfc..b9d910331 100644 --- a/loginutils/login.c +++ b/loginutils/login.c | |||
@@ -454,7 +454,7 @@ int login_main(int argc UNUSED_PARAM, char **argv) | |||
454 | else { | 454 | else { |
455 | if (safe_waitpid(child_pid, NULL, 0) == -1) | 455 | if (safe_waitpid(child_pid, NULL, 0) == -1) |
456 | bb_perror_msg("waitpid"); | 456 | bb_perror_msg("waitpid"); |
457 | update_utmp(child_pid, DEAD_PROCESS, NULL, NULL, NULL); | 457 | update_utmp_DEAD_PROCESS(child_pid); |
458 | } | 458 | } |
459 | IF_PAM(login_pam_end(pamh);) | 459 | IF_PAM(login_pam_end(pamh);) |
460 | return 0; | 460 | return 0; |
diff --git a/networking/telnetd.c b/networking/telnetd.c index 9e7a84cce..6aee95871 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -462,15 +462,7 @@ static void handle_sigchld(int sig UNUSED_PARAM) | |||
462 | while (ts) { | 462 | while (ts) { |
463 | if (ts->shell_pid == pid) { | 463 | if (ts->shell_pid == pid) { |
464 | ts->shell_pid = -1; | 464 | ts->shell_pid = -1; |
465 | // man utmp: | 465 | update_utmp_DEAD_PROCESS(pid); |
466 | // When init(8) finds that a process has exited, it locates its utmp entry | ||
467 | // by ut_pid, sets ut_type to DEAD_PROCESS, and clears ut_user, ut_host | ||
468 | // and ut_time with null bytes. | ||
469 | // [same applies to other processes which maintain utmp entries, like telnetd] | ||
470 | // | ||
471 | // We do not bother actually clearing fields: | ||
472 | // it might be interesting to know who was logged in and from where | ||
473 | update_utmp(pid, DEAD_PROCESS, /*tty_name:*/ NULL, /*username:*/ NULL, /*hostname:*/ NULL); | ||
474 | break; | 466 | break; |
475 | } | 467 | } |
476 | ts = ts->next; | 468 | ts = ts->next; |
@@ -739,7 +731,7 @@ int telnetd_main(int argc UNUSED_PARAM, char **argv) | |||
739 | continue; | 731 | continue; |
740 | kill_session: | 732 | kill_session: |
741 | if (ts->shell_pid > 0) | 733 | if (ts->shell_pid > 0) |
742 | update_utmp(ts->shell_pid, DEAD_PROCESS, /*tty_name:*/ NULL, /*username:*/ NULL, /*hostname:*/ NULL); | 734 | update_utmp_DEAD_PROCESS(ts->shell_pid); |
743 | free_session(ts); | 735 | free_session(ts); |
744 | ts = next; | 736 | ts = next; |
745 | } | 737 | } |