summaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2017-11-03 14:16:08 +0000
committerRon Yorston <rmy@pobox.com>2017-11-03 14:16:08 +0000
commitd6ce08aeb85b3698ddaa281016b70e16aeb9fb35 (patch)
tree02ad9bc0684859515fe891f3d6b0a1086e0db156 /miscutils
parentab450021a99ba66126cc6d668fb06ec3829a572b (diff)
parenta5060b8364faa7c677c8950f1315c451403b0660 (diff)
downloadbusybox-w32-d6ce08aeb85b3698ddaa281016b70e16aeb9fb35.tar.gz
busybox-w32-d6ce08aeb85b3698ddaa281016b70e16aeb9fb35.tar.bz2
busybox-w32-d6ce08aeb85b3698ddaa281016b70e16aeb9fb35.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/bbconfig.c3
-rw-r--r--miscutils/devmem.c4
-rw-r--r--miscutils/flash_eraseall.c3
-rw-r--r--miscutils/flash_lock_unlock.c3
-rw-r--r--miscutils/i2c_tools.c40
-rw-r--r--miscutils/lsscsi.c9
-rw-r--r--miscutils/time.c22
-rw-r--r--miscutils/ubi_tools.c3
8 files changed, 58 insertions, 29 deletions
diff --git a/miscutils/bbconfig.c b/miscutils/bbconfig.c
index bcc9caa7c..2151c622c 100644
--- a/miscutils/bbconfig.c
+++ b/miscutils/bbconfig.c
@@ -1,5 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* This file was released into the public domain by Paul Fox. 2/*
3 * This file was released into the public domain by Paul Fox.
3 */ 4 */
4//config:config BBCONFIG 5//config:config BBCONFIG
5//config: bool "bbconfig (9.7 kb)" 6//config: bool "bbconfig (9.7 kb)"
diff --git a/miscutils/devmem.c b/miscutils/devmem.c
index 624054770..51ac3f22f 100644
--- a/miscutils/devmem.c
+++ b/miscutils/devmem.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Copyright (C) 2000, Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl)
3 * Copyright (C) 2008, BusyBox Team. -solar 4/26/08
2 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 4 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
3 * Copyright (C) 2000, Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl)
4 * Copyright (C) 2008, BusyBox Team. -solar 4/26/08
5 */ 5 */
6//config:config DEVMEM 6//config:config DEVMEM
7//config: bool "devmem (2.5 kb)" 7//config: bool "devmem (2.5 kb)"
diff --git a/miscutils/flash_eraseall.c b/miscutils/flash_eraseall.c
index a6ce41f27..fab21291c 100644
--- a/miscutils/flash_eraseall.c
+++ b/miscutils/flash_eraseall.c
@@ -1,5 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* eraseall.c -- erase the whole of a MTD device 2/*
3 * eraseall.c -- erase the whole of a MTD device
3 * 4 *
4 * Ported to busybox from mtd-utils. 5 * Ported to busybox from mtd-utils.
5 * 6 *
diff --git a/miscutils/flash_lock_unlock.c b/miscutils/flash_lock_unlock.c
index 6f2c049f4..12f72efaf 100644
--- a/miscutils/flash_lock_unlock.c
+++ b/miscutils/flash_lock_unlock.c
@@ -1,5 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* Ported to busybox from mtd-utils. 2/*
3 * Ported to busybox from mtd-utils.
3 * 4 *
4 * Licensed under GPLv2, see file LICENSE in this source tree. 5 * Licensed under GPLv2, see file LICENSE in this source tree.
5 */ 6 */
diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c
index fc392d9dc..82f9842bd 100644
--- a/miscutils/i2c_tools.c
+++ b/miscutils/i2c_tools.c
@@ -562,14 +562,19 @@ int i2cset_main(int argc, char **argv)
562 opt_m = (1 << 2), opt_r = (1 << 3); 562 opt_m = (1 << 2), opt_r = (1 << 3);
563 563
564 int bus_num, bus_addr, data_addr, mode = I2C_SMBUS_BYTE, pec = 0; 564 int bus_num, bus_addr, data_addr, mode = I2C_SMBUS_BYTE, pec = 0;
565 int val, blen = 0, mask = 0, fd, status; 565 int val, blen, mask, fd, status;
566 unsigned char block[I2C_SMBUS_BLOCK_MAX]; 566 unsigned char block[I2C_SMBUS_BLOCK_MAX];
567 char *opt_m_arg = NULL; 567 char *opt_m_arg = NULL;
568 unsigned opts; 568 unsigned opts;
569 569
570 opts = getopt32(argv, "^" "fym:r" "\0" "-3"/*from 3 to ? args*/, &opt_m_arg); 570 opts = getopt32(argv, "^"
571 "fym:r"
572 "\0" "-3", /* minimum 3 args */
573 &opt_m_arg
574 );
571 argv += optind; 575 argv += optind;
572 argc -= optind; 576 argc -= optind;
577 argc--; /* now argv[argc] is last arg */
573 578
574 bus_num = i2c_bus_lookup(argv[0]); 579 bus_num = i2c_bus_lookup(argv[0]);
575 bus_addr = i2c_parse_bus_addr(argv[1]); 580 bus_addr = i2c_parse_bus_addr(argv[1]);
@@ -579,20 +584,26 @@ int i2cset_main(int argc, char **argv)
579 if (!argv[4] && argv[3][0] != 'c') { 584 if (!argv[4] && argv[3][0] != 'c') {
580 mode = I2C_SMBUS_BYTE_DATA; /* Implicit b */ 585 mode = I2C_SMBUS_BYTE_DATA; /* Implicit b */
581 } else { 586 } else {
582 switch (argv[argc-1][0]) { 587 switch (argv[argc][0]) {
583 case 'c': /* Already set */ break; 588 case 'c': /* Already set */
584 case 'b': mode = I2C_SMBUS_BYTE_DATA; break; 589 break;
585 case 'w': mode = I2C_SMBUS_WORD_DATA; break; 590 case 'b': mode = I2C_SMBUS_BYTE_DATA;
586 case 's': mode = I2C_SMBUS_BLOCK_DATA; break; 591 break;
587 case 'i': mode = I2C_SMBUS_I2C_BLOCK_DATA; break; 592 case 'w': mode = I2C_SMBUS_WORD_DATA;
593 break;
594 case 's': mode = I2C_SMBUS_BLOCK_DATA;
595 break;
596 case 'i': mode = I2C_SMBUS_I2C_BLOCK_DATA;
597 break;
588 default: 598 default:
589 bb_error_msg("invalid mode"); 599 bb_error_msg("invalid mode");
590 bb_show_usage(); 600 bb_show_usage();
591 } 601 }
592 602
593 pec = argv[argc-1][1] == 'p'; 603 pec = (argv[argc][1] == 'p');
594 if (mode == I2C_SMBUS_BLOCK_DATA || 604 if (mode == I2C_SMBUS_BLOCK_DATA
595 mode == I2C_SMBUS_I2C_BLOCK_DATA) { 605 || mode == I2C_SMBUS_I2C_BLOCK_DATA
606 ) {
596 if (pec && mode == I2C_SMBUS_I2C_BLOCK_DATA) 607 if (pec && mode == I2C_SMBUS_I2C_BLOCK_DATA)
597 bb_error_msg_and_die( 608 bb_error_msg_and_die(
598 "PEC not supported for I2C " 609 "PEC not supported for I2C "
@@ -606,6 +617,8 @@ int i2cset_main(int argc, char **argv)
606 } 617 }
607 618
608 /* Prepare the value(s) to be written according to current mode. */ 619 /* Prepare the value(s) to be written according to current mode. */
620 mask = 0;
621 blen = 0;
609 switch (mode) { 622 switch (mode) {
610 case I2C_SMBUS_BYTE_DATA: 623 case I2C_SMBUS_BYTE_DATA:
611 val = xstrtou_range(argv[3], 0, 0, 0xff); 624 val = xstrtou_range(argv[3], 0, 0, 0xff);
@@ -615,8 +628,9 @@ int i2cset_main(int argc, char **argv)
615 break; 628 break;
616 case I2C_SMBUS_BLOCK_DATA: 629 case I2C_SMBUS_BLOCK_DATA:
617 case I2C_SMBUS_I2C_BLOCK_DATA: 630 case I2C_SMBUS_I2C_BLOCK_DATA:
618 for (blen = 3; blen < (argc - 1); blen++) 631 for (blen = 3; blen < argc; blen++)
619 block[blen] = xstrtou_range(argv[blen], 0, 0, 0xff); 632 block[blen - 3] = xstrtou_range(argv[blen], 0, 0, 0xff);
633 blen -= 3;
620 val = -1; 634 val = -1;
621 break; 635 break;
622 default: 636 default:
diff --git a/miscutils/lsscsi.c b/miscutils/lsscsi.c
index d7cd51056..0aaa01ded 100644
--- a/miscutils/lsscsi.c
+++ b/miscutils/lsscsi.c
@@ -25,6 +25,8 @@
25 25
26#include "libbb.h" 26#include "libbb.h"
27 27
28static const char scsi_dir[] ALIGN1 = "/sys/bus/scsi/devices";
29
28static char *get_line(const char *filename, char *buf, unsigned *bufsize_p) 30static char *get_line(const char *filename, char *buf, unsigned *bufsize_p)
29{ 31{
30 unsigned bufsize = *bufsize_p; 32 unsigned bufsize = *bufsize_p;
@@ -53,7 +55,7 @@ int lsscsi_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
53 struct dirent *de; 55 struct dirent *de;
54 DIR *dir; 56 DIR *dir;
55 57
56 xchdir("/sys/bus/scsi/devices"); 58 xchdir(scsi_dir);
57 59
58 dir = xopendir("."); 60 dir = xopendir(".");
59 while ((de = readdir(dir)) != NULL) { 61 while ((de = readdir(dir)) != NULL) {
@@ -112,7 +114,10 @@ int lsscsi_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
112 ); 114 );
113 /* TODO: also output device column, e.g. "/dev/sdX" */ 115 /* TODO: also output device column, e.g. "/dev/sdX" */
114 116
115 xchdir(".."); 117 /* chdir("..") may not work as expected,
118 * since we might have followed a symlink.
119 */
120 xchdir(scsi_dir);
116 } 121 }
117 122
118 if (ENABLE_FEATURE_CLEAN_UP) 123 if (ENABLE_FEATURE_CLEAN_UP)
diff --git a/miscutils/time.c b/miscutils/time.c
index 65dbcdcf3..61f078755 100644
--- a/miscutils/time.c
+++ b/miscutils/time.c
@@ -1,13 +1,14 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 'time' utility to display resource usage of processes. 2/*
3 Copyright (C) 1990, 91, 92, 93, 96 Free Software Foundation, Inc. 3 * 'time' utility to display resource usage of processes.
4 4 * Copyright (C) 1990, 91, 92, 93, 96 Free Software Foundation, Inc.
5 Licensed under GPLv2, see file LICENSE in this source tree. 5 *
6*/ 6 * Licensed under GPLv2, see file LICENSE in this source tree.
7 */
7/* Originally written by David Keppel <pardo@cs.washington.edu>. 8/* Originally written by David Keppel <pardo@cs.washington.edu>.
8 Heavily modified by David MacKenzie <djm@gnu.ai.mit.edu>. 9 * Heavily modified by David MacKenzie <djm@gnu.ai.mit.edu>.
9 Heavily modified for busybox by Erik Andersen <andersen@codepoet.org> 10 * Heavily modified for busybox by Erik Andersen <andersen@codepoet.org>
10*/ 11 */
11//config:config TIME 12//config:config TIME
12//config: bool "time (7 kb)" 13//config: bool "time (7 kb)"
13//config: default y 14//config: default y
@@ -441,11 +442,16 @@ int time_main(int argc UNUSED_PARAM, char **argv)
441 output_format = posix_format; 442 output_format = posix_format;
442 output_fd = STDERR_FILENO; 443 output_fd = STDERR_FILENO;
443 if (opt & OPT_o) { 444 if (opt & OPT_o) {
445#ifndef O_CLOEXEC
446# define O_CLOEXEC 0
447#endif
444 output_fd = xopen(output_filename, 448 output_fd = xopen(output_filename,
445 (opt & OPT_a) /* append? */ 449 (opt & OPT_a) /* append? */
446 ? (O_CREAT | O_WRONLY | O_CLOEXEC | O_APPEND) 450 ? (O_CREAT | O_WRONLY | O_CLOEXEC | O_APPEND)
447 : (O_CREAT | O_WRONLY | O_CLOEXEC | O_TRUNC) 451 : (O_CREAT | O_WRONLY | O_CLOEXEC | O_TRUNC)
448 ); 452 );
453 if (!O_CLOEXEC)
454 close_on_exec_on(output_fd);
449 } 455 }
450 456
451 run_command(argv, &res); 457 run_command(argv, &res);
diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c
index 1ef8fd90e..a947abab5 100644
--- a/miscutils/ubi_tools.c
+++ b/miscutils/ubi_tools.c
@@ -1,4 +1,5 @@
1/* Ported to busybox from mtd-utils. 1/*
2 * Ported to busybox from mtd-utils.
2 * 3 *
3 * Licensed under GPLv2, see file LICENSE in this source tree. 4 * Licensed under GPLv2, see file LICENSE in this source tree.
4 */ 5 */