From 0ef64bdb40c54681e8dd5ab8df42ac88e4ab1d4a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 16 Aug 2010 20:14:46 +0200 Subject: *: make GNU licensing statement forms more regular This change retains "or later" state! No licensing _changes_ here, only form is adjusted (article, space between "GPL" and "v2" and so on). Signed-off-by: Denys Vlasenko --- shell/Kbuild.src | 2 +- shell/ash.c | 2 +- shell/ash_ptr_hack.c | 2 +- shell/bbsh.c | 2 +- shell/cttyhack.c | 4 ++-- shell/hush.c | 2 +- shell/match.c | 2 +- shell/math.c | 2 +- shell/random.c | 2 +- shell/random.h | 2 +- shell/shell_common.c | 2 +- shell/shell_common.h | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) (limited to 'shell') diff --git a/shell/Kbuild.src b/shell/Kbuild.src index a669bdfb0..c00aec92a 100644 --- a/shell/Kbuild.src +++ b/shell/Kbuild.src @@ -2,7 +2,7 @@ # # Copyright (C) 1999-2005 by Erik Andersen # -# Licensed under the GPL v2, see the file LICENSE in this tarball. +# Licensed under GPLv2, see file LICENSE in this source tree. lib-y:= diff --git a/shell/ash.c b/shell/ash.c index 4fbae2498..c8e7e3b06 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -13,7 +13,7 @@ * Copyright (c) 1997-2005 Herbert Xu * was re-ported from NetBSD and debianized. * - * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. + * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ /* diff --git a/shell/ash_ptr_hack.c b/shell/ash_ptr_hack.c index 68d907292..f69840825 100644 --- a/shell/ash_ptr_hack.c +++ b/shell/ash_ptr_hack.c @@ -2,7 +2,7 @@ /* * Copyright (C) 2008 by Denys Vlasenko * - * Licensed under GPLv2, see file LICENSE in this tarball for details. + * Licensed under GPLv2, see file LICENSE in this source tree. */ struct globals_misc; diff --git a/shell/bbsh.c b/shell/bbsh.c index 83132f928..8e25db458 100644 --- a/shell/bbsh.c +++ b/shell/bbsh.c @@ -4,7 +4,7 @@ * * Copyright 2006 Rob Landley * - * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ // A section of code that gets repeatedly or conditionally executed is stored diff --git a/shell/cttyhack.c b/shell/cttyhack.c index 7a5e1ffd2..d1cb7fcc3 100644 --- a/shell/cttyhack.c +++ b/shell/cttyhack.c @@ -1,8 +1,8 @@ /* vi: set sw=4 ts=4: */ /* - * Licensed under GPLv2 - * * Copyright (c) 2007 Denys Vlasenko + * + * Licensed under GPLv2, see file LICENSE in this source tree. */ #include "libbb.h" diff --git a/shell/hush.c b/shell/hush.c index df4058998..e8dfb2499 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -79,7 +79,7 @@ * $ "export" i=`echo 'aaa bbb'`; echo "$i" * aaa * - * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. + * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ #include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ #include /* for malloc_trim */ diff --git a/shell/match.c b/shell/match.c index fb6a38ef1..8b1ddacd5 100644 --- a/shell/match.c +++ b/shell/match.c @@ -4,7 +4,7 @@ * This code is derived from software contributed to Berkeley by * Kenneth Almquist. * - * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. + * Licensed under GPLv2 or later, see file LICENSE in this source tree. * * Copyright (c) 1989, 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. diff --git a/shell/math.c b/shell/math.c index 91fb28f05..f0cc2e35d 100644 --- a/shell/math.c +++ b/shell/math.c @@ -23,7 +23,7 @@ * rewrote arith (see notes to this), added locale support, * rewrote dynamic variables. * - * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. + * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ /* Copyright (c) 2001 Aaron Lehmann diff --git a/shell/random.c b/shell/random.c index 7f5821cbc..853ab085a 100644 --- a/shell/random.c +++ b/shell/random.c @@ -4,7 +4,7 @@ * * Copyright (C) 2009 Denys Vlasenko * - * Licensed under GPLv2, see file LICENSE in this tarball for details. + * Licensed under GPLv2, see file LICENSE in this source tree. */ #include "libbb.h" #include "random.h" diff --git a/shell/random.h b/shell/random.h index 08563402c..180c48abb 100644 --- a/shell/random.h +++ b/shell/random.h @@ -4,7 +4,7 @@ * * Copyright (C) 2009 Denys Vlasenko * - * Licensed under GPLv2, see file LICENSE in this tarball for details. + * Licensed under GPLv2, see file LICENSE in this source tree. */ #ifndef SHELL_RANDOM_H #define SHELL_RANDOM_H 1 diff --git a/shell/shell_common.c b/shell/shell_common.c index dc363e298..9345005c7 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -14,7 +14,7 @@ * Copyright (c) 2010 Denys Vlasenko * Split from ash.c * - * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. + * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ #include "libbb.h" #include "shell_common.h" diff --git a/shell/shell_common.h b/shell/shell_common.h index 1e9f6a691..f06bc4120 100644 --- a/shell/shell_common.h +++ b/shell/shell_common.h @@ -14,7 +14,7 @@ * Copyright (c) 2010 Denys Vlasenko * Split from ash.c * - * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. + * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ #ifndef SHELL_COMMON_H #define SHELL_COMMON_H 1 -- cgit v1.2.3-55-g6feb From b32a5436633f53f0abf0fa29105cf7e5b65091cf Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 29 Aug 2010 13:29:02 +0200 Subject: nandwrite: complain on malformed -s NUM Elsewhere: use common error message. -30 bytes net size change Signed-off-by: Denys Vlasenko --- coreutils/printf.c | 4 ++-- miscutils/nandwrite.c | 2 ++ procps/kill.c | 4 ++-- procps/renice.c | 2 +- shell/shell_common.c | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) (limited to 'shell') diff --git a/coreutils/printf.c b/coreutils/printf.c index 3497148e3..2cc238439 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -66,7 +66,7 @@ static int multiconvert(const char *arg, void *result, converter convert) errno = 0; convert(arg, result); if (errno) { - bb_error_msg("%s: invalid number", arg); + bb_error_msg("invalid number '%s'", arg); return 1; } return 0; @@ -230,7 +230,7 @@ static int get_width_prec(const char *str) { int v = bb_strtoi(str, NULL, 10); if (errno) { - bb_error_msg("%s: invalid number", str); + bb_error_msg("invalid number '%s'", str); v = 0; } return v; diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c index d0e4397fb..8df0fdc81 100644 --- a/miscutils/nandwrite.c +++ b/miscutils/nandwrite.c @@ -72,6 +72,8 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv) xioctl(fd, MEMGETINFO, &meminfo); mtdoffset = bb_strtou(opt_s, NULL, 0); + if (errno) + bb_error_msg_and_die("invalid number '%s'", opt_s); /* Pull it into a CPU register (hopefully) - smaller code that way */ meminfo_writesize = meminfo.writesize; diff --git a/procps/kill.c b/procps/kill.c index 4ed94b0ec..b51d44a70 100644 --- a/procps/kill.c +++ b/procps/kill.c @@ -153,7 +153,7 @@ int kill_main(int argc, char **argv) arg = argv[i]; omit = bb_strtoi(arg, NULL, 10); if (errno) { - bb_error_msg("bad pid '%s'", arg); + bb_error_msg("invalid number '%s'", arg); ret = 1; goto resume; } @@ -211,7 +211,7 @@ int kill_main(int argc, char **argv) arg++; pid = bb_strtoi(arg, NULL, 10); if (errno) { - bb_error_msg("bad pid '%s'", arg); + bb_error_msg("invalid number '%s'", arg); errors++; } else if (kill(pid, signo) != 0) { bb_perror_msg("can't kill pid %d", (int)pid); diff --git a/procps/renice.c b/procps/renice.c index 81ee89cfb..0a73cbeeb 100644 --- a/procps/renice.c +++ b/procps/renice.c @@ -91,7 +91,7 @@ int renice_main(int argc UNUSED_PARAM, char **argv) } else { who = bb_strtou(arg, NULL, 10); if (errno) { - bb_error_msg("bad value: %s", arg); + bb_error_msg("invalid number '%s'", arg); goto HAD_ERROR; } } diff --git a/shell/shell_common.c b/shell/shell_common.c index 9345005c7..e9effd2d0 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -422,7 +422,7 @@ shell_builtin_ulimit(char **argv) else val = bb_strtoull(val_str, NULL, 10); if (errno) { - bb_error_msg("bad number"); + bb_error_msg("invalid number '%s'", val_str); return EXIT_FAILURE; } val <<= l->factor_shift; -- cgit v1.2.3-55-g6feb From f7a8433535b7072b61acf31d97dab7da1d4b140b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 30 Aug 2010 13:54:12 +0200 Subject: ash: add another ${v/a/b} test we currently fail Signed-off-by: Denys Vlasenko --- shell/ash_test/ash-vars/var_bash5.right | 4 ++++ shell/ash_test/ash-vars/var_bash5.tests | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 shell/ash_test/ash-vars/var_bash5.right create mode 100755 shell/ash_test/ash-vars/var_bash5.tests (limited to 'shell') diff --git a/shell/ash_test/ash-vars/var_bash5.right b/shell/ash_test/ash-vars/var_bash5.right new file mode 100644 index 000000000..278ed3228 --- /dev/null +++ b/shell/ash_test/ash-vars/var_bash5.right @@ -0,0 +1,4 @@ +a/ +a/d +a/e/f +Done: 0 diff --git a/shell/ash_test/ash-vars/var_bash5.tests b/shell/ash_test/ash-vars/var_bash5.tests new file mode 100755 index 000000000..3f49321e1 --- /dev/null +++ b/shell/ash_test/ash-vars/var_bash5.tests @@ -0,0 +1,11 @@ +# This testcase checks whether slashes in ${v/a/b} are parsed before or after expansions +# in a part + +v='a/b/c' +s='b/c' +r='e/f' +echo "${v/$s}" +echo "${v/$s/d}" +echo "${v/$s/$r}" + +echo Done: $? -- cgit v1.2.3-55-g6feb From 0ff78a0166b284215a15a41e82e200301fb45f1e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 30 Aug 2010 15:20:07 +0200 Subject: ash: small code shrink (-21 bytes) Signed-off-by: Denys Vlasenko --- shell/ash.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index c8e7e3b06..921367be5 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -11146,10 +11146,9 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) if (dqvarnest > 0) { dqvarnest--; } - USTPUTC(CTLENDVAR, out); - } else { - USTPUTC(c, out); + c = CTLENDVAR; } + USTPUTC(c, out); break; #if ENABLE_SH_MATH_SUPPORT case CLP: /* '(' in arithmetic */ @@ -11158,25 +11157,23 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) break; case CRP: /* ')' in arithmetic */ if (parenlevel > 0) { - USTPUTC(c, out); - --parenlevel; + parenlevel--; } else { if (pgetc() == ')') { if (--arinest == 0) { - USTPUTC(CTLENDARI, out); syntax = prevsyntax; dblquote = (syntax == DQSYNTAX); - } else - USTPUTC(')', out); + c = CTLENDARI; + } } else { /* * unbalanced parens * (don't 2nd guess - no error) */ pungetc(); - USTPUTC(')', out); } } + USTPUTC(c, out); break; #endif case CBQUOTE: /* '`' */ -- cgit v1.2.3-55-g6feb From 8d3e225a2d1d980bcedb825f294b6a8041fe3f1b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 31 Aug 2010 12:42:06 +0200 Subject: libbb: add xfstat function function old new delta xfstat - 25 +25 mkfs_ext2_main 2421 2423 +2 mkfs_reiser_main 1197 1194 -3 next 312 307 -5 ar_main 533 522 -11 mkfs_minix_main 2938 2924 -14 mkfs_vfat_main 1511 1495 -16 writeTarFile 272 255 -17 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/6 up/down: 27/-66) Total: -39 bytes Signed-off-by: Denys Vlasenko --- archival/ar.c | 3 +-- archival/tar.c | 3 +-- include/libbb.h | 1 + libbb/dump.c | 4 +--- libbb/update_passwd.c | 2 +- libbb/xfuncs_printf.c | 10 ++++++++++ miscutils/ubi_attach_detach.c | 4 ++-- shell/ash.c | 8 ++++++-- util-linux/mkfs_ext2.c | 2 +- util-linux/mkfs_minix.c | 3 +-- util-linux/mkfs_reiser.c | 4 ++-- util-linux/mkfs_vfat.c | 3 +-- util-linux/mkswap.c | 3 +-- 13 files changed, 29 insertions(+), 21 deletions(-) (limited to 'shell') diff --git a/archival/ar.c b/archival/ar.c index bce62f76d..05556c6cb 100644 --- a/archival/ar.c +++ b/archival/ar.c @@ -123,8 +123,7 @@ static int write_ar_archive(archive_handle_t *handle) struct stat st; archive_handle_t *out_handle; - if (fstat(handle->src_fd, &st) == -1) - bb_simple_perror_msg_and_die(handle->ar__name); + xfstat(handle->src_fd, &st, handle->ar__name); /* if archive exists, create a new handle for output. * we create it in place of the old one. diff --git a/archival/tar.c b/archival/tar.c index b5cbf4197..2176ad2ac 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -572,8 +572,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, /* Store the stat info for the tarball's file, so * can avoid including the tarball into itself.... */ - if (fstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf) < 0) - bb_perror_msg_and_die("can't stat tar file"); + xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file"); #if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 if (gzip) diff --git a/include/libbb.h b/include/libbb.h index 43e525cb9..6fb0438f5 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -411,6 +411,7 @@ void bb_unsetenv(const char *key) FAST_FUNC; void bb_unsetenv_and_free(char *key) FAST_FUNC; void xunlink(const char *pathname) FAST_FUNC; void xstat(const char *pathname, struct stat *buf) FAST_FUNC; +void xfstat(int fd, struct stat *buf, const char *errmsg) FAST_FUNC; int xopen(const char *pathname, int flags) FAST_FUNC; int xopen_nonblocking(const char *pathname) FAST_FUNC; int xopen3(const char *pathname, int flags, int mode) FAST_FUNC; diff --git a/libbb/dump.c b/libbb/dump.c index a739ff61e..4db3f06f0 100644 --- a/libbb/dump.c +++ b/libbb/dump.c @@ -323,9 +323,7 @@ static void do_skip(priv_dumper_t *dumper, const char *fname, int statok) struct stat sbuf; if (statok) { - if (fstat(STDIN_FILENO, &sbuf)) { - bb_simple_perror_msg_and_die(fname); - } + xfstat(STDIN_FILENO, &sbuf, fname); if (!(S_ISCHR(sbuf.st_mode) || S_ISBLK(sbuf.st_mode) || S_ISFIFO(sbuf.st_mode)) && dumper->pub.dump_skip >= sbuf.st_size ) { diff --git a/libbb/update_passwd.c b/libbb/update_passwd.c index e050dfc0e..a2be0f155 100644 --- a/libbb/update_passwd.c +++ b/libbb/update_passwd.c @@ -133,7 +133,7 @@ int FAST_FUNC update_passwd(const char *filename, goto close_old_fp; created: - if (!fstat(old_fd, &sb)) { + if (fstat(old_fd, &sb) == 0) { fchmod(new_fd, sb.st_mode & 0777); /* ignore errors */ fchown(new_fd, sb.st_uid, sb.st_gid); } diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index b99f906df..c6db38d33 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c @@ -436,6 +436,16 @@ void FAST_FUNC xstat(const char *name, struct stat *stat_buf) bb_perror_msg_and_die("can't stat '%s'", name); } +void FAST_FUNC xfstat(int fd, struct stat *stat_buf, const char *errmsg) +{ + /* errmsg is usually a file name, but not always: + * xfstat may be called in a spot where file name is no longer + * available, and caller may give e.g. "can't stat input file" string. + */ + if (fstat(fd, stat_buf)) + bb_simple_perror_msg_and_die(errmsg); +} + // selinux_or_die() - die if SELinux is disabled. void FAST_FUNC selinux_or_die(void) { diff --git a/miscutils/ubi_attach_detach.c b/miscutils/ubi_attach_detach.c index 15377aa37..18ffd4df2 100644 --- a/miscutils/ubi_attach_detach.c +++ b/miscutils/ubi_attach_detach.c @@ -63,9 +63,9 @@ int ubi_attach_detach_main(int argc UNUSED_PARAM, char **argv) ubi_ctrl = argv[optind]; fd = xopen(ubi_ctrl, O_RDWR); - //fstat(fd, &st); + //xfstat(fd, &st, ubi_ctrl); //if (!S_ISCHR(st.st_mode)) - // bb_error_msg_and_die("'%s' is not a char device", ubi_ctrl); + // bb_error_msg_and_die("%s: not a char device", ubi_ctrl); if (do_attach) { if (!(opts & OPTION_M)) diff --git a/shell/ash.c b/shell/ash.c index 921367be5..28a8bb60c 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -4989,9 +4989,13 @@ noclobberopen(const char *fname) * revealed that it was a regular file, and the file has not been * replaced, return the file descriptor. */ - if (fstat(fd, &finfo2) == 0 && !S_ISREG(finfo2.st_mode) - && finfo.st_dev == finfo2.st_dev && finfo.st_ino == finfo2.st_ino) + if (fstat(fd, &finfo2) == 0 + && !S_ISREG(finfo2.st_mode) + && finfo.st_dev == finfo2.st_dev + && finfo.st_ino == finfo2.st_ino + ) { return fd; + } /* The file has been replaced. badness. */ close(fd); diff --git a/util-linux/mkfs_ext2.c b/util-linux/mkfs_ext2.c index 1c2b3b2e2..6dccd3a5d 100644 --- a/util-linux/mkfs_ext2.c +++ b/util-linux/mkfs_ext2.c @@ -221,7 +221,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) // open the device, check the device is a block device xmove_fd(xopen(argv[0], O_WRONLY), fd); - fstat(fd, &st); + xfstat(fd, &st, argv[0]); if (!S_ISBLK(st.st_mode) && !(option_mask32 & OPT_F)) bb_error_msg_and_die("%s: not a block device", argv[0]); diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c index 9e826aef3..95499ba17 100644 --- a/util-linux/mkfs_minix.c +++ b/util-linux/mkfs_minix.c @@ -686,8 +686,7 @@ int mkfs_minix_main(int argc UNUSED_PARAM, char **argv) bb_error_msg_and_die("can't format mounted filesystem"); xmove_fd(xopen(G.device_name, O_RDWR), dev_fd); - if (fstat(dev_fd, &statbuf) < 0) - bb_error_msg_and_die("can't stat '%s'", G.device_name); + xfstat(dev_fd, &statbuf, G.device_name); if (!S_ISBLK(statbuf.st_mode)) opt &= ~1; // clear -c (check) diff --git a/util-linux/mkfs_reiser.c b/util-linux/mkfs_reiser.c index 6e172d6d3..00ce8f1d1 100644 --- a/util-linux/mkfs_reiser.c +++ b/util-linux/mkfs_reiser.c @@ -168,9 +168,9 @@ int mkfs_reiser_main(int argc UNUSED_PARAM, char **argv) // check the device is a block device fd = xopen(argv[0], O_WRONLY | O_EXCL); - fstat(fd, &st); + xfstat(fd, &st, argv[0]); if (!S_ISBLK(st.st_mode) && !(option_mask32 & OPT_f)) - bb_error_msg_and_die("not a block device"); + bb_error_msg_and_die("%s: not a block device", argv[0]); // check if it is mounted // N.B. what if we format a file? find_mount_point will return false negative since diff --git a/util-linux/mkfs_vfat.c b/util-linux/mkfs_vfat.c index 211e67e97..45760f7c5 100644 --- a/util-linux/mkfs_vfat.c +++ b/util-linux/mkfs_vfat.c @@ -245,8 +245,7 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv) volume_id = time(NULL); dev = xopen(device_name, O_RDWR); - if (fstat(dev, &st) < 0) - bb_simple_perror_msg_and_die(device_name); + xfstat(dev, &st, device_name); // // Get image size and sector size diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c index 61a786e92..53537fcd9 100644 --- a/util-linux/mkswap.c +++ b/util-linux/mkswap.c @@ -15,8 +15,7 @@ static void mkswap_selinux_setcontext(int fd, const char *path) if (!is_selinux_enabled()) return; - if (fstat(fd, &stbuf) < 0) - bb_perror_msg_and_die("fstat failed"); + xfstat(fd, &stbuf, argv[0]); if (S_ISREG(stbuf.st_mode)) { security_context_t newcon; security_context_t oldcon = NULL; -- cgit v1.2.3-55-g6feb