diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-05 11:30:34 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-05 11:30:34 +0000 |
| commit | beffd43d8e393b68787a00d9c6078a2b367afd01 (patch) | |
| tree | 485a6f36aa57e182801babc1365f128bfaa52f5e | |
| parent | 7e0fbf9c26350a819661241bc925cb88f26bb992 (diff) | |
| download | busybox-w32-beffd43d8e393b68787a00d9c6078a2b367afd01.tar.gz busybox-w32-beffd43d8e393b68787a00d9c6078a2b367afd01.tar.bz2 busybox-w32-beffd43d8e393b68787a00d9c6078a2b367afd01.zip | |
busybox --install -s: prevent puzzling "/bin/busybox: Invalid argument" message
libbb: comment out realpath, add readlink which doesn't warn
| -rw-r--r-- | applets/applets.c | 7 | ||||
| -rw-r--r-- | include/libbb.h | 9 | ||||
| -rw-r--r-- | libbb/xreadlink.c | 22 |
3 files changed, 24 insertions, 14 deletions
diff --git a/applets/applets.c b/applets/applets.c index c2040b9a3..ec268ca2d 100644 --- a/applets/applets.c +++ b/applets/applets.c | |||
| @@ -546,7 +546,7 @@ static int busybox_main(char **argv) | |||
| 546 | help: | 546 | help: |
| 547 | output_width = 80; | 547 | output_width = 80; |
| 548 | if (ENABLE_FEATURE_AUTOWIDTH) { | 548 | if (ENABLE_FEATURE_AUTOWIDTH) { |
| 549 | /* Obtain the terminal width. */ | 549 | /* Obtain the terminal width */ |
| 550 | get_terminal_width_height(0, &output_width, NULL); | 550 | get_terminal_width_height(0, &output_width, NULL); |
| 551 | } | 551 | } |
| 552 | /* leading tab and room to wrap */ | 552 | /* leading tab and room to wrap */ |
| @@ -580,12 +580,11 @@ static int busybox_main(char **argv) | |||
| 580 | 580 | ||
| 581 | if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { | 581 | if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { |
| 582 | const char *busybox; | 582 | const char *busybox; |
| 583 | busybox = xmalloc_readlink_or_warn(bb_busybox_exec_path); | 583 | busybox = xmalloc_readlink(bb_busybox_exec_path); |
| 584 | if (!busybox) | 584 | if (!busybox) |
| 585 | busybox = bb_busybox_exec_path; | 585 | busybox = bb_busybox_exec_path; |
| 586 | /* -s makes symlinks */ | 586 | /* -s makes symlinks */ |
| 587 | install_links(busybox, | 587 | install_links(busybox, argv[2] && strcmp(argv[2], "-s") == 0); |
| 588 | argv[2] && strcmp(argv[2], "-s") == 0); | ||
| 589 | return 0; | 588 | return 0; |
| 590 | } | 589 | } |
| 591 | 590 | ||
diff --git a/include/libbb.h b/include/libbb.h index cf00b5250..f1658945c 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -249,9 +249,10 @@ void xmove_fd(int, int); | |||
| 249 | DIR *xopendir(const char *path); | 249 | DIR *xopendir(const char *path); |
| 250 | DIR *warn_opendir(const char *path); | 250 | DIR *warn_opendir(const char *path); |
| 251 | 251 | ||
| 252 | char *xrealloc_getcwd_or_warn(char *cwd); | 252 | /* UNUSED: char *xmalloc_realpath(const char *path); */ |
| 253 | char *xmalloc_readlink(const char *path); | ||
| 253 | char *xmalloc_readlink_or_warn(const char *path); | 254 | char *xmalloc_readlink_or_warn(const char *path); |
| 254 | char *xmalloc_realpath(const char *path); | 255 | char *xrealloc_getcwd_or_warn(char *cwd); |
| 255 | 256 | ||
| 256 | 257 | ||
| 257 | //TODO: signal(sid, f) is the same? then why? | 258 | //TODO: signal(sid, f) is the same? then why? |
| @@ -317,8 +318,8 @@ enum { | |||
| 317 | }; | 318 | }; |
| 318 | /* Create stream socket, and allocate suitable lsa. | 319 | /* Create stream socket, and allocate suitable lsa. |
| 319 | * (lsa of correct size and lsa->sa.sa_family (AF_INET/AF_INET6)) | 320 | * (lsa of correct size and lsa->sa.sa_family (AF_INET/AF_INET6)) |
| 320 | * af == AF_UNSPEC will result in trying to create IPv6, and | 321 | * af == AF_UNSPEC will result in trying to create IPv6 socket, |
| 321 | * if kernel doesn't support it, IPv4. | 322 | * and if kernel doesn't support it, IPv4. |
| 322 | */ | 323 | */ |
| 323 | int xsocket_type(len_and_sockaddr **lsap, USE_FEATURE_IPV6(int af,) int sock_type); | 324 | int xsocket_type(len_and_sockaddr **lsap, USE_FEATURE_IPV6(int af,) int sock_type); |
| 324 | int xsocket_stream(len_and_sockaddr **lsap); | 325 | int xsocket_stream(len_and_sockaddr **lsap); |
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c index 18a8b9467..4d87b944d 100644 --- a/libbb/xreadlink.c +++ b/libbb/xreadlink.c | |||
| @@ -10,8 +10,7 @@ | |||
| 10 | * NOTE: This function returns a malloced char* that you will have to free | 10 | * NOTE: This function returns a malloced char* that you will have to free |
| 11 | * yourself. You have been warned. | 11 | * yourself. You have been warned. |
| 12 | */ | 12 | */ |
| 13 | 13 | char *xmalloc_readlink(const char *path) | |
| 14 | char *xmalloc_readlink_or_warn(const char *path) | ||
| 15 | { | 14 | { |
| 16 | enum { GROWBY = 80 }; /* how large we will grow strings by */ | 15 | enum { GROWBY = 80 }; /* how large we will grow strings by */ |
| 17 | 16 | ||
| @@ -20,20 +19,30 @@ char *xmalloc_readlink_or_warn(const char *path) | |||
| 20 | 19 | ||
| 21 | do { | 20 | do { |
| 22 | buf = xrealloc(buf, bufsize += GROWBY); | 21 | buf = xrealloc(buf, bufsize += GROWBY); |
| 23 | readsize = readlink(path, buf, bufsize); /* 1st try */ | 22 | readsize = readlink(path, buf, bufsize); |
| 24 | if (readsize == -1) { | 23 | if (readsize == -1) { |
| 25 | bb_perror_msg("%s", path); | ||
| 26 | free(buf); | 24 | free(buf); |
| 27 | return NULL; | 25 | return NULL; |
| 28 | } | 26 | } |
| 29 | } | 27 | } while (bufsize < readsize + 1); |
| 30 | while (bufsize < readsize + 1); | ||
| 31 | 28 | ||
| 32 | buf[readsize] = '\0'; | 29 | buf[readsize] = '\0'; |
| 33 | 30 | ||
| 34 | return buf; | 31 | return buf; |
| 35 | } | 32 | } |
| 36 | 33 | ||
| 34 | char *xmalloc_readlink_or_warn(const char *path) | ||
| 35 | { | ||
| 36 | char *buf = xmalloc_readlink(path); | ||
| 37 | if (!buf) { | ||
| 38 | /* EINVAL => "file: Invalid argument" => puzzled user */ | ||
| 39 | bb_error_msg("%s: cannot read link (not a symlink?)", path); | ||
| 40 | } | ||
| 41 | return buf; | ||
| 42 | } | ||
| 43 | |||
| 44 | /* UNUSED */ | ||
| 45 | #if 0 | ||
| 37 | char *xmalloc_realpath(const char *path) | 46 | char *xmalloc_realpath(const char *path) |
| 38 | { | 47 | { |
| 39 | #if defined(__GLIBC__) && !defined(__UCLIBC__) | 48 | #if defined(__GLIBC__) && !defined(__UCLIBC__) |
| @@ -46,3 +55,4 @@ char *xmalloc_realpath(const char *path) | |||
| 46 | return xstrdup(realpath(path, buf)); | 55 | return xstrdup(realpath(path, buf)); |
| 47 | #endif | 56 | #endif |
| 48 | } | 57 | } |
| 58 | #endif | ||
