diff options
38 files changed, 228 insertions, 234 deletions
diff --git a/archival/libunarchive/get_header_ar.c b/archival/libunarchive/get_header_ar.c index 7372ada..b91c6f9 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) (saved in variable long_name) that conatains the real filename */ const unsigned int long_offset = atoi(&ar.formatted.name[1]); if (long_offset >= ar_long_name_size) { - bb_error_msg_and_die("Cant resolve long filename"); + bb_error_msg_and_die("can't resolve long filename"); } typed->name = xstrdup(ar_long_names + long_offset); } diff --git a/archival/libunarchive/open_transformer.c b/archival/libunarchive/open_transformer.c index 99e71ec..456d3e9 100644 --- a/archival/libunarchive/open_transformer.c +++ b/archival/libunarchive/open_transformer.c @@ -18,23 +18,23 @@ int open_transformer(int src_fd, int pid; if (pipe(fd_pipe) != 0) { - bb_perror_msg_and_die("Can't create pipe"); + bb_perror_msg_and_die("can't create pipe"); } pid = fork(); if (pid == -1) { - bb_perror_msg_and_die("Fork failed"); + bb_perror_msg_and_die("fork failed"); } if (pid == 0) { /* child process */ - close(fd_pipe[0]); /* We don't wan't to read from the parent */ - // FIXME: error check? - transformer(src_fd, fd_pipe[1]); - close(fd_pipe[1]); /* Send EOF */ + close(fd_pipe[0]); /* We don't wan't to read from the parent */ + // FIXME: error check? + transformer(src_fd, fd_pipe[1]); + close(fd_pipe[1]); /* Send EOF */ close(src_fd); - exit(0); - /* notreached */ + exit(0); + /* notreached */ } /* parent process */ diff --git a/archival/tar.c b/archival/tar.c index 5935cca..2c4280c 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -457,7 +457,7 @@ static int writeTarFile(const int tar_fd, const int verboseFlag, if (n == 0 && vfork_exec_errno != 0) { errno = vfork_exec_errno; - bb_perror_msg_and_die("Could not exec %s", zip_exec); + bb_perror_msg_and_die("cannot exec %s", zip_exec); } else if ((n < 0) && (errno == EAGAIN || errno == EINTR)) continue; /* try it again */ break; diff --git a/coreutils/diff.c b/coreutils/diff.c index 65757d7..2915d40 100644 --- a/coreutils/diff.c +++ b/coreutils/diff.c @@ -1202,7 +1202,7 @@ int diff_main(int argc, char **argv) * driver routine. Both drivers use the contents of stb1 and stb2. */ if (argc < 2) { - bb_error_msg("Missing filename"); + bb_error_msg("missing filename"); bb_show_usage(); } if (strcmp(argv[0], "-") == 0) { @@ -1216,12 +1216,12 @@ int diff_main(int argc, char **argv) } else xstat(argv[1], &stb2); if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode))) - bb_error_msg_and_die("Can't compare - to a directory"); + bb_error_msg_and_die("can't compare - to a directory"); if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { #if ENABLE_FEATURE_DIFF_DIR diffdir(argv[0], argv[1]); #else - bb_error_msg_and_die("Directory comparison not supported"); + bb_error_msg_and_die("directory comparison not supported"); #endif } else { if (S_ISDIR(stb1.st_mode)) { diff --git a/editors/vi.c b/editors/vi.c index fa30cf2..a25e966 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -2353,7 +2353,7 @@ static int file_insert(Byte * fn, Byte * p, int size) #endif fd = open((char *) fn, O_RDONLY); // try read-only if (fd < 0) { - psbs("\"%s\" %s", fn, "could not open file"); + psbs("\"%s\" %s", fn, "cannot open file"); goto fi0; } #ifdef CONFIG_FEATURE_VI_READONLY @@ -2367,11 +2367,11 @@ static int file_insert(Byte * fn, Byte * p, int size) if (cnt < 0) { cnt = -1; p = text_hole_delete(p, p + size - 1); // un-do buffer insert - psbs("could not read file \"%s\"", fn); + psbs("cannot read file \"%s\"", fn); } else if (cnt < size) { // There was a partial read, shrink unused space text[] p = text_hole_delete(p + cnt, p + (size - cnt) - 1); // un-do buffer insert - psbs("could not read all of file \"%s\"", fn); + psbs("cannot read all of file \"%s\"", fn); } if (cnt >= size) file_modified++; diff --git a/include/libbb.h b/include/libbb.h index 767a337..0bcabf1 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) extern DIR *warn_opendir(const char *path); extern DIR *xopendir(const char *path); -extern int remove_file(const char *path, int flags); -extern int copy_file(const char *source, const char *dest, int flags); extern ssize_t safe_read(int fd, void *buf, size_t count); -extern ssize_t full_read(int fd, void *buf, size_t len); +extern ssize_t full_read(int fd, void *buf, size_t count); +extern void xread(int fd, void *buf, size_t count); +extern unsigned char xread_char(int fd); +extern char *reads(int fd, char *buf, size_t count); +ssize_t read_close(int fd, void *buf, size_t count); +ssize_t open_read_close(const char *filename, void *buf, size_t count); +void *xmalloc_open_read_close(const char *filename, size_t *sizep); + extern ssize_t safe_write(int fd, const void *buf, size_t count); -extern ssize_t full_write(int fd, const void *buf, size_t len); +extern ssize_t full_write(int fd, const void *buf, size_t count); +extern void xwrite(int fd, void *buf, size_t count); + +extern int remove_file(const char *path, int flags); +extern int copy_file(const char *source, const char *dest, int flags); + extern int recursive_action(const char *fileName, int recurse, int followLinks, int depthFirst, 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 extern void xsetenv(const char *key, const char *value); extern int xopen(const char *pathname, int flags); extern int xopen3(const char *pathname, int flags, int mode); -extern void xread(int fd, void *buf, size_t count); -extern unsigned char xread_char(int fd); -extern void xlseek(int fd, off_t offset, int whence); -extern void xwrite(int fd, void *buf, size_t count); +extern off_t xlseek(int fd, off_t offset, int whence); extern const char bb_uuenc_tbl_base64[]; extern const char bb_uuenc_tbl_std[]; diff --git a/init/init.c b/init/init.c index 8257b7f..99a11e5 100644 --- a/init/init.c +++ b/init/init.c @@ -561,7 +561,7 @@ static pid_t run(const struct init_action *a) execv(cmdpath, cmd); /* We're still here? Some error happened. */ - message(LOG | CONSOLE, "Bummer, could not run '%s': %m", cmdpath); + message(LOG | CONSOLE, "Bummer, cannot run '%s': %m", cmdpath); _exit(-1); } sigprocmask(SIG_SETMASK, &omask, NULL); diff --git a/libbb/Kbuild b/libbb/Kbuild index 27ed68c..3b16f5c 100644 --- a/libbb/Kbuild +++ b/libbb/Kbuild @@ -9,7 +9,7 @@ lib-y:= \ compare_string_array.o concat_path_file.o copy_file.o copyfd.o \ crc32.o create_icmp_socket.o create_icmp6_socket.o \ device_open.o dump.o error_msg.o error_msg_and_die.o \ - find_pid_by_name.o find_root_device.o fgets_str.o full_read.o \ + find_pid_by_name.o find_root_device.o fgets_str.o \ full_write.o get_last_path_component.o get_line_from_file.o \ herror_msg.o herror_msg_and_die.o \ human_readable.o inet_common.o inode_hash.o isdirectory.o \ @@ -19,7 +19,7 @@ lib-y:= \ perror_msg_and_die.o get_console.o \ process_escape_sequence.o procps.o \ recursive_action.o remove_file.o \ - restricted_shell.o run_parts.o run_shell.o safe_read.o safe_write.o \ + restricted_shell.o run_parts.o run_shell.o read.o safe_write.o \ safe_strncpy.o setup_environment.o sha1.o simplify_path.o \ trim.o u_signal_names.o vdprintf.o verror_msg.o \ 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 068d166..0000000 --- a/libbb/full_read.c +++ /dev/null @@ -1,42 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Utility routines. - * - * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> - * - * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. - */ - -#include <stdio.h> -#include <unistd.h> -#include "libbb.h" - -/* - * Read all of the supplied buffer from a file. - * This does multiple reads as necessary. - * Returns the amount read, or -1 on an error. - * A short read is returned on an end of file. - */ -ssize_t full_read(int fd, void *buf, size_t len) -{ - ssize_t cc; - ssize_t total; - - total = 0; - - while (len) { - cc = safe_read(fd, buf, len); - - if (cc < 0) - return cc; /* read() returns -1 on failure. */ - - if (cc == 0) - break; - - buf = ((char *)buf) + cc; - total += cc; - len -= cc; - } - - return total; -} diff --git a/libbb/procps.c b/libbb/procps.c index 2bcd2cc..eba9070 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -22,15 +22,9 @@ static int read_to_buf(const char *filename, void *buf) { - int fd; ssize_t ret; - - fd = open(filename, O_RDONLY); - if (fd < 0) - return -1; - ret = read(fd, buf, PROCPS_BUFSIZE-1); - ((char *)buf)[ret > 0 ? ret : 0] = 0; - close(fd); + ret = open_read_close(filename, buf, PROCPS_BUFSIZE-1); + ((char *)buf)[ret > 0 ? ret : 0] = '\0'; return ret; } diff --git a/libbb/read.c b/libbb/read.c new file mode 100644 index 0000000..1c2945f --- /dev/null +++ b/libbb/read.c @@ -0,0 +1,133 @@ +/* vi: set sw=4 ts=4: */ +/* + * Utility routines. + * + * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> + * + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + */ + +#include "libbb.h" + +ssize_t safe_read(int fd, void *buf, size_t count) +{ + ssize_t n; + + do { + n = read(fd, buf, count); + } while (n < 0 && errno == EINTR); + + return n; +} + +/* + * Read all of the supplied buffer from a file. + * This does multiple reads as necessary. + * Returns the amount read, or -1 on an error. + * A short read is returned on an end of file. + */ +ssize_t full_read(int fd, void *buf, size_t len) +{ + ssize_t cc; + ssize_t total; + + total = 0; + + while (len) { + cc = safe_read(fd, buf, len); + + if (cc < 0) + return cc; /* read() returns -1 on failure. */ + + if (cc == 0) + break; + + buf = ((char *)buf) + cc; + total += cc; + len -= cc; + } + + return total; +} + +// Die with an error message if we can't read the entire buffer. +void xread(int fd, void *buf, size_t count) +{ + if (count) { + ssize_t size = full_read(fd, buf, count); + if (size != count) + bb_error_msg_and_die("short read"); + } +} + +// Die with an error message if we can't read one character. +unsigned char xread_char(int fd) +{ + char tmp; + + xread(fd, &tmp, 1); + + return tmp; +} + +// Read one line a-la fgets. Works only on seekable streams +char *reads(int fd, char *buffer, size_t size) +{ + char *p; + + if (size < 2) + return NULL; + size = full_read(fd, buffer, size-1); + if ((ssize_t)size <= 0) + return NULL; + + buffer[size] = '\0'; + p = strchr(buffer, '\n'); + if (p) { + off_t offset; + *p++ = '\0'; + offset = (p-buffer) - size; + // set fd position the right after the \n + if (offset && lseek(fd, offset, SEEK_CUR) == (off_t)-1) + return NULL; + } + return buffer; +} + +ssize_t read_close(int fd, void *buf, size_t size) +{ + int e; + size = full_read(fd, buf, size); + e = errno; + close(fd); + errno = e; + return size; +} + +ssize_t open_read_close(const char *filename, void *buf, size_t size) +{ + int fd = open(filename, O_RDONLY); + if (fd < 0) + return fd; + return read_close(fd, buf, size); +} + +void *xmalloc_open_read_close(const char *filename, size_t *sizep) +{ + char *buf; + size_t size = sizep ? *sizep : INT_MAX; + int fd = xopen(filename, O_RDONLY); + off_t len = xlseek(fd, 0, SEEK_END); + xlseek(fd, 0, SEEK_SET); + + if (len > size) + bb_error_msg_and_die("file '%s' is too big", filename); + size = len; + buf = xmalloc(size+1); + size = read_close(fd, buf, size); + if ((ssize_t)size < 0) + bb_perror_msg_and_die("'%s'", filename); + buf[size] = '\0'; + if (sizep) *sizep = size; + return buf; +} diff --git a/libbb/safe_read.c b/libbb/safe_read.c deleted file mode 100644 index a59934a..0000000 --- a/libbb/safe_read.c +++ /dev/null @@ -1,26 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Utility routines. - * - * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> - * - * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. - */ - -#include <stdio.h> -#include <errno.h> -#include <unistd.h> -#include "libbb.h" - - - -ssize_t safe_read(int fd, void *buf, size_t count) -{ - ssize_t n; - - do { - n = read(fd, buf, count); - } while (n < 0 && errno == EINTR); - - return n; -} diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index efc9194..0a5abb8 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -95,7 +95,7 @@ int xopen(const char *pathname, int flags) if (ENABLE_DEBUG && (flags & O_CREAT)) bb_error_msg_and_die("xopen() with O_CREAT"); - return xopen3(pathname, flags, 0777); + return xopen3(pathname, flags, 0666); } // 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) return ret; } -// Die with an error message if we can't read the entire buffer. -void xread(int fd, void *buf, size_t count) -{ - if (count) { - ssize_t size = full_read(fd, buf, count); - if (size != count) - bb_error_msg_and_die("short read"); - } -} - // Die with an error message if we can't write the entire buffer. void xwrite(int fd, void *buf, size_t count) { @@ -131,20 +121,12 @@ void xwrite(int fd, void *buf, size_t count) } // Die with an error message if we can't lseek to the right spot. -void xlseek(int fd, off_t offset, int whence) +off_t xlseek(int fd, off_t offset, int whence) { - if (offset != lseek(fd, offset, whence)) - bb_error_msg_and_die("lseek"); -} - -// Die with an error message if we can't read one character. -unsigned char xread_char(int fd) -{ - char tmp; - - xread(fd, &tmp, 1); - - return tmp; + off_t off = lseek(fd, offset, whence); + if (off == (off_t)-1) + bb_perror_msg_and_die("lseek"); + return off; } // Die with supplied error message if this FILE * has ferror set. @@ -309,7 +291,7 @@ off_t fdlength(int fd) // If we can read from the current location, it's bigger. - if (lseek(fd, pos, 0)>=0 && safe_read(fd, &temp, 1)==1) { + if (lseek(fd, pos, SEEK_SET)>=0 && safe_read(fd, &temp, 1)==1) { if (bottom == top) bottom = top = (top+1) * 2; else bottom = pos; diff --git a/loginutils/deluser.c b/loginutils/deluser.c index f432068..bbbd77d 100644 --- a/loginutils/deluser.c +++ b/loginutils/deluser.c @@ -70,7 +70,7 @@ static void del_line_matching(const char *login, const char *filename) fclose(passwd); } } else { - bb_error_msg("Can't find '%s' in '%s'", login, filename); + bb_error_msg("can't find '%s' in '%s'", login, filename); } free(buffer); } diff --git a/miscutils/crond.c b/miscutils/crond.c index 623e8c3..eaed1ea 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c @@ -120,7 +120,7 @@ static void crondlog(const char *ctl, ...) close(logfd); #if ENABLE_DEBUG_CROND_OPTION } else { - bb_perror_msg("Can't open log file"); + bb_perror_msg("can't open log file"); #endif } } @@ -924,7 +924,7 @@ static void RunJob(const char *user, CronLine * line) line->cl_MailFlag = 1; fdprintf(mailFd, "To: %s\nSubject: cron: %s\n\n", user, line->cl_Shell); - line->cl_MailPos = lseek(mailFd, 0, 1); + line->cl_MailPos = lseek(mailFd, 0, SEEK_CUR); } else { crondlog("\024unable to create mail file user %s file %s, output to /dev/null\n", user, mailFile); } diff --git a/miscutils/crontab.c b/miscutils/crontab.c index a3bfd49..6ae1b02 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c @@ -171,7 +171,7 @@ int crontab_main(int ac, char **av) } EditFile(caller, tmp); remove(tmp); - lseek(fd, 0L, 0); + lseek(fd, 0L, SEEK_SET); repFd = fd; } option = REPLACE; diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c index e465801..6ff5cc2 100644 --- a/miscutils/makedevs.c +++ b/miscutils/makedevs.c @@ -187,7 +187,7 @@ int makedevs_main(int argc, char **argv) sprintf(full_name_inc, "%s%d", full_name, i); rdev = (major << 8) + minor + (i * increment - start); if (mknod(full_name_inc, mode, rdev) == -1) { - bb_perror_msg("line %d: could not create node %s", linenum, full_name_inc); + bb_perror_msg("line %d: cannot create node %s", linenum, full_name_inc); ret = EXIT_FAILURE; } else if (chown(full_name_inc, uid, gid) == -1) { @@ -203,7 +203,7 @@ int makedevs_main(int argc, char **argv) } else { rdev = (major << 8) + minor; if (mknod(full_name, mode, rdev) == -1) { - bb_perror_msg("line %d: could not create node %s", linenum, full_name); + bb_perror_msg("line %d: cannot create node %s", linenum, full_name); ret = EXIT_FAILURE; } else if (chown(full_name, uid, gid) == -1) { diff --git a/miscutils/nmeter.c b/miscutils/nmeter.c index e83de38..d71bd6a 100644 --- a/miscutils/nmeter.c +++ b/miscutils/nmeter.c @@ -88,12 +88,7 @@ static void put_question_marks(int count) static int readfile_z(char *buf, int sz, const char* fname) { - int fd; - fd = xopen(fname, O_RDONLY); - // We are not checking for short reads (valid only because - // we are reading /proc files) - sz = read(fd, buf, sz-1); - close(fd); + sz = open_read_close(fname, buf, sz-1); if (sz < 0) { buf[0] = '\0'; return 1; @@ -776,15 +771,12 @@ int nmeter_main(int argc, char* argv[]) s_stat *last = NULL; s_stat *s; char *cur, *prev; - int fd; if (argc != 2) bb_show_usage(); - fd = xopen("/proc/version", O_RDONLY); - if (read(fd, buf, sizeof(buf)) > 0) - is26 = (strstr(buf, "Linux version 2.4.")==NULL); - close(fd); + if (open_read_close("/proc/version", buf, sizeof(buf)) > 0) + is26 = (strstr(buf, " 2.4.")==NULL); // Can use argv[1] directly, but this will mess up // parameters as seen by e.g. ps. Making a copy... diff --git a/modutils/insmod.c b/modutils/insmod.c index 3d9add1..882fcf8 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c @@ -4186,10 +4186,10 @@ int insmod_main( int argc, char **argv) m_addr = create_module(m_name, m_size); if (m_addr == -1) switch (errno) { case EEXIST: - bb_error_msg("A module named %s already exists", m_name); + bb_error_msg("a module named %s already exists", m_name); goto out; case ENOMEM: - bb_error_msg("Can't allocate kernel memory for module; needed %lu bytes", + bb_error_msg("can't allocate kernel memory for module; needed %lu bytes", m_size); goto out; default: diff --git a/modutils/lsmod.c b/modutils/lsmod.c index ac1cded..2bf4afb 100644 --- a/modutils/lsmod.c +++ b/modutils/lsmod.c @@ -147,9 +147,8 @@ int lsmod_main(int argc, char **argv) check_tainted(); #if defined(CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT) { - char line[4096]; - - while (fgets(line, sizeof(line), file)) { + char *line; + while ((line = xmalloc_fgets(file)) != NULL) { char *tok; tok = strtok(line, " \t"); @@ -175,7 +174,8 @@ int lsmod_main(int argc, char **argv) tok = ""; printf(" %s", tok); } - printf("\n"); + puts(""); + free(line); } fclose(file); } diff --git a/modutils/modprobe.c b/modutils/modprobe.c index b629390..ab595c8 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c @@ -93,35 +93,6 @@ static int parse_tag_value ( char *buffer, char **ptag, char **pvalue ) return 1; } -/* Jump through hoops to simulate how fgets() grabs just one line at a - * time... Don't use any stdio since modprobe gets called from a kernel - * thread and stdio junk can overflow the limited stack... - */ -static char *reads ( int fd, char *buffer, size_t len ) -{ - int n = read ( fd, buffer, len ); - - if ( n > 0 ) { - char *p; - - buffer [len-1] = 0; - p = strchr ( buffer, '\n' ); - - if ( p ) { - off_t offset; - - offset = lseek ( fd, 0L, SEEK_CUR ); // Get the current file descriptor offset - lseek ( fd, offset-n + (p-buffer) + 1, SEEK_SET ); // Set the file descriptor offset to right after the \n - - p[1] = 0; - } - return buffer; - } - - else - return 0; -} - /* * This function appends an option to a list */ @@ -913,7 +884,7 @@ int modprobe_main(int argc, char** argv) depend = build_dep ( ); if ( !depend ) - bb_error_msg_and_die ( "could not parse modules.dep" ); + bb_error_msg_and_die ( "cannot parse modules.dep" ); if (remove_opt) { do { diff --git a/networking/fakeidentd.c b/networking/fakeidentd.c index c8d3276..18e86c5 100644 --- a/networking/fakeidentd.c +++ b/networking/fakeidentd.c @@ -140,7 +140,7 @@ static int godaemon(void) case 0: pw = getpwnam(nobodystr); if (pw == NULL) - bb_error_msg_and_die("Cannot find uid/gid of user '%s'", nobodystr); + bb_error_msg_and_die("cannot find uid/gid of user '%s'", nobodystr); nobody = pw->pw_uid; nogrp = pw->pw_gid; writepid(nobody, nogrp); diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index 47126ee..aafeaf6 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c @@ -166,7 +166,7 @@ int ftp_receive(ftp_host_info_t *server, FILE *control_stream, if (do_continue) { fd_local = xopen(local_path, O_APPEND | O_WRONLY); } else { - fd_local = xopen3(local_path, O_CREAT | O_TRUNC | O_WRONLY, 0777); + fd_local = xopen3(local_path, O_CREAT | O_TRUNC | O_WRONLY, 0666); } } diff --git a/networking/inetd.c b/networking/inetd.c index 9664253..75b2b14 100644 --- a/networking/inetd.c +++ b/networking/inetd.c @@ -1371,7 +1371,7 @@ inetd_main(int argc, char *argv[]) socklen_t plen = sizeof(peer); if (getpeername(ctrl, (struct sockaddr *) &peer, &plen) < 0) { - bb_error_msg("could not getpeername"); + bb_error_msg("cannot getpeername"); close(ctrl); continue; } diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c index de11d9d..a595e96 100644 --- a/networking/libiproute/libnetlink.c +++ b/networking/libiproute/libnetlink.c @@ -126,7 +126,7 @@ int rtnl_dump_filter(struct rtnl_handle *rth, int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *), void *arg2) { - char buf[8192]; + char buf[8192]; struct sockaddr_nl nladdr; struct iovec iov = { buf, sizeof(buf) }; diff --git a/networking/netstat.c b/networking/netstat.c index bc5c619..8e481f6 100644 --- a/networking/netstat.c +++ b/networking/netstat.c @@ -496,7 +496,6 @@ static void unix_do_one(int nr, const char *line) static void do_info(const char *file, const char *name, void (*proc)(int, const char *)) { - char buffer[8192]; int lnr = 0; FILE *procinfo; @@ -505,12 +504,15 @@ static void do_info(const char *file, const char *name, void (*proc)(int, const if (errno != ENOENT) { perror(file); } else { - bb_error_msg("no support for `%s' on this system", name); + bb_error_msg("no support for '%s' on this system", name); } } else { do { - if (fgets(buffer, sizeof(buffer), procinfo)) + char *buffer = xmalloc_fgets(procinfo); + if (buffer) { (proc)(lnr++, buffer); + free(buffer); + } } while (!feof(procinfo)); fclose(procinfo); } diff --git a/networking/traceroute.c b/networking/traceroute.c index 84ce8ae..3b59063 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -417,7 +417,7 @@ ifaddrlist(struct IFADDRLIST **ipaddrp) ++nipaddr; } if (nipaddr == 0) - bb_error_msg_and_die ("Can't find any network interfaces"); + bb_error_msg_and_die ("can't find any network interfaces"); (void)close(fd); *ipaddrp = st_ifaddrlist; @@ -472,7 +472,7 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from) fclose(f); if (device[0] == '\0') - bb_error_msg_and_die ("Can't find interface"); + bb_error_msg_and_die ("can't find interface"); /* Get the interface address list */ n = ifaddrlist(&al); @@ -482,7 +482,7 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from) if (strcmp(device, al->device) == 0) break; if (i <= 0) - bb_error_msg_and_die("Can't find interface %s", device); + bb_error_msg_and_die("can't find interface %s", device); setsin(from, al->addr); } @@ -1156,7 +1156,7 @@ traceroute_main(int argc, char *argv[]) if (strcmp(device, al->device) == 0) break; if (i <= 0) { - bb_error_msg_and_die("Can't find interface %s", device); + bb_error_msg_and_die("can't find interface %s", device); } } diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c index 587339f..0866920 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) } if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) { - bb_perror_msg("Could not setsocketopt on raw socket"); + bb_perror_msg("cannot setsocketopt on raw socket"); close(s); return -1; } diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c index f9f5a3b..439aa02 100644 --- a/networking/udhcp/clientpacket.c +++ b/networking/udhcp/clientpacket.c @@ -39,16 +39,13 @@ unsigned long random_xid(void) { static int initialized; if (!initialized) { - int fd; unsigned long seed; - fd = open("/dev/urandom", 0); - if (fd < 0 || read(fd, &seed, sizeof(seed)) < 0) { - bb_info_msg("Could not load seed " + if (open_read_close("/dev/urandom", &seed, sizeof(seed)) < 0) { + bb_info_msg("Cannot load seed " "from /dev/urandom: %s", strerror(errno)); seed = time(0); } - if (fd >= 0) close(fd); srand(seed); initialized++; } diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c index ded0f7b..8dba2ef 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) } } - bb_error_msg("Could not add option 0x%02x", code); + bb_error_msg("cannot add option 0x%02x", code); return 0; } diff --git a/networking/udhcp/signalpipe.c b/networking/udhcp/signalpipe.c index 6c4a9f1..bece419 100644 --- a/networking/udhcp/signalpipe.c +++ b/networking/udhcp/signalpipe.c @@ -36,7 +36,7 @@ static int signal_pipe[2]; static void signal_handler(int sig) { if (send(signal_pipe[1], &sig, sizeof(sig), MSG_DONTWAIT) < 0) - bb_perror_msg("Could not send signal"); + bb_perror_msg("cannot send signal"); } diff --git a/networking/wget.c b/networking/wget.c index 264ae44..7a931f3 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -219,9 +219,7 @@ int wget_main(int argc, char **argv) } else if (opt & WGET_OPT_CONTINUE) { output_fd = open(fname_out, O_WRONLY); if (output_fd >= 0) { - beg_range = lseek(output_fd, 0, SEEK_END); - if (beg_range == (off_t)-1) - bb_perror_msg_and_die("lseek"); + beg_range = xlseek(output_fd, 0, SEEK_END); } /* File doesn't exist. We do not create file here yet. We are not sure it exists on remove side */ diff --git a/procps/fuser.c b/procps/fuser.c index aae24f5..4906797 100644 --- a/procps/fuser.c +++ b/procps/fuser.c @@ -292,7 +292,7 @@ static int fuser_kill_pid_list(pid_list *plist, int sig) if(curr->pid > 0 && curr->pid != mypid) { if (kill(curr->pid, sig) != 0) { bb_perror_msg( - "Could not kill pid '%d'", curr->pid); + "cannot kill pid '%d'", curr->pid); success = 0; } } @@ -342,7 +342,7 @@ int fuser_main(int argc, char **argv) if(!fuser_file_to_dev_inode( argv[fni[i]], &dev, &inode)) { if (ENABLE_FEATURE_CLEAN_UP) free(inodes); - bb_perror_msg_and_die("Could not open '%s'", argv[fni[i]]); + bb_perror_msg_and_die("cannot open '%s'", argv[fni[i]]); } fuser_add_inode(inodes, dev, inode); } diff --git a/procps/top.c b/procps/top.c index 14a3870..06a84c9 100644 --- a/procps/top.c +++ b/procps/top.c @@ -448,7 +448,7 @@ int top_main(int argc, char **argv) memcpy(top + n, p, sizeof(procps_status_t)); } if (ntop == 0) { - bb_error_msg_and_die("Can't find process info in /proc"); + bb_error_msg_and_die("can't find process info in /proc"); } #ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE if (!prev_hist_count) { diff --git a/shell/msh.c b/shell/msh.c index df6f321..cb29471 100644 --- a/shell/msh.c +++ b/shell/msh.c @@ -2954,7 +2954,7 @@ static int iosetup(struct ioword *iop, int pipein, int pipeout) case IOWRITE | IOCAT: if ((u = open(cp, 1)) >= 0) { - lseek(u, (long) 0, 2); + lseek(u, (long) 0, SEEK_END); break; } case IOWRITE: @@ -4686,7 +4686,7 @@ static void pushio(struct ioarg *argp, int (*fn) (struct ioarg *)) /* This line appears to be active when running scripts from command line */ if ((isatty(e.iop->argp->afile) == 0) && (e.iop == &iostack[0] - || lseek(e.iop->argp->afile, 0L, 1) != -1)) { + || lseek(e.iop->argp->afile, 0L, SEEK_CUR) != -1)) { if (++bufid == AFID_NOBUF) /* counter rollover check, AFID_NOBUF = 11111111 */ bufid = AFID_ID; /* AFID_ID = 0 */ @@ -4831,7 +4831,7 @@ static int filechar(struct ioarg *ap) if ((i = ap->afid != bp->id) || bp->bufp == bp->ebufp) { if (i) - lseek(ap->afile, ap->afpos, 0); + lseek(ap->afile, ap->afpos, SEEK_SET); i = safe_read(ap->afile, bp->buf, sizeof(bp->buf)); diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index cce3133..1aff87c 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c @@ -51,11 +51,11 @@ static time_t read_rtc(int utc) if (( rtc = open ( "/dev/rtc", O_RDONLY )) < 0 ) { if (( rtc = open ( "/dev/misc/rtc", O_RDONLY )) < 0 ) - bb_perror_msg_and_die ( "Could not access RTC" ); + bb_perror_msg_and_die ( "cannot access RTC" ); } memset ( &tm, 0, sizeof( struct tm )); if ( ioctl ( rtc, RTC_RD_TIME, &tm ) < 0 ) - bb_perror_msg_and_die ( "Could not read time from RTC" ); + bb_perror_msg_and_die ( "cannot read time from RTC" ); tm.tm_isdst = -1; /* not known */ close ( rtc ); @@ -85,14 +85,14 @@ static void write_rtc(time_t t, int utc) if (( rtc = open ( "/dev/rtc", O_WRONLY )) < 0 ) { if (( rtc = open ( "/dev/misc/rtc", O_WRONLY )) < 0 ) - bb_perror_msg_and_die ( "Could not access RTC" ); + bb_perror_msg_and_die ( "cannot access RTC" ); } tm = *( utc ? gmtime ( &t ) : localtime ( &t )); tm.tm_isdst = 0; if ( ioctl ( rtc, RTC_SET_TIME, &tm ) < 0 ) - bb_perror_msg_and_die ( "Could not set the RTC time" ); + bb_perror_msg_and_die ( "cannot set the RTC time" ); close ( rtc ); } diff --git a/util-linux/mdev.c b/util-linux/mdev.c index f433936..1df144f 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -39,10 +39,8 @@ static void make_device(char *path, int delete) if (!delete) { strcat(path, "/dev"); - fd = open(path, O_RDONLY); - len = read(fd, temp + 1, 64); + len = open_read_close(path, temp + 1, 64); *temp++ = 0; - close(fd); if (len < 1) return; } diff --git a/util-linux/readprofile.c b/util-linux/readprofile.c index b368067..e635f6b 100644 --- a/util-linux/readprofile.c +++ b/util-linux/readprofile.c @@ -44,9 +44,9 @@ static const char defaultpro[] = "/proc/profile"; int readprofile_main(int argc, char **argv) { FILE *map; - int proFd; const char *mapFile, *proFile, *mult=0; - unsigned long len=0, indx=1; + unsigned long indx=1; + size_t len; uint64_t add0=0; unsigned int step; unsigned int *buf, total, fn_len; @@ -97,20 +97,8 @@ int readprofile_main(int argc, char **argv) /* * Use an fd for the profiling buffer, to skip stdio overhead */ - - proFd = xopen(proFile,O_RDONLY); - - if (((int)(len=lseek(proFd,0,SEEK_END)) < 0) - || (lseek(proFd,0,SEEK_SET) < 0)) - bb_perror_msg_and_die(proFile); - - buf = xmalloc(len); - - if (read(proFd,buf,len) != len) - bb_perror_msg_and_die(proFile); - - close(proFd); - + len = INT_MAX; + buf = xmalloc_open_read_close(proFile, &len); if (!optNative) { int entries = len/sizeof(*buf); int big = 0,small = 0,i; @@ -123,8 +111,8 @@ int readprofile_main(int argc, char **argv) small++; } if (big > small) { - bb_error_msg("Assuming reversed byte order. " - "Use -n to force native byte order."); + bb_error_msg("assuming reversed byte order, " + "use -n to force native byte order"); for (p = buf; p < buf+entries; p++) for (i = 0; i < sizeof(*buf)/2; i++) { unsigned char *b = (unsigned char *) p; |