diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-14 02:23:43 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-14 02:23:43 +0000 |
| commit | ea62077b850076c4d7dc3cf78ebd1888928c6ddf (patch) | |
| tree | 37b7584ae40b99edb5583fbc4392b62ffdadf278 | |
| parent | 88ca06769028e442bf873b270c176ca0e9f021f8 (diff) | |
| download | busybox-w32-ea62077b850076c4d7dc3cf78ebd1888928c6ddf.tar.gz busybox-w32-ea62077b850076c4d7dc3cf78ebd1888928c6ddf.tar.bz2 busybox-w32-ea62077b850076c4d7dc3cf78ebd1888928c6ddf.zip | |
add open_read_close() and similar stuff
38 files changed, 228 insertions, 234 deletions
diff --git a/archival/libunarchive/get_header_ar.c b/archival/libunarchive/get_header_ar.c index 7372ada32..b91c6f97d 100644 --- a/archival/libunarchive/get_header_ar.c +++ b/archival/libunarchive/get_header_ar.c | |||
| @@ -79,7 +79,7 @@ char get_header_ar(archive_handle_t *archive_handle) | |||
| 79 | (saved in variable long_name) that conatains the real filename */ | 79 | (saved in variable long_name) that conatains the real filename */ |
| 80 | const unsigned int long_offset = atoi(&ar.formatted.name[1]); | 80 | const unsigned int long_offset = atoi(&ar.formatted.name[1]); |
| 81 | if (long_offset >= ar_long_name_size) { | 81 | if (long_offset >= ar_long_name_size) { |
| 82 | bb_error_msg_and_die("Cant resolve long filename"); | 82 | bb_error_msg_and_die("can't resolve long filename"); |
| 83 | } | 83 | } |
| 84 | typed->name = xstrdup(ar_long_names + long_offset); | 84 | typed->name = xstrdup(ar_long_names + long_offset); |
| 85 | } | 85 | } |
diff --git a/archival/libunarchive/open_transformer.c b/archival/libunarchive/open_transformer.c index 99e71ec2e..456d3e986 100644 --- a/archival/libunarchive/open_transformer.c +++ b/archival/libunarchive/open_transformer.c | |||
| @@ -18,23 +18,23 @@ int open_transformer(int src_fd, | |||
| 18 | int pid; | 18 | int pid; |
| 19 | 19 | ||
| 20 | if (pipe(fd_pipe) != 0) { | 20 | if (pipe(fd_pipe) != 0) { |
| 21 | bb_perror_msg_and_die("Can't create pipe"); | 21 | bb_perror_msg_and_die("can't create pipe"); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | pid = fork(); | 24 | pid = fork(); |
| 25 | if (pid == -1) { | 25 | if (pid == -1) { |
| 26 | bb_perror_msg_and_die("Fork failed"); | 26 | bb_perror_msg_and_die("fork failed"); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | if (pid == 0) { | 29 | if (pid == 0) { |
| 30 | /* child process */ | 30 | /* child process */ |
| 31 | close(fd_pipe[0]); /* We don't wan't to read from the parent */ | 31 | close(fd_pipe[0]); /* We don't wan't to read from the parent */ |
| 32 | // FIXME: error check? | 32 | // FIXME: error check? |
| 33 | transformer(src_fd, fd_pipe[1]); | 33 | transformer(src_fd, fd_pipe[1]); |
| 34 | close(fd_pipe[1]); /* Send EOF */ | 34 | close(fd_pipe[1]); /* Send EOF */ |
| 35 | close(src_fd); | 35 | close(src_fd); |
| 36 | exit(0); | 36 | exit(0); |
| 37 | /* notreached */ | 37 | /* notreached */ |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | /* parent process */ | 40 | /* parent process */ |
diff --git a/archival/tar.c b/archival/tar.c index 5935ccaa3..2c4280cc4 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
| @@ -457,7 +457,7 @@ static int writeTarFile(const int tar_fd, const int verboseFlag, | |||
| 457 | 457 | ||
| 458 | if (n == 0 && vfork_exec_errno != 0) { | 458 | if (n == 0 && vfork_exec_errno != 0) { |
| 459 | errno = vfork_exec_errno; | 459 | errno = vfork_exec_errno; |
| 460 | bb_perror_msg_and_die("Could not exec %s", zip_exec); | 460 | bb_perror_msg_and_die("cannot exec %s", zip_exec); |
| 461 | } else if ((n < 0) && (errno == EAGAIN || errno == EINTR)) | 461 | } else if ((n < 0) && (errno == EAGAIN || errno == EINTR)) |
| 462 | continue; /* try it again */ | 462 | continue; /* try it again */ |
| 463 | break; | 463 | break; |
diff --git a/coreutils/diff.c b/coreutils/diff.c index 65757d7d1..2915d4009 100644 --- a/coreutils/diff.c +++ b/coreutils/diff.c | |||
| @@ -1202,7 +1202,7 @@ int diff_main(int argc, char **argv) | |||
| 1202 | * driver routine. Both drivers use the contents of stb1 and stb2. | 1202 | * driver routine. Both drivers use the contents of stb1 and stb2. |
| 1203 | */ | 1203 | */ |
| 1204 | if (argc < 2) { | 1204 | if (argc < 2) { |
| 1205 | bb_error_msg("Missing filename"); | 1205 | bb_error_msg("missing filename"); |
| 1206 | bb_show_usage(); | 1206 | bb_show_usage(); |
| 1207 | } | 1207 | } |
| 1208 | if (strcmp(argv[0], "-") == 0) { | 1208 | if (strcmp(argv[0], "-") == 0) { |
| @@ -1216,12 +1216,12 @@ int diff_main(int argc, char **argv) | |||
| 1216 | } else | 1216 | } else |
| 1217 | xstat(argv[1], &stb2); | 1217 | xstat(argv[1], &stb2); |
| 1218 | if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode))) | 1218 | if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode))) |
| 1219 | bb_error_msg_and_die("Can't compare - to a directory"); | 1219 | bb_error_msg_and_die("can't compare - to a directory"); |
| 1220 | if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { | 1220 | if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { |
| 1221 | #if ENABLE_FEATURE_DIFF_DIR | 1221 | #if ENABLE_FEATURE_DIFF_DIR |
| 1222 | diffdir(argv[0], argv[1]); | 1222 | diffdir(argv[0], argv[1]); |
| 1223 | #else | 1223 | #else |
| 1224 | bb_error_msg_and_die("Directory comparison not supported"); | 1224 | bb_error_msg_and_die("directory comparison not supported"); |
| 1225 | #endif | 1225 | #endif |
| 1226 | } else { | 1226 | } else { |
| 1227 | if (S_ISDIR(stb1.st_mode)) { | 1227 | if (S_ISDIR(stb1.st_mode)) { |
diff --git a/editors/vi.c b/editors/vi.c index fa30cf29c..a25e96657 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
| @@ -2353,7 +2353,7 @@ static int file_insert(Byte * fn, Byte * p, int size) | |||
| 2353 | #endif | 2353 | #endif |
| 2354 | fd = open((char *) fn, O_RDONLY); // try read-only | 2354 | fd = open((char *) fn, O_RDONLY); // try read-only |
| 2355 | if (fd < 0) { | 2355 | if (fd < 0) { |
| 2356 | psbs("\"%s\" %s", fn, "could not open file"); | 2356 | psbs("\"%s\" %s", fn, "cannot open file"); |
| 2357 | goto fi0; | 2357 | goto fi0; |
| 2358 | } | 2358 | } |
| 2359 | #ifdef CONFIG_FEATURE_VI_READONLY | 2359 | #ifdef CONFIG_FEATURE_VI_READONLY |
| @@ -2367,11 +2367,11 @@ static int file_insert(Byte * fn, Byte * p, int size) | |||
| 2367 | if (cnt < 0) { | 2367 | if (cnt < 0) { |
| 2368 | cnt = -1; | 2368 | cnt = -1; |
| 2369 | p = text_hole_delete(p, p + size - 1); // un-do buffer insert | 2369 | p = text_hole_delete(p, p + size - 1); // un-do buffer insert |
| 2370 | psbs("could not read file \"%s\"", fn); | 2370 | psbs("cannot read file \"%s\"", fn); |
| 2371 | } else if (cnt < size) { | 2371 | } else if (cnt < size) { |
| 2372 | // There was a partial read, shrink unused space text[] | 2372 | // There was a partial read, shrink unused space text[] |
| 2373 | p = text_hole_delete(p + cnt, p + (size - cnt) - 1); // un-do buffer insert | 2373 | p = text_hole_delete(p + cnt, p + (size - cnt) - 1); // un-do buffer insert |
| 2374 | psbs("could not read all of file \"%s\"", fn); | 2374 | psbs("cannot read all of file \"%s\"", fn); |
| 2375 | } | 2375 | } |
| 2376 | if (cnt >= size) | 2376 | if (cnt >= size) |
| 2377 | file_modified++; | 2377 | file_modified++; |
diff --git a/include/libbb.h b/include/libbb.h index 767a3378b..0bcabf17b 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -205,12 +205,22 @@ extern int is_directory(const char *name, int followLinks, struct stat *statBuf) | |||
| 205 | extern DIR *warn_opendir(const char *path); | 205 | extern DIR *warn_opendir(const char *path); |
| 206 | extern DIR *xopendir(const char *path); | 206 | extern DIR *xopendir(const char *path); |
| 207 | 207 | ||
| 208 | extern int remove_file(const char *path, int flags); | ||
| 209 | extern int copy_file(const char *source, const char *dest, int flags); | ||
| 210 | extern ssize_t safe_read(int fd, void *buf, size_t count); | 208 | extern ssize_t safe_read(int fd, void *buf, size_t count); |
| 211 | extern ssize_t full_read(int fd, void *buf, size_t len); | 209 | extern ssize_t full_read(int fd, void *buf, size_t count); |
| 210 | extern void xread(int fd, void *buf, size_t count); | ||
| 211 | extern unsigned char xread_char(int fd); | ||
| 212 | extern char *reads(int fd, char *buf, size_t count); | ||
| 213 | ssize_t read_close(int fd, void *buf, size_t count); | ||
| 214 | ssize_t open_read_close(const char *filename, void *buf, size_t count); | ||
| 215 | void *xmalloc_open_read_close(const char *filename, size_t *sizep); | ||
| 216 | |||
| 212 | extern ssize_t safe_write(int fd, const void *buf, size_t count); | 217 | extern ssize_t safe_write(int fd, const void *buf, size_t count); |
| 213 | extern ssize_t full_write(int fd, const void *buf, size_t len); | 218 | extern ssize_t full_write(int fd, const void *buf, size_t count); |
| 219 | extern void xwrite(int fd, void *buf, size_t count); | ||
| 220 | |||
| 221 | extern int remove_file(const char *path, int flags); | ||
| 222 | extern int copy_file(const char *source, const char *dest, int flags); | ||
| 223 | |||
| 214 | extern int recursive_action(const char *fileName, int recurse, | 224 | extern int recursive_action(const char *fileName, int recurse, |
| 215 | int followLinks, int depthFirst, | 225 | int followLinks, int depthFirst, |
| 216 | int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData), | 226 | int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData), |
| @@ -592,10 +602,7 @@ extern int obscure(const char *old, const char *newval, const struct passwd *pwd | |||
| 592 | extern void xsetenv(const char *key, const char *value); | 602 | extern void xsetenv(const char *key, const char *value); |
| 593 | extern int xopen(const char *pathname, int flags); | 603 | extern int xopen(const char *pathname, int flags); |
| 594 | extern int xopen3(const char *pathname, int flags, int mode); | 604 | extern int xopen3(const char *pathname, int flags, int mode); |
| 595 | extern void xread(int fd, void *buf, size_t count); | 605 | extern off_t xlseek(int fd, off_t offset, int whence); |
| 596 | extern unsigned char xread_char(int fd); | ||
| 597 | extern void xlseek(int fd, off_t offset, int whence); | ||
| 598 | extern void xwrite(int fd, void *buf, size_t count); | ||
| 599 | 606 | ||
| 600 | extern const char bb_uuenc_tbl_base64[]; | 607 | extern const char bb_uuenc_tbl_base64[]; |
| 601 | extern const char bb_uuenc_tbl_std[]; | 608 | extern const char bb_uuenc_tbl_std[]; |
diff --git a/init/init.c b/init/init.c index 8257b7fb0..99a11e526 100644 --- a/init/init.c +++ b/init/init.c | |||
| @@ -561,7 +561,7 @@ static pid_t run(const struct init_action *a) | |||
| 561 | execv(cmdpath, cmd); | 561 | execv(cmdpath, cmd); |
| 562 | 562 | ||
| 563 | /* We're still here? Some error happened. */ | 563 | /* We're still here? Some error happened. */ |
| 564 | message(LOG | CONSOLE, "Bummer, could not run '%s': %m", cmdpath); | 564 | message(LOG | CONSOLE, "Bummer, cannot run '%s': %m", cmdpath); |
| 565 | _exit(-1); | 565 | _exit(-1); |
| 566 | } | 566 | } |
| 567 | sigprocmask(SIG_SETMASK, &omask, NULL); | 567 | sigprocmask(SIG_SETMASK, &omask, NULL); |
diff --git a/libbb/Kbuild b/libbb/Kbuild index 27ed68c2c..3b16f5c45 100644 --- a/libbb/Kbuild +++ b/libbb/Kbuild | |||
| @@ -9,7 +9,7 @@ lib-y:= \ | |||
| 9 | compare_string_array.o concat_path_file.o copy_file.o copyfd.o \ | 9 | compare_string_array.o concat_path_file.o copy_file.o copyfd.o \ |
| 10 | crc32.o create_icmp_socket.o create_icmp6_socket.o \ | 10 | crc32.o create_icmp_socket.o create_icmp6_socket.o \ |
| 11 | device_open.o dump.o error_msg.o error_msg_and_die.o \ | 11 | device_open.o dump.o error_msg.o error_msg_and_die.o \ |
| 12 | find_pid_by_name.o find_root_device.o fgets_str.o full_read.o \ | 12 | find_pid_by_name.o find_root_device.o fgets_str.o \ |
| 13 | full_write.o get_last_path_component.o get_line_from_file.o \ | 13 | full_write.o get_last_path_component.o get_line_from_file.o \ |
| 14 | herror_msg.o herror_msg_and_die.o \ | 14 | herror_msg.o herror_msg_and_die.o \ |
| 15 | human_readable.o inet_common.o inode_hash.o isdirectory.o \ | 15 | human_readable.o inet_common.o inode_hash.o isdirectory.o \ |
| @@ -19,7 +19,7 @@ lib-y:= \ | |||
| 19 | perror_msg_and_die.o get_console.o \ | 19 | perror_msg_and_die.o get_console.o \ |
| 20 | process_escape_sequence.o procps.o \ | 20 | process_escape_sequence.o procps.o \ |
| 21 | recursive_action.o remove_file.o \ | 21 | recursive_action.o remove_file.o \ |
| 22 | restricted_shell.o run_parts.o run_shell.o safe_read.o safe_write.o \ | 22 | restricted_shell.o run_parts.o run_shell.o read.o safe_write.o \ |
| 23 | safe_strncpy.o setup_environment.o sha1.o simplify_path.o \ | 23 | safe_strncpy.o setup_environment.o sha1.o simplify_path.o \ |
| 24 | trim.o u_signal_names.o vdprintf.o verror_msg.o \ | 24 | trim.o u_signal_names.o vdprintf.o verror_msg.o \ |
| 25 | vherror_msg.o vperror_msg.o wfopen.o xconnect.o xgetcwd.o \ | 25 | vherror_msg.o vperror_msg.o wfopen.o xconnect.o xgetcwd.o \ |
diff --git a/libbb/full_read.c b/libbb/full_read.c deleted file mode 100644 index 068d16698..000000000 --- a/libbb/full_read.c +++ /dev/null | |||
| @@ -1,42 +0,0 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Utility routines. | ||
| 4 | * | ||
| 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | ||
| 6 | * | ||
| 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include <stdio.h> | ||
| 11 | #include <unistd.h> | ||
| 12 | #include "libbb.h" | ||
| 13 | |||
| 14 | /* | ||
| 15 | * Read all of the supplied buffer from a file. | ||
| 16 | * This does multiple reads as necessary. | ||
| 17 | * Returns the amount read, or -1 on an error. | ||
| 18 | * A short read is returned on an end of file. | ||
| 19 | */ | ||
| 20 | ssize_t full_read(int fd, void *buf, size_t len) | ||
| 21 | { | ||
| 22 | ssize_t cc; | ||
| 23 | ssize_t total; | ||
| 24 | |||
| 25 | total = 0; | ||
| 26 | |||
| 27 | while (len) { | ||
| 28 | cc = safe_read(fd, buf, len); | ||
| 29 | |||
| 30 | if (cc < 0) | ||
| 31 | return cc; /* read() returns -1 on failure. */ | ||
| 32 | |||
| 33 | if (cc == 0) | ||
| 34 | break; | ||
| 35 | |||
| 36 | buf = ((char *)buf) + cc; | ||
| 37 | total += cc; | ||
| 38 | len -= cc; | ||
| 39 | } | ||
| 40 | |||
| 41 | return total; | ||
| 42 | } | ||
diff --git a/libbb/procps.c b/libbb/procps.c index 2bcd2cced..eba90705c 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
| @@ -22,15 +22,9 @@ | |||
| 22 | 22 | ||
| 23 | static int read_to_buf(const char *filename, void *buf) | 23 | static int read_to_buf(const char *filename, void *buf) |
| 24 | { | 24 | { |
| 25 | int fd; | ||
| 26 | ssize_t ret; | 25 | ssize_t ret; |
| 27 | 26 | ret = open_read_close(filename, buf, PROCPS_BUFSIZE-1); | |
| 28 | fd = open(filename, O_RDONLY); | 27 | ((char *)buf)[ret > 0 ? ret : 0] = '\0'; |
| 29 | if (fd < 0) | ||
| 30 | return -1; | ||
| 31 | ret = read(fd, buf, PROCPS_BUFSIZE-1); | ||
| 32 | ((char *)buf)[ret > 0 ? ret : 0] = 0; | ||
| 33 | close(fd); | ||
| 34 | return ret; | 28 | return ret; |
| 35 | } | 29 | } |
| 36 | 30 | ||
diff --git a/libbb/read.c b/libbb/read.c new file mode 100644 index 000000000..1c2945f45 --- /dev/null +++ b/libbb/read.c | |||
| @@ -0,0 +1,133 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Utility routines. | ||
| 4 | * | ||
| 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | ||
| 6 | * | ||
| 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include "libbb.h" | ||
| 11 | |||
| 12 | ssize_t safe_read(int fd, void *buf, size_t count) | ||
| 13 | { | ||
| 14 | ssize_t n; | ||
| 15 | |||
| 16 | do { | ||
| 17 | n = read(fd, buf, count); | ||
| 18 | } while (n < 0 && errno == EINTR); | ||
| 19 | |||
| 20 | return n; | ||
| 21 | } | ||
| 22 | |||
| 23 | /* | ||
| 24 | * Read all of the supplied buffer from a file. | ||
| 25 | * This does multiple reads as necessary. | ||
| 26 | * Returns the amount read, or -1 on an error. | ||
| 27 | * A short read is returned on an end of file. | ||
| 28 | */ | ||
| 29 | ssize_t full_read(int fd, void *buf, size_t len) | ||
| 30 | { | ||
| 31 | ssize_t cc; | ||
| 32 | ssize_t total; | ||
| 33 | |||
| 34 | total = 0; | ||
| 35 | |||
| 36 | while (len) { | ||
| 37 | cc = safe_read(fd, buf, len); | ||
| 38 | |||
| 39 | if (cc < 0) | ||
| 40 | return cc; /* read() returns -1 on failure. */ | ||
| 41 | |||
| 42 | if (cc == 0) | ||
| 43 | break; | ||
| 44 | |||
| 45 | buf = ((char *)buf) + cc; | ||
| 46 | total += cc; | ||
| 47 | len -= cc; | ||
| 48 | } | ||
| 49 | |||
| 50 | return total; | ||
| 51 | } | ||
| 52 | |||
| 53 | // Die with an error message if we can't read the entire buffer. | ||
| 54 | void xread(int fd, void *buf, size_t count) | ||
| 55 | { | ||
| 56 | if (count) { | ||
| 57 | ssize_t size = full_read(fd, buf, count); | ||
| 58 | if (size != count) | ||
| 59 | bb_error_msg_and_die("short read"); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | // Die with an error message if we can't read one character. | ||
| 64 | unsigned char xread_char(int fd) | ||
| 65 | { | ||
| 66 | char tmp; | ||
| 67 | |||
| 68 | xread(fd, &tmp, 1); | ||
| 69 | |||
| 70 | return tmp; | ||
| 71 | } | ||
| 72 | |||
| 73 | // Read one line a-la fgets. Works only on seekable streams | ||
| 74 | char *reads(int fd, char *buffer, size_t size) | ||
| 75 | { | ||
| 76 | char *p; | ||
| 77 | |||
| 78 | if (size < 2) | ||
| 79 | return NULL; | ||
| 80 | size = full_read(fd, buffer, size-1); | ||
| 81 | if ((ssize_t)size <= 0) | ||
| 82 | return NULL; | ||
| 83 | |||
| 84 | buffer[size] = '\0'; | ||
| 85 | p = strchr(buffer, '\n'); | ||
| 86 | if (p) { | ||
| 87 | off_t offset; | ||
| 88 | *p++ = '\0'; | ||
| 89 | offset = (p-buffer) - size; | ||
| 90 | // set fd position the right after the \n | ||
| 91 | if (offset && lseek(fd, offset, SEEK_CUR) == (off_t)-1) | ||
| 92 | return NULL; | ||
| 93 | } | ||
| 94 | return buffer; | ||
| 95 | } | ||
| 96 | |||
| 97 | ssize_t read_close(int fd, void *buf, size_t size) | ||
| 98 | { | ||
| 99 | int e; | ||
| 100 | size = full_read(fd, buf, size); | ||
| 101 | e = errno; | ||
| 102 | close(fd); | ||
| 103 | errno = e; | ||
| 104 | return size; | ||
| 105 | } | ||
| 106 | |||
| 107 | ssize_t open_read_close(const char *filename, void *buf, size_t size) | ||
| 108 | { | ||
| 109 | int fd = open(filename, O_RDONLY); | ||
| 110 | if (fd < 0) | ||
| 111 | return fd; | ||
| 112 | return read_close(fd, buf, size); | ||
| 113 | } | ||
| 114 | |||
| 115 | void *xmalloc_open_read_close(const char *filename, size_t *sizep) | ||
| 116 | { | ||
| 117 | char *buf; | ||
| 118 | size_t size = sizep ? *sizep : INT_MAX; | ||
| 119 | int fd = xopen(filename, O_RDONLY); | ||
| 120 | off_t len = xlseek(fd, 0, SEEK_END); | ||
| 121 | xlseek(fd, 0, SEEK_SET); | ||
| 122 | |||
| 123 | if (len > size) | ||
| 124 | bb_error_msg_and_die("file '%s' is too big", filename); | ||
| 125 | size = len; | ||
| 126 | buf = xmalloc(size+1); | ||
| 127 | size = read_close(fd, buf, size); | ||
| 128 | if ((ssize_t)size < 0) | ||
| 129 | bb_perror_msg_and_die("'%s'", filename); | ||
| 130 | buf[size] = '\0'; | ||
| 131 | if (sizep) *sizep = size; | ||
| 132 | return buf; | ||
| 133 | } | ||
diff --git a/libbb/safe_read.c b/libbb/safe_read.c deleted file mode 100644 index a59934a4d..000000000 --- a/libbb/safe_read.c +++ /dev/null | |||
| @@ -1,26 +0,0 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Utility routines. | ||
| 4 | * | ||
| 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | ||
| 6 | * | ||
| 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include <stdio.h> | ||
| 11 | #include <errno.h> | ||
| 12 | #include <unistd.h> | ||
| 13 | #include "libbb.h" | ||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | ssize_t safe_read(int fd, void *buf, size_t count) | ||
| 18 | { | ||
| 19 | ssize_t n; | ||
| 20 | |||
| 21 | do { | ||
| 22 | n = read(fd, buf, count); | ||
| 23 | } while (n < 0 && errno == EINTR); | ||
| 24 | |||
| 25 | return n; | ||
| 26 | } | ||
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index efc919491..0a5abb878 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
| @@ -95,7 +95,7 @@ int xopen(const char *pathname, int flags) | |||
| 95 | if (ENABLE_DEBUG && (flags & O_CREAT)) | 95 | if (ENABLE_DEBUG && (flags & O_CREAT)) |
| 96 | bb_error_msg_and_die("xopen() with O_CREAT"); | 96 | bb_error_msg_and_die("xopen() with O_CREAT"); |
| 97 | 97 | ||
| 98 | return xopen3(pathname, flags, 0777); | 98 | return xopen3(pathname, flags, 0666); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | // Die if we can't open a new file and return an fd. | 101 | // Die if we can't open a new file and return an fd. |
| @@ -110,16 +110,6 @@ int xopen3(const char *pathname, int flags, int mode) | |||
| 110 | return ret; | 110 | return ret; |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | // Die with an error message if we can't read the entire buffer. | ||
| 114 | void xread(int fd, void *buf, size_t count) | ||
| 115 | { | ||
| 116 | if (count) { | ||
| 117 | ssize_t size = full_read(fd, buf, count); | ||
| 118 | if (size != count) | ||
| 119 | bb_error_msg_and_die("short read"); | ||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | // Die with an error message if we can't write the entire buffer. | 113 | // Die with an error message if we can't write the entire buffer. |
| 124 | void xwrite(int fd, void *buf, size_t count) | 114 | void xwrite(int fd, void *buf, size_t count) |
| 125 | { | 115 | { |
| @@ -131,20 +121,12 @@ void xwrite(int fd, void *buf, size_t count) | |||
| 131 | } | 121 | } |
| 132 | 122 | ||
| 133 | // Die with an error message if we can't lseek to the right spot. | 123 | // Die with an error message if we can't lseek to the right spot. |
| 134 | void xlseek(int fd, off_t offset, int whence) | 124 | off_t xlseek(int fd, off_t offset, int whence) |
| 135 | { | 125 | { |
| 136 | if (offset != lseek(fd, offset, whence)) | 126 | off_t off = lseek(fd, offset, whence); |
| 137 | bb_error_msg_and_die("lseek"); | 127 | if (off == (off_t)-1) |
| 138 | } | 128 | bb_perror_msg_and_die("lseek"); |
| 139 | 129 | return off; | |
| 140 | // Die with an error message if we can't read one character. | ||
| 141 | unsigned char xread_char(int fd) | ||
| 142 | { | ||
| 143 | char tmp; | ||
| 144 | |||
| 145 | xread(fd, &tmp, 1); | ||
| 146 | |||
| 147 | return tmp; | ||
| 148 | } | 130 | } |
| 149 | 131 | ||
| 150 | // Die with supplied error message if this FILE * has ferror set. | 132 | // Die with supplied error message if this FILE * has ferror set. |
| @@ -309,7 +291,7 @@ off_t fdlength(int fd) | |||
| 309 | 291 | ||
| 310 | // If we can read from the current location, it's bigger. | 292 | // If we can read from the current location, it's bigger. |
| 311 | 293 | ||
| 312 | if (lseek(fd, pos, 0)>=0 && safe_read(fd, &temp, 1)==1) { | 294 | if (lseek(fd, pos, SEEK_SET)>=0 && safe_read(fd, &temp, 1)==1) { |
| 313 | if (bottom == top) bottom = top = (top+1) * 2; | 295 | if (bottom == top) bottom = top = (top+1) * 2; |
| 314 | else bottom = pos; | 296 | else bottom = pos; |
| 315 | 297 | ||
diff --git a/loginutils/deluser.c b/loginutils/deluser.c index f4320687e..bbbd77dbd 100644 --- a/loginutils/deluser.c +++ b/loginutils/deluser.c | |||
| @@ -70,7 +70,7 @@ static void del_line_matching(const char *login, const char *filename) | |||
| 70 | fclose(passwd); | 70 | fclose(passwd); |
| 71 | } | 71 | } |
| 72 | } else { | 72 | } else { |
| 73 | bb_error_msg("Can't find '%s' in '%s'", login, filename); | 73 | bb_error_msg("can't find '%s' in '%s'", login, filename); |
| 74 | } | 74 | } |
| 75 | free(buffer); | 75 | free(buffer); |
| 76 | } | 76 | } |
diff --git a/miscutils/crond.c b/miscutils/crond.c index 623e8c359..eaed1ea69 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
| @@ -120,7 +120,7 @@ static void crondlog(const char *ctl, ...) | |||
| 120 | close(logfd); | 120 | close(logfd); |
| 121 | #if ENABLE_DEBUG_CROND_OPTION | 121 | #if ENABLE_DEBUG_CROND_OPTION |
| 122 | } else { | 122 | } else { |
| 123 | bb_perror_msg("Can't open log file"); | 123 | bb_perror_msg("can't open log file"); |
| 124 | #endif | 124 | #endif |
| 125 | } | 125 | } |
| 126 | } | 126 | } |
| @@ -924,7 +924,7 @@ static void RunJob(const char *user, CronLine * line) | |||
| 924 | line->cl_MailFlag = 1; | 924 | line->cl_MailFlag = 1; |
| 925 | fdprintf(mailFd, "To: %s\nSubject: cron: %s\n\n", user, | 925 | fdprintf(mailFd, "To: %s\nSubject: cron: %s\n\n", user, |
| 926 | line->cl_Shell); | 926 | line->cl_Shell); |
| 927 | line->cl_MailPos = lseek(mailFd, 0, 1); | 927 | line->cl_MailPos = lseek(mailFd, 0, SEEK_CUR); |
| 928 | } else { | 928 | } else { |
| 929 | crondlog("\024unable to create mail file user %s file %s, output to /dev/null\n", user, mailFile); | 929 | crondlog("\024unable to create mail file user %s file %s, output to /dev/null\n", user, mailFile); |
| 930 | } | 930 | } |
diff --git a/miscutils/crontab.c b/miscutils/crontab.c index a3bfd495d..6ae1b020c 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c | |||
| @@ -171,7 +171,7 @@ int crontab_main(int ac, char **av) | |||
| 171 | } | 171 | } |
| 172 | EditFile(caller, tmp); | 172 | EditFile(caller, tmp); |
| 173 | remove(tmp); | 173 | remove(tmp); |
| 174 | lseek(fd, 0L, 0); | 174 | lseek(fd, 0L, SEEK_SET); |
| 175 | repFd = fd; | 175 | repFd = fd; |
| 176 | } | 176 | } |
| 177 | option = REPLACE; | 177 | option = REPLACE; |
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c index e4658010c..6ff5cc223 100644 --- a/miscutils/makedevs.c +++ b/miscutils/makedevs.c | |||
| @@ -187,7 +187,7 @@ int makedevs_main(int argc, char **argv) | |||
| 187 | sprintf(full_name_inc, "%s%d", full_name, i); | 187 | sprintf(full_name_inc, "%s%d", full_name, i); |
| 188 | rdev = (major << 8) + minor + (i * increment - start); | 188 | rdev = (major << 8) + minor + (i * increment - start); |
| 189 | if (mknod(full_name_inc, mode, rdev) == -1) { | 189 | if (mknod(full_name_inc, mode, rdev) == -1) { |
| 190 | bb_perror_msg("line %d: could not create node %s", linenum, full_name_inc); | 190 | bb_perror_msg("line %d: cannot create node %s", linenum, full_name_inc); |
| 191 | ret = EXIT_FAILURE; | 191 | ret = EXIT_FAILURE; |
| 192 | } | 192 | } |
| 193 | else if (chown(full_name_inc, uid, gid) == -1) { | 193 | else if (chown(full_name_inc, uid, gid) == -1) { |
| @@ -203,7 +203,7 @@ int makedevs_main(int argc, char **argv) | |||
| 203 | } else { | 203 | } else { |
| 204 | rdev = (major << 8) + minor; | 204 | rdev = (major << 8) + minor; |
| 205 | if (mknod(full_name, mode, rdev) == -1) { | 205 | if (mknod(full_name, mode, rdev) == -1) { |
| 206 | bb_perror_msg("line %d: could not create node %s", linenum, full_name); | 206 | bb_perror_msg("line %d: cannot create node %s", linenum, full_name); |
| 207 | ret = EXIT_FAILURE; | 207 | ret = EXIT_FAILURE; |
| 208 | } | 208 | } |
| 209 | else if (chown(full_name, uid, gid) == -1) { | 209 | else if (chown(full_name, uid, gid) == -1) { |
diff --git a/miscutils/nmeter.c b/miscutils/nmeter.c index e83de38ec..d71bd6add 100644 --- a/miscutils/nmeter.c +++ b/miscutils/nmeter.c | |||
| @@ -88,12 +88,7 @@ static void put_question_marks(int count) | |||
| 88 | 88 | ||
| 89 | static int readfile_z(char *buf, int sz, const char* fname) | 89 | static int readfile_z(char *buf, int sz, const char* fname) |
| 90 | { | 90 | { |
| 91 | int fd; | 91 | sz = open_read_close(fname, buf, sz-1); |
| 92 | fd = xopen(fname, O_RDONLY); | ||
| 93 | // We are not checking for short reads (valid only because | ||
| 94 | // we are reading /proc files) | ||
| 95 | sz = read(fd, buf, sz-1); | ||
| 96 | close(fd); | ||
| 97 | if (sz < 0) { | 92 | if (sz < 0) { |
| 98 | buf[0] = '\0'; | 93 | buf[0] = '\0'; |
| 99 | return 1; | 94 | return 1; |
| @@ -776,15 +771,12 @@ int nmeter_main(int argc, char* argv[]) | |||
| 776 | s_stat *last = NULL; | 771 | s_stat *last = NULL; |
| 777 | s_stat *s; | 772 | s_stat *s; |
| 778 | char *cur, *prev; | 773 | char *cur, *prev; |
| 779 | int fd; | ||
| 780 | 774 | ||
| 781 | if (argc != 2) | 775 | if (argc != 2) |
| 782 | bb_show_usage(); | 776 | bb_show_usage(); |
| 783 | 777 | ||
| 784 | fd = xopen("/proc/version", O_RDONLY); | 778 | if (open_read_close("/proc/version", buf, sizeof(buf)) > 0) |
| 785 | if (read(fd, buf, sizeof(buf)) > 0) | 779 | is26 = (strstr(buf, " 2.4.")==NULL); |
| 786 | is26 = (strstr(buf, "Linux version 2.4.")==NULL); | ||
| 787 | close(fd); | ||
| 788 | 780 | ||
| 789 | // Can use argv[1] directly, but this will mess up | 781 | // Can use argv[1] directly, but this will mess up |
| 790 | // parameters as seen by e.g. ps. Making a copy... | 782 | // parameters as seen by e.g. ps. Making a copy... |
diff --git a/modutils/insmod.c b/modutils/insmod.c index 3d9add19a..882fcf80f 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c | |||
| @@ -4186,10 +4186,10 @@ int insmod_main( int argc, char **argv) | |||
| 4186 | m_addr = create_module(m_name, m_size); | 4186 | m_addr = create_module(m_name, m_size); |
| 4187 | if (m_addr == -1) switch (errno) { | 4187 | if (m_addr == -1) switch (errno) { |
| 4188 | case EEXIST: | 4188 | case EEXIST: |
| 4189 | bb_error_msg("A module named %s already exists", m_name); | 4189 | bb_error_msg("a module named %s already exists", m_name); |
| 4190 | goto out; | 4190 | goto out; |
| 4191 | case ENOMEM: | 4191 | case ENOMEM: |
| 4192 | bb_error_msg("Can't allocate kernel memory for module; needed %lu bytes", | 4192 | bb_error_msg("can't allocate kernel memory for module; needed %lu bytes", |
| 4193 | m_size); | 4193 | m_size); |
| 4194 | goto out; | 4194 | goto out; |
| 4195 | default: | 4195 | default: |
diff --git a/modutils/lsmod.c b/modutils/lsmod.c index ac1cded2b..2bf4afbe9 100644 --- a/modutils/lsmod.c +++ b/modutils/lsmod.c | |||
| @@ -147,9 +147,8 @@ int lsmod_main(int argc, char **argv) | |||
| 147 | check_tainted(); | 147 | check_tainted(); |
| 148 | #if defined(CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT) | 148 | #if defined(CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT) |
| 149 | { | 149 | { |
| 150 | char line[4096]; | 150 | char *line; |
| 151 | 151 | while ((line = xmalloc_fgets(file)) != NULL) { | |
| 152 | while (fgets(line, sizeof(line), file)) { | ||
| 153 | char *tok; | 152 | char *tok; |
| 154 | 153 | ||
| 155 | tok = strtok(line, " \t"); | 154 | tok = strtok(line, " \t"); |
| @@ -175,7 +174,8 @@ int lsmod_main(int argc, char **argv) | |||
| 175 | tok = ""; | 174 | tok = ""; |
| 176 | printf(" %s", tok); | 175 | printf(" %s", tok); |
| 177 | } | 176 | } |
| 178 | printf("\n"); | 177 | puts(""); |
| 178 | free(line); | ||
| 179 | } | 179 | } |
| 180 | fclose(file); | 180 | fclose(file); |
| 181 | } | 181 | } |
diff --git a/modutils/modprobe.c b/modutils/modprobe.c index b629390e4..ab595c847 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c | |||
| @@ -93,35 +93,6 @@ static int parse_tag_value ( char *buffer, char **ptag, char **pvalue ) | |||
| 93 | return 1; | 93 | return 1; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | /* Jump through hoops to simulate how fgets() grabs just one line at a | ||
| 97 | * time... Don't use any stdio since modprobe gets called from a kernel | ||
| 98 | * thread and stdio junk can overflow the limited stack... | ||
| 99 | */ | ||
| 100 | static char *reads ( int fd, char *buffer, size_t len ) | ||
| 101 | { | ||
| 102 | int n = read ( fd, buffer, len ); | ||
| 103 | |||
| 104 | if ( n > 0 ) { | ||
| 105 | char *p; | ||
| 106 | |||
| 107 | buffer [len-1] = 0; | ||
| 108 | p = strchr ( buffer, '\n' ); | ||
| 109 | |||
| 110 | if ( p ) { | ||
| 111 | off_t offset; | ||
| 112 | |||
| 113 | offset = lseek ( fd, 0L, SEEK_CUR ); // Get the current file descriptor offset | ||
| 114 | lseek ( fd, offset-n + (p-buffer) + 1, SEEK_SET ); // Set the file descriptor offset to right after the \n | ||
| 115 | |||
| 116 | p[1] = 0; | ||
| 117 | } | ||
| 118 | return buffer; | ||
| 119 | } | ||
| 120 | |||
| 121 | else | ||
| 122 | return 0; | ||
| 123 | } | ||
| 124 | |||
| 125 | /* | 96 | /* |
| 126 | * This function appends an option to a list | 97 | * This function appends an option to a list |
| 127 | */ | 98 | */ |
| @@ -913,7 +884,7 @@ int modprobe_main(int argc, char** argv) | |||
| 913 | depend = build_dep ( ); | 884 | depend = build_dep ( ); |
| 914 | 885 | ||
| 915 | if ( !depend ) | 886 | if ( !depend ) |
| 916 | bb_error_msg_and_die ( "could not parse modules.dep" ); | 887 | bb_error_msg_and_die ( "cannot parse modules.dep" ); |
| 917 | 888 | ||
| 918 | if (remove_opt) { | 889 | if (remove_opt) { |
| 919 | do { | 890 | do { |
diff --git a/networking/fakeidentd.c b/networking/fakeidentd.c index c8d32765a..18e86c50b 100644 --- a/networking/fakeidentd.c +++ b/networking/fakeidentd.c | |||
| @@ -140,7 +140,7 @@ static int godaemon(void) | |||
| 140 | case 0: | 140 | case 0: |
| 141 | pw = getpwnam(nobodystr); | 141 | pw = getpwnam(nobodystr); |
| 142 | if (pw == NULL) | 142 | if (pw == NULL) |
| 143 | bb_error_msg_and_die("Cannot find uid/gid of user '%s'", nobodystr); | 143 | bb_error_msg_and_die("cannot find uid/gid of user '%s'", nobodystr); |
| 144 | nobody = pw->pw_uid; | 144 | nobody = pw->pw_uid; |
| 145 | nogrp = pw->pw_gid; | 145 | nogrp = pw->pw_gid; |
| 146 | writepid(nobody, nogrp); | 146 | writepid(nobody, nogrp); |
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index 47126ee83..aafeaf6e9 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c | |||
| @@ -166,7 +166,7 @@ int ftp_receive(ftp_host_info_t *server, FILE *control_stream, | |||
| 166 | if (do_continue) { | 166 | if (do_continue) { |
| 167 | fd_local = xopen(local_path, O_APPEND | O_WRONLY); | 167 | fd_local = xopen(local_path, O_APPEND | O_WRONLY); |
| 168 | } else { | 168 | } else { |
| 169 | fd_local = xopen3(local_path, O_CREAT | O_TRUNC | O_WRONLY, 0777); | 169 | fd_local = xopen3(local_path, O_CREAT | O_TRUNC | O_WRONLY, 0666); |
| 170 | } | 170 | } |
| 171 | } | 171 | } |
| 172 | 172 | ||
diff --git a/networking/inetd.c b/networking/inetd.c index 966425385..75b2b14a7 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
| @@ -1371,7 +1371,7 @@ inetd_main(int argc, char *argv[]) | |||
| 1371 | socklen_t plen = sizeof(peer); | 1371 | socklen_t plen = sizeof(peer); |
| 1372 | 1372 | ||
| 1373 | if (getpeername(ctrl, (struct sockaddr *) &peer, &plen) < 0) { | 1373 | if (getpeername(ctrl, (struct sockaddr *) &peer, &plen) < 0) { |
| 1374 | bb_error_msg("could not getpeername"); | 1374 | bb_error_msg("cannot getpeername"); |
| 1375 | close(ctrl); | 1375 | close(ctrl); |
| 1376 | continue; | 1376 | continue; |
| 1377 | } | 1377 | } |
diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c index de11d9dac..a595e967f 100644 --- a/networking/libiproute/libnetlink.c +++ b/networking/libiproute/libnetlink.c | |||
| @@ -126,7 +126,7 @@ int rtnl_dump_filter(struct rtnl_handle *rth, | |||
| 126 | int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *), | 126 | int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *), |
| 127 | void *arg2) | 127 | void *arg2) |
| 128 | { | 128 | { |
| 129 | char buf[8192]; | 129 | char buf[8192]; |
| 130 | struct sockaddr_nl nladdr; | 130 | struct sockaddr_nl nladdr; |
| 131 | struct iovec iov = { buf, sizeof(buf) }; | 131 | struct iovec iov = { buf, sizeof(buf) }; |
| 132 | 132 | ||
diff --git a/networking/netstat.c b/networking/netstat.c index bc5c61974..8e481f67b 100644 --- a/networking/netstat.c +++ b/networking/netstat.c | |||
| @@ -496,7 +496,6 @@ static void unix_do_one(int nr, const char *line) | |||
| 496 | 496 | ||
| 497 | static void do_info(const char *file, const char *name, void (*proc)(int, const char *)) | 497 | static void do_info(const char *file, const char *name, void (*proc)(int, const char *)) |
| 498 | { | 498 | { |
| 499 | char buffer[8192]; | ||
| 500 | int lnr = 0; | 499 | int lnr = 0; |
| 501 | FILE *procinfo; | 500 | FILE *procinfo; |
| 502 | 501 | ||
| @@ -505,12 +504,15 @@ static void do_info(const char *file, const char *name, void (*proc)(int, const | |||
| 505 | if (errno != ENOENT) { | 504 | if (errno != ENOENT) { |
| 506 | perror(file); | 505 | perror(file); |
| 507 | } else { | 506 | } else { |
| 508 | bb_error_msg("no support for `%s' on this system", name); | 507 | bb_error_msg("no support for '%s' on this system", name); |
| 509 | } | 508 | } |
| 510 | } else { | 509 | } else { |
| 511 | do { | 510 | do { |
| 512 | if (fgets(buffer, sizeof(buffer), procinfo)) | 511 | char *buffer = xmalloc_fgets(procinfo); |
| 512 | if (buffer) { | ||
| 513 | (proc)(lnr++, buffer); | 513 | (proc)(lnr++, buffer); |
| 514 | free(buffer); | ||
| 515 | } | ||
| 514 | } while (!feof(procinfo)); | 516 | } while (!feof(procinfo)); |
| 515 | fclose(procinfo); | 517 | fclose(procinfo); |
| 516 | } | 518 | } |
diff --git a/networking/traceroute.c b/networking/traceroute.c index 84ce8ae69..3b590630c 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
| @@ -417,7 +417,7 @@ ifaddrlist(struct IFADDRLIST **ipaddrp) | |||
| 417 | ++nipaddr; | 417 | ++nipaddr; |
| 418 | } | 418 | } |
| 419 | if (nipaddr == 0) | 419 | if (nipaddr == 0) |
| 420 | bb_error_msg_and_die ("Can't find any network interfaces"); | 420 | bb_error_msg_and_die ("can't find any network interfaces"); |
| 421 | (void)close(fd); | 421 | (void)close(fd); |
| 422 | 422 | ||
| 423 | *ipaddrp = st_ifaddrlist; | 423 | *ipaddrp = st_ifaddrlist; |
| @@ -472,7 +472,7 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from) | |||
| 472 | fclose(f); | 472 | fclose(f); |
| 473 | 473 | ||
| 474 | if (device[0] == '\0') | 474 | if (device[0] == '\0') |
| 475 | bb_error_msg_and_die ("Can't find interface"); | 475 | bb_error_msg_and_die ("can't find interface"); |
| 476 | 476 | ||
| 477 | /* Get the interface address list */ | 477 | /* Get the interface address list */ |
| 478 | n = ifaddrlist(&al); | 478 | n = ifaddrlist(&al); |
| @@ -482,7 +482,7 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from) | |||
| 482 | if (strcmp(device, al->device) == 0) | 482 | if (strcmp(device, al->device) == 0) |
| 483 | break; | 483 | break; |
| 484 | if (i <= 0) | 484 | if (i <= 0) |
| 485 | bb_error_msg_and_die("Can't find interface %s", device); | 485 | bb_error_msg_and_die("can't find interface %s", device); |
| 486 | 486 | ||
| 487 | setsin(from, al->addr); | 487 | setsin(from, al->addr); |
| 488 | } | 488 | } |
| @@ -1156,7 +1156,7 @@ traceroute_main(int argc, char *argv[]) | |||
| 1156 | if (strcmp(device, al->device) == 0) | 1156 | if (strcmp(device, al->device) == 0) |
| 1157 | break; | 1157 | break; |
| 1158 | if (i <= 0) { | 1158 | if (i <= 0) { |
| 1159 | bb_error_msg_and_die("Can't find interface %s", device); | 1159 | bb_error_msg_and_die("can't find interface %s", device); |
| 1160 | } | 1160 | } |
| 1161 | } | 1161 | } |
| 1162 | 1162 | ||
diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c index 587339f9b..086692082 100644 --- a/networking/udhcp/arpping.c +++ b/networking/udhcp/arpping.c | |||
| @@ -49,7 +49,7 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface) | |||
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) { | 51 | if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) { |
| 52 | bb_perror_msg("Could not setsocketopt on raw socket"); | 52 | bb_perror_msg("cannot setsocketopt on raw socket"); |
| 53 | close(s); | 53 | close(s); |
| 54 | return -1; | 54 | return -1; |
| 55 | } | 55 | } |
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c index f9f5a3b8c..439aa0250 100644 --- a/networking/udhcp/clientpacket.c +++ b/networking/udhcp/clientpacket.c | |||
| @@ -39,16 +39,13 @@ unsigned long random_xid(void) | |||
| 39 | { | 39 | { |
| 40 | static int initialized; | 40 | static int initialized; |
| 41 | if (!initialized) { | 41 | if (!initialized) { |
| 42 | int fd; | ||
| 43 | unsigned long seed; | 42 | unsigned long seed; |
| 44 | 43 | ||
| 45 | fd = open("/dev/urandom", 0); | 44 | if (open_read_close("/dev/urandom", &seed, sizeof(seed)) < 0) { |
| 46 | if (fd < 0 || read(fd, &seed, sizeof(seed)) < 0) { | 45 | bb_info_msg("Cannot load seed " |
| 47 | bb_info_msg("Could not load seed " | ||
| 48 | "from /dev/urandom: %s", strerror(errno)); | 46 | "from /dev/urandom: %s", strerror(errno)); |
| 49 | seed = time(0); | 47 | seed = time(0); |
| 50 | } | 48 | } |
| 51 | if (fd >= 0) close(fd); | ||
| 52 | srand(seed); | 49 | srand(seed); |
| 53 | initialized++; | 50 | initialized++; |
| 54 | } | 51 | } |
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c index ded0f7b9b..8dba2ef69 100644 --- a/networking/udhcp/options.c +++ b/networking/udhcp/options.c | |||
| @@ -171,6 +171,6 @@ int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data) | |||
| 171 | } | 171 | } |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | bb_error_msg("Could not add option 0x%02x", code); | 174 | bb_error_msg("cannot add option 0x%02x", code); |
| 175 | return 0; | 175 | return 0; |
| 176 | } | 176 | } |
diff --git a/networking/udhcp/signalpipe.c b/networking/udhcp/signalpipe.c index 6c4a9f1f2..bece4193a 100644 --- a/networking/udhcp/signalpipe.c +++ b/networking/udhcp/signalpipe.c | |||
| @@ -36,7 +36,7 @@ static int signal_pipe[2]; | |||
| 36 | static void signal_handler(int sig) | 36 | static void signal_handler(int sig) |
| 37 | { | 37 | { |
| 38 | if (send(signal_pipe[1], &sig, sizeof(sig), MSG_DONTWAIT) < 0) | 38 | if (send(signal_pipe[1], &sig, sizeof(sig), MSG_DONTWAIT) < 0) |
| 39 | bb_perror_msg("Could not send signal"); | 39 | bb_perror_msg("cannot send signal"); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | 42 | ||
diff --git a/networking/wget.c b/networking/wget.c index 264ae4483..7a931f363 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
| @@ -219,9 +219,7 @@ int wget_main(int argc, char **argv) | |||
| 219 | } else if (opt & WGET_OPT_CONTINUE) { | 219 | } else if (opt & WGET_OPT_CONTINUE) { |
| 220 | output_fd = open(fname_out, O_WRONLY); | 220 | output_fd = open(fname_out, O_WRONLY); |
| 221 | if (output_fd >= 0) { | 221 | if (output_fd >= 0) { |
| 222 | beg_range = lseek(output_fd, 0, SEEK_END); | 222 | beg_range = xlseek(output_fd, 0, SEEK_END); |
| 223 | if (beg_range == (off_t)-1) | ||
| 224 | bb_perror_msg_and_die("lseek"); | ||
| 225 | } | 223 | } |
| 226 | /* File doesn't exist. We do not create file here yet. | 224 | /* File doesn't exist. We do not create file here yet. |
| 227 | We are not sure it exists on remove side */ | 225 | We are not sure it exists on remove side */ |
diff --git a/procps/fuser.c b/procps/fuser.c index aae24f50c..4906797cf 100644 --- a/procps/fuser.c +++ b/procps/fuser.c | |||
| @@ -292,7 +292,7 @@ static int fuser_kill_pid_list(pid_list *plist, int sig) | |||
| 292 | if(curr->pid > 0 && curr->pid != mypid) { | 292 | if(curr->pid > 0 && curr->pid != mypid) { |
| 293 | if (kill(curr->pid, sig) != 0) { | 293 | if (kill(curr->pid, sig) != 0) { |
| 294 | bb_perror_msg( | 294 | bb_perror_msg( |
| 295 | "Could not kill pid '%d'", curr->pid); | 295 | "cannot kill pid '%d'", curr->pid); |
| 296 | success = 0; | 296 | success = 0; |
| 297 | } | 297 | } |
| 298 | } | 298 | } |
| @@ -342,7 +342,7 @@ int fuser_main(int argc, char **argv) | |||
| 342 | if(!fuser_file_to_dev_inode( | 342 | if(!fuser_file_to_dev_inode( |
| 343 | argv[fni[i]], &dev, &inode)) { | 343 | argv[fni[i]], &dev, &inode)) { |
| 344 | if (ENABLE_FEATURE_CLEAN_UP) free(inodes); | 344 | if (ENABLE_FEATURE_CLEAN_UP) free(inodes); |
| 345 | bb_perror_msg_and_die("Could not open '%s'", argv[fni[i]]); | 345 | bb_perror_msg_and_die("cannot open '%s'", argv[fni[i]]); |
| 346 | } | 346 | } |
| 347 | fuser_add_inode(inodes, dev, inode); | 347 | fuser_add_inode(inodes, dev, inode); |
| 348 | } | 348 | } |
diff --git a/procps/top.c b/procps/top.c index 14a3870a1..06a84c90c 100644 --- a/procps/top.c +++ b/procps/top.c | |||
| @@ -448,7 +448,7 @@ int top_main(int argc, char **argv) | |||
| 448 | memcpy(top + n, p, sizeof(procps_status_t)); | 448 | memcpy(top + n, p, sizeof(procps_status_t)); |
| 449 | } | 449 | } |
| 450 | if (ntop == 0) { | 450 | if (ntop == 0) { |
| 451 | bb_error_msg_and_die("Can't find process info in /proc"); | 451 | bb_error_msg_and_die("can't find process info in /proc"); |
| 452 | } | 452 | } |
| 453 | #ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE | 453 | #ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE |
| 454 | if (!prev_hist_count) { | 454 | if (!prev_hist_count) { |
diff --git a/shell/msh.c b/shell/msh.c index df6f321aa..cb2947137 100644 --- a/shell/msh.c +++ b/shell/msh.c | |||
| @@ -2954,7 +2954,7 @@ static int iosetup(struct ioword *iop, int pipein, int pipeout) | |||
| 2954 | 2954 | ||
| 2955 | case IOWRITE | IOCAT: | 2955 | case IOWRITE | IOCAT: |
| 2956 | if ((u = open(cp, 1)) >= 0) { | 2956 | if ((u = open(cp, 1)) >= 0) { |
| 2957 | lseek(u, (long) 0, 2); | 2957 | lseek(u, (long) 0, SEEK_END); |
| 2958 | break; | 2958 | break; |
| 2959 | } | 2959 | } |
| 2960 | case IOWRITE: | 2960 | case IOWRITE: |
| @@ -4686,7 +4686,7 @@ static void pushio(struct ioarg *argp, int (*fn) (struct ioarg *)) | |||
| 4686 | /* This line appears to be active when running scripts from command line */ | 4686 | /* This line appears to be active when running scripts from command line */ |
| 4687 | if ((isatty(e.iop->argp->afile) == 0) | 4687 | if ((isatty(e.iop->argp->afile) == 0) |
| 4688 | && (e.iop == &iostack[0] | 4688 | && (e.iop == &iostack[0] |
| 4689 | || lseek(e.iop->argp->afile, 0L, 1) != -1)) { | 4689 | || lseek(e.iop->argp->afile, 0L, SEEK_CUR) != -1)) { |
| 4690 | if (++bufid == AFID_NOBUF) /* counter rollover check, AFID_NOBUF = 11111111 */ | 4690 | if (++bufid == AFID_NOBUF) /* counter rollover check, AFID_NOBUF = 11111111 */ |
| 4691 | bufid = AFID_ID; /* AFID_ID = 0 */ | 4691 | bufid = AFID_ID; /* AFID_ID = 0 */ |
| 4692 | 4692 | ||
| @@ -4831,7 +4831,7 @@ static int filechar(struct ioarg *ap) | |||
| 4831 | if ((i = ap->afid != bp->id) || bp->bufp == bp->ebufp) { | 4831 | if ((i = ap->afid != bp->id) || bp->bufp == bp->ebufp) { |
| 4832 | 4832 | ||
| 4833 | if (i) | 4833 | if (i) |
| 4834 | lseek(ap->afile, ap->afpos, 0); | 4834 | lseek(ap->afile, ap->afpos, SEEK_SET); |
| 4835 | 4835 | ||
| 4836 | i = safe_read(ap->afile, bp->buf, sizeof(bp->buf)); | 4836 | i = safe_read(ap->afile, bp->buf, sizeof(bp->buf)); |
| 4837 | 4837 | ||
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index cce31335e..1aff87c11 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c | |||
| @@ -51,11 +51,11 @@ static time_t read_rtc(int utc) | |||
| 51 | 51 | ||
| 52 | if (( rtc = open ( "/dev/rtc", O_RDONLY )) < 0 ) { | 52 | if (( rtc = open ( "/dev/rtc", O_RDONLY )) < 0 ) { |
| 53 | if (( rtc = open ( "/dev/misc/rtc", O_RDONLY )) < 0 ) | 53 | if (( rtc = open ( "/dev/misc/rtc", O_RDONLY )) < 0 ) |
| 54 | bb_perror_msg_and_die ( "Could not access RTC" ); | 54 | bb_perror_msg_and_die ( "cannot access RTC" ); |
| 55 | } | 55 | } |
| 56 | memset ( &tm, 0, sizeof( struct tm )); | 56 | memset ( &tm, 0, sizeof( struct tm )); |
| 57 | if ( ioctl ( rtc, RTC_RD_TIME, &tm ) < 0 ) | 57 | if ( ioctl ( rtc, RTC_RD_TIME, &tm ) < 0 ) |
| 58 | bb_perror_msg_and_die ( "Could not read time from RTC" ); | 58 | bb_perror_msg_and_die ( "cannot read time from RTC" ); |
| 59 | tm.tm_isdst = -1; /* not known */ | 59 | tm.tm_isdst = -1; /* not known */ |
| 60 | 60 | ||
| 61 | close ( rtc ); | 61 | close ( rtc ); |
| @@ -85,14 +85,14 @@ static void write_rtc(time_t t, int utc) | |||
| 85 | 85 | ||
| 86 | if (( rtc = open ( "/dev/rtc", O_WRONLY )) < 0 ) { | 86 | if (( rtc = open ( "/dev/rtc", O_WRONLY )) < 0 ) { |
| 87 | if (( rtc = open ( "/dev/misc/rtc", O_WRONLY )) < 0 ) | 87 | if (( rtc = open ( "/dev/misc/rtc", O_WRONLY )) < 0 ) |
| 88 | bb_perror_msg_and_die ( "Could not access RTC" ); | 88 | bb_perror_msg_and_die ( "cannot access RTC" ); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | tm = *( utc ? gmtime ( &t ) : localtime ( &t )); | 91 | tm = *( utc ? gmtime ( &t ) : localtime ( &t )); |
| 92 | tm.tm_isdst = 0; | 92 | tm.tm_isdst = 0; |
| 93 | 93 | ||
| 94 | if ( ioctl ( rtc, RTC_SET_TIME, &tm ) < 0 ) | 94 | if ( ioctl ( rtc, RTC_SET_TIME, &tm ) < 0 ) |
| 95 | bb_perror_msg_and_die ( "Could not set the RTC time" ); | 95 | bb_perror_msg_and_die ( "cannot set the RTC time" ); |
| 96 | 96 | ||
| 97 | close ( rtc ); | 97 | close ( rtc ); |
| 98 | } | 98 | } |
diff --git a/util-linux/mdev.c b/util-linux/mdev.c index f43393692..1df144fa9 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c | |||
| @@ -39,10 +39,8 @@ static void make_device(char *path, int delete) | |||
| 39 | 39 | ||
| 40 | if (!delete) { | 40 | if (!delete) { |
| 41 | strcat(path, "/dev"); | 41 | strcat(path, "/dev"); |
| 42 | fd = open(path, O_RDONLY); | 42 | len = open_read_close(path, temp + 1, 64); |
| 43 | len = read(fd, temp + 1, 64); | ||
| 44 | *temp++ = 0; | 43 | *temp++ = 0; |
| 45 | close(fd); | ||
| 46 | if (len < 1) return; | 44 | if (len < 1) return; |
| 47 | } | 45 | } |
| 48 | 46 | ||
diff --git a/util-linux/readprofile.c b/util-linux/readprofile.c index b368067ef..e635f6bf3 100644 --- a/util-linux/readprofile.c +++ b/util-linux/readprofile.c | |||
| @@ -44,9 +44,9 @@ static const char defaultpro[] = "/proc/profile"; | |||
| 44 | int readprofile_main(int argc, char **argv) | 44 | int readprofile_main(int argc, char **argv) |
| 45 | { | 45 | { |
| 46 | FILE *map; | 46 | FILE *map; |
| 47 | int proFd; | ||
| 48 | const char *mapFile, *proFile, *mult=0; | 47 | const char *mapFile, *proFile, *mult=0; |
| 49 | unsigned long len=0, indx=1; | 48 | unsigned long indx=1; |
| 49 | size_t len; | ||
| 50 | uint64_t add0=0; | 50 | uint64_t add0=0; |
| 51 | unsigned int step; | 51 | unsigned int step; |
| 52 | unsigned int *buf, total, fn_len; | 52 | unsigned int *buf, total, fn_len; |
| @@ -97,20 +97,8 @@ int readprofile_main(int argc, char **argv) | |||
| 97 | /* | 97 | /* |
| 98 | * Use an fd for the profiling buffer, to skip stdio overhead | 98 | * Use an fd for the profiling buffer, to skip stdio overhead |
| 99 | */ | 99 | */ |
| 100 | 100 | len = INT_MAX; | |
| 101 | proFd = xopen(proFile,O_RDONLY); | 101 | buf = xmalloc_open_read_close(proFile, &len); |
| 102 | |||
| 103 | if (((int)(len=lseek(proFd,0,SEEK_END)) < 0) | ||
| 104 | || (lseek(proFd,0,SEEK_SET) < 0)) | ||
| 105 | bb_perror_msg_and_die(proFile); | ||
| 106 | |||
| 107 | buf = xmalloc(len); | ||
| 108 | |||
| 109 | if (read(proFd,buf,len) != len) | ||
| 110 | bb_perror_msg_and_die(proFile); | ||
| 111 | |||
| 112 | close(proFd); | ||
| 113 | |||
| 114 | if (!optNative) { | 102 | if (!optNative) { |
| 115 | int entries = len/sizeof(*buf); | 103 | int entries = len/sizeof(*buf); |
| 116 | int big = 0,small = 0,i; | 104 | int big = 0,small = 0,i; |
| @@ -123,8 +111,8 @@ int readprofile_main(int argc, char **argv) | |||
| 123 | small++; | 111 | small++; |
| 124 | } | 112 | } |
| 125 | if (big > small) { | 113 | if (big > small) { |
| 126 | bb_error_msg("Assuming reversed byte order. " | 114 | bb_error_msg("assuming reversed byte order, " |
| 127 | "Use -n to force native byte order."); | 115 | "use -n to force native byte order"); |
| 128 | for (p = buf; p < buf+entries; p++) | 116 | for (p = buf; p < buf+entries; p++) |
| 129 | for (i = 0; i < sizeof(*buf)/2; i++) { | 117 | for (i = 0; i < sizeof(*buf)/2; i++) { |
| 130 | unsigned char *b = (unsigned char *) p; | 118 | unsigned char *b = (unsigned char *) p; |
