diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-12-23 23:36:47 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-12-23 23:36:47 +0000 |
commit | 4e12b1a2a9e68685dff61acaee1e1f6c377d978c (patch) | |
tree | 6d2745f77060d05f843eb186c5227246667d33cb | |
parent | b3523b9cd3ba71b82e36466b17aae3d65a53203e (diff) | |
download | busybox-w32-4e12b1a2a9e68685dff61acaee1e1f6c377d978c.tar.gz busybox-w32-4e12b1a2a9e68685dff61acaee1e1f6c377d978c.tar.bz2 busybox-w32-4e12b1a2a9e68685dff61acaee1e1f6c377d978c.zip |
libbb: introduce and use xmalloc_ttyname (-32 in bss).
ash: small code shrink
text data bss dec hex filename
793669 504 7524 801697 c3ba1 busybox_old
793659 504 7492 801655 c3b77 busybox_unstripped
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | coreutils/tty.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | init/mesg.c | 2 | ||||
-rw-r--r-- | libbb/xfuncs.c | 11 | ||||
-rw-r--r-- | loginutils/login.c | 8 | ||||
-rw-r--r-- | loginutils/su.c | 2 | ||||
-rw-r--r-- | selinux/sestatus.c | 5 | ||||
-rw-r--r-- | shell/ash.c | 6 |
9 files changed, 26 insertions, 13 deletions
@@ -23,7 +23,7 @@ Rob Landley suggested these: | |||
23 | lash is phased out. hush can be configured down to be nearly as small, | 23 | lash is phased out. hush can be configured down to be nearly as small, |
24 | but less buggy :) | 24 | but less buggy :) |
25 | init | 25 | init |
26 | General cleanup (should use ENABLE_FEATURE_INIT_SYSLOG and ENABLE_FEATURE_INIT_DEBUG). | 26 | General cleanup (should use ENABLE_FEATURE_INIT_SYSLOG). |
27 | Do a SUSv3 audit | 27 | Do a SUSv3 audit |
28 | Look at the full Single Unix Specification version 3 (available online at | 28 | Look at the full Single Unix Specification version 3 (available online at |
29 | "http://www.opengroup.org/onlinepubs/009695399/nfindex.html") and | 29 | "http://www.opengroup.org/onlinepubs/009695399/nfindex.html") and |
diff --git a/coreutils/tty.c b/coreutils/tty.c index e83289440..d49fb50b6 100644 --- a/coreutils/tty.c +++ b/coreutils/tty.c | |||
@@ -30,7 +30,7 @@ int tty_main(int argc, char **argv SKIP_INCLUDE_SUSv2(UNUSED_PARAM)) | |||
30 | 30 | ||
31 | retval = 0; | 31 | retval = 0; |
32 | 32 | ||
33 | s = ttyname(0); | 33 | s = xmalloc_ttyname(0); |
34 | if (s == NULL) { | 34 | if (s == NULL) { |
35 | /* According to SUSv3, ttyname can fail with EBADF or ENOTTY. | 35 | /* According to SUSv3, ttyname can fail with EBADF or ENOTTY. |
36 | * We know the file descriptor is good, so failure means not a tty. */ | 36 | * We know the file descriptor is good, so failure means not a tty. */ |
diff --git a/include/libbb.h b/include/libbb.h index e6767e39e..e0541a731 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1144,6 +1144,7 @@ const char *nth_string(const char *strings, int n) FAST_FUNC; | |||
1144 | extern void print_login_issue(const char *issue_file, const char *tty) FAST_FUNC; | 1144 | extern void print_login_issue(const char *issue_file, const char *tty) FAST_FUNC; |
1145 | extern void print_login_prompt(void) FAST_FUNC; | 1145 | extern void print_login_prompt(void) FAST_FUNC; |
1146 | 1146 | ||
1147 | char *xmalloc_ttyname(int fd) FAST_FUNC; | ||
1147 | /* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */ | 1148 | /* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */ |
1148 | int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FUNC; | 1149 | int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FUNC; |
1149 | 1150 | ||
diff --git a/init/mesg.c b/init/mesg.c index cfb517f60..ca230f363 100644 --- a/init/mesg.c +++ b/init/mesg.c | |||
@@ -25,7 +25,7 @@ int mesg_main(int argc, char **argv) | |||
25 | if (--argc == 0 | 25 | if (--argc == 0 |
26 | || (argc == 1 && ((c = **++argv) == 'y' || c == 'n')) | 26 | || (argc == 1 && ((c = **++argv) == 'y' || c == 'n')) |
27 | ) { | 27 | ) { |
28 | tty = ttyname(STDERR_FILENO); | 28 | tty = xmalloc_ttyname(STDERR_FILENO); |
29 | if (tty == NULL) { | 29 | if (tty == NULL) { |
30 | tty = "ttyname"; | 30 | tty = "ttyname"; |
31 | } else if (stat(tty, &sb) == 0) { | 31 | } else if (stat(tty, &sb) == 0) { |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index f3c3c538c..a86efc298 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -268,6 +268,17 @@ off_t FAST_FUNC fdlength(int fd) | |||
268 | } | 268 | } |
269 | #endif | 269 | #endif |
270 | 270 | ||
271 | char* FAST_FUNC xmalloc_ttyname(int fd) | ||
272 | { | ||
273 | char *buf = xzalloc(128); | ||
274 | int r = ttyname_r(fd, buf, 127); | ||
275 | if (r) { | ||
276 | free(buf); | ||
277 | buf = NULL; | ||
278 | } | ||
279 | return buf; | ||
280 | } | ||
281 | |||
271 | /* It is perfectly ok to pass in a NULL for either width or for | 282 | /* It is perfectly ok to pass in a NULL for either width or for |
272 | * height, in which case that value will not be set. */ | 283 | * height, in which case that value will not be set. */ |
273 | int FAST_FUNC get_terminal_width_height(int fd, unsigned *width, unsigned *height) | 284 | int FAST_FUNC get_terminal_width_height(int fd, unsigned *width, unsigned *height) |
diff --git a/loginutils/login.c b/loginutils/login.c index a18b4d5d7..af871436a 100644 --- a/loginutils/login.c +++ b/loginutils/login.c | |||
@@ -275,7 +275,7 @@ int login_main(int argc UNUSED_PARAM, char **argv) | |||
275 | if (!isatty(0) || !isatty(1) || !isatty(2)) | 275 | if (!isatty(0) || !isatty(1) || !isatty(2)) |
276 | return EXIT_FAILURE; /* Must be a terminal */ | 276 | return EXIT_FAILURE; /* Must be a terminal */ |
277 | safe_strncpy(full_tty, "UNKNOWN", sizeof(full_tty)); | 277 | safe_strncpy(full_tty, "UNKNOWN", sizeof(full_tty)); |
278 | tmp = ttyname(0); | 278 | tmp = xmalloc_ttyname(STDIN_FILENO); |
279 | if (tmp) { | 279 | if (tmp) { |
280 | safe_strncpy(full_tty, tmp, sizeof(full_tty)); | 280 | safe_strncpy(full_tty, tmp, sizeof(full_tty)); |
281 | if (strncmp(full_tty, "/dev/", 5) == 0) | 281 | if (strncmp(full_tty, "/dev/", 5) == 0) |
@@ -285,12 +285,12 @@ int login_main(int argc UNUSED_PARAM, char **argv) | |||
285 | read_or_build_utent(&utent, run_by_root); | 285 | read_or_build_utent(&utent, run_by_root); |
286 | 286 | ||
287 | if (opt & LOGIN_OPT_h) { | 287 | if (opt & LOGIN_OPT_h) { |
288 | USE_FEATURE_UTMP( | 288 | if (ENABLE_FEATURE_UTMP) |
289 | safe_strncpy(utent.ut_host, opt_host, sizeof(utent.ut_host)); | 289 | safe_strncpy(utent.ut_host, opt_host, sizeof(utent.ut_host)); |
290 | ) | ||
291 | fromhost = xasprintf(" on '%s' from '%s'", short_tty, opt_host); | 290 | fromhost = xasprintf(" on '%s' from '%s'", short_tty, opt_host); |
292 | } else | 291 | } else { |
293 | fromhost = xasprintf(" on '%s'", short_tty); | 292 | fromhost = xasprintf(" on '%s'", short_tty); |
293 | } | ||
294 | 294 | ||
295 | /* Was breaking "login <username>" from shell command line: */ | 295 | /* Was breaking "login <username>" from shell command line: */ |
296 | /*bb_setpgrp();*/ | 296 | /*bb_setpgrp();*/ |
diff --git a/loginutils/su.c b/loginutils/su.c index e7e0001c7..de8c18d25 100644 --- a/loginutils/su.c +++ b/loginutils/su.c | |||
@@ -44,7 +44,7 @@ int su_main(int argc UNUSED_PARAM, char **argv) | |||
44 | But getlogin can fail -- usually due to lack of utmp entry. | 44 | But getlogin can fail -- usually due to lack of utmp entry. |
45 | in this case resort to getpwuid. */ | 45 | in this case resort to getpwuid. */ |
46 | old_user = xstrdup(USE_FEATURE_UTMP(getlogin() ? : ) (pw = getpwuid(cur_uid)) ? pw->pw_name : ""); | 46 | old_user = xstrdup(USE_FEATURE_UTMP(getlogin() ? : ) (pw = getpwuid(cur_uid)) ? pw->pw_name : ""); |
47 | tty = ttyname(2) ? : "none"; | 47 | tty = xmalloc_ttyname(2) ? : "none"; |
48 | openlog(applet_name, 0, LOG_AUTH); | 48 | openlog(applet_name, 0, LOG_AUTH); |
49 | } | 49 | } |
50 | 50 | ||
diff --git a/selinux/sestatus.c b/selinux/sestatus.c index 216629615..1a02a6b0c 100644 --- a/selinux/sestatus.c +++ b/selinux/sestatus.c | |||
@@ -114,7 +114,8 @@ static void display_verbose(void) | |||
114 | /* files contexts */ | 114 | /* files contexts */ |
115 | puts("\nFile contexts:"); | 115 | puts("\nFile contexts:"); |
116 | 116 | ||
117 | cterm = ttyname(0); | 117 | cterm = xmalloc_ttyname(0); |
118 | //FIXME: if cterm == NULL, we segfault!?? | ||
118 | puts(cterm); | 119 | puts(cterm); |
119 | if (cterm && lgetfilecon(cterm, &con) >= 0) { | 120 | if (cterm && lgetfilecon(cterm, &con) >= 0) { |
120 | printf(COL_FMT "%s\n", "Controlling term:", con); | 121 | printf(COL_FMT "%s\n", "Controlling term:", con); |
@@ -122,7 +123,7 @@ static void display_verbose(void) | |||
122 | freecon(con); | 123 | freecon(con); |
123 | } | 124 | } |
124 | 125 | ||
125 | for (i=0; fc[i] != NULL; i++) { | 126 | for (i = 0; fc[i] != NULL; i++) { |
126 | struct stat stbuf; | 127 | struct stat stbuf; |
127 | 128 | ||
128 | if (lgetfilecon(fc[i], &con) < 0) | 129 | if (lgetfilecon(fc[i], &con) < 0) |
diff --git a/shell/ash.c b/shell/ash.c index 2fc903b37..492ccd79f 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -13691,7 +13691,7 @@ int ash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
13691 | int ash_main(int argc UNUSED_PARAM, char **argv) | 13691 | int ash_main(int argc UNUSED_PARAM, char **argv) |
13692 | { | 13692 | { |
13693 | char *shinit; | 13693 | char *shinit; |
13694 | volatile int state; | 13694 | volatile smallint state; |
13695 | struct jmploc jmploc; | 13695 | struct jmploc jmploc; |
13696 | struct stackmark smark; | 13696 | struct stackmark smark; |
13697 | 13697 | ||
@@ -13714,7 +13714,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
13714 | state = 0; | 13714 | state = 0; |
13715 | if (setjmp(jmploc.loc)) { | 13715 | if (setjmp(jmploc.loc)) { |
13716 | int e; | 13716 | int e; |
13717 | int s; | 13717 | smallint s; |
13718 | 13718 | ||
13719 | reset(); | 13719 | reset(); |
13720 | 13720 | ||
@@ -13769,7 +13769,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
13769 | } | 13769 | } |
13770 | } | 13770 | } |
13771 | #endif | 13771 | #endif |
13772 | if (argv[0] && argv[0][0] == '-') | 13772 | if (/* argv[0] && */ argv[0][0] == '-') |
13773 | isloginsh = 1; | 13773 | isloginsh = 1; |
13774 | if (isloginsh) { | 13774 | if (isloginsh) { |
13775 | state = 1; | 13775 | state = 1; |