busybox --install -s: prevent puzzling "/bin/busybox: Invalid argument" message

libbb: comment out realpath, add readlink which doesn't warn
This commit is contained in:
Denis Vlasenko 2007-09-05 11:30:34 +00:00
parent 7e0fbf9c26
commit beffd43d8e
3 changed files with 24 additions and 14 deletions

View File

@ -546,7 +546,7 @@ static int busybox_main(char **argv)
help: help:
output_width = 80; output_width = 80;
if (ENABLE_FEATURE_AUTOWIDTH) { if (ENABLE_FEATURE_AUTOWIDTH) {
/* Obtain the terminal width. */ /* Obtain the terminal width */
get_terminal_width_height(0, &output_width, NULL); get_terminal_width_height(0, &output_width, NULL);
} }
/* leading tab and room to wrap */ /* leading tab and room to wrap */
@ -580,12 +580,11 @@ static int busybox_main(char **argv)
if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) {
const char *busybox; const char *busybox;
busybox = xmalloc_readlink_or_warn(bb_busybox_exec_path); busybox = xmalloc_readlink(bb_busybox_exec_path);
if (!busybox) if (!busybox)
busybox = bb_busybox_exec_path; busybox = bb_busybox_exec_path;
/* -s makes symlinks */ /* -s makes symlinks */
install_links(busybox, install_links(busybox, argv[2] && strcmp(argv[2], "-s") == 0);
argv[2] && strcmp(argv[2], "-s") == 0);
return 0; return 0;
} }

View File

@ -249,9 +249,10 @@ void xmove_fd(int, int);
DIR *xopendir(const char *path); DIR *xopendir(const char *path);
DIR *warn_opendir(const char *path); DIR *warn_opendir(const char *path);
char *xrealloc_getcwd_or_warn(char *cwd); /* UNUSED: char *xmalloc_realpath(const char *path); */
char *xmalloc_readlink(const char *path);
char *xmalloc_readlink_or_warn(const char *path); char *xmalloc_readlink_or_warn(const char *path);
char *xmalloc_realpath(const char *path); char *xrealloc_getcwd_or_warn(char *cwd);
//TODO: signal(sid, f) is the same? then why? //TODO: signal(sid, f) is the same? then why?
@ -317,8 +318,8 @@ enum {
}; };
/* Create stream socket, and allocate suitable lsa. /* Create stream socket, and allocate suitable lsa.
* (lsa of correct size and lsa->sa.sa_family (AF_INET/AF_INET6)) * (lsa of correct size and lsa->sa.sa_family (AF_INET/AF_INET6))
* af == AF_UNSPEC will result in trying to create IPv6, and * af == AF_UNSPEC will result in trying to create IPv6 socket,
* if kernel doesn't support it, IPv4. * and if kernel doesn't support it, IPv4.
*/ */
int xsocket_type(len_and_sockaddr **lsap, USE_FEATURE_IPV6(int af,) int sock_type); int xsocket_type(len_and_sockaddr **lsap, USE_FEATURE_IPV6(int af,) int sock_type);
int xsocket_stream(len_and_sockaddr **lsap); int xsocket_stream(len_and_sockaddr **lsap);

View File

@ -10,8 +10,7 @@
* NOTE: This function returns a malloced char* that you will have to free * NOTE: This function returns a malloced char* that you will have to free
* yourself. You have been warned. * yourself. You have been warned.
*/ */
char *xmalloc_readlink(const char *path)
char *xmalloc_readlink_or_warn(const char *path)
{ {
enum { GROWBY = 80 }; /* how large we will grow strings by */ enum { GROWBY = 80 }; /* how large we will grow strings by */
@ -20,20 +19,30 @@ char *xmalloc_readlink_or_warn(const char *path)
do { do {
buf = xrealloc(buf, bufsize += GROWBY); buf = xrealloc(buf, bufsize += GROWBY);
readsize = readlink(path, buf, bufsize); /* 1st try */ readsize = readlink(path, buf, bufsize);
if (readsize == -1) { if (readsize == -1) {
bb_perror_msg("%s", path);
free(buf); free(buf);
return NULL; return NULL;
} }
} } while (bufsize < readsize + 1);
while (bufsize < readsize + 1);
buf[readsize] = '\0'; buf[readsize] = '\0';
return buf; return buf;
} }
char *xmalloc_readlink_or_warn(const char *path)
{
char *buf = xmalloc_readlink(path);
if (!buf) {
/* EINVAL => "file: Invalid argument" => puzzled user */
bb_error_msg("%s: cannot read link (not a symlink?)", path);
}
return buf;
}
/* UNUSED */
#if 0
char *xmalloc_realpath(const char *path) char *xmalloc_realpath(const char *path)
{ {
#if defined(__GLIBC__) && !defined(__UCLIBC__) #if defined(__GLIBC__) && !defined(__UCLIBC__)
@ -46,3 +55,4 @@ char *xmalloc_realpath(const char *path)
return xstrdup(realpath(path, buf)); return xstrdup(realpath(path, buf));
#endif #endif
} }
#endif