aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/Config.src2
-rw-r--r--libbb/appletlib.c20
-rw-r--r--libbb/bb_pwd.c4
-rw-r--r--libbb/get_shell_name.c27
-rw-r--r--libbb/getopt32.c15
-rw-r--r--libbb/inet_common.c16
-rw-r--r--libbb/procps.c14
-rw-r--r--libbb/progress.c10
-rw-r--r--libbb/setup_environment.c3
-rw-r--r--libbb/unicode.c28
-rw-r--r--libbb/xconnect.c5
11 files changed, 95 insertions, 49 deletions
diff --git a/libbb/Config.src b/libbb/Config.src
index 18bdc5151..a25af23b4 100644
--- a/libbb/Config.src
+++ b/libbb/Config.src
@@ -183,7 +183,7 @@ config FEATURE_SKIP_ROOTFS
183config MONOTONIC_SYSCALL 183config MONOTONIC_SYSCALL
184 bool "Use clock_gettime(CLOCK_MONOTONIC) syscall" 184 bool "Use clock_gettime(CLOCK_MONOTONIC) syscall"
185 default n 185 default n
186 depends on PLATFORM_LINUX 186 select PLATFORM_LINUX
187 help 187 help
188 Use clock_gettime(CLOCK_MONOTONIC) syscall for measuring 188 Use clock_gettime(CLOCK_MONOTONIC) syscall for measuring
189 time intervals (time, ping, traceroute etc need this). 189 time intervals (time, ping, traceroute etc need this).
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 4e32414b4..50e53aa25 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -713,12 +713,22 @@ static int busybox_main(char **argv)
713 if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { 713 if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) {
714 int use_symbolic_links; 714 int use_symbolic_links;
715 const char *busybox; 715 const char *busybox;
716
716 busybox = xmalloc_readlink(bb_busybox_exec_path); 717 busybox = xmalloc_readlink(bb_busybox_exec_path);
717 if (!busybox) 718 if (!busybox) {
718 busybox = bb_busybox_exec_path; 719 /* bb_busybox_exec_path is usually "/proc/self/exe".
719 /* busybox --install [-s] [DIR]: */ 720 * In chroot, readlink("/proc/self/exe") usually fails.
720 /* -s: make symlinks */ 721 * In such case, better use argv[0] as symlink target
721 /* DIR: directory to install links to */ 722 * if it is a full path name.
723 */
724 if (argv[0][0] != '/')
725 bb_error_msg_and_die("'%s' is not an absolute path", argv[0]);
726 busybox = argv[0];
727 }
728 /* busybox --install [-s] [DIR]:
729 * -s: make symlinks
730 * DIR: directory to install links to
731 */
722 use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && argv++); 732 use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && argv++);
723 install_links(busybox, use_symbolic_links, argv[2]); 733 install_links(busybox, use_symbolic_links, argv[2]);
724 return 0; 734 return 0;
diff --git a/libbb/bb_pwd.c b/libbb/bb_pwd.c
index 32406cb58..4829b723a 100644
--- a/libbb/bb_pwd.c
+++ b/libbb/bb_pwd.c
@@ -72,13 +72,13 @@ char* FAST_FUNC gid2group(gid_t gid)
72 return (gr) ? gr->gr_name : NULL; 72 return (gr) ? gr->gr_name : NULL;
73} 73}
74 74
75char* FAST_FUNC uid2uname_utoa(long uid) 75char* FAST_FUNC uid2uname_utoa(uid_t uid)
76{ 76{
77 char *name = uid2uname(uid); 77 char *name = uid2uname(uid);
78 return (name) ? name : utoa(uid); 78 return (name) ? name : utoa(uid);
79} 79}
80 80
81char* FAST_FUNC gid2group_utoa(long gid) 81char* FAST_FUNC gid2group_utoa(gid_t gid)
82{ 82{
83 char *name = gid2group(gid); 83 char *name = gid2group(gid);
84 return (name) ? name : utoa(gid); 84 return (name) ? name : utoa(gid);
diff --git a/libbb/get_shell_name.c b/libbb/get_shell_name.c
new file mode 100644
index 000000000..d196d293d
--- /dev/null
+++ b/libbb/get_shell_name.c
@@ -0,0 +1,27 @@
1/*
2 * Copyright 2011, Denys Vlasenko
3 *
4 * Licensed under GPLv2, see file LICENSE in this source tree.
5 */
6
7//kbuild:lib-y += get_shell_name.o
8
9#include "libbb.h"
10
11const char *get_shell_name(void)
12{
13 struct passwd *pw;
14 char *shell;
15
16 shell = getenv("SHELL");
17 if (shell && shell[0])
18 return shell;
19
20#if !ENABLE_PLATFORM_MINGW32
21 pw = getpwuid(getuid());
22 if (pw && pw->pw_shell && pw->pw_shell[0])
23 return pw->pw_shell;
24#endif
25
26 return DEFAULT_SHELL;
27}
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index 053ffc349..8087b3ba6 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -542,8 +542,6 @@ getopt32(char **argv, const char *applet_opts, ...)
542#endif 542#endif
543 /* optarg = NULL; opterr = 0; optopt = 0; - do we need this?? */ 543 /* optarg = NULL; opterr = 0; optopt = 0; - do we need this?? */
544 544
545 pargv = NULL;
546
547 /* Note: just "getopt() <= 0" will not work well for 545 /* Note: just "getopt() <= 0" will not work well for
548 * "fake" short options, like this one: 546 * "fake" short options, like this one:
549 * wget $'-\203' "Test: test" http://kernel.org/ 547 * wget $'-\203' "Test: test" http://kernel.org/
@@ -574,19 +572,16 @@ getopt32(char **argv, const char *applet_opts, ...)
574 flags ^= trigger; 572 flags ^= trigger;
575 if (on_off->counter) 573 if (on_off->counter)
576 (*(on_off->counter))++; 574 (*(on_off->counter))++;
577 if (on_off->param_type == PARAM_LIST) { 575 if (optarg) {
578 if (optarg) 576 if (on_off->param_type == PARAM_LIST) {
579 llist_add_to_end((llist_t **)(on_off->optarg), optarg); 577 llist_add_to_end((llist_t **)(on_off->optarg), optarg);
580 } else if (on_off->param_type == PARAM_INT) { 578 } else if (on_off->param_type == PARAM_INT) {
581 if (optarg)
582//TODO: xatoi_positive indirectly pulls in printf machinery 579//TODO: xatoi_positive indirectly pulls in printf machinery
583 *(unsigned*)(on_off->optarg) = xatoi_positive(optarg); 580 *(unsigned*)(on_off->optarg) = xatoi_positive(optarg);
584 } else if (on_off->optarg) { 581 } else if (on_off->optarg) {
585 if (optarg)
586 *(char **)(on_off->optarg) = optarg; 582 *(char **)(on_off->optarg) = optarg;
583 }
587 } 584 }
588 if (pargv != NULL)
589 break;
590 } 585 }
591 586
592 /* check depending requires for given options */ 587 /* check depending requires for given options */
diff --git a/libbb/inet_common.c b/libbb/inet_common.c
index 6f585ebd9..207720e96 100644
--- a/libbb/inet_common.c
+++ b/libbb/inet_common.c
@@ -164,17 +164,17 @@ char* FAST_FUNC INET_rresolve(struct sockaddr_in *s_in, int numeric, uint32_t ne
164 164
165int FAST_FUNC INET6_resolve(const char *name, struct sockaddr_in6 *sin6) 165int FAST_FUNC INET6_resolve(const char *name, struct sockaddr_in6 *sin6)
166{ 166{
167 struct addrinfo req, *ai; 167 struct addrinfo req, *ai = NULL;
168 int s; 168 int s;
169 169
170 memset(&req, '\0', sizeof req); 170 memset(&req, 0, sizeof(req));
171 req.ai_family = AF_INET6; 171 req.ai_family = AF_INET6;
172 s = getaddrinfo(name, NULL, &req, &ai); 172 s = getaddrinfo(name, NULL, &req, &ai);
173 if (s) { 173 if (s != 0) {
174 bb_error_msg("getaddrinfo: %s: %d", name, s); 174 bb_error_msg("getaddrinfo: %s: %d", name, s);
175 return -1; 175 return -1;
176 } 176 }
177 memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6)); 177 memcpy(sin6, ai->ai_addr, sizeof(*sin6));
178 freeaddrinfo(ai); 178 freeaddrinfo(ai);
179 return 0; 179 return 0;
180} 180}
@@ -209,9 +209,11 @@ char* FAST_FUNC INET6_rresolve(struct sockaddr_in6 *sin6, int numeric)
209 return xstrdup("*"); 209 return xstrdup("*");
210 } 210 }
211 211
212 s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6), 212 s = getnameinfo((struct sockaddr *) sin6, sizeof(*sin6),
213 name, sizeof(name), NULL, 0, 0); 213 name, sizeof(name),
214 if (s) { 214 /*serv,servlen:*/ NULL, 0,
215 0);
216 if (s != 0) {
215 bb_error_msg("getnameinfo failed"); 217 bb_error_msg("getnameinfo failed");
216 return NULL; 218 return NULL;
217 } 219 }
diff --git a/libbb/procps.c b/libbb/procps.c
index c68d3e655..58772d4e9 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -12,13 +12,13 @@
12#include "libbb.h" 12#include "libbb.h"
13 13
14 14
15typedef struct unsigned_to_name_map_t { 15typedef struct id_to_name_map_t {
16 long id; 16 uid_t id;
17 char name[USERNAME_MAX_SIZE]; 17 char name[USERNAME_MAX_SIZE];
18} unsigned_to_name_map_t; 18} id_to_name_map_t;
19 19
20typedef struct cache_t { 20typedef struct cache_t {
21 unsigned_to_name_map_t *cache; 21 id_to_name_map_t *cache;
22 int size; 22 int size;
23} cache_t; 23} cache_t;
24 24
@@ -39,7 +39,7 @@ void FAST_FUNC clear_username_cache(void)
39#if 0 /* more generic, but we don't need that yet */ 39#if 0 /* more generic, but we don't need that yet */
40/* Returns -N-1 if not found. */ 40/* Returns -N-1 if not found. */
41/* cp->cache[N] is allocated and must be filled in this case */ 41/* cp->cache[N] is allocated and must be filled in this case */
42static int get_cached(cache_t *cp, unsigned id) 42static int get_cached(cache_t *cp, uid_t id)
43{ 43{
44 int i; 44 int i;
45 for (i = 0; i < cp->size; i++) 45 for (i = 0; i < cp->size; i++)
@@ -52,8 +52,8 @@ static int get_cached(cache_t *cp, unsigned id)
52} 52}
53#endif 53#endif
54 54
55static char* get_cached(cache_t *cp, long id, 55static char* get_cached(cache_t *cp, uid_t id,
56 char* FAST_FUNC x2x_utoa(long id)) 56 char* FAST_FUNC x2x_utoa(uid_t id))
57{ 57{
58 int i; 58 int i;
59 for (i = 0; i < cp->size; i++) 59 for (i = 0; i < cp->size; i++)
diff --git a/libbb/progress.c b/libbb/progress.c
index df43dad5c..372feb0c2 100644
--- a/libbb/progress.c
+++ b/libbb/progress.c
@@ -127,10 +127,12 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
127 /* 32-bit CPU and 64-bit off_t. 127 /* 32-bit CPU and 64-bit off_t.
128 * Use a 40-bit shift, it is easier to do on 32-bit CPU. 128 * Use a 40-bit shift, it is easier to do on 32-bit CPU.
129 */ 129 */
130 if (totalsize >= (uoff_t)(1ULL << 54)) { 130/* ONE suppresses "warning: shift count >= width of type" */
131 totalsize = (uint32_t)(totalsize >> 32) >> 8; 131#define ONE (sizeof(off_t) > 4)
132 beg_size = (uint32_t)(beg_size >> 32) >> 8; 132 if (totalsize >= (uoff_t)(1ULL << 54*ONE)) {
133 transferred = (uint32_t)(transferred >> 32) >> 8; 133 totalsize = (uint32_t)(totalsize >> 32*ONE) >> 8;
134 beg_size = (uint32_t)(beg_size >> 32*ONE) >> 8;
135 transferred = (uint32_t)(transferred >> 32*ONE) >> 8;
134 kiloscale = 4; 136 kiloscale = 4;
135 } 137 }
136 } 138 }
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c
index a95fbc5bf..73229ca6c 100644
--- a/libbb/setup_environment.c
+++ b/libbb/setup_environment.c
@@ -32,6 +32,9 @@
32 32
33void FAST_FUNC setup_environment(const char *shell, int flags, const struct passwd *pw) 33void FAST_FUNC setup_environment(const char *shell, int flags, const struct passwd *pw)
34{ 34{
35 if (!shell || !shell[0])
36 shell = DEFAULT_SHELL;
37
35 /* Change the current working directory to be the home directory 38 /* Change the current working directory to be the home directory
36 * of the user */ 39 * of the user */
37 if (chdir(pw->pw_dir)) { 40 if (chdir(pw->pw_dir)) {
diff --git a/libbb/unicode.c b/libbb/unicode.c
index 08a4c7427..d01efd9a2 100644
--- a/libbb/unicode.c
+++ b/libbb/unicode.c
@@ -23,37 +23,43 @@ uint8_t unicode_status;
23 23
24/* Unicode support using libc locale support. */ 24/* Unicode support using libc locale support. */
25 25
26void FAST_FUNC init_unicode(void) 26void FAST_FUNC reinit_unicode(const char *LANG UNUSED_PARAM)
27{ 27{
28 static const char unicode_0x394[] = { 0xce, 0x94, 0 }; 28 static const char unicode_0x394[] = { 0xce, 0x94, 0 };
29 size_t width; 29 size_t width;
30 30
31 if (unicode_status != UNICODE_UNKNOWN) 31//TODO: call setlocale(LC_ALL, LANG) here?
32 return; 32
33 /* In unicode, this is a one character string */ 33 /* In unicode, this is a one character string */
34// can use unicode_strlen(string) too, but otherwise unicode_strlen() is unused 34// can use unicode_strlen(string) too, but otherwise unicode_strlen() is unused
35 width = mbstowcs(NULL, unicode_0x394, INT_MAX); 35 width = mbstowcs(NULL, unicode_0x394, INT_MAX);
36 unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF); 36 unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF);
37} 37}
38 38
39void FAST_FUNC init_unicode(void)
40{
41 if (unicode_status == UNICODE_UNKNOWN)
42 reinit_unicode(NULL /*getenv("LANG")*/);
43}
44
39#else 45#else
40 46
41/* Homegrown Unicode support. It knows only C and Unicode locales. */ 47/* Homegrown Unicode support. It knows only C and Unicode locales. */
42 48
43# if ENABLE_FEATURE_CHECK_UNICODE_IN_ENV 49# if ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
44void FAST_FUNC init_unicode(void) 50void FAST_FUNC reinit_unicode(const char *LANG)
45{ 51{
46 char *lang;
47
48 if (unicode_status != UNICODE_UNKNOWN)
49 return;
50
51 unicode_status = UNICODE_OFF; 52 unicode_status = UNICODE_OFF;
52 lang = getenv("LANG"); 53 if (!LANG || !(strstr(LANG, ".utf") || strstr(LANG, ".UTF")))
53 if (!lang || !(strstr(lang, ".utf") || strstr(lang, ".UTF")))
54 return; 54 return;
55 unicode_status = UNICODE_ON; 55 unicode_status = UNICODE_ON;
56} 56}
57
58void FAST_FUNC init_unicode(void)
59{
60 if (unicode_status == UNICODE_UNKNOWN)
61 reinit_unicode(getenv("LANG"));
62}
57# endif 63# endif
58 64
59static size_t wcrtomb_internal(char *s, wchar_t wc) 65static size_t wcrtomb_internal(char *s, wchar_t wc)
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 3a6585caa..127e2a5fc 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -255,7 +255,7 @@ IF_NOT_FEATURE_IPV6(sa_family_t af = AF_INET;)
255 255
256 memset(&hint, 0 , sizeof(hint)); 256 memset(&hint, 0 , sizeof(hint));
257 hint.ai_family = af; 257 hint.ai_family = af;
258 /* Needed. Or else we will get each address thrice (or more) 258 /* Need SOCK_STREAM, or else we get each address thrice (or more)
259 * for each possible socket type (tcp,udp,raw...): */ 259 * for each possible socket type (tcp,udp,raw...): */
260 hint.ai_socktype = SOCK_STREAM; 260 hint.ai_socktype = SOCK_STREAM;
261 hint.ai_flags = ai_flags & ~DIE_ON_ERROR; 261 hint.ai_flags = ai_flags & ~DIE_ON_ERROR;
@@ -285,7 +285,8 @@ IF_NOT_FEATURE_IPV6(sa_family_t af = AF_INET;)
285 set_port: 285 set_port:
286 set_nport(r, htons(port)); 286 set_nport(r, htons(port));
287 ret: 287 ret:
288 freeaddrinfo(result); 288 if (result)
289 freeaddrinfo(result);
289 return r; 290 return r;
290} 291}
291#if !ENABLE_FEATURE_IPV6 292#if !ENABLE_FEATURE_IPV6