summaryrefslogtreecommitdiffstats
path: root/toolbox
diff options
context:
space:
mode:
Diffstat (limited to 'toolbox')
-rw-r--r--toolbox/Android.mk219
-rw-r--r--toolbox/alarm.c190
-rw-r--r--toolbox/bsd-compatibility.h8
-rw-r--r--toolbox/chcon.c25
-rw-r--r--toolbox/chmod.c101
-rw-r--r--toolbox/clear.c41
-rw-r--r--toolbox/cmp.c91
-rw-r--r--toolbox/date.c227
-rw-r--r--toolbox/dmesg.c58
-rw-r--r--toolbox/dynarray.c103
-rw-r--r--toolbox/dynarray.h80
-rw-r--r--toolbox/exists.c16
-rwxr-xr-xtoolbox/generate-input.h-labels.py93
-rw-r--r--toolbox/getenforce.c30
-rw-r--r--toolbox/getevent.c21
-rw-r--r--toolbox/getevent.h727
-rw-r--r--toolbox/getprop.c50
-rw-r--r--toolbox/getsebool.c104
-rw-r--r--toolbox/hd.c97
-rw-r--r--toolbox/id.c57
-rw-r--r--toolbox/ifconfig.c157
-rw-r--r--toolbox/insmod.c97
-rw-r--r--toolbox/ioctl.c146
-rw-r--r--toolbox/ionice.c1
-rw-r--r--toolbox/load_policy.c49
-rw-r--r--toolbox/ls.c118
-rw-r--r--toolbox/lsmod.c10
-rw-r--r--toolbox/lsof.c1
-rw-r--r--toolbox/lsusb.c227
-rw-r--r--toolbox/md5.c71
-rw-r--r--toolbox/mkdir.c77
-rw-r--r--toolbox/mknod.c95
-rw-r--r--toolbox/mkswap.c93
-rw-r--r--toolbox/netstat.c154
-rw-r--r--toolbox/newfs_msdos.c10
-rw-r--r--toolbox/nohup.c26
-rw-r--r--toolbox/notify.c145
-rw-r--r--toolbox/ps.c51
-rw-r--r--toolbox/pwcache.c61
-rw-r--r--toolbox/r.c3
-rw-r--r--toolbox/readlink.c95
-rw-r--r--toolbox/readtty.c183
-rw-r--r--toolbox/renice.c1
-rw-r--r--toolbox/restorecon.c62
-rw-r--r--toolbox/rmmod.c53
-rw-r--r--toolbox/rotatefb.c71
-rw-r--r--toolbox/route.c113
-rw-r--r--toolbox/runcon.c28
-rw-r--r--toolbox/schedtop.c330
-rw-r--r--toolbox/sendevent.c47
-rw-r--r--toolbox/setenforce.c44
-rw-r--r--toolbox/setkey.c89
-rw-r--r--toolbox/setprop.c18
-rw-r--r--toolbox/setsebool.c46
-rw-r--r--toolbox/smd.c41
-rw-r--r--toolbox/swapoff.c20
-rw-r--r--toolbox/swapon.c66
-rw-r--r--toolbox/syren.c158
-rw-r--r--toolbox/toolbox.c15
-rw-r--r--toolbox/top.c6
-rw-r--r--toolbox/touch.c114
-rw-r--r--toolbox/umount.c90
-rw-r--r--toolbox/upstream-netbsd/bin/cat/cat.c329
-rw-r--r--toolbox/upstream-netbsd/bin/cp/cp.c548
-rw-r--r--toolbox/upstream-netbsd/bin/cp/extern.h61
-rw-r--r--toolbox/upstream-netbsd/bin/cp/utils.c444
-rw-r--r--toolbox/upstream-netbsd/bin/kill/kill.c253
-rw-r--r--toolbox/upstream-netbsd/bin/ln/ln.c230
-rw-r--r--toolbox/upstream-netbsd/bin/mv/mv.c396
-rw-r--r--toolbox/upstream-netbsd/bin/mv/pathnames.h45
-rw-r--r--toolbox/upstream-netbsd/bin/rm/rm.c625
-rw-r--r--toolbox/upstream-netbsd/bin/rmdir/rmdir.c121
-rw-r--r--toolbox/upstream-netbsd/bin/sleep/sleep.c159
-rw-r--r--toolbox/upstream-netbsd/bin/sync/sync.c59
-rw-r--r--toolbox/upstream-netbsd/sbin/chown/chown.c302
-rw-r--r--toolbox/upstream-netbsd/usr.bin/grep/file.c2
-rw-r--r--toolbox/upstream-netbsd/usr.bin/printenv/printenv.c102
-rw-r--r--toolbox/uptime.c77
-rw-r--r--toolbox/vmstat.c247
-rw-r--r--toolbox/watchprops.c1
-rw-r--r--toolbox/wipe.c176
81 files changed, 452 insertions, 9345 deletions
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index 84714cf..ad99a39 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -9,230 +9,75 @@ common_cflags := \
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := upstream-netbsd/bin/cat/cat.c
-LOCAL_CFLAGS += $(common_cflags) -Dmain=cat_main
-LOCAL_MODULE := libtoolbox_cat
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := upstream-netbsd/sbin/chown/chown.c
-LOCAL_CFLAGS += $(common_cflags) -Dmain=chown_main
-LOCAL_MODULE := libtoolbox_chown
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := \
- upstream-netbsd/bin/cp/cp.c \
- upstream-netbsd/bin/cp/utils.c
-LOCAL_CFLAGS += $(common_cflags) -Dmain=cp_main
-LOCAL_MODULE := libtoolbox_cp
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
upstream-netbsd/bin/dd/args.c \
upstream-netbsd/bin/dd/conv.c \
upstream-netbsd/bin/dd/dd.c \
upstream-netbsd/bin/dd/dd_hostops.c \
upstream-netbsd/bin/dd/misc.c \
- upstream-netbsd/bin/dd/position.c
+ upstream-netbsd/bin/dd/position.c \
+ upstream-netbsd/lib/libc/gen/getbsize.c \
+ upstream-netbsd/lib/libc/gen/humanize_number.c \
+ upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
+ upstream-netbsd/lib/libc/string/swab.c \
+ upstream-netbsd/lib/libutil/raise_default_signal.c
LOCAL_CFLAGS += $(common_cflags) -Dmain=dd_main -DNO_CONV
LOCAL_MODULE := libtoolbox_dd
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := upstream-netbsd/usr.bin/du/du.c
LOCAL_CFLAGS += $(common_cflags) -Dmain=du_main
LOCAL_MODULE := libtoolbox_du
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := \
- upstream-netbsd/usr.bin/grep/fastgrep.c \
- upstream-netbsd/usr.bin/grep/file.c \
- upstream-netbsd/usr.bin/grep/grep.c \
- upstream-netbsd/usr.bin/grep/queue.c \
- upstream-netbsd/usr.bin/grep/util.c
-LOCAL_CFLAGS += $(common_cflags) -Dmain=grep_main
-LOCAL_MODULE := libtoolbox_grep
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := upstream-netbsd/bin/kill/kill.c
-LOCAL_CFLAGS += $(common_cflags) -Dmain=kill_main
-LOCAL_MODULE := libtoolbox_kill
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := upstream-netbsd/bin/ln/ln.c
-LOCAL_CFLAGS += $(common_cflags) -Dmain=ln_main
-LOCAL_MODULE := libtoolbox_ln
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := upstream-netbsd/bin/mv/mv.c
-LOCAL_CFLAGS += $(common_cflags) -Dmain=mv_main -D__SVR4
-LOCAL_MODULE := libtoolbox_mv
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := upstream-netbsd/usr.bin/printenv/printenv.c
-LOCAL_CFLAGS += $(common_cflags) -Dmain=printenv_main
-LOCAL_MODULE := libtoolbox_printenv
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := upstream-netbsd/bin/rm/rm.c
-LOCAL_CFLAGS += $(common_cflags) -Dmain=rm_main
-LOCAL_MODULE := libtoolbox_rm
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := upstream-netbsd/bin/rmdir/rmdir.c
-LOCAL_CFLAGS += $(common_cflags) -Dmain=rmdir_main
-LOCAL_MODULE := libtoolbox_rmdir
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := upstream-netbsd/bin/sleep/sleep.c
-LOCAL_CFLAGS += $(common_cflags) -Dmain=sleep_main
-LOCAL_MODULE := libtoolbox_sleep
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := upstream-netbsd/bin/sync/sync.c
-LOCAL_CFLAGS += $(common_cflags) -Dmain=sync_main
-LOCAL_MODULE := libtoolbox_sync
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
BSD_TOOLS := \
- cat \
- chown \
- cp \
dd \
du \
- grep \
- kill \
- ln \
- mv \
- printenv \
- rm \
- rmdir \
- sleep \
- sync \
OUR_TOOLS := \
- chcon \
- chmod \
- clear \
- cmp \
- date \
df \
- dmesg \
- getenforce \
getevent \
- getprop \
- getsebool \
- hd \
- id \
- ifconfig \
iftop \
- insmod \
ioctl \
ionice \
- load_policy \
log \
ls \
- lsmod \
lsof \
- md5 \
- mkdir \
- mknod \
- mkswap \
mount \
nandread \
- netstat \
newfs_msdos \
- nohup \
- notify \
ps \
- readlink \
- renice \
- restorecon \
prlimit \
- rmmod \
- route \
- runcon \
- schedtop \
+ renice \
sendevent \
- setenforce \
- setprop \
- setsebool \
- smd \
start \
stop \
- swapoff \
- swapon \
top \
- touch \
- umount \
uptime \
- vmstat \
watchprops \
- wipe \
-
-ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
-OUR_TOOLS += r
-endif
ALL_TOOLS = $(BSD_TOOLS) $(OUR_TOOLS)
LOCAL_SRC_FILES := \
- upstream-netbsd/lib/libc/gen/getbsize.c \
- upstream-netbsd/lib/libc/gen/humanize_number.c \
- upstream-netbsd/lib/libc/stdlib/strsuftoll.c \
- upstream-netbsd/lib/libc/string/swab.c \
- upstream-netbsd/lib/libutil/raise_default_signal.c \
- dynarray.c \
- pwcache.c \
- $(patsubst %,%.c,$(OUR_TOOLS)) \
toolbox.c \
+ $(patsubst %,%.c,$(OUR_TOOLS)) \
LOCAL_CFLAGS += $(common_cflags)
-LOCAL_C_INCLUDES += external/openssl/include
-
LOCAL_SHARED_LIBRARIES := \
- libcrypto \
libcutils \
libselinux \
-# libusbhost is only used by lsusb, and that isn't usually included in toolbox.
-# The linker strips out all the unused library code in the normal case.
-LOCAL_STATIC_LIBRARIES := \
- libusbhost \
-
LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))
LOCAL_MODULE := toolbox
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
+
+# Install the symlinks.
+LOCAL_POST_INSTALL_CMD := $(hide) $(foreach t,$(ALL_TOOLS),ln -sf toolbox $(TARGET_OUT)/bin/$(t);)
# Including this will define $(intermediates).
#
@@ -247,19 +92,33 @@ $(TOOLS_H): $(LOCAL_PATH)/Android.mk
$(TOOLS_H):
$(transform-generated-source)
-# Make #!/system/bin/toolbox launchers for each tool.
-#
-SYMLINKS := $(addprefix $(TARGET_OUT)/bin/,$(ALL_TOOLS))
-$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE)
-$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
- @echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
- @mkdir -p $(dir $@)
- @rm -rf $@
- $(hide) ln -sf $(TOOLBOX_BINARY) $@
+$(LOCAL_PATH)/getevent.c: $(intermediates)/input.h-labels.h
+
+INPUT_H_LABELS_H := $(intermediates)/input.h-labels.h
+$(INPUT_H_LABELS_H): PRIVATE_LOCAL_PATH := $(LOCAL_PATH)
+$(INPUT_H_LABELS_H): PRIVATE_CUSTOM_TOOL = $(PRIVATE_LOCAL_PATH)/generate-input.h-labels.py > $@
+$(INPUT_H_LABELS_H): $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/generate-input.h-labels.py
+$(INPUT_H_LABELS_H):
+ $(transform-generated-source)
+
+# We only want 'r' on userdebug and eng builds.
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := r.c
+LOCAL_CFLAGS += $(common_cflags)
+LOCAL_MODULE := r
+LOCAL_MODULE_TAGS := debug
+include $(BUILD_EXECUTABLE)
-ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
-# We need this so that the installed files could be picked up based on the
-# local module name
-ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
- $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
+# We build BSD grep separately, so it can provide egrep and fgrep too.
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := \
+ upstream-netbsd/usr.bin/grep/fastgrep.c \
+ upstream-netbsd/usr.bin/grep/file.c \
+ upstream-netbsd/usr.bin/grep/grep.c \
+ upstream-netbsd/usr.bin/grep/queue.c \
+ upstream-netbsd/usr.bin/grep/util.c
+LOCAL_CFLAGS += $(common_cflags)
+LOCAL_MODULE := grep
+LOCAL_POST_INSTALL_CMD := $(hide) $(foreach t,egrep fgrep,ln -sf grep $(TARGET_OUT)/bin/$(t);)
+include $(BUILD_EXECUTABLE)
diff --git a/toolbox/alarm.c b/toolbox/alarm.c
deleted file mode 100644
index 9bd58aa..0000000
--- a/toolbox/alarm.c
+++ /dev/null
@@ -1,190 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-#include <time.h>
-#include <asm/ioctl.h>
-//#include <linux/rtc.h>
-#include <linux/android_alarm.h>
-
-int alarm_main(int argc, char *argv[])
-{
- int c;
- int res;
- struct tm tm;
- time_t t;
- struct timespec ts;
-// struct rtc_time rtc_time;
- char strbuf[26];
- int afd;
- int nfd;
-// struct timeval timeout = { 0, 0 };
- int wait = 0;
- fd_set rfds;
- const char wake_lock_id[] = "alarm_test";
- int waitalarmmask = 0;
-
- int useutc = 0;
- android_alarm_type_t alarmtype_low = ANDROID_ALARM_RTC_WAKEUP;
- android_alarm_type_t alarmtype_high = ANDROID_ALARM_RTC_WAKEUP;
- android_alarm_type_t alarmtype = 0;
-
- do {
- //c = getopt(argc, argv, "uw:");
- c = getopt(argc, argv, "uwat:");
- if (c == EOF)
- break;
- switch (c) {
- case 'u':
- useutc = 1;
- break;
- case 't':
- alarmtype_low = alarmtype_high = strtol(optarg, NULL, 0);
- break;
- case 'a':
- alarmtype_low = ANDROID_ALARM_RTC_WAKEUP;
- alarmtype_high = ANDROID_ALARM_TYPE_COUNT - 1;
- break;
- case 'w':
- //timeout.tv_sec = strtol(optarg, NULL, 0);
- wait = 1;
- break;
- case '?':
- fprintf(stderr, "%s: invalid option -%c\n",
- argv[0], optopt);
- exit(1);
- }
- } while (1);
- if(optind + 2 < argc) {
- fprintf(stderr,"%s [-uwa] [-t type] [seconds]\n", argv[0]);
- return 1;
- }
-
- afd = open("/dev/alarm", O_RDWR);
- if(afd < 0) {
- fprintf(stderr, "Unable to open rtc: %s\n", strerror(errno));
- return 1;
- }
-
- if(optind == argc) {
- for(alarmtype = alarmtype_low; alarmtype <= alarmtype_high; alarmtype++) {
- waitalarmmask |= 1U << alarmtype;
- }
-#if 0
- res = ioctl(fd, RTC_ALM_READ, &tm);
- if(res < 0) {
- fprintf(stderr, "Unable to read alarm: %s\n", strerror(errno));
- return 1;
- }
-#endif
-#if 0
- t = timegm(&tm);
- if(useutc)
- gmtime_r(&t, &tm);
- else
- localtime_r(&t, &tm);
-#endif
-#if 0
- asctime_r(&tm, strbuf);
- printf("%s", strbuf);
-#endif
- }
- else if(optind + 1 == argc) {
-#if 0
- res = ioctl(fd, RTC_RD_TIME, &tm);
- if(res < 0) {
- fprintf(stderr, "Unable to set alarm: %s\n", strerror(errno));
- return 1;
- }
- asctime_r(&tm, strbuf);
- printf("Now: %s", strbuf);
- time(&tv.tv_sec);
-#endif
-#if 0
- time(&ts.tv_sec);
- ts.tv_nsec = 0;
-
- //strptime(argv[optind], NULL, &tm);
- //tv.tv_sec = mktime(&tm);
- //tv.tv_usec = 0;
-#endif
- for(alarmtype = alarmtype_low; alarmtype <= alarmtype_high; alarmtype++) {
- waitalarmmask |= 1U << alarmtype;
- res = ioctl(afd, ANDROID_ALARM_GET_TIME(alarmtype), &ts);
- if(res < 0) {
- fprintf(stderr, "Unable to get current time: %s\n", strerror(errno));
- return 1;
- }
- ts.tv_sec += strtol(argv[optind], NULL, 0);
- //strtotimeval(argv[optind], &tv);
- gmtime_r(&ts.tv_sec, &tm);
- printf("time %s -> %ld.%09ld\n", argv[optind], ts.tv_sec, ts.tv_nsec);
- asctime_r(&tm, strbuf);
- printf("Requested %s", strbuf);
-
- res = ioctl(afd, ANDROID_ALARM_SET(alarmtype), &ts);
- if(res < 0) {
- fprintf(stderr, "Unable to set alarm: %s\n", strerror(errno));
- return 1;
- }
- }
-#if 0
- res = ioctl(fd, RTC_ALM_SET, &tm);
- if(res < 0) {
- fprintf(stderr, "Unable to set alarm: %s\n", strerror(errno));
- return 1;
- }
- res = ioctl(fd, RTC_AIE_ON);
- if(res < 0) {
- fprintf(stderr, "Unable to enable alarm: %s\n", strerror(errno));
- return 1;
- }
-#endif
- }
- else {
- fprintf(stderr,"%s [-u] [date]\n", argv[0]);
- return 1;
- }
-
- if(wait) {
- while(waitalarmmask) {
- printf("wait for alarm %x\n", waitalarmmask);
- res = ioctl(afd, ANDROID_ALARM_WAIT);
- if(res < 0) {
- fprintf(stderr, "alarm wait failed\n");
- }
- printf("got alarm %x\n", res);
- waitalarmmask &= ~res;
- nfd = open("/sys/android_power/acquire_full_wake_lock", O_RDWR);
- write(nfd, wake_lock_id, sizeof(wake_lock_id) - 1);
- close(nfd);
- //sleep(5);
- nfd = open("/sys/android_power/release_wake_lock", O_RDWR);
- write(nfd, wake_lock_id, sizeof(wake_lock_id) - 1);
- close(nfd);
- }
- printf("done\n");
- }
-#if 0
- FD_ZERO(&rfds);
- FD_SET(fd, &rfds);
- res = select(fd + 1, &rfds, NULL, NULL, &timeout);
- if(res < 0) {
- fprintf(stderr, "select failed: %s\n", strerror(errno));
- return 1;
- }
- if(res > 0) {
- int event;
- read(fd, &event, sizeof(event));
- fprintf(stderr, "got %x\n", event);
- }
- else {
- fprintf(stderr, "timeout waiting for alarm\n");
- }
-#endif
-
- close(afd);
-
- return 0;
-}
diff --git a/toolbox/bsd-compatibility.h b/toolbox/bsd-compatibility.h
index 9c6c34a..434d370 100644
--- a/toolbox/bsd-compatibility.h
+++ b/toolbox/bsd-compatibility.h
@@ -50,16 +50,8 @@
#define S_ISWHT(x) false
-// TODO: should this be in bionic? (glibc does this, even though it's not quite right.)
-#define O_RSYNC O_SYNC
-
__BEGIN_DECLS
-/* From NetBSD <grp.h> and <pwd.h>. */
-char* group_from_gid(gid_t gid, int noname);
-int uid_from_user(const char* name, uid_t* uid);
-char* user_from_uid(uid_t uid, int noname);
-
/* From NetBSD <stdlib.h>. */
#define HN_DECIMAL 0x01
#define HN_NOSPACE 0x02
diff --git a/toolbox/chcon.c b/toolbox/chcon.c
deleted file mode 100644
index d594b9b..0000000
--- a/toolbox/chcon.c
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <selinux/selinux.h>
-
-int chcon_main(int argc, char **argv)
-{
- int rc, i;
-
- if (argc < 3) {
- fprintf(stderr, "usage: %s context path...\n", argv[0]);
- exit(1);
- }
-
- for (i = 2; i < argc; i++) {
- rc = setfilecon(argv[i], argv[1]);
- if (rc < 0) {
- fprintf(stderr, "%s: Could not label %s with %s: %s\n",
- argv[0], argv[i], argv[1], strerror(errno));
- exit(2);
- }
- }
- exit(0);
-}
diff --git a/toolbox/chmod.c b/toolbox/chmod.c
deleted file mode 100644
index 2a524e9..0000000
--- a/toolbox/chmod.c
+++ /dev/null
@@ -1,101 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <errno.h>
-#include <sys/limits.h>
-#include <sys/stat.h>
-
-#include <unistd.h>
-#include <time.h>
-
-void recurse_chmod(char* path, int mode)
-{
- struct dirent *dp;
- DIR *dir = opendir(path);
- if (dir == NULL) {
- // not a directory, carry on
- return;
- }
- char *subpath = malloc(sizeof(char)*PATH_MAX);
- int pathlen = strlen(path);
-
- while ((dp = readdir(dir)) != NULL) {
- if (strcmp(dp->d_name, ".") == 0 ||
- strcmp(dp->d_name, "..") == 0) continue;
-
- if (strlen(dp->d_name) + pathlen + 2/*NUL and slash*/ > PATH_MAX) {
- fprintf(stderr, "Invalid path specified: too long\n");
- exit(1);
- }
-
- strcpy(subpath, path);
- strcat(subpath, "/");
- strcat(subpath, dp->d_name);
-
- if (chmod(subpath, mode) < 0) {
- fprintf(stderr, "Unable to chmod %s: %s\n", subpath, strerror(errno));
- exit(1);
- }
-
- recurse_chmod(subpath, mode);
- }
- free(subpath);
- closedir(dir);
-}
-
-static int usage()
-{
- fprintf(stderr, "Usage: chmod [OPTION] <MODE> <FILE>\n");
- fprintf(stderr, " -R, --recursive change files and directories recursively\n");
- fprintf(stderr, " --help display this help and exit\n");
-
- return 10;
-}
-
-int chmod_main(int argc, char **argv)
-{
- int i;
-
- if (argc < 3 || strcmp(argv[1], "--help") == 0) {
- return usage();
- }
-
- int recursive = (strcmp(argv[1], "-R") == 0 ||
- strcmp(argv[1], "--recursive") == 0) ? 1 : 0;
-
- if (recursive && argc < 4) {
- return usage();
- }
-
- if (recursive) {
- argc--;
- argv++;
- }
-
- int mode = 0;
- const char* s = argv[1];
- while (*s) {
- if (*s >= '0' && *s <= '7') {
- mode = (mode<<3) | (*s-'0');
- }
- else {
- fprintf(stderr, "Bad mode\n");
- return 10;
- }
- s++;
- }
-
- for (i = 2; i < argc; i++) {
- if (chmod(argv[i], mode) < 0) {
- fprintf(stderr, "Unable to chmod %s: %s\n", argv[i], strerror(errno));
- return 10;
- }
- if (recursive) {
- recurse_chmod(argv[i], mode);
- }
- }
- return 0;
-}
-
diff --git a/toolbox/clear.c b/toolbox/clear.c
deleted file mode 100644
index df46ad2..0000000
--- a/toolbox/clear.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2012, The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-
-int clear_main(int argc, char **argv) {
- /* This prints the clear screen and move cursor to top-left corner control
- * characters for VT100 terminals. This means it will not work on
- * non-VT100 compliant terminals, namely Windows' cmd.exe, but should
- * work on anything unix-y. */
- fputs("\x1b[2J\x1b[H", stdout);
- return 0;
-}
diff --git a/toolbox/cmp.c b/toolbox/cmp.c
deleted file mode 100644
index 80635ad..0000000
--- a/toolbox/cmp.c
+++ /dev/null
@@ -1,91 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-
-int cmp_main(int argc, char *argv[])
-{
- int c;
- int fd1, fd2;
- char buf1[4096], buf2[4096];
- int res, res1, res2;
- int rv = 0;
- int i;
- int filepos = 0;
-
- int show_byte = 0;
- int show_all = 0;
- int limit = 0;
-
- do {
- c = getopt(argc, argv, "bln:");
- if (c == EOF)
- break;
- switch (c) {
- case 'b':
- show_byte = 1;
- break;
- case 'l':
- show_all = 1;
- break;
- case 'n':
- limit = atoi(optarg);
- break;
- case '?':
- fprintf(stderr, "%s: invalid option -%c\n",
- argv[0], optopt);
- exit(1);
- }
- } while (1);
-
- if (optind + 2 != argc) {
- fprintf(stderr, "Usage: %s [-b] [-l] [-n count] file1 file2\n", argv[0]);
- exit(1);
- }
-
- fd1 = open(argv[optind], O_RDONLY);
- if(fd1 < 0) {
- fprintf(stderr, "could not open %s, %s\n", argv[optind], strerror(errno));
- return 1;
- }
-
- fd2 = open(argv[optind+1], O_RDONLY);
- if(fd2 < 0) {
- fprintf(stderr, "could not open %s, %s\n", argv[optind+1], strerror(errno));
- return 1;
- }
-
- while(1) {
- res1 = read(fd1, &buf1, sizeof(buf1));
- res2 = read(fd2, &buf2, sizeof(buf2));
- res = res1 < res2 ? res1 : res2;
- if(res1 == 0 && res2 == 0) {
- return rv;
- }
- for(i = 0; i < res; i++) {
- if(buf1[i] != buf2[i]) {
- printf("%s %s differ byte %d", argv[optind], argv[optind+1], filepos + i);
- if(show_byte)
- printf(" 0x%02x 0x%02x", buf1[i], buf2[i]);
- printf("\n");
- if(!show_all)
- return 1;
- rv = 1;
- }
- if(limit) {
- limit--;
- if(limit == 0)
- return rv;
- }
- }
- if(res1 != res2 || res < 0) {
- printf("%s on %s\n", res < 0 ? "Read error" : "EOF", res1 < res2 ? argv[optind] : argv[optind+1]);
- return 1;
- }
- filepos += res;
- }
-}
diff --git a/toolbox/date.c b/toolbox/date.c
deleted file mode 100644
index 70ce1d5..0000000
--- a/toolbox/date.c
+++ /dev/null
@@ -1,227 +0,0 @@
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <linux/android_alarm.h>
-#include <linux/rtc.h>
-#include <sys/ioctl.h>
-
-static int settime_alarm(struct timespec *ts) {
- int fd, ret;
-
- fd = open("/dev/alarm", O_RDWR);
- if (fd < 0)
- return fd;
-
- ret = ioctl(fd, ANDROID_ALARM_SET_RTC, ts);
- close(fd);
- return ret;
-}
-
-static int settime_alarm_tm(struct tm *tm) {
- time_t t;
- struct timespec ts;
-
- t = mktime(tm);
- ts.tv_sec = t;
- ts.tv_nsec = 0;
- return settime_alarm(&ts);
-}
-
-static int settime_alarm_timeval(struct timeval *tv) {
- struct timespec ts;
-
- ts.tv_sec = tv->tv_sec;
- ts.tv_nsec = tv->tv_usec * 1000;
- return settime_alarm(&ts);
-}
-
-static int settime_rtc_tm(struct tm *tm) {
- int fd, ret;
- struct timeval tv;
- struct rtc_time rtc;
-
- fd = open("/dev/rtc0", O_RDWR);
- if (fd < 0)
- return fd;
-
- tv.tv_sec = mktime(tm);
- tv.tv_usec = 0;
-
- ret = settimeofday(&tv, NULL);
- if (ret < 0)
- goto done;
-
- memset(&rtc, 0, sizeof(rtc));
- rtc.tm_sec = tm->tm_sec;
- rtc.tm_min = tm->tm_min;
- rtc.tm_hour = tm->tm_hour;
- rtc.tm_mday = tm->tm_mday;
- rtc.tm_mon = tm->tm_mon;
- rtc.tm_year = tm->tm_year;
- rtc.tm_wday = tm->tm_wday;
- rtc.tm_yday = tm->tm_yday;
- rtc.tm_isdst = tm->tm_isdst;
-
- ret = ioctl(fd, RTC_SET_TIME, rtc);
-done:
- close(fd);
- return ret;
-}
-
-static int settime_rtc_timeval(struct timeval *tv) {
- struct tm tm, *err;
- time_t t = tv->tv_sec;
-
- err = gmtime_r(&t, &tm);
- if (!err)
- return -1;
-
- return settime_rtc_tm(&tm);
-}
-
-static void settime(char *s) {
- struct tm tm;
- int day = atoi(s);
- int hour;
-
- while (*s && *s != '.')
- s++;
-
- if (*s)
- s++;
-
- hour = atoi(s);
-
- tm.tm_year = day / 10000 - 1900;
- tm.tm_mon = (day % 10000) / 100 - 1;
- tm.tm_mday = (day % 100);
- tm.tm_hour = hour / 10000;
- tm.tm_min = (hour % 10000) / 100;
- tm.tm_sec = (hour % 100);
- tm.tm_isdst = -1;
-
- if (settime_alarm_tm(&tm) < 0)
- settime_rtc_tm(&tm);
-}
-
-static char *parse_time(const char *str, struct timeval *ts) {
- char *s;
- long fs = 0; /* fractional seconds */
-
- ts->tv_sec = strtoumax(str, &s, 10);
-
- if (*s == '.') {
- s++;
- int count = 0;
-
- /* read up to 6 digits (microseconds) */
- while (*s && isdigit(*s)) {
- if (++count < 7) {
- fs = fs*10 + (*s - '0');
- }
- s++;
- }
-
- for (; count < 6; count++) {
- fs *= 10;
- }
- }
-
- ts->tv_usec = fs;
- return s;
-}
-
-int date_main(int argc, char *argv[])
-{
- int c;
- int res;
- struct tm tm;
- time_t t;
- struct timeval tv;
- char strbuf[260];
-
- int useutc = 0;
-
- tzset();
-
- do {
- c = getopt(argc, argv, "us:");
- if (c == EOF)
- break;
- switch (c) {
- case 'u':
- useutc = 1;
- break;
- case 's':
- settime(optarg);
- break;
- case '?':
- fprintf(stderr, "%s: invalid option -%c\n",
- argv[0], optopt);
- exit(1);
- }
- } while (1);
- if(optind + 2 < argc) {
- fprintf(stderr,"%s [-u] [date]\n", argv[0]);
- return 1;
- }
-
- int hasfmt = argc == optind + 1 && argv[optind][0] == '+';
- if(optind == argc || hasfmt) {
- time(&t);
- if (useutc) {
- gmtime_r(&t, &tm);
- strftime(strbuf, sizeof(strbuf),
- (hasfmt ? argv[optind] + 1 : "%a %b %e %H:%M:%S GMT %Y"),
- &tm);
- } else {
- localtime_r(&t, &tm);
- strftime(strbuf, sizeof(strbuf),
- (hasfmt ? argv[optind] + 1 : "%a %b %e %H:%M:%S %Z %Y"),
- &tm);
- }
- printf("%s\n", strbuf);
- }
- else if(optind + 1 == argc) {
-#if 0
- struct tm *tmptr;
- tmptr = getdate(argv[optind]);
- if(tmptr == NULL) {
- fprintf(stderr,"getdate_r failed\n");
- return 1;
- }
- tm = *tmptr;
-#if 0
- if(getdate_r(argv[optind], &tm) < 0) {
- fprintf(stderr,"getdate_r failed %s\n", strerror(errno));
- return 1;
- }
-#endif
-#endif
- //strptime(argv[optind], NULL, &tm);
- //tv.tv_sec = mktime(&tm);
- //tv.tv_usec = 0;
- parse_time(argv[optind], &tv);
- printf("time %s -> %lu.%lu\n", argv[optind], tv.tv_sec, tv.tv_usec);
- res = settime_alarm_timeval(&tv);
- if (res < 0)
- res = settime_rtc_timeval(&tv);
- if(res < 0) {
- fprintf(stderr,"settimeofday failed %s\n", strerror(errno));
- return 1;
- }
- }
- else {
- fprintf(stderr,"%s [-s 20070325.123456] [-u] [date]\n", argv[0]);
- return 1;
- }
-
- return 0;
-}
diff --git a/toolbox/dmesg.c b/toolbox/dmesg.c
deleted file mode 100644
index 9c73b00..0000000
--- a/toolbox/dmesg.c
+++ /dev/null
@@ -1,58 +0,0 @@
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <errno.h>
-#include <sys/klog.h>
-#include <string.h>
-
-#define FALLBACK_KLOG_BUF_SHIFT 17 /* CONFIG_LOG_BUF_SHIFT from our kernel */
-#define FALLBACK_KLOG_BUF_LEN (1 << FALLBACK_KLOG_BUF_SHIFT)
-
-int dmesg_main(int argc, char **argv)
-{
- char *buffer;
- char *p;
- ssize_t ret;
- int n, op, klog_buf_len;
-
- klog_buf_len = klogctl(KLOG_SIZE_BUFFER, 0, 0);
-
- if (klog_buf_len <= 0) {
- klog_buf_len = FALLBACK_KLOG_BUF_LEN;
- }
-
- buffer = (char *)malloc(klog_buf_len + 1);
-
- if (!buffer) {
- perror("malloc");
- return EXIT_FAILURE;
- }
-
- p = buffer;
-
- if((argc == 2) && (!strcmp(argv[1],"-c"))) {
- op = KLOG_READ_CLEAR;
- } else {
- op = KLOG_READ_ALL;
- }
-
- n = klogctl(op, buffer, klog_buf_len);
- if (n < 0) {
- perror("klogctl");
- return EXIT_FAILURE;
- }
- buffer[n] = '\0';
-
- while((ret = write(STDOUT_FILENO, p, n))) {
- if (ret == -1) {
- if (errno == EINTR)
- continue;
- perror("write");
- return EXIT_FAILURE;
- }
- p += ret;
- n -= ret;
- }
-
- return 0;
-}
diff --git a/toolbox/dynarray.c b/toolbox/dynarray.c
deleted file mode 100644
index e9b7b03..0000000
--- a/toolbox/dynarray.c
+++ /dev/null
@@ -1,103 +0,0 @@
-#include "dynarray.h"
-#include <stdlib.h>
-#include <limits.h>
-
-void
-dynarray_init( dynarray_t *a )
-{
- a->count = a->capacity = 0;
- a->items = NULL;
-}
-
-
-static void
-dynarray_reserve_more( dynarray_t *a, int count )
-{
- int old_cap = a->capacity;
- int new_cap = old_cap;
- const int max_cap = INT_MAX/sizeof(void*);
- void** new_items;
- int new_count = a->count + count;
-
- if (count <= 0)
- return;
-
- if (count > max_cap - a->count)
- abort();
-
- new_count = a->count + count;
-
- while (new_cap < new_count) {
- old_cap = new_cap;
- new_cap += (new_cap >> 2) + 4;
- if (new_cap < old_cap || new_cap > max_cap) {
- new_cap = max_cap;
- }
- }
- new_items = realloc(a->items, new_cap*sizeof(void*));
- if (new_items == NULL)
- abort();
-
- a->items = new_items;
- a->capacity = new_cap;
-}
-
-void
-dynarray_append( dynarray_t *a, void* item )
-{
- if (a->count >= a->capacity)
- dynarray_reserve_more(a, 1);
-
- a->items[a->count++] = item;
-}
-
-void
-dynarray_done( dynarray_t *a )
-{
- free(a->items);
- a->items = NULL;
- a->count = a->capacity = 0;
-}
-
-// string arrays
-
-void strlist_init( strlist_t *list )
-{
- dynarray_init(list);
-}
-
-void strlist_append_b( strlist_t *list, const void* str, size_t slen )
-{
- char *copy = malloc(slen+1);
- memcpy(copy, str, slen);
- copy[slen] = '\0';
- dynarray_append(list, copy);
-}
-
-void strlist_append_dup( strlist_t *list, const char *str)
-{
- strlist_append_b(list, str, strlen(str));
-}
-
-void strlist_done( strlist_t *list )
-{
- STRLIST_FOREACH(list, string, free(string));
- dynarray_done(list);
-}
-
-static int strlist_compare_strings(const void* a, const void* b)
-{
- const char *sa = *(const char **)a;
- const char *sb = *(const char **)b;
- return strcmp(sa, sb);
-}
-
-void strlist_sort( strlist_t *list )
-{
- if (list->count > 0) {
- qsort(list->items,
- (size_t)list->count,
- sizeof(void*),
- strlist_compare_strings);
- }
-}
diff --git a/toolbox/dynarray.h b/toolbox/dynarray.h
deleted file mode 100644
index f73fb3b..0000000
--- a/toolbox/dynarray.h
+++ /dev/null
@@ -1,80 +0,0 @@
-#ifndef DYNARRAY_H
-#define DYNARRAY_H
-
-#include <stddef.h>
-
-/* simple dynamic array of pointers */
-typedef struct {
- int count;
- int capacity;
- void** items;
-} dynarray_t;
-
-#define DYNARRAY_INITIALIZER { 0, 0, NULL }
-
-void dynarray_init( dynarray_t *a );
-void dynarray_done( dynarray_t *a );
-
-void dynarray_append( dynarray_t *a, void* item );
-
-/* Used to iterate over a dynarray_t
- * _array :: pointer to the array
- * _item_type :: type of objects pointed to by the array
- * _item :: name of a local variable defined within the loop
- * with type '_item_type'
- * _stmnt :: C statement that will be executed in each iteration.
- *
- * You case use 'break' and 'continue' within _stmnt
- *
- * This macro is only intended for simple uses. I.e. do not add or
- * remove items from the array during iteration.
- */
-#define DYNARRAY_FOREACH_TYPE(_array,_item_type,_item,_stmnt) \
- do { \
- int _nn_##__LINE__ = 0; \
- for (;_nn_##__LINE__ < (_array)->count; ++ _nn_##__LINE__) { \
- _item_type _item = (_item_type)(_array)->items[_nn_##__LINE__]; \
- _stmnt; \
- } \
- } while (0)
-
-#define DYNARRAY_FOREACH(_array,_item,_stmnt) \
- DYNARRAY_FOREACH_TYPE(_array,void *,_item,_stmnt)
-
-/* Simple dynamic string arrays
- *
- * NOTE: A strlist_t owns the strings it references.
- */
-typedef dynarray_t strlist_t;
-
-#define STRLIST_INITIALIZER DYNARRAY_INITIALIZER
-
-/* Used to iterate over a strlist_t
- * _list :: pointer to strlist_t object
- * _string :: name of local variable name defined within the loop with
- * type 'char*'
- * _stmnt :: C statement executed in each iteration
- *
- * This macro is only intended for simple uses. Do not add or remove items
- * to/from the list during iteration.
- */
-#define STRLIST_FOREACH(_list,_string,_stmnt) \
- DYNARRAY_FOREACH_TYPE(_list,char *,_string,_stmnt)
-
-void strlist_init( strlist_t *list );
-
-/* note: strlist_done will free all the strings owned by the list */
-void strlist_done( strlist_t *list );
-
-/* append a new string made of the first 'slen' characters from 'str'
- * followed by a trailing zero.
- */
-void strlist_append_b( strlist_t *list, const void* str, size_t slen );
-
-/* append the copy of a given input string to a strlist_t */
-void strlist_append_dup( strlist_t *list, const char *str);
-
-/* sort the strings in a given list (using strcmp) */
-void strlist_sort( strlist_t *list );
-
-#endif /* DYNARRAY_H */ \ No newline at end of file
diff --git a/toolbox/exists.c b/toolbox/exists.c
deleted file mode 100644
index e348668..0000000
--- a/toolbox/exists.c
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-int exists_main(int argc, char *argv[])
-{
- struct stat s;
-
- if(argc < 2) return 1;
-
- if(stat(argv[1], &s)) {
- return 1;
- } else {
- return 0;
- }
-}
diff --git a/toolbox/generate-input.h-labels.py b/toolbox/generate-input.h-labels.py
new file mode 100755
index 0000000..ebb9588
--- /dev/null
+++ b/toolbox/generate-input.h-labels.py
@@ -0,0 +1,93 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2015 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the 'License');
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an 'AS IS' BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# pylint: disable=bad-indentation,bad-continuation
+
+import os
+import re
+
+input_prop_list = []
+ev_list = []
+syn_list = []
+key_list = []
+rel_list = []
+abs_list = []
+sw_list = []
+msc_list = []
+led_list = []
+rep_list = []
+snd_list = []
+mt_tool_list = []
+ff_status_list = []
+ff_list = []
+
+r = re.compile(r'#define\s+(\S+)\s+((?:0x)?\d+)')
+
+with open('bionic/libc/kernel/uapi/linux/input.h', 'r') as f:
+ for line in f:
+ m = r.match(line)
+ if m:
+ name = m.group(1)
+ if name.startswith("INPUT_PROP_"):
+ input_prop_list.append(name)
+ elif name.startswith("EV_"):
+ ev_list.append(name)
+ elif name.startswith("SYN_"):
+ syn_list.append(name)
+ elif name.startswith("KEY_") or name.startswith("BTN_"):
+ key_list.append(name)
+ elif name.startswith("REL_"):
+ rel_list.append(name)
+ elif name.startswith("ABS_"):
+ abs_list.append(name)
+ elif name.startswith("SW_"):
+ sw_list.append(name)
+ elif name.startswith("MSC_"):
+ msc_list.append(name)
+ elif name.startswith("LED_"):
+ led_list.append(name)
+ elif name.startswith("REP_"):
+ rep_list.append(name)
+ elif name.startswith("SND_"):
+ snd_list.append(name)
+ elif name.startswith("MT_TOOL_"):
+ mt_tool_list.append(name)
+ elif name.startswith("FF_STATUS_"):
+ ff_status_list.append(name)
+ elif name.startswith("FF_"):
+ ff_list.append(name)
+
+def Dump(struct_name, values):
+ print 'static struct label %s[] = {' % (struct_name)
+ for value in values:
+ print ' LABEL(%s),' % (value)
+ print ' LABEL_END,'
+ print '};'
+
+Dump("input_prop_labels", input_prop_list)
+Dump("ev_labels", ev_list)
+Dump("syn_labels", syn_list)
+Dump("key_labels", key_list)
+Dump("rel_labels", rel_list)
+Dump("abs_labels", abs_list)
+Dump("sw_labels", sw_list)
+Dump("msc_labels", msc_list)
+Dump("led_labels", led_list)
+Dump("rep_labels", rep_list)
+Dump("snd_labels", snd_list)
+Dump("mt_tool_labels", mt_tool_list)
+Dump("ff_status_labels", ff_status_list)
+Dump("ff_labels", ff_list)
diff --git a/toolbox/getenforce.c b/toolbox/getenforce.c
deleted file mode 100644
index 9e7589a..0000000
--- a/toolbox/getenforce.c
+++ /dev/null
@@ -1,30 +0,0 @@
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <selinux/selinux.h>
-
-int getenforce_main(int argc, char **argv)
-{
- int rc;
-
- rc = is_selinux_enabled();
- if (rc <= 0) {
- printf("Disabled\n");
- return 0;
- }
-
- rc = security_getenforce();
- if (rc < 0) {
- fprintf(stderr, "Could not get enforcing status: %s\n",
- strerror(errno));
- return 2;
- }
-
- if (rc)
- printf("Enforcing\n");
- else
- printf("Permissive\n");
-
- return 0;
-}
diff --git a/toolbox/getevent.c b/toolbox/getevent.c
index da83ec3..30053af 100644
--- a/toolbox/getevent.c
+++ b/toolbox/getevent.c
@@ -10,8 +10,27 @@
#include <sys/poll.h>
#include <linux/input.h>
#include <errno.h>
+#include <unistd.h>
-#include "getevent.h"
+struct label {
+ const char *name;
+ int value;
+};
+
+#define LABEL(constant) { #constant, constant }
+#define LABEL_END { NULL, -1 }
+
+static struct label key_value_labels[] = {
+ { "UP", 0 },
+ { "DOWN", 1 },
+ { "REPEAT", 2 },
+ LABEL_END,
+};
+
+#include "input.h-labels.h"
+
+#undef LABEL
+#undef LABEL_END
static struct pollfd *ufds;
static char **device_names;
diff --git a/toolbox/getevent.h b/toolbox/getevent.h
deleted file mode 100644
index 0482d04..0000000
--- a/toolbox/getevent.h
+++ /dev/null
@@ -1,727 +0,0 @@
-#include <linux/input.h>
-
-struct label {
- const char *name;
- int value;
-};
-
-#define LABEL(constant) { #constant, constant }
-#define LABEL_END { NULL, -1 }
-
-static struct label input_prop_labels[] = {
- LABEL(INPUT_PROP_POINTER),
- LABEL(INPUT_PROP_DIRECT),
- LABEL(INPUT_PROP_BUTTONPAD),
- LABEL(INPUT_PROP_SEMI_MT),
- LABEL_END,
-};
-
-static struct label ev_labels[] = {
- LABEL(EV_SYN),
- LABEL(EV_KEY),
- LABEL(EV_REL),
- LABEL(EV_ABS),
- LABEL(EV_MSC),
- LABEL(EV_SW),
- LABEL(EV_LED),
- LABEL(EV_SND),
- LABEL(EV_REP),
- LABEL(EV_FF),
- LABEL(EV_PWR),
- LABEL(EV_FF_STATUS),
- LABEL_END,
-};
-
-static struct label syn_labels[] = {
- LABEL(SYN_REPORT),
- LABEL(SYN_CONFIG),
- LABEL(SYN_MT_REPORT),
- LABEL(SYN_DROPPED),
- LABEL_END,
-};
-
-static struct label key_labels[] = {
- LABEL(KEY_RESERVED),
- LABEL(KEY_ESC),
- LABEL(KEY_1),
- LABEL(KEY_2),
- LABEL(KEY_3),
- LABEL(KEY_4),
- LABEL(KEY_5),
- LABEL(KEY_6),
- LABEL(KEY_7),
- LABEL(KEY_8),
- LABEL(KEY_9),
- LABEL(KEY_0),
- LABEL(KEY_MINUS),
- LABEL(KEY_EQUAL),
- LABEL(KEY_BACKSPACE),
- LABEL(KEY_TAB),
- LABEL(KEY_Q),
- LABEL(KEY_W),
- LABEL(KEY_E),
- LABEL(KEY_R),
- LABEL(KEY_T),
- LABEL(KEY_Y),
- LABEL(KEY_U),
- LABEL(KEY_I),
- LABEL(KEY_O),
- LABEL(KEY_P),
- LABEL(KEY_LEFTBRACE),
- LABEL(KEY_RIGHTBRACE),
- LABEL(KEY_ENTER),
- LABEL(KEY_LEFTCTRL),
- LABEL(KEY_A),
- LABEL(KEY_S),
- LABEL(KEY_D),
- LABEL(KEY_F),
- LABEL(KEY_G),
- LABEL(KEY_H),
- LABEL(KEY_J),
- LABEL(KEY_K),
- LABEL(KEY_L),
- LABEL(KEY_SEMICOLON),
- LABEL(KEY_APOSTROPHE),
- LABEL(KEY_GRAVE),
- LABEL(KEY_LEFTSHIFT),
- LABEL(KEY_BACKSLASH),
- LABEL(KEY_Z),
- LABEL(KEY_X),
- LABEL(KEY_C),
- LABEL(KEY_V),
- LABEL(KEY_B),
- LABEL(KEY_N),
- LABEL(KEY_M),
- LABEL(KEY_COMMA),
- LABEL(KEY_DOT),
- LABEL(KEY_SLASH),
- LABEL(KEY_RIGHTSHIFT),
- LABEL(KEY_KPASTERISK),
- LABEL(KEY_LEFTALT),
- LABEL(KEY_SPACE),
- LABEL(KEY_CAPSLOCK),
- LABEL(KEY_F1),
- LABEL(KEY_F2),
- LABEL(KEY_F3),
- LABEL(KEY_F4),
- LABEL(KEY_F5),
- LABEL(KEY_F6),
- LABEL(KEY_F7),
- LABEL(KEY_F8),
- LABEL(KEY_F9),
- LABEL(KEY_F10),
- LABEL(KEY_NUMLOCK),
- LABEL(KEY_SCROLLLOCK),
- LABEL(KEY_KP7),
- LABEL(KEY_KP8),
- LABEL(KEY_KP9),
- LABEL(KEY_KPMINUS),
- LABEL(KEY_KP4),
- LABEL(KEY_KP5),
- LABEL(KEY_KP6),
- LABEL(KEY_KPPLUS),
- LABEL(KEY_KP1),
- LABEL(KEY_KP2),
- LABEL(KEY_KP3),
- LABEL(KEY_KP0),
- LABEL(KEY_KPDOT),
- LABEL(KEY_ZENKAKUHANKAKU),
- LABEL(KEY_102ND),
- LABEL(KEY_F11),
- LABEL(KEY_F12),
- LABEL(KEY_RO),
- LABEL(KEY_KATAKANA),
- LABEL(KEY_HIRAGANA),
- LABEL(KEY_HENKAN),
- LABEL(KEY_KATAKANAHIRAGANA),
- LABEL(KEY_MUHENKAN),
- LABEL(KEY_KPJPCOMMA),
- LABEL(KEY_KPENTER),
- LABEL(KEY_RIGHTCTRL),
- LABEL(KEY_KPSLASH),
- LABEL(KEY_SYSRQ),
- LABEL(KEY_RIGHTALT),
- LABEL(KEY_LINEFEED),
- LABEL(KEY_HOME),
- LABEL(KEY_UP),
- LABEL(KEY_PAGEUP),
- LABEL(KEY_LEFT),
- LABEL(KEY_RIGHT),
- LABEL(KEY_END),
- LABEL(KEY_DOWN),
- LABEL(KEY_PAGEDOWN),
- LABEL(KEY_INSERT),
- LABEL(KEY_DELETE),
- LABEL(KEY_MACRO),
- LABEL(KEY_MUTE),
- LABEL(KEY_VOLUMEDOWN),
- LABEL(KEY_VOLUMEUP),
- LABEL(KEY_POWER),
- LABEL(KEY_KPEQUAL),
- LABEL(KEY_KPPLUSMINUS),
- LABEL(KEY_PAUSE),
- LABEL(KEY_SCALE),
- LABEL(KEY_KPCOMMA),
- LABEL(KEY_HANGEUL),
- LABEL(KEY_HANGUEL),
- LABEL(KEY_HANJA),
- LABEL(KEY_YEN),
- LABEL(KEY_LEFTMETA),
- LABEL(KEY_RIGHTMETA),
- LABEL(KEY_COMPOSE),
- LABEL(KEY_STOP),
- LABEL(KEY_AGAIN),
- LABEL(KEY_PROPS),
- LABEL(KEY_UNDO),
- LABEL(KEY_FRONT),
- LABEL(KEY_COPY),
- LABEL(KEY_OPEN),
- LABEL(KEY_PASTE),
- LABEL(KEY_FIND),
- LABEL(KEY_CUT),
- LABEL(KEY_HELP),
- LABEL(KEY_MENU),
- LABEL(KEY_CALC),
- LABEL(KEY_SETUP),
- LABEL(KEY_SLEEP),
- LABEL(KEY_WAKEUP),
- LABEL(KEY_FILE),
- LABEL(KEY_SENDFILE),
- LABEL(KEY_DELETEFILE),
- LABEL(KEY_XFER),
- LABEL(KEY_PROG1),
- LABEL(KEY_PROG2),
- LABEL(KEY_WWW),
- LABEL(KEY_MSDOS),
- LABEL(KEY_COFFEE),
- LABEL(KEY_SCREENLOCK),
- LABEL(KEY_DIRECTION),
- LABEL(KEY_CYCLEWINDOWS),
- LABEL(KEY_MAIL),
- LABEL(KEY_BOOKMARKS),
- LABEL(KEY_COMPUTER),
- LABEL(KEY_BACK),
- LABEL(KEY_FORWARD),
- LABEL(KEY_CLOSECD),
- LABEL(KEY_EJECTCD),
- LABEL(KEY_EJECTCLOSECD),
- LABEL(KEY_NEXTSONG),
- LABEL(KEY_PLAYPAUSE),
- LABEL(KEY_PREVIOUSSONG),
- LABEL(KEY_STOPCD),
- LABEL(KEY_RECORD),
- LABEL(KEY_REWIND),
- LABEL(KEY_PHONE),
- LABEL(KEY_ISO),
- LABEL(KEY_CONFIG),
- LABEL(KEY_HOMEPAGE),
- LABEL(KEY_REFRESH),
- LABEL(KEY_EXIT),
- LABEL(KEY_MOVE),
- LABEL(KEY_EDIT),
- LABEL(KEY_SCROLLUP),
- LABEL(KEY_SCROLLDOWN),
- LABEL(KEY_KPLEFTPAREN),
- LABEL(KEY_KPRIGHTPAREN),
- LABEL(KEY_NEW),
- LABEL(KEY_REDO),
- LABEL(KEY_F13),
- LABEL(KEY_F14),
- LABEL(KEY_F15),
- LABEL(KEY_F16),
- LABEL(KEY_F17),
- LABEL(KEY_F18),
- LABEL(KEY_F19),
- LABEL(KEY_F20),
- LABEL(KEY_F21),
- LABEL(KEY_F22),
- LABEL(KEY_F23),
- LABEL(KEY_F24),
- LABEL(KEY_PLAYCD),
- LABEL(KEY_PAUSECD),
- LABEL(KEY_PROG3),
- LABEL(KEY_PROG4),
- LABEL(KEY_DASHBOARD),
- LABEL(KEY_SUSPEND),
- LABEL(KEY_CLOSE),
- LABEL(KEY_PLAY),
- LABEL(KEY_FASTFORWARD),
- LABEL(KEY_BASSBOOST),
- LABEL(KEY_PRINT),
- LABEL(KEY_HP),
- LABEL(KEY_CAMERA),
- LABEL(KEY_SOUND),
- LABEL(KEY_QUESTION),
- LABEL(KEY_EMAIL),
- LABEL(KEY_CHAT),
- LABEL(KEY_SEARCH),
- LABEL(KEY_CONNECT),
- LABEL(KEY_FINANCE),
- LABEL(KEY_SPORT),
- LABEL(KEY_SHOP),
- LABEL(KEY_ALTERASE),
- LABEL(KEY_CANCEL),
- LABEL(KEY_BRIGHTNESSDOWN),
- LABEL(KEY_BRIGHTNESSUP),
- LABEL(KEY_MEDIA),
- LABEL(KEY_SWITCHVIDEOMODE),
- LABEL(KEY_KBDILLUMTOGGLE),
- LABEL(KEY_KBDILLUMDOWN),
- LABEL(KEY_KBDILLUMUP),
- LABEL(KEY_SEND),
- LABEL(KEY_REPLY),
- LABEL(KEY_FORWARDMAIL),
- LABEL(KEY_SAVE),
- LABEL(KEY_DOCUMENTS),
- LABEL(KEY_BATTERY),
- LABEL(KEY_BLUETOOTH),
- LABEL(KEY_WLAN),
- LABEL(KEY_UWB),
- LABEL(KEY_UNKNOWN),
- LABEL(KEY_VIDEO_NEXT),
- LABEL(KEY_VIDEO_PREV),
- LABEL(KEY_BRIGHTNESS_CYCLE),
- LABEL(KEY_BRIGHTNESS_ZERO),
- LABEL(KEY_DISPLAY_OFF),
- LABEL(KEY_WIMAX),
- LABEL(KEY_RFKILL),
- LABEL(BTN_0),
- LABEL(BTN_1),
- LABEL(BTN_2),
- LABEL(BTN_3),
- LABEL(BTN_4),
- LABEL(BTN_5),
- LABEL(BTN_6),
- LABEL(BTN_7),
- LABEL(BTN_8),
- LABEL(BTN_9),
- LABEL(BTN_LEFT),
- LABEL(BTN_RIGHT),
- LABEL(BTN_MIDDLE),
- LABEL(BTN_SIDE),
- LABEL(BTN_EXTRA),
- LABEL(BTN_FORWARD),
- LABEL(BTN_BACK),
- LABEL(BTN_TASK),
- LABEL(BTN_JOYSTICK),
- LABEL(BTN_TRIGGER),
- LABEL(BTN_THUMB),
- LABEL(BTN_THUMB2),
- LABEL(BTN_TOP),
- LABEL(BTN_TOP2),
- LABEL(BTN_PINKIE),
- LABEL(BTN_BASE),
- LABEL(BTN_BASE2),
- LABEL(BTN_BASE3),
- LABEL(BTN_BASE4),
- LABEL(BTN_BASE5),
- LABEL(BTN_BASE6),
- LABEL(BTN_DEAD),
- LABEL(BTN_A),
- LABEL(BTN_B),
- LABEL(BTN_C),
- LABEL(BTN_X),
- LABEL(BTN_Y),
- LABEL(BTN_Z),
- LABEL(BTN_TL),
- LABEL(BTN_TR),
- LABEL(BTN_TL2),
- LABEL(BTN_TR2),
- LABEL(BTN_SELECT),
- LABEL(BTN_START),
- LABEL(BTN_MODE),
- LABEL(BTN_THUMBL),
- LABEL(BTN_THUMBR),
- LABEL(BTN_TOOL_PEN),
- LABEL(BTN_TOOL_RUBBER),
- LABEL(BTN_TOOL_BRUSH),
- LABEL(BTN_TOOL_PENCIL),
- LABEL(BTN_TOOL_AIRBRUSH),
- LABEL(BTN_TOOL_FINGER),
- LABEL(BTN_TOOL_MOUSE),
- LABEL(BTN_TOOL_LENS),
- LABEL(BTN_TOUCH),
- LABEL(BTN_STYLUS),
- LABEL(BTN_STYLUS2),
- LABEL(BTN_TOOL_DOUBLETAP),
- LABEL(BTN_TOOL_TRIPLETAP),
- LABEL(BTN_TOOL_QUADTAP),
- LABEL(BTN_GEAR_DOWN),
- LABEL(BTN_GEAR_UP),
- LABEL(KEY_OK),
- LABEL(KEY_SELECT),
- LABEL(KEY_GOTO),
- LABEL(KEY_CLEAR),
- LABEL(KEY_POWER2),
- LABEL(KEY_OPTION),
- LABEL(KEY_INFO),
- LABEL(KEY_TIME),
- LABEL(KEY_VENDOR),
- LABEL(KEY_ARCHIVE),
- LABEL(KEY_PROGRAM),
- LABEL(KEY_CHANNEL),
- LABEL(KEY_FAVORITES),
- LABEL(KEY_EPG),
- LABEL(KEY_PVR),
- LABEL(KEY_MHP),
- LABEL(KEY_LANGUAGE),
- LABEL(KEY_TITLE),
- LABEL(KEY_SUBTITLE),
- LABEL(KEY_ANGLE),
- LABEL(KEY_ZOOM),
- LABEL(KEY_MODE),
- LABEL(KEY_KEYBOARD),
- LABEL(KEY_SCREEN),
- LABEL(KEY_PC),
- LABEL(KEY_TV),
- LABEL(KEY_TV2),
- LABEL(KEY_VCR),
- LABEL(KEY_VCR2),
- LABEL(KEY_SAT),
- LABEL(KEY_SAT2),
- LABEL(KEY_CD),
- LABEL(KEY_TAPE),
- LABEL(KEY_RADIO),
- LABEL(KEY_TUNER),
- LABEL(KEY_PLAYER),
- LABEL(KEY_TEXT),
- LABEL(KEY_DVD),
- LABEL(KEY_AUX),
- LABEL(KEY_MP3),
- LABEL(KEY_AUDIO),
- LABEL(KEY_VIDEO),
- LABEL(KEY_DIRECTORY),
- LABEL(KEY_LIST),
- LABEL(KEY_MEMO),
- LABEL(KEY_CALENDAR),
- LABEL(KEY_RED),
- LABEL(KEY_GREEN),
- LABEL(KEY_YELLOW),
- LABEL(KEY_BLUE),
- LABEL(KEY_CHANNELUP),
- LABEL(KEY_CHANNELDOWN),
- LABEL(KEY_FIRST),
- LABEL(KEY_LAST),
- LABEL(KEY_AB),
- LABEL(KEY_NEXT),
- LABEL(KEY_RESTART),
- LABEL(KEY_SLOW),
- LABEL(KEY_SHUFFLE),
- LABEL(KEY_BREAK),
- LABEL(KEY_PREVIOUS),
- LABEL(KEY_DIGITS),
- LABEL(KEY_TEEN),
- LABEL(KEY_TWEN),
- LABEL(KEY_VIDEOPHONE),
- LABEL(KEY_GAMES),
- LABEL(KEY_ZOOMIN),
- LABEL(KEY_ZOOMOUT),
- LABEL(KEY_ZOOMRESET),
- LABEL(KEY_WORDPROCESSOR),
- LABEL(KEY_EDITOR),
- LABEL(KEY_SPREADSHEET),
- LABEL(KEY_GRAPHICSEDITOR),
- LABEL(KEY_PRESENTATION),
- LABEL(KEY_DATABASE),
- LABEL(KEY_NEWS),
- LABEL(KEY_VOICEMAIL),
- LABEL(KEY_ADDRESSBOOK),
- LABEL(KEY_MESSENGER),
- LABEL(KEY_DISPLAYTOGGLE),
- LABEL(KEY_SPELLCHECK),
- LABEL(KEY_LOGOFF),
- LABEL(KEY_DOLLAR),
- LABEL(KEY_EURO),
- LABEL(KEY_FRAMEBACK),
- LABEL(KEY_FRAMEFORWARD),
- LABEL(KEY_CONTEXT_MENU),
- LABEL(KEY_MEDIA_REPEAT),
- LABEL(KEY_10CHANNELSUP),
- LABEL(KEY_10CHANNELSDOWN),
- LABEL(KEY_IMAGES),
- LABEL(KEY_DEL_EOL),
- LABEL(KEY_DEL_EOS),
- LABEL(KEY_INS_LINE),
- LABEL(KEY_DEL_LINE),
- LABEL(KEY_FN),
- LABEL(KEY_FN_ESC),
- LABEL(KEY_FN_F1),
- LABEL(KEY_FN_F2),
- LABEL(KEY_FN_F3),
- LABEL(KEY_FN_F4),
- LABEL(KEY_FN_F5),
- LABEL(KEY_FN_F6),
- LABEL(KEY_FN_F7),
- LABEL(KEY_FN_F8),
- LABEL(KEY_FN_F9),
- LABEL(KEY_FN_F10),
- LABEL(KEY_FN_F11),
- LABEL(KEY_FN_F12),
- LABEL(KEY_FN_1),
- LABEL(KEY_FN_2),
- LABEL(KEY_FN_D),
- LABEL(KEY_FN_E),
- LABEL(KEY_FN_F),
- LABEL(KEY_FN_S),
- LABEL(KEY_FN_B),
- LABEL(KEY_BRL_DOT1),
- LABEL(KEY_BRL_DOT2),
- LABEL(KEY_BRL_DOT3),
- LABEL(KEY_BRL_DOT4),
- LABEL(KEY_BRL_DOT5),
- LABEL(KEY_BRL_DOT6),
- LABEL(KEY_BRL_DOT7),
- LABEL(KEY_BRL_DOT8),
- LABEL(KEY_BRL_DOT9),
- LABEL(KEY_BRL_DOT10),
- LABEL(KEY_NUMERIC_0),
- LABEL(KEY_NUMERIC_1),
- LABEL(KEY_NUMERIC_2),
- LABEL(KEY_NUMERIC_3),
- LABEL(KEY_NUMERIC_4),
- LABEL(KEY_NUMERIC_5),
- LABEL(KEY_NUMERIC_6),
- LABEL(KEY_NUMERIC_7),
- LABEL(KEY_NUMERIC_8),
- LABEL(KEY_NUMERIC_9),
- LABEL(KEY_NUMERIC_STAR),
- LABEL(KEY_NUMERIC_POUND),
- LABEL(KEY_CAMERA_FOCUS),
- LABEL(KEY_WPS_BUTTON),
- LABEL(KEY_TOUCHPAD_TOGGLE),
- LABEL(KEY_TOUCHPAD_ON),
- LABEL(KEY_TOUCHPAD_OFF),
- LABEL(KEY_CAMERA_ZOOMIN),
- LABEL(KEY_CAMERA_ZOOMOUT),
- LABEL(KEY_CAMERA_UP),
- LABEL(KEY_CAMERA_DOWN),
- LABEL(KEY_CAMERA_LEFT),
- LABEL(KEY_CAMERA_RIGHT),
- LABEL(BTN_TRIGGER_HAPPY1),
- LABEL(BTN_TRIGGER_HAPPY2),
- LABEL(BTN_TRIGGER_HAPPY3),
- LABEL(BTN_TRIGGER_HAPPY4),
- LABEL(BTN_TRIGGER_HAPPY5),
- LABEL(BTN_TRIGGER_HAPPY6),
- LABEL(BTN_TRIGGER_HAPPY7),
- LABEL(BTN_TRIGGER_HAPPY8),
- LABEL(BTN_TRIGGER_HAPPY9),
- LABEL(BTN_TRIGGER_HAPPY10),
- LABEL(BTN_TRIGGER_HAPPY11),
- LABEL(BTN_TRIGGER_HAPPY12),
- LABEL(BTN_TRIGGER_HAPPY13),
- LABEL(BTN_TRIGGER_HAPPY14),
- LABEL(BTN_TRIGGER_HAPPY15),
- LABEL(BTN_TRIGGER_HAPPY16),
- LABEL(BTN_TRIGGER_HAPPY17),
- LABEL(BTN_TRIGGER_HAPPY18),
- LABEL(BTN_TRIGGER_HAPPY19),
- LABEL(BTN_TRIGGER_HAPPY20),
- LABEL(BTN_TRIGGER_HAPPY21),
- LABEL(BTN_TRIGGER_HAPPY22),
- LABEL(BTN_TRIGGER_HAPPY23),
- LABEL(BTN_TRIGGER_HAPPY24),
- LABEL(BTN_TRIGGER_HAPPY25),
- LABEL(BTN_TRIGGER_HAPPY26),
- LABEL(BTN_TRIGGER_HAPPY27),
- LABEL(BTN_TRIGGER_HAPPY28),
- LABEL(BTN_TRIGGER_HAPPY29),
- LABEL(BTN_TRIGGER_HAPPY30),
- LABEL(BTN_TRIGGER_HAPPY31),
- LABEL(BTN_TRIGGER_HAPPY32),
- LABEL(BTN_TRIGGER_HAPPY33),
- LABEL(BTN_TRIGGER_HAPPY34),
- LABEL(BTN_TRIGGER_HAPPY35),
- LABEL(BTN_TRIGGER_HAPPY36),
- LABEL(BTN_TRIGGER_HAPPY37),
- LABEL(BTN_TRIGGER_HAPPY38),
- LABEL(BTN_TRIGGER_HAPPY39),
- LABEL(BTN_TRIGGER_HAPPY40),
- LABEL_END,
-};
-
-static struct label rel_labels[] = {
- LABEL(REL_X),
- LABEL(REL_Y),
- LABEL(REL_Z),
- LABEL(REL_RX),
- LABEL(REL_RY),
- LABEL(REL_RZ),
- LABEL(REL_HWHEEL),
- LABEL(REL_DIAL),
- LABEL(REL_WHEEL),
- LABEL(REL_MISC),
- LABEL_END,
-};
-
-static struct label abs_labels[] = {
- LABEL(ABS_X),
- LABEL(ABS_Y),
- LABEL(ABS_Z),
- LABEL(ABS_RX),
- LABEL(ABS_RY),
- LABEL(ABS_RZ),
- LABEL(ABS_THROTTLE),
- LABEL(ABS_RUDDER),
- LABEL(ABS_WHEEL),
- LABEL(ABS_GAS),
- LABEL(ABS_BRAKE),
- LABEL(ABS_HAT0X),
- LABEL(ABS_HAT0Y),
- LABEL(ABS_HAT1X),
- LABEL(ABS_HAT1Y),
- LABEL(ABS_HAT2X),
- LABEL(ABS_HAT2Y),
- LABEL(ABS_HAT3X),
- LABEL(ABS_HAT3Y),
- LABEL(ABS_PRESSURE),
- LABEL(ABS_DISTANCE),
- LABEL(ABS_TILT_X),
- LABEL(ABS_TILT_Y),
- LABEL(ABS_TOOL_WIDTH),
- LABEL(ABS_VOLUME),
- LABEL(ABS_MISC),
- LABEL(ABS_MT_SLOT),
- LABEL(ABS_MT_TOUCH_MAJOR),
- LABEL(ABS_MT_TOUCH_MINOR),
- LABEL(ABS_MT_WIDTH_MAJOR),
- LABEL(ABS_MT_WIDTH_MINOR),
- LABEL(ABS_MT_ORIENTATION),
- LABEL(ABS_MT_POSITION_X),
- LABEL(ABS_MT_POSITION_Y),
- LABEL(ABS_MT_TOOL_TYPE),
- LABEL(ABS_MT_BLOB_ID),
- LABEL(ABS_MT_TRACKING_ID),
- LABEL(ABS_MT_PRESSURE),
- LABEL(ABS_MT_DISTANCE),
- LABEL_END,
-};
-
-static struct label sw_labels[] = {
- LABEL(SW_LID),
- LABEL(SW_TABLET_MODE),
- LABEL(SW_HEADPHONE_INSERT),
- LABEL(SW_RFKILL_ALL),
- LABEL(SW_RADIO),
- LABEL(SW_MICROPHONE_INSERT),
- LABEL(SW_DOCK),
- LABEL(SW_LINEOUT_INSERT),
- LABEL(SW_JACK_PHYSICAL_INSERT),
- LABEL(SW_VIDEOOUT_INSERT),
- LABEL(SW_CAMERA_LENS_COVER),
- LABEL(SW_KEYPAD_SLIDE),
- LABEL(SW_FRONT_PROXIMITY),
- LABEL(SW_ROTATE_LOCK),
- LABEL_END,
-};
-
-static struct label msc_labels[] = {
- LABEL(MSC_SERIAL),
- LABEL(MSC_PULSELED),
- LABEL(MSC_GESTURE),
- LABEL(MSC_RAW),
- LABEL(MSC_SCAN),
- LABEL_END,
-};
-
-static struct label led_labels[] = {
- LABEL(LED_NUML),
- LABEL(LED_CAPSL),
- LABEL(LED_SCROLLL),
- LABEL(LED_COMPOSE),
- LABEL(LED_KANA),
- LABEL(LED_SLEEP),
- LABEL(LED_SUSPEND),
- LABEL(LED_MUTE),
- LABEL(LED_MISC),
- LABEL(LED_MAIL),
- LABEL(LED_CHARGING),
- LABEL_END,
-};
-
-static struct label rep_labels[] = {
- LABEL(REP_DELAY),
- LABEL(REP_PERIOD),
- LABEL_END,
-};
-
-static struct label snd_labels[] = {
- LABEL(SND_CLICK),
- LABEL(SND_BELL),
- LABEL(SND_TONE),
- LABEL_END,
-};
-
-#if 0
-static struct label id_labels[] = {
- LABEL(ID_BUS),
- LABEL(ID_VENDOR),
- LABEL(ID_PRODUCT),
- LABEL(ID_VERSION),
- LABEL_END,
-};
-
-static struct label bus_labels[] = {
- LABEL(BUS_PCI),
- LABEL(BUS_ISAPNP),
- LABEL(BUS_USB),
- LABEL(BUS_HIL),
- LABEL(BUS_BLUETOOTH),
- LABEL(BUS_VIRTUAL),
- LABEL(BUS_ISA),
- LABEL(BUS_I8042),
- LABEL(BUS_XTKBD),
- LABEL(BUS_RS232),
- LABEL(BUS_GAMEPORT),
- LABEL(BUS_PARPORT),
- LABEL(BUS_AMIGA),
- LABEL(BUS_ADB),
- LABEL(BUS_I2C),
- LABEL(BUS_HOST),
- LABEL(BUS_GSC),
- LABEL(BUS_ATARI),
- LABEL(BUS_SPI),
- LABEL_END,
-};
-#endif
-
-static struct label mt_tool_labels[] = {
- LABEL(MT_TOOL_FINGER),
- LABEL(MT_TOOL_PEN),
- LABEL(MT_TOOL_MAX),
- LABEL_END,
-};
-
-static struct label ff_status_labels[] = {
- LABEL(FF_STATUS_STOPPED),
- LABEL(FF_STATUS_PLAYING),
- LABEL(FF_STATUS_MAX),
- LABEL_END,
-};
-
-static struct label ff_labels[] = {
- LABEL(FF_RUMBLE),
- LABEL(FF_PERIODIC),
- LABEL(FF_CONSTANT),
- LABEL(FF_SPRING),
- LABEL(FF_FRICTION),
- LABEL(FF_DAMPER),
- LABEL(FF_INERTIA),
- LABEL(FF_RAMP),
- LABEL(FF_SQUARE),
- LABEL(FF_TRIANGLE),
- LABEL(FF_SINE),
- LABEL(FF_SAW_UP),
- LABEL(FF_SAW_DOWN),
- LABEL(FF_CUSTOM),
- LABEL(FF_GAIN),
- LABEL(FF_AUTOCENTER),
- LABEL_END,
-};
-
-static struct label key_value_labels[] = {
- { "UP", 0 },
- { "DOWN", 1 },
- { "REPEAT", 2 },
- LABEL_END,
-};
diff --git a/toolbox/getprop.c b/toolbox/getprop.c
deleted file mode 100644
index dcc0ea0..0000000
--- a/toolbox/getprop.c
+++ /dev/null
@@ -1,50 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <cutils/properties.h>
-
-#include "dynarray.h"
-
-static void record_prop(const char* key, const char* name, void* opaque)
-{
- strlist_t* list = opaque;
- char temp[PROP_VALUE_MAX + PROP_NAME_MAX + 16];
- snprintf(temp, sizeof temp, "[%s]: [%s]", key, name);
- strlist_append_dup(list, temp);
-}
-
-static void list_properties(void)
-{
- strlist_t list[1] = { STRLIST_INITIALIZER };
-
- /* Record properties in the string list */
- (void)property_list(record_prop, list);
-
- /* Sort everything */
- strlist_sort(list);
-
- /* print everything */
- STRLIST_FOREACH(list, str, printf("%s\n", str));
-
- /* voila */
- strlist_done(list);
-}
-
-int getprop_main(int argc, char *argv[])
-{
- if (argc == 1) {
- list_properties();
- } else {
- char value[PROPERTY_VALUE_MAX];
- char *default_value;
- if(argc > 2) {
- default_value = argv[2];
- } else {
- default_value = "";
- }
-
- property_get(argv[1], value, default_value);
- printf("%s\n", value);
- }
- return 0;
-}
diff --git a/toolbox/getsebool.c b/toolbox/getsebool.c
deleted file mode 100644
index aab5200..0000000
--- a/toolbox/getsebool.c
+++ /dev/null
@@ -1,104 +0,0 @@
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <getopt.h>
-#include <errno.h>
-#include <string.h>
-#include <selinux/selinux.h>
-
-static void usage(const char *progname)
-{
- fprintf(stderr, "usage: %s -a or %s boolean...\n", progname, progname);
- exit(1);
-}
-
-int getsebool_main(int argc, char **argv)
-{
- int i, get_all = 0, rc = 0, active, pending, len = 0, opt;
- char **names;
-
- while ((opt = getopt(argc, argv, "a")) > 0) {
- switch (opt) {
- case 'a':
- if (argc > 2)
- usage(argv[0]);
- if (is_selinux_enabled() <= 0) {
- fprintf(stderr, "%s: SELinux is disabled\n",
- argv[0]);
- return 1;
- }
- errno = 0;
- rc = security_get_boolean_names(&names, &len);
- if (rc) {
- fprintf(stderr,
- "%s: Unable to get boolean names: %s\n",
- argv[0], strerror(errno));
- return 1;
- }
- if (!len) {
- printf("No booleans\n");
- return 0;
- }
- get_all = 1;
- break;
- default:
- usage(argv[0]);
- }
- }
-
- if (is_selinux_enabled() <= 0) {
- fprintf(stderr, "%s: SELinux is disabled\n", argv[0]);
- return 1;
- }
- if (!len) {
- if (argc < 2)
- usage(argv[0]);
- len = argc - 1;
- names = malloc(sizeof(char *) * len);
- if (!names) {
- fprintf(stderr, "%s: out of memory\n", argv[0]);
- return 2;
- }
- for (i = 0; i < len; i++) {
- names[i] = strdup(argv[i + 1]);
- if (!names[i]) {
- fprintf(stderr, "%s: out of memory\n",
- argv[0]);
- return 2;
- }
- }
- }
-
- for (i = 0; i < len; i++) {
- active = security_get_boolean_active(names[i]);
- if (active < 0) {
- if (get_all && errno == EACCES)
- continue;
- fprintf(stderr, "Error getting active value for %s\n",
- names[i]);
- rc = -1;
- goto out;
- }
- pending = security_get_boolean_pending(names[i]);
- if (pending < 0) {
- fprintf(stderr, "Error getting pending value for %s\n",
- names[i]);
- rc = -1;
- goto out;
- }
- if (pending != active) {
- printf("%s --> %s pending: %s\n", names[i],
- (active ? "on" : "off"),
- (pending ? "on" : "off"));
- } else {
- printf("%s --> %s\n", names[i],
- (active ? "on" : "off"));
- }
- }
-
-out:
- for (i = 0; i < len; i++)
- free(names[i]);
- free(names);
- return rc;
-}
diff --git a/toolbox/hd.c b/toolbox/hd.c
deleted file mode 100644
index 7c9998e..0000000
--- a/toolbox/hd.c
+++ /dev/null
@@ -1,97 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-
-int hd_main(int argc, char *argv[])
-{
- int c;
- int fd;
- unsigned char buf[4096];
- int res;
- int read_len;
- int i;
- int filepos = 0;
- int sum;
- int lsum;
-
- int base = -1;
- int count = 0;
- int repeat = 0;
-
- do {
- c = getopt(argc, argv, "b:c:r:");
- if (c == EOF)
- break;
- switch (c) {
- case 'b':
- base = strtol(optarg, NULL, 0);
- break;
- case 'c':
- count = strtol(optarg, NULL, 0);
- break;
- case 'r':
- repeat = strtol(optarg, NULL, 0);
- break;
- case '?':
- fprintf(stderr, "%s: invalid option -%c\n",
- argv[0], optopt);
- exit(1);
- }
- } while (1);
-
- if (optind + 1 != argc) {
- fprintf(stderr, "Usage: %s [-b base] [-c count] [-r delay] file\n", argv[0]);
- exit(1);
- }
-
- fd = open(argv[optind], O_RDONLY);
- if(fd < 0) {
- fprintf(stderr, "could not open %s, %s\n", argv[optind], strerror(errno));
- return 1;
- }
-
- do {
- if(base >= 0) {
- lseek(fd, base, SEEK_SET);
- filepos = base;
- }
- sum = 0;
- lsum = 0;
- while(1) {
- read_len = sizeof(buf);
- if(count > 0 && base + count - filepos < read_len)
- read_len = base + count - filepos;
- res = read(fd, &buf, read_len);
- if(res == 0)
- break;
- for(i = 0; i < res; i++) {
- if((i & 15) == 0) {
- printf("%08x: ", filepos + i);
- }
- lsum += buf[i];
- sum += buf[i];
- printf("%02x ", buf[i]);
- if(((i & 15) == 15) || (i == res - 1)) {
- printf("s %x\n", lsum);
- lsum = 0;
- }
- }
- if(res < 0) {
- printf("Read error on %s, offset %d len %d, %s\n", argv[optind], filepos, read_len, strerror(errno));
- return 1;
- }
- filepos += res;
- if(filepos == base + count)
- break;
- }
- printf("sum %x\n", sum);
- if(repeat)
- sleep(repeat);
- } while(repeat);
- return 0;
-}
diff --git a/toolbox/id.c b/toolbox/id.c
deleted file mode 100644
index 8ec79c1..0000000
--- a/toolbox/id.c
+++ /dev/null
@@ -1,57 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <pwd.h>
-#include <grp.h>
-#include <selinux/selinux.h>
-
-static void print_uid(uid_t uid)
-{
- struct passwd *pw = getpwuid(uid);
-
- if (pw) {
- printf("%d(%s)", uid, pw->pw_name);
- } else {
- printf("%d",uid);
- }
-}
-
-static void print_gid(gid_t gid)
-{
- struct group *gr = getgrgid(gid);
- if (gr) {
- printf("%d(%s)", gid, gr->gr_name);
- } else {
- printf("%d",gid);
- }
-}
-
-int id_main(int argc, char **argv)
-{
- gid_t list[64];
- int n, max;
- char *secctx;
-
- max = getgroups(64, list);
- if (max < 0) max = 0;
-
- printf("uid=");
- print_uid(getuid());
- printf(" gid=");
- print_gid(getgid());
- if (max) {
- printf(" groups=");
- print_gid(list[0]);
- for(n = 1; n < max; n++) {
- printf(",");
- print_gid(list[n]);
- }
- }
- if (getcon(&secctx) == 0) {
- printf(" context=%s", secctx);
- free(secctx);
- }
- printf("\n");
- return 0;
-}
diff --git a/toolbox/ifconfig.c b/toolbox/ifconfig.c
deleted file mode 100644
index b953176..0000000
--- a/toolbox/ifconfig.c
+++ /dev/null
@@ -1,157 +0,0 @@
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <errno.h>
-#include <string.h>
-#include <ctype.h>
-
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <linux/if.h>
-#include <linux/sockios.h>
-#include <arpa/inet.h>
-
-static void die(const char *s)
-{
- fprintf(stderr,"error: %s (%s)\n", s, strerror(errno));
- exit(-1);
-}
-
-static void setflags(int s, struct ifreq *ifr, int set, int clr)
-{
- if(ioctl(s, SIOCGIFFLAGS, ifr) < 0) die("SIOCGIFFLAGS");
- ifr->ifr_flags = (ifr->ifr_flags & (~clr)) | set;
- if(ioctl(s, SIOCSIFFLAGS, ifr) < 0) die("SIOCSIFFLAGS");
-}
-
-static inline void init_sockaddr_in(struct sockaddr_in *sin, const char *addr)
-{
- sin->sin_family = AF_INET;
- sin->sin_port = 0;
- sin->sin_addr.s_addr = inet_addr(addr);
-}
-
-static void setmtu(int s, struct ifreq *ifr, const char *mtu)
-{
- int m = atoi(mtu);
- ifr->ifr_mtu = m;
- if(ioctl(s, SIOCSIFMTU, ifr) < 0) die("SIOCSIFMTU");
-}
-static void setdstaddr(int s, struct ifreq *ifr, const char *addr)
-{
- init_sockaddr_in((struct sockaddr_in *) &ifr->ifr_dstaddr, addr);
- if(ioctl(s, SIOCSIFDSTADDR, ifr) < 0) die("SIOCSIFDSTADDR");
-}
-
-static void setnetmask(int s, struct ifreq *ifr, const char *addr)
-{
- init_sockaddr_in((struct sockaddr_in *) &ifr->ifr_netmask, addr);
- if(ioctl(s, SIOCSIFNETMASK, ifr) < 0) die("SIOCSIFNETMASK");
-}
-
-static void setaddr(int s, struct ifreq *ifr, const char *addr)
-{
- init_sockaddr_in((struct sockaddr_in *) &ifr->ifr_addr, addr);
- if(ioctl(s, SIOCSIFADDR, ifr) < 0) die("SIOCSIFADDR");
-}
-
-int ifconfig_main(int argc, char *argv[])
-{
- struct ifreq ifr;
- int s;
- unsigned int flags;
- char astring[20];
- char mstring[20];
- char *updown, *brdcst, *loopbk, *ppp, *running, *multi;
-
- argc--;
- argv++;
-
- if(argc == 0) return 0;
-
- memset(&ifr, 0, sizeof(struct ifreq));
- strncpy(ifr.ifr_name, argv[0], IFNAMSIZ);
- ifr.ifr_name[IFNAMSIZ-1] = 0;
- argc--, argv++;
-
- if((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- die("cannot open control socket\n");
- }
-
- if (argc == 0) {
- if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
- perror(ifr.ifr_name);
- return -1;
- } else
- strlcpy(astring,
- inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr),
- sizeof(astring));
-
- if (ioctl(s, SIOCGIFNETMASK, &ifr) < 0) {
- perror(ifr.ifr_name);
- return -1;
- } else
- strlcpy(mstring,
- inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr),
- sizeof(mstring));
-
- if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0) {
- perror(ifr.ifr_name);
- return -1;
- } else
- flags = ifr.ifr_flags;
-
- printf("%s: ip %s mask %s flags [", ifr.ifr_name,
- astring,
- mstring
- );
-
- updown = (flags & IFF_UP) ? "up" : "down";
- brdcst = (flags & IFF_BROADCAST) ? " broadcast" : "";
- loopbk = (flags & IFF_LOOPBACK) ? " loopback" : "";
- ppp = (flags & IFF_POINTOPOINT) ? " point-to-point" : "";
- running = (flags & IFF_RUNNING) ? " running" : "";
- multi = (flags & IFF_MULTICAST) ? " multicast" : "";
- printf("%s%s%s%s%s%s]\n", updown, brdcst, loopbk, ppp, running, multi);
- return 0;
- }
-
- while(argc > 0) {
- if (!strcmp(argv[0], "up")) {
- setflags(s, &ifr, IFF_UP, 0);
- } else if (!strcmp(argv[0], "mtu")) {
- argc--, argv++;
- if (!argc) {
- errno = EINVAL;
- die("expecting a value for parameter \"mtu\"");
- }
- setmtu(s, &ifr, argv[0]);
- } else if (!strcmp(argv[0], "-pointopoint")) {
- setflags(s, &ifr, IFF_POINTOPOINT, 1);
- } else if (!strcmp(argv[0], "pointopoint")) {
- argc--, argv++;
- if (!argc) {
- errno = EINVAL;
- die("expecting an IP address for parameter \"pointtopoint\"");
- }
- setdstaddr(s, &ifr, argv[0]);
- setflags(s, &ifr, IFF_POINTOPOINT, 0);
- } else if (!strcmp(argv[0], "down")) {
- setflags(s, &ifr, 0, IFF_UP);
- } else if (!strcmp(argv[0], "netmask")) {
- argc--, argv++;
- if (!argc) {
- errno = EINVAL;
- die("expecting an IP address for parameter \"netmask\"");
- }
- setnetmask(s, &ifr, argv[0]);
- } else if (isdigit(argv[0][0])) {
- setaddr(s, &ifr, argv[0]);
- setflags(s, &ifr, IFF_UP, 0);
- }
- argc--, argv++;
- }
- return 0;
-}
diff --git a/toolbox/insmod.c b/toolbox/insmod.c
deleted file mode 100644
index d252433..0000000
--- a/toolbox/insmod.c
+++ /dev/null
@@ -1,97 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <malloc.h>
-#include <errno.h>
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-extern int init_module(void *, unsigned long, const char *);
-
-static void *read_file(const char *filename, ssize_t *_size)
-{
- int ret, fd;
- struct stat sb;
- ssize_t size;
- void *buffer = NULL;
-
- /* open the file */
- fd = open(filename, O_RDONLY);
- if (fd < 0)
- return NULL;
-
- /* find out how big it is */
- if (fstat(fd, &sb) < 0)
- goto bail;
- size = sb.st_size;
-
- /* allocate memory for it to be read into */
- buffer = malloc(size);
- if (!buffer)
- goto bail;
-
- /* slurp it into our buffer */
- ret = read(fd, buffer, size);
- if (ret != size)
- goto bail;
-
- /* let the caller know how big it is */
- *_size = size;
-
-bail:
- close(fd);
- return buffer;
-}
-
-int insmod_main(int argc, char **argv)
-{
- void *file;
- ssize_t size = 0;
- char opts[1024];
- int ret;
-
- /* make sure we've got an argument */
- if (argc < 2) {
- fprintf(stderr, "usage: insmod <module.o>\n");
- return -1;
- }
-
- /* read the file into memory */
- file = read_file(argv[1], &size);
- if (!file) {
- fprintf(stderr, "insmod: can't open '%s'\n", argv[1]);
- return -1;
- }
-
- opts[0] = '\0';
- if (argc > 2) {
- int i, len;
- char *end = opts + sizeof(opts) - 1;
- char *ptr = opts;
-
- for (i = 2; (i < argc) && (ptr < end); i++) {
- len = MIN(strlen(argv[i]), (size_t)(end - ptr));
- memcpy(ptr, argv[i], len);
- ptr += len;
- *ptr++ = ' ';
- }
- *(ptr - 1) = '\0';
- }
-
- /* pass it to the kernel */
- ret = init_module(file, size, opts);
- if (ret != 0) {
- fprintf(stderr,
- "insmod: init_module '%s' failed (%s)\n",
- argv[1], strerror(errno));
- }
-
- /* free the file buffer */
- free(file);
-
- return ret;
-}
-
diff --git a/toolbox/ioctl.c b/toolbox/ioctl.c
index fd90812..093e467 100644
--- a/toolbox/ioctl.c
+++ b/toolbox/ioctl.c
@@ -1,35 +1,81 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
+/*
+ * Copyright (c) 2008, The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google, Inc. nor the names of its contributors
+ * may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <error.h>
#include <fcntl.h>
#include <getopt.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
#include <string.h>
-#include <linux/kd.h>
-#include <linux/vt.h>
-#include <errno.h>
-#include <pthread.h>
#include <sys/ioctl.h>
+#include <unistd.h>
-int ioctl_main(int argc, char *argv[])
-{
- int c;
- int fd;
- int res;
+static void usage() {
+ fprintf(stderr, "%s [-l <length>] [-a <argsize>] [-rdh] <device> <ioctlnr>\n"
+ " -l <length> Length of io buffer\n"
+ " -a <argsize> Size of each argument (1-8)\n"
+ " -r Open device in read only mode\n"
+ " -d Direct argument (no iobuffer)\n"
+ " -h Print help\n", getprogname());
+ exit(1);
+}
+
+static int xstrtoi(const char* s, const char* what) {
+ char* endp;
+ errno = 0;
+ long result = strtol(s, &endp, 0);
+ if (errno != 0 || *endp != '\0') {
+ error(1, errno, "couldn't parse %s '%s'", what, s);
+ }
+ if (result > INT_MAX || result < INT_MIN) {
+ error(1, errno, "%s '%s' out of range", what, s);
+ }
+ return result;
+}
+int ioctl_main(int argc, char* argv[]) {
int read_only = 0;
int length = -1;
int arg_size = 4;
int direct_arg = 0;
- uint32_t ioctl_nr;
+
void *ioctl_args = NULL;
uint8_t *ioctl_argp;
uint8_t *ioctl_argp_save = NULL;
int rem;
- do {
- c = getopt(argc, argv, "rdl:a:h");
- if (c == EOF)
- break;
+ int c;
+ while ((c = getopt(argc, argv, "rdl:a:h")) != -1) {
switch (c) {
case 'r':
read_only = 1;
@@ -38,43 +84,44 @@ int ioctl_main(int argc, char *argv[])
direct_arg = 1;
break;
case 'l':
- length = strtol(optarg, NULL, 0);
+ length = xstrtoi(optarg, "length");
break;
case 'a':
- arg_size = strtol(optarg, NULL, 0);
+ arg_size = xstrtoi(optarg, "argument size");
break;
case 'h':
- fprintf(stderr, "%s [-l <length>] [-a <argsize>] [-rdh] <device> <ioctlnr>\n"
- " -l <lenght> Length of io buffer\n"
- " -a <argsize> Size of each argument (1-8)\n"
- " -r Open device in read only mode\n"
- " -d Direct argument (no iobuffer)\n"
- " -h Print help\n", argv[0]);
- return -1;
- case '?':
- fprintf(stderr, "%s: invalid option -%c\n",
- argv[0], optopt);
- exit(1);
+ usage();
+ break;
+ default:
+ error(1, 0, "invalid option -%c", optopt);
}
- } while (1);
+ }
- if(optind + 2 > argc) {
- fprintf(stderr, "%s: too few arguments\n", argv[0]);
- exit(1);
+ if (optind + 2 > argc) {
+ usage();
}
- if (!strcmp(argv[optind], "-")) {
+ const char* device = argv[optind];
+ int fd;
+ if (strcmp(device, "-") == 0) {
fd = STDIN_FILENO;
} else {
- fd = open(argv[optind], read_only ? O_RDONLY : (O_RDWR | O_SYNC));
- if (fd < 0) {
- fprintf(stderr, "cannot open %s\n", argv[optind]);
- return 1;
+ fd = open(device, read_only ? O_RDONLY : (O_RDWR | O_SYNC));
+ if (fd == -1) {
+ error(1, errno, "cannot open %s", argv[optind]);
}
}
optind++;
-
- ioctl_nr = strtol(argv[optind], NULL, 0);
+
+ // IOCTL(2) wants second parameter as a signed int.
+ // Let's let the user specify either negative numbers or large positive
+ // numbers, for the case where ioctl number is larger than INT_MAX.
+ errno = 0;
+ char* endp;
+ int ioctl_nr = UINT_MAX & strtoll(argv[optind], &endp, 0);
+ if (errno != 0 || *endp != '\0') {
+ error(1, errno, "couldn't parse ioctl number '%s'", argv[optind]);
+ }
optind++;
if(direct_arg) {
@@ -90,11 +137,10 @@ int ioctl_main(int argc, char *argv[])
ioctl_argp_save = ioctl_argp = ioctl_args;
rem = length;
- while(optind < argc) {
+ while (optind < argc) {
uint64_t tmp = strtoull(argv[optind], NULL, 0);
- if(rem < arg_size) {
- fprintf(stderr, "%s: too many arguments\n", argv[0]);
- exit(1);
+ if (rem < arg_size) {
+ error(1, 0, "too many arguments");
}
memcpy(ioctl_argp, &tmp, arg_size);
ioctl_argp += arg_size;
@@ -107,8 +153,9 @@ int ioctl_main(int argc, char *argv[])
while(rem--) {
printf(" 0x%02x", *ioctl_argp_save++);
}
- printf("\n");
+ printf(" to %s\n", device);
+ int res;
if(direct_arg)
res = ioctl(fd, ioctl_nr, *(uint32_t*)ioctl_args);
else if(length)
@@ -117,10 +164,10 @@ int ioctl_main(int argc, char *argv[])
res = ioctl(fd, ioctl_nr, 0);
if (res < 0) {
free(ioctl_args);
- fprintf(stderr, "ioctl 0x%x failed, %d\n", ioctl_nr, res);
- return 1;
+ error(1, errno, "ioctl 0x%x failed (returned %d)", ioctl_nr, res);
}
- if(length) {
+
+ if (length) {
printf("return buf:");
ioctl_argp = ioctl_args;
rem = length;
@@ -130,5 +177,6 @@ int ioctl_main(int argc, char *argv[])
printf("\n");
}
free(ioctl_args);
+ close(fd);
return 0;
}
diff --git a/toolbox/ionice.c b/toolbox/ionice.c
index 4a182f2..7abc261 100644
--- a/toolbox/ionice.c
+++ b/toolbox/ionice.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <errno.h>
diff --git a/toolbox/load_policy.c b/toolbox/load_policy.c
deleted file mode 100644
index 90d48c4..0000000
--- a/toolbox/load_policy.c
+++ /dev/null
@@ -1,49 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <errno.h>
-#include <selinux/selinux.h>
-
-int load_policy_main(int argc, char **argv)
-{
- int fd, rc;
- struct stat sb;
- void *map;
- const char *path;
-
- if (argc != 2) {
- fprintf(stderr, "usage: %s policy-file\n", argv[0]);
- exit(1);
- }
-
- path = argv[1];
- fd = open(path, O_RDONLY);
- if (fd < 0) {
- fprintf(stderr, "Could not open %s: %s\n", path, strerror(errno));
- exit(2);
- }
-
- if (fstat(fd, &sb) < 0) {
- fprintf(stderr, "Could not stat %s: %s\n", path, strerror(errno));
- exit(3);
- }
-
- map = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- if (map == MAP_FAILED) {
- fprintf(stderr, "Could not mmap %s: %s\n", path, strerror(errno));
- exit(4);
- }
-
- rc = security_load_policy(map, sb.st_size);
- if (rc < 0) {
- fprintf(stderr, "Could not load %s: %s\n", path, strerror(errno));
- exit(5);
- }
- munmap(map, sb.st_size);
- close(fd);
- exit(0);
-}
diff --git a/toolbox/ls.c b/toolbox/ls.c
index 963fcb5..9a89dd4 100644
--- a/toolbox/ls.c
+++ b/toolbox/ls.c
@@ -1,23 +1,119 @@
+#include <dirent.h>
+#include <errno.h>
+#include <grp.h>
+#include <limits.h>
+#include <pwd.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
#include <sys/types.h>
-#include <dirent.h>
-#include <errno.h>
+#include <time.h>
+#include <unistd.h>
#include <selinux/selinux.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <time.h>
+// simple dynamic array of strings.
+typedef struct {
+ int count;
+ int capacity;
+ void** items;
+} strlist_t;
+
+#define STRLIST_INITIALIZER { 0, 0, NULL }
+
+/* Used to iterate over a strlist_t
+ * _list :: pointer to strlist_t object
+ * _item :: name of local variable name defined within the loop with
+ * type 'char*'
+ * _stmnt :: C statement executed in each iteration
+ *
+ * This macro is only intended for simple uses. Do not add or remove items
+ * to/from the list during iteration.
+ */
+#define STRLIST_FOREACH(_list,_item,_stmnt) \
+ do { \
+ int _nn_##__LINE__ = 0; \
+ for (;_nn_##__LINE__ < (_list)->count; ++ _nn_##__LINE__) { \
+ char* _item = (char*)(_list)->items[_nn_##__LINE__]; \
+ _stmnt; \
+ } \
+ } while (0)
+
+static void dynarray_reserve_more( strlist_t *a, int count ) {
+ int old_cap = a->capacity;
+ int new_cap = old_cap;
+ const int max_cap = INT_MAX/sizeof(void*);
+ void** new_items;
+ int new_count = a->count + count;
+
+ if (count <= 0)
+ return;
+
+ if (count > max_cap - a->count)
+ abort();
+
+ new_count = a->count + count;
+
+ while (new_cap < new_count) {
+ old_cap = new_cap;
+ new_cap += (new_cap >> 2) + 4;
+ if (new_cap < old_cap || new_cap > max_cap) {
+ new_cap = max_cap;
+ }
+ }
+ new_items = realloc(a->items, new_cap*sizeof(void*));
+ if (new_items == NULL)
+ abort();
-#include <pwd.h>
-#include <grp.h>
+ a->items = new_items;
+ a->capacity = new_cap;
+}
-#include <linux/kdev_t.h>
-#include <limits.h>
+void strlist_init( strlist_t *list ) {
+ list->count = list->capacity = 0;
+ list->items = NULL;
+}
+
+// append a new string made of the first 'slen' characters from 'str'
+// followed by a trailing zero.
+void strlist_append_b( strlist_t *list, const void* str, size_t slen ) {
+ char *copy = malloc(slen+1);
+ memcpy(copy, str, slen);
+ copy[slen] = '\0';
+ if (list->count >= list->capacity)
+ dynarray_reserve_more(list, 1);
+ list->items[list->count++] = copy;
+}
+
+// append the copy of a given input string to a strlist_t.
+void strlist_append_dup( strlist_t *list, const char *str) {
+ strlist_append_b(list, str, strlen(str));
+}
+
+// note: strlist_done will free all the strings owned by the list.
+void strlist_done( strlist_t *list ) {
+ STRLIST_FOREACH(list, string, free(string));
+ free(list->items);
+ list->items = NULL;
+ list->count = list->capacity = 0;
+}
+
+static int strlist_compare_strings(const void* a, const void* b) {
+ const char *sa = *(const char **)a;
+ const char *sb = *(const char **)b;
+ return strcmp(sa, sb);
+}
+
+/* sort the strings in a given list (using strcmp) */
+void strlist_sort( strlist_t *list ) {
+ if (list->count > 0) {
+ qsort(list->items, (size_t)list->count, sizeof(void*), strlist_compare_strings);
+ }
+}
-#include "dynarray.h"
// bits for flags argument
#define LIST_LONG (1 << 0)
@@ -200,7 +296,7 @@ static int listfile_long(const char *path, struct stat *s, int flags)
case S_IFCHR:
printf("%s %-8s %-8s %3d, %3d %s %s\n",
mode, user, group,
- (int) MAJOR(s->st_rdev), (int) MINOR(s->st_rdev),
+ major(s->st_rdev), minor(s->st_rdev),
date, name);
break;
case S_IFREG:
diff --git a/toolbox/lsmod.c b/toolbox/lsmod.c
deleted file mode 100644
index 8b55ee6..0000000
--- a/toolbox/lsmod.c
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <stdio.h>
-
-extern int cat_main(int argc, char **argv);
-
-int lsmod_main(int argc, char **argv)
-{
- char *cat_argv[] = { "cat", "/proc/modules", NULL };
- return cat_main(2, cat_argv);
-}
-
diff --git a/toolbox/lsof.c b/toolbox/lsof.c
index bee981d..982f5aa 100644
--- a/toolbox/lsof.c
+++ b/toolbox/lsof.c
@@ -35,6 +35,7 @@
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <pwd.h>
diff --git a/toolbox/lsusb.c b/toolbox/lsusb.c
deleted file mode 100644
index 236e74b..0000000
--- a/toolbox/lsusb.c
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <endian.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-
-#include <usbhost/usbhost.h>
-
-static int verbose = 0;
-static char str_buff[4096];
-
-static const char *get_str(struct usb_device *dev, int id)
-{
- char *str = usb_device_get_string(dev, id);
-
- if (id && str) {
- strlcpy(str_buff, str, sizeof(str_buff));
- free(str);
- } else {
- snprintf(str_buff, sizeof(str_buff), "%02x", id);
- }
-
- return str_buff;
-}
-
-
-static void lsusb_parse_device_descriptor(struct usb_device *dev,
- struct usb_device_descriptor *desc)
-{
- printf(" Device Descriptor\n");
- printf("\tbcdUSB: %04x\n", letoh16(desc->bcdUSB));
- printf("\tbDeviceClass: %02x\n", desc->bDeviceClass);
- printf("\tbDeviceSubClass: %02x\n", desc->bDeviceSubClass);
- printf("\tbDeviceProtocol: %02x\n", desc->bDeviceProtocol);
- printf("\tbMaxPacketSize0: %02x\n", desc->bMaxPacketSize0);
- printf("\tidVendor: %04x\n", letoh16(desc->idVendor));
- printf("\tidProduct: %04x\n", letoh16(desc->idProduct));
- printf("\tbcdDevice: %04x\n", letoh16(desc->bcdDevice));
- printf("\tiManufacturer: %s\n", get_str(dev, desc->iManufacturer));
- printf("\tiProduct: %s\n", get_str(dev, desc->iProduct));
- printf("\tiSerialNumber: %s\n", get_str(dev,desc->iSerialNumber));
- printf("\tbNumConfiguration: %02x\n", desc->bNumConfigurations);
- printf("\n");
-}
-
-static void lsusb_parse_config_descriptor(struct usb_device *dev,
- struct usb_config_descriptor *desc)
-{
- printf(" Config Descriptor\n");
- printf("\twTotalLength: %04x\n", letoh16(desc->wTotalLength));
- printf("\tbNumInterfaces: %02x\n", desc->bNumInterfaces);
- printf("\tbConfigurationValue: %02x\n", desc->bConfigurationValue);
- printf("\tiConfiguration: %s\n", get_str(dev, desc->iConfiguration));
- printf("\tbmAttributes: %02x\n", desc->bmAttributes);
- printf("\tbMaxPower: %d mA\n", desc->bMaxPower * 2);
- printf("\n");
-}
-
-static void lsusb_parse_interface_descriptor(struct usb_device *dev,
- struct usb_interface_descriptor *desc)
-{
- printf(" Interface Descriptor\n");
- printf("\tbInterfaceNumber: %02x\n", desc->bInterfaceNumber);
- printf("\tbAlternateSetting: %02x\n", desc->bAlternateSetting);
- printf("\tbNumEndpoints: %02x\n", desc->bNumEndpoints);
- printf("\tbInterfaceClass: %02x\n", desc->bInterfaceClass);
- printf("\tbInterfaceSubClass: %02x\n", desc->bInterfaceSubClass);
- printf("\tbInterfaceProtocol: %02x\n", desc->bInterfaceProtocol);
- printf("\tiInterface: %s\n", get_str(dev, desc->iInterface));
- printf("\n");
-}
-
-static void lsusb_parse_endpoint_descriptor(struct usb_device *dev,
- struct usb_endpoint_descriptor *desc)
-{
- printf(" Endpoint Descriptor\n");
- printf("\tbEndpointAddress: %02x\n", desc->bEndpointAddress);
- printf("\tbmAttributes: %02x\n", desc->bmAttributes);
- printf("\twMaxPacketSize: %02x\n", letoh16(desc->wMaxPacketSize));
- printf("\tbInterval: %02x\n", desc->bInterval);
- printf("\tbRefresh: %02x\n", desc->bRefresh);
- printf("\tbSynchAddress: %02x\n", desc->bSynchAddress);
- printf("\n");
-}
-
-static void lsusb_dump_descriptor(struct usb_device *dev,
- struct usb_descriptor_header *desc)
-{
- int i;
- printf(" Descriptor type %02x\n", desc->bDescriptorType);
-
- for (i = 0; i < desc->bLength; i++ ) {
- if ((i % 16) == 0)
- printf("\t%02x:", i);
- printf(" %02x", ((uint8_t *)desc)[i]);
- if ((i % 16) == 15)
- printf("\n");
- }
-
- if ((i % 16) != 0)
- printf("\n");
- printf("\n");
-}
-
-static void lsusb_parse_descriptor(struct usb_device *dev,
- struct usb_descriptor_header *desc)
-{
- switch (desc->bDescriptorType) {
- case USB_DT_DEVICE:
- lsusb_parse_device_descriptor(dev, (struct usb_device_descriptor *) desc);
- break;
-
- case USB_DT_CONFIG:
- lsusb_parse_config_descriptor(dev, (struct usb_config_descriptor *) desc);
- break;
-
- case USB_DT_INTERFACE:
- lsusb_parse_interface_descriptor(dev, (struct usb_interface_descriptor *) desc);
- break;
-
- case USB_DT_ENDPOINT:
- lsusb_parse_endpoint_descriptor(dev, (struct usb_endpoint_descriptor *) desc);
- break;
-
- default:
- lsusb_dump_descriptor(dev, desc);
-
- break;
- }
-}
-
-static int lsusb_device_added(const char *dev_name, void *client_data)
-{
- struct usb_device *dev = usb_device_open(dev_name);
-
- if (!dev) {
- fprintf(stderr, "can't open device %s: %s\n", dev_name, strerror(errno));
- return 0;
- }
-
- if (verbose) {
- struct usb_descriptor_iter iter;
- struct usb_descriptor_header *desc;
-
- printf("%s:\n", dev_name);
-
- usb_descriptor_iter_init(dev, &iter);
-
- while ((desc = usb_descriptor_iter_next(&iter)) != NULL)
- lsusb_parse_descriptor(dev, desc);
-
- } else {
- uint16_t vid, pid;
- char *mfg_name, *product_name, *serial;
-
- vid = usb_device_get_vendor_id(dev);
- pid = usb_device_get_product_id(dev);
- mfg_name = usb_device_get_manufacturer_name(dev);
- product_name = usb_device_get_product_name(dev);
- serial = usb_device_get_serial(dev);
-
- printf("%s: %04x:%04x %s %s %s\n", dev_name, vid, pid,
- mfg_name, product_name, serial);
-
- free(mfg_name);
- free(product_name);
- free(serial);
- }
-
- usb_device_close(dev);
-
- return 0;
-}
-
-static int lsusb_device_removed(const char *dev_name, void *client_data)
-{
- return 0;
-}
-
-
-static int lsusb_discovery_done(void *client_data)
-{
- return 1;
-}
-
-
-
-int lsusb_main(int argc, char **argv)
-{
- struct usb_host_context *ctx;
-
- if (argc == 2 && !strcmp(argv[1], "-v"))
- verbose = 1;
-
- ctx = usb_host_init();
- if (!ctx) {
- perror("usb_host_init:");
- return 1;
- }
-
- usb_host_run(ctx,
- lsusb_device_added,
- lsusb_device_removed,
- lsusb_discovery_done,
- NULL);
-
- usb_host_cleanup(ctx);
-
- return 0;
-}
-
diff --git a/toolbox/md5.c b/toolbox/md5.c
deleted file mode 100644
index 5de4d9e..0000000
--- a/toolbox/md5.c
+++ /dev/null
@@ -1,71 +0,0 @@
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <openssl/md5.h>
-
-static int usage()
-{
- fprintf(stderr,"md5 file ...\n");
- return -1;
-}
-
-static int do_md5(const char *path)
-{
- unsigned int i;
- int fd;
- MD5_CTX md5_ctx;
- unsigned char md5[MD5_DIGEST_LENGTH];
-
- fd = open(path, O_RDONLY);
- if (fd < 0) {
- fprintf(stderr,"could not open %s, %s\n", path, strerror(errno));
- return -1;
- }
-
- MD5_Init(&md5_ctx);
-
- while (1) {
- char buf[4096];
- ssize_t rlen;
- rlen = read(fd, buf, sizeof(buf));
- if (rlen == 0)
- break;
- else if (rlen < 0) {
- (void)close(fd);
- fprintf(stderr,"could not read %s, %s\n", path, strerror(errno));
- return -1;
- }
- MD5_Update(&md5_ctx, buf, rlen);
- }
- if (close(fd)) {
- fprintf(stderr,"could not close %s, %s\n", path, strerror(errno));
- return -1;
- }
-
- MD5_Final(md5, &md5_ctx);
-
- for (i = 0; i < (int)sizeof(md5); i++)
- printf("%02x", md5[i]);
- printf(" %s\n", path);
-
- return 0;
-}
-
-int md5_main(int argc, char *argv[])
-{
- int i, ret = 0;
-
- if (argc < 2)
- return usage();
-
- /* loop over the file args */
- for (i = 1; i < argc; i++) {
- if (do_md5(argv[i]))
- ret = 1;
- }
-
- return ret;
-}
diff --git a/toolbox/mkdir.c b/toolbox/mkdir.c
deleted file mode 100644
index 398d350..0000000
--- a/toolbox/mkdir.c
+++ /dev/null
@@ -1,77 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/limits.h>
-#include <sys/stat.h>
-
-static int usage()
-{
- fprintf(stderr,"mkdir [OPTION] <target>\n");
- fprintf(stderr," --help display usage and exit\n");
- fprintf(stderr," -p, --parents create parent directories as needed\n");
- return -1;
-}
-
-int mkdir_main(int argc, char *argv[])
-{
- int ret;
- if(argc < 2 || strcmp(argv[1], "--help") == 0) {
- return usage();
- }
-
- int recursive = (strcmp(argv[1], "-p") == 0 ||
- strcmp(argv[1], "--parents") == 0) ? 1 : 0;
-
- if(recursive && argc < 3) {
- // -p specified without a path
- return usage();
- }
-
- if(recursive) {
- argc--;
- argv++;
- }
-
- char currpath[PATH_MAX], *pathpiece;
- struct stat st;
-
- while(argc > 1) {
- argc--;
- argv++;
- if(recursive) {
- // reset path
- strcpy(currpath, "");
- // create the pieces of the path along the way
- pathpiece = strtok(argv[0], "/");
- if(argv[0][0] == '/') {
- // prepend / if needed
- strcat(currpath, "/");
- }
- while(pathpiece != NULL) {
- if(strlen(currpath) + strlen(pathpiece) + 2/*NUL and slash*/ > PATH_MAX) {
- fprintf(stderr, "Invalid path specified: too long\n");
- return 1;
- }
- strcat(currpath, pathpiece);
- strcat(currpath, "/");
- if(stat(currpath, &st) != 0) {
- ret = mkdir(currpath, 0777);
- if(ret < 0) {
- fprintf(stderr, "mkdir failed for %s, %s\n", currpath, strerror(errno));
- return ret;
- }
- }
- pathpiece = strtok(NULL, "/");
- }
- } else {
- ret = mkdir(argv[0], 0777);
- if(ret < 0) {
- fprintf(stderr, "mkdir failed for %s, %s\n", argv[0], strerror(errno));
- return ret;
- }
- }
- }
-
- return 0;
-}
diff --git a/toolbox/mknod.c b/toolbox/mknod.c
deleted file mode 100644
index 0fedece..0000000
--- a/toolbox/mknod.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2014, The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-
-static int print_usage() {
- fprintf(stderr, "mknod <path> [b|c|u|p] <major> <minor>\n");
- return EXIT_FAILURE;
-}
-
-int mknod_main(int argc, char **argv) {
- char *path = NULL;
- int major = 0;
- int minor = 0;
- int args = 0;
- mode_t mode = 0660;
-
- /* Check correct argument count is 3 or 5 */
- if (argc != 3 && argc != 5) {
- fprintf(stderr, "Incorrect argument count\n");
- return print_usage();
- }
-
- path = argv[1];
-
- const char node_type = *argv[2];
- switch (node_type) {
- case 'b':
- mode |= S_IFBLK;
- args = 5;
- break;
- case 'c':
- case 'u':
- mode |= S_IFCHR;
- args = 5;
- break;
- case 'p':
- mode |= S_IFIFO;
- args = 3;
- break;
- default:
- fprintf(stderr, "Invalid node type '%c'\n", node_type);
- return print_usage();
- }
-
- if (argc != args) {
- if (args == 5) {
- fprintf(stderr, "Node type '%c' requires <major> and <minor>\n", node_type);
- } else {
- fprintf(stderr, "Node type '%c' does not require <major> and <minor>\n", node_type);
- }
- return print_usage();
- }
-
- if (args == 5) {
- major = atoi(argv[3]);
- minor = atoi(argv[4]);
- }
-
- if (mknod(path, mode, makedev(major, minor))) {
- perror("Unable to create node");
- return EXIT_FAILURE;
- }
- return 0;
-}
diff --git a/toolbox/mkswap.c b/toolbox/mkswap.c
deleted file mode 100644
index 0904152..0000000
--- a/toolbox/mkswap.c
+++ /dev/null
@@ -1,93 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/swap.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-/* XXX This needs to be obtained from kernel headers. See b/9336527 */
-struct linux_swap_header {
- char bootbits[1024]; /* Space for disklabel etc. */
- uint32_t version;
- uint32_t last_page;
- uint32_t nr_badpages;
- unsigned char sws_uuid[16];
- unsigned char sws_volume[16];
- uint32_t padding[117];
- uint32_t badpages[1];
-};
-
-#define MAGIC_SWAP_HEADER "SWAPSPACE2"
-#define MAGIC_SWAP_HEADER_LEN 10
-#define MIN_PAGES 10
-
-int mkswap_main(int argc, char **argv)
-{
- int err = 0;
- int fd;
- ssize_t len;
- off_t swap_size;
- int pagesize;
- struct linux_swap_header sw_hdr;
-
- if (argc != 2) {
- fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
- return -EINVAL;
- }
-
- fd = open(argv[1], O_WRONLY);
- if (fd < 0) {
- err = errno;
- fprintf(stderr, "Cannot open %s\n", argv[1]);
- return err;
- }
-
- pagesize = getpagesize();
- /* Determine the length of the swap file */
- swap_size = lseek(fd, 0, SEEK_END);
- if (swap_size < MIN_PAGES * pagesize) {
- fprintf(stderr, "Swap file needs to be at least %dkB\n",
- (MIN_PAGES * pagesize) >> 10);
- err = -ENOSPC;
- goto err;
- }
- if (lseek(fd, 0, SEEK_SET)) {
- err = errno;
- fprintf(stderr, "Can't seek to the beginning of the file\n");
- goto err;
- }
-
- memset(&sw_hdr, 0, sizeof(sw_hdr));
- sw_hdr.version = 1;
- sw_hdr.last_page = (swap_size / pagesize) - 1;
-
- len = write(fd, &sw_hdr, sizeof(sw_hdr));
- if (len != sizeof(sw_hdr)) {
- err = errno;
- fprintf(stderr, "Failed to write swap header into %s\n", argv[1]);
- goto err;
- }
-
- /* Write the magic header */
- if (lseek(fd, pagesize - MAGIC_SWAP_HEADER_LEN, SEEK_SET) < 0) {
- err = errno;
- fprintf(stderr, "Failed to seek into %s\n", argv[1]);
- goto err;
- }
-
- len = write(fd, MAGIC_SWAP_HEADER, MAGIC_SWAP_HEADER_LEN);
- if (len != MAGIC_SWAP_HEADER_LEN) {
- err = errno;
- fprintf(stderr, "Failed to write magic swap header into %s\n", argv[1]);
- goto err;
- }
-
- if (fsync(fd) < 0) {
- err = errno;
- fprintf(stderr, "Failed to sync %s\n", argv[1]);
- goto err;
- }
-err:
- close(fd);
- return err;
-}
diff --git a/toolbox/netstat.c b/toolbox/netstat.c
deleted file mode 100644
index 05dc640..0000000
--- a/toolbox/netstat.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright (c) 2008, The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <arpa/inet.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-
-typedef union iaddr iaddr;
-typedef union iaddr6 iaddr6;
-
-union iaddr {
- unsigned u;
- unsigned char b[4];
-};
-
-union iaddr6 {
- struct {
- unsigned a;
- unsigned b;
- unsigned c;
- unsigned d;
- } u;
- unsigned char b[16];
-};
-
-static const char *state2str(unsigned state)
-{
- switch(state){
- case 0x1: return "ESTABLISHED";
- case 0x2: return "SYN_SENT";
- case 0x3: return "SYN_RECV";
- case 0x4: return "FIN_WAIT1";
- case 0x5: return "FIN_WAIT2";
- case 0x6: return "TIME_WAIT";
- case 0x7: return "CLOSE";
- case 0x8: return "CLOSE_WAIT";
- case 0x9: return "LAST_ACK";
- case 0xA: return "LISTEN";
- case 0xB: return "CLOSING";
- default: return "UNKNOWN";
- }
-}
-
-/* addr + : + port + \0 */
-#define ADDR_LEN INET6_ADDRSTRLEN + 1 + 5 + 1
-
-static void addr2str(int af, const void *addr, unsigned port, char *buf)
-{
- if (inet_ntop(af, addr, buf, ADDR_LEN) == NULL) {
- *buf = '\0';
- return;
- }
- size_t len = strlen(buf);
- if (port) {
- snprintf(buf+len, ADDR_LEN-len, ":%d", port);
- } else {
- strncat(buf+len, ":*", ADDR_LEN-len-1);
- }
-}
-
-static void ipv4(const char *filename, const char *label) {
- FILE *fp = fopen(filename, "r");
- if (fp == NULL) {
- return;
- }
- char buf[BUFSIZ];
- fgets(buf, BUFSIZ, fp);
- while (fgets(buf, BUFSIZ, fp)){
- char lip[ADDR_LEN];
- char rip[ADDR_LEN];
- iaddr laddr, raddr;
- unsigned lport, rport, state, txq, rxq, num;
- int n = sscanf(buf, " %d: %x:%x %x:%x %x %x:%x",
- &num, &laddr.u, &lport, &raddr.u, &rport,
- &state, &txq, &rxq);
- if (n == 8) {
- addr2str(AF_INET, &laddr, lport, lip);
- addr2str(AF_INET, &raddr, rport, rip);
-
- printf("%4s %6d %6d %-22s %-22s %s\n",
- label, rxq, txq, lip, rip,
- state2str(state));
- }
- }
- fclose(fp);
-}
-
-static void ipv6(const char *filename, const char *label) {
- FILE *fp = fopen(filename, "r");
- if (fp == NULL) {
- return;
- }
- char buf[BUFSIZ];
- fgets(buf, BUFSIZ, fp);
- while (fgets(buf, BUFSIZ, fp)){
- char lip[ADDR_LEN];
- char rip[ADDR_LEN];
- iaddr6 laddr6, raddr6;
- unsigned lport, rport, state, txq, rxq, num;
- int n = sscanf(buf, " %d: %8x%8x%8x%8x:%x %8x%8x%8x%8x:%x %x %x:%x",
- &num, &laddr6.u.a, &laddr6.u.b, &laddr6.u.c, &laddr6.u.d, &lport,
- &raddr6.u.a, &raddr6.u.b, &raddr6.u.c, &raddr6.u.d, &rport,
- &state, &txq, &rxq);
- if (n == 14) {
- addr2str(AF_INET6, &laddr6, lport, lip);
- addr2str(AF_INET6, &raddr6, rport, rip);
-
- printf("%4s %6d %6d %-22s %-22s %s\n",
- label, rxq, txq, lip, rip,
- state2str(state));
- }
- }
- fclose(fp);
-}
-
-int netstat_main(int argc, char *argv[])
-{
- printf("Proto Recv-Q Send-Q Local Address Foreign Address State\n");
- ipv4("/proc/net/tcp", "tcp");
- ipv4("/proc/net/udp", "udp");
- ipv6("/proc/net/tcp6", "tcp6");
- ipv6("/proc/net/udp6", "udp6");
- return 0;
-}
diff --git a/toolbox/newfs_msdos.c b/toolbox/newfs_msdos.c
index 01517fd..5b98a01 100644
--- a/toolbox/newfs_msdos.c
+++ b/toolbox/newfs_msdos.c
@@ -798,6 +798,7 @@ static void getdiskinfo(int fd, const char *fname, const char *dtype,
__unused int oflag,struct bpb *bpb)
{
struct hd_geometry geom;
+ u_long block_size;
if (ioctl(fd, BLKSSZGET, &bpb->bps)) {
fprintf(stderr, "Error getting bytes / sector (%s)\n", strerror(errno));
@@ -806,11 +807,18 @@ static void getdiskinfo(int fd, const char *fname, const char *dtype,
ckgeom(fname, bpb->bps, "bytes/sector");
- if (ioctl(fd, BLKGETSIZE, &bpb->bsec)) {
+ if (ioctl(fd, BLKGETSIZE, &block_size)) {
fprintf(stderr, "Error getting blocksize (%s)\n", strerror(errno));
exit(1);
}
+ if (block_size > UINT32_MAX) {
+ fprintf(stderr, "Error blocksize too large: %lu\n", block_size);
+ exit(1);
+ }
+
+ bpb->bsec = (u_int)block_size;
+
if (ioctl(fd, HDIO_GETGEO, &geom)) {
fprintf(stderr, "Error getting gemoetry (%s) - trying sane values\n", strerror(errno));
geom.heads = 64;
diff --git a/toolbox/nohup.c b/toolbox/nohup.c
deleted file mode 100644
index 363999d..0000000
--- a/toolbox/nohup.c
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-int nohup_main(int argc, char *argv[])
-{
- if (argc < 2) {
- fprintf(stderr, "Usage: %s [-n] program args...\n", argv[0]);
- return EXIT_FAILURE;
- }
- signal(SIGHUP, SIG_IGN);
- argv++;
- if (strcmp(argv[0], "-n") == 0) {
- argv++;
- signal(SIGINT, SIG_IGN);
- signal(SIGSTOP, SIG_IGN);
- signal(SIGTTIN, SIG_IGN);
- signal(SIGTTOU, SIG_IGN);
- signal(SIGQUIT, SIG_IGN);
- signal(SIGTERM, SIG_IGN);
- }
- execvp(argv[0], argv);
- perror(argv[0]);
- return EXIT_FAILURE;
-}
diff --git a/toolbox/notify.c b/toolbox/notify.c
deleted file mode 100644
index c983ed5..0000000
--- a/toolbox/notify.c
+++ /dev/null
@@ -1,145 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/inotify.h>
-#include <errno.h>
-
-int notify_main(int argc, char *argv[])
-{
- int c;
- int nfd, ffd;
- int res;
- char event_buf[512];
- struct inotify_event *event;
- int event_mask = IN_ALL_EVENTS;
- int event_count = 1;
- int print_files = 0;
- int verbose = 2;
- int width = 80;
- char **file_names;
- int file_count;
- int id_offset = 0;
- int i;
- char *buf;
-
- do {
- c = getopt(argc, argv, "m:c:pv:w:");
- if (c == EOF)
- break;
- switch (c) {
- case 'm':
- event_mask = strtol(optarg, NULL, 0);
- break;
- case 'c':
- event_count = atoi(optarg);
- break;
- case 'p':
- print_files = 1;
- break;
- case 'v':
- verbose = atoi(optarg);
- break;
- case 'w':
- width = atoi(optarg);
- break;
- case '?':
- fprintf(stderr, "%s: invalid option -%c\n",
- argv[0], optopt);
- exit(1);
- }
- } while (1);
-
- if (argc <= optind) {
- fprintf(stderr, "Usage: %s [-m eventmask] [-c count] [-p] [-v verbosity] path [path ...]\n", argv[0]);
- return 1;
- }
-
- nfd = inotify_init();
- if(nfd < 0) {
- fprintf(stderr, "inotify_init failed, %s\n", strerror(errno));
- return 1;
- }
- file_names = argv + optind;
- file_count = argc - optind;
- for(i = 0; i < file_count; i++) {
- res = inotify_add_watch(nfd, file_names[i], event_mask);
- if(res < 0) {
- fprintf(stderr, "inotify_add_watch failed for %s, %s\n", file_names[i], strerror(errno));
- return 1;
- }
- if(i == 0)
- id_offset = -res;
- if(res + id_offset != i) {
- fprintf(stderr, "%s got unexpected id %d instead of %d\n", file_names[i], res, i);
- return 1;
- }
- }
-
- buf = malloc(width + 2);
-
- while(1) {
- int event_pos = 0;
- res = read(nfd, event_buf, sizeof(event_buf));
- if(res < (int)sizeof(*event)) {
- if(errno == EINTR)
- continue;
- fprintf(stderr, "could not get event, %s\n", strerror(errno));
- return 1;
- }
- //printf("got %d bytes of event information\n", res);
- while(res >= (int)sizeof(*event)) {
- int event_size;
- event = (struct inotify_event *)(event_buf + event_pos);
- if(verbose >= 2)
- printf("%s: %08x %08x \"%s\"\n", file_names[event->wd + id_offset], event->mask, event->cookie, event->len ? event->name : "");
- else if(verbose >= 2)
- printf("%s: %08x \"%s\"\n", file_names[event->wd + id_offset], event->mask, event->len ? event->name : "");
- else if(verbose >= 1)
- printf("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");
- if(print_files && (event->mask & IN_MODIFY)) {
- char filename[512];
- ssize_t read_len;
- char *display_name;
- int buflen;
- strcpy(filename, file_names[event->wd + id_offset]);
- if(event->len) {
- strcat(filename, "/");
- strcat(filename, event->name);
- }
- ffd = open(filename, O_RDONLY);
- display_name = (verbose >= 2 || event->len == 0) ? filename : event->name;
- buflen = width - strlen(display_name);
- read_len = read(ffd, buf, buflen);
- if(read_len > 0) {
- if(read_len < buflen && buf[read_len-1] != '\n') {
- buf[read_len] = '\n';
- read_len++;
- }
- if(read_len == buflen) {
- buf[--read_len] = '\0';
- buf[--read_len] = '\n';
- buf[--read_len] = '.';
- buf[--read_len] = '.';
- buf[--read_len] = '.';
- }
- else {
- buf[read_len] = '\0';
- }
- printf("%s: %s", display_name, buf);
- }
- close(ffd);
- }
- if(event_count && --event_count == 0)
- return 0;
- event_size = sizeof(*event) + event->len;
- res -= event_size;
- event_pos += event_size;
- }
- }
-
- return 0;
-}
diff --git a/toolbox/ps.c b/toolbox/ps.c
index 5458f6b..cf3f05a 100644
--- a/toolbox/ps.c
+++ b/toolbox/ps.c
@@ -1,15 +1,14 @@
-#include <stdio.h>
-#include <stdlib.h>
#include <ctype.h>
+#include <dirent.h>
#include <fcntl.h>
-
+#include <inttypes.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-
#include <sys/stat.h>
#include <sys/types.h>
-#include <dirent.h>
-
-#include <pwd.h>
+#include <unistd.h>
#include <cutils/sched_policy.h>
@@ -31,7 +30,14 @@ static char *nexttok(char **strp)
#define SHOW_NUMERIC_UID 32
#define SHOW_ABI 64
+#if __LP64__
+#define PC_WIDTH 10 /* Realistically, the top bits will be 0, so don't waste space. */
+#else
+#define PC_WIDTH (2*sizeof(uintptr_t))
+#endif
+
static int display_flags = 0;
+static int ppid_filter = 0;
static void print_exe_abi(int pid);
@@ -45,7 +51,8 @@ static int ps_line(int pid, int tid, char *namefilter)
int fd, r;
char *ptr, *name, *state;
int ppid;
- unsigned wchan, rss, vss, eip;
+ unsigned rss, vss;
+ uintptr_t eip;
unsigned utime, stime;
int prio, nice, rtprio, sched, psr;
struct passwd *pw;
@@ -125,7 +132,7 @@ static int ps_line(int pid, int tid, char *namefilter)
nexttok(&ptr); // blocked
nexttok(&ptr); // sigignore
nexttok(&ptr); // sigcatch
- wchan = strtoul(nexttok(&ptr), 0, 10); // wchan
+ nexttok(&ptr); // wchan
nexttok(&ptr); // nswap
nexttok(&ptr); // cnswap
nexttok(&ptr); // exit signal
@@ -147,7 +154,11 @@ static int ps_line(int pid, int tid, char *namefilter)
strcpy(user,pw->pw_name);
}
- if(!namefilter || !strncmp(name, namefilter, strlen(namefilter))) {
+ if(ppid_filter != 0 && ppid != ppid_filter) {
+ return 0;
+ }
+
+ if(!namefilter || !strncmp(cmdline[0] ? cmdline : name, namefilter, strlen(namefilter))) {
if (display_flags & SHOW_MACLABEL) {
fd = open(macline, O_RDONLY);
strcpy(macline, "-");
@@ -173,7 +184,16 @@ static int ps_line(int pid, int tid, char *namefilter)
else
printf(" %.2s ", get_sched_policy_name(p));
}
- printf(" %08x %08x %s ", wchan, eip, state);
+ char path[PATH_MAX];
+ snprintf(path, sizeof(path), "/proc/%d/wchan", pid);
+ char wchan[10];
+ int fd = open(path, O_RDONLY);
+ ssize_t wchan_len = read(fd, wchan, sizeof(wchan));
+ if (wchan_len == -1) {
+ wchan[wchan_len = 0] = '\0';
+ }
+ close(fd);
+ printf(" %10.*s %0*" PRIxPTR " %s ", (int) wchan_len, wchan, (int) PC_WIDTH, eip, state);
if (display_flags & SHOW_ABI) {
print_exe_abi(pid);
}
@@ -268,6 +288,10 @@ int ps_main(int argc, char **argv)
display_flags |= SHOW_CPU;
} else if(!strcmp(argv[1],"--abi")) {
display_flags |= SHOW_ABI;
+ } else if(!strcmp(argv[1],"--ppid")) {
+ ppid_filter = atoi(argv[2]);
+ argc--;
+ argv++;
} else if(isdigit(argv[1][0])){
pidfilter = atoi(argv[1]);
} else {
@@ -278,12 +302,13 @@ int ps_main(int argc, char **argv)
}
if (display_flags & SHOW_MACLABEL) {
- printf("LABEL USER PID PPID NAME\n");
+ printf("LABEL USER PID PPID NAME\n");
} else {
- printf("USER PID PPID VSIZE RSS %s%s %s WCHAN PC %sNAME\n",
+ printf("USER PID PPID VSIZE RSS %s%s %sWCHAN %*s %sNAME\n",
(display_flags&SHOW_CPU)?"CPU ":"",
(display_flags&SHOW_PRIO)?"PRIO NICE RTPRI SCHED ":"",
(display_flags&SHOW_POLICY)?"PCY " : "",
+ (int) PC_WIDTH, "PC",
(display_flags&SHOW_ABI)?"ABI " : "");
}
while((de = readdir(d)) != 0){
diff --git a/toolbox/pwcache.c b/toolbox/pwcache.c
deleted file mode 100644
index 9d81981..0000000
--- a/toolbox/pwcache.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2014, The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <grp.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <sys/types.h>
-
-int uid_from_user(const char* name, uid_t* uid) {
- struct passwd* pw = getpwnam(name);
- if (pw == NULL) {
- return -1;
- }
- *uid = pw->pw_uid;
- return 0;
-}
-
-char* group_from_gid(gid_t gid, int noname) {
- struct group* g = getgrgid(gid);
- if (g == NULL) {
- static char buf[32];
- snprintf(buf, sizeof(buf), "%lu", (long) gid);
- return noname ? NULL : buf;
- }
- return g->gr_name;
-}
-
-char* user_from_uid(uid_t uid, int noname) {
- struct passwd* pw = getpwuid(uid);
- if (pw == NULL) {
- static char buf[32];
- snprintf(buf, sizeof(buf), "%lu", (long) uid);
- return noname ? NULL : buf;
- }
- return pw->pw_name;
-}
diff --git a/toolbox/r.c b/toolbox/r.c
index 3b80db7..b96cdb2 100644
--- a/toolbox/r.c
+++ b/toolbox/r.c
@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
+#include <unistd.h>
#if __LP64__
#define strtoptr strtoull
@@ -18,7 +19,7 @@ static int usage()
return -1;
}
-int r_main(int argc, char *argv[])
+int main(int argc, char *argv[])
{
if(argc < 2) return usage();
diff --git a/toolbox/readlink.c b/toolbox/readlink.c
deleted file mode 100644
index d114e20..0000000
--- a/toolbox/readlink.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2013, The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-static int skip_newline, quiet_errors, canonicalize;
-
-static void usage(char* name) {
- fprintf(stderr, "Usage: %s [OPTION]... FILE\n", name);
-}
-
-int readlink_main(int argc, char* argv[]) {
- int c;
- while ((c = getopt(argc, argv, "nfqs")) != -1) {
- switch (c) {
- case 'n':
- skip_newline = 1;
- break;
- case 'f':
- canonicalize = 1;
- break;
- case 'q':
- case 's':
- quiet_errors = 1;
- break;
- case '?':
- default:
- usage(argv[0]);
- return EXIT_FAILURE;
- }
- }
- int index = optind;
- if (argc - index != 1) {
- usage(argv[0]);
- return EXIT_FAILURE;
- }
-
- char name[PATH_MAX+1];
- if (canonicalize) {
- if(!realpath(argv[optind], name)) {
- if (!quiet_errors) {
- perror("readlink");
- }
- return EXIT_FAILURE;
- }
- } else {
- ssize_t len = readlink(argv[1], name, PATH_MAX);
-
- if (len < 0) {
- if (!quiet_errors) {
- perror("readlink");
- }
- return EXIT_FAILURE;
- }
- name[len] = '\0';
- }
-
- fputs(name, stdout);
- if (!skip_newline) {
- fputs("\n", stdout);
- }
-
- return EXIT_SUCCESS;
-}
diff --git a/toolbox/readtty.c b/toolbox/readtty.c
deleted file mode 100644
index 2b27548..0000000
--- a/toolbox/readtty.c
+++ /dev/null
@@ -1,183 +0,0 @@
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-struct {
- char key;
- char *chars;
-} map[] = {
- { '1', "_ -1?!,.:;\"'<=>()_" },
- { '2', "Cabc2ABC" },
- { '3', "Fdef3DEF" },
- { '4', "Ighi4GHI" },
- { '5', "Ljkl5JKL" },
- { '6', "Omno6MNO" },
- { '7', "Spqrs7PQRS" },
- { '8', "Vtuv8TUV" },
- { '9', "Zwxyz9WXYZ" },
- { '0', "*+&0@/#*" },
-};
-
-char next_char(char key, char current)
-{
- int i;
- char *next;
- for(i = 0; i < sizeof(map) / sizeof(map[0]); i++) {
- if(key == map[i].key) {
- next = strchr(map[i].chars, current);
- if(next && next[1])
- return next[1];
- return map[i].chars[1];
- }
- }
- return key;
-}
-
-char prev_char(char key, char current)
-{
- int i;
- char *next;
- for(i = 0; i < sizeof(map) / sizeof(map[0]); i++) {
- if(key == map[i].key) {
- next = strchr(map[i].chars+1, current);
- if(next && next[-1])
- return next[-1];
- return map[i].chars[1];
- }
- }
- return key;
-}
-
-int readtty_main(int argc, char *argv[])
-{
- int c;
- //int flags;
- char buf[1];
- int res;
- struct termios ttyarg;
- struct termios savedttyarg;
- int nonblock = 0;
- int timeout = 0;
- int flush = 0;
- int phone = 0;
- char *accept = NULL;
- char *rejectstring = NULL;
- char last_char_in = 0;
- char current_char = 0;
- char *exit_string = NULL;
- int exit_match = 0;
-
- do {
- c = getopt(argc, argv, "nt:fa:r:pe:");
- if (c == EOF)
- break;
- switch (c) {
- case 't':
- timeout = atoi(optarg);
- break;
- case 'n':
- nonblock = 1;
- break;
- case 'f':
- flush = 1;
- break;
- case 'a':
- accept = optarg;
- break;
- case 'r':
- rejectstring = optarg;
- break;
- case 'p':
- phone = 1;
- break;
- case 'e':
- exit_string = optarg;
- break;
- case '?':
- fprintf(stderr, "%s: invalid option -%c\n",
- argv[0], optopt);
- exit(1);
- }
- } while (1);
-
- if(flush)
- tcflush(STDIN_FILENO, TCIFLUSH);
- ioctl(STDIN_FILENO, TCGETS , &savedttyarg) ; /* set changed tty arguments */
- ttyarg = savedttyarg;
- ttyarg.c_cc[VMIN] = (timeout > 0 || nonblock) ? 0 : 1; /* minimum of 0 chars */
- ttyarg.c_cc[VTIME] = timeout; /* wait max 15/10 sec */
- ttyarg.c_iflag = BRKINT | ICRNL;
- ttyarg.c_lflag &= ~(ECHO | ICANON);
- ioctl(STDIN_FILENO, TCSETS , &ttyarg);
-
- while (1) {
- res = read(STDIN_FILENO, buf, 1);
- if(res <= 0) {
- if(phone) {
- if(current_char) {
- write(STDERR_FILENO, &current_char, 1);
- write(STDOUT_FILENO, &current_char, 1);
- if(exit_string && current_char == exit_string[exit_match]) {
- exit_match++;
- if(exit_string[exit_match] == '\0')
- break;
- }
- else
- exit_match = 0;
- current_char = 0;
- }
- continue;
- }
- break;
- }
- if(accept && strchr(accept, buf[0]) == NULL) {
- if(rejectstring) {
- write(STDOUT_FILENO, rejectstring, strlen(rejectstring));
- break;
- }
- if(flush)
- tcflush(STDIN_FILENO, TCIFLUSH);
- continue;
- }
- if(phone) {
- //if(!isprint(buf[0])) {
- // fprintf(stderr, "got unprintable character 0x%x\n", buf[0]);
- //}
- if(buf[0] == '\0') {
- if(current_char) {
- current_char = prev_char(last_char_in, current_char);
- write(STDERR_FILENO, &current_char, 1);
- write(STDERR_FILENO, "\b", 1);
- }
- continue;
- }
- if(current_char && buf[0] != last_char_in) {
- write(STDERR_FILENO, &current_char, 1);
- write(STDOUT_FILENO, &current_char, 1);
- if(exit_string && current_char == exit_string[exit_match]) {
- exit_match++;
- if(exit_string[exit_match] == '\0')
- break;
- }
- else
- exit_match = 0;
- current_char = 0;
- }
- last_char_in = buf[0];
- current_char = next_char(last_char_in, current_char);
- write(STDERR_FILENO, &current_char, 1);
- write(STDERR_FILENO, "\b", 1);
- continue;
- }
- write(STDOUT_FILENO, buf, 1);
- break;
- }
- ioctl(STDIN_FILENO, TCSETS , &savedttyarg) ; /* set changed tty arguments */
-
- return 0;
-}
diff --git a/toolbox/renice.c b/toolbox/renice.c
index 9dfeb51..99a06f4 100644
--- a/toolbox/renice.c
+++ b/toolbox/renice.c
@@ -32,6 +32,7 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sched.h>
diff --git a/toolbox/restorecon.c b/toolbox/restorecon.c
deleted file mode 100644
index 3568625..0000000
--- a/toolbox/restorecon.c
+++ /dev/null
@@ -1,62 +0,0 @@
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <selinux/selinux.h>
-#include <selinux/android.h>
-
-static const char *progname;
-
-static void usage(void)
-{
- fprintf(stderr, "usage: %s [-DFnrRv] pathname...\n", progname);
- exit(1);
-}
-
-int restorecon_main(int argc, char **argv)
-{
- int ch, i, rc;
- unsigned int flags = 0;
-
- progname = argv[0];
-
- do {
- ch = getopt(argc, argv, "DFnrRv");
- if (ch == EOF)
- break;
- switch (ch) {
- case 'D':
- flags |= SELINUX_ANDROID_RESTORECON_DATADATA;
- break;
- case 'F':
- flags |= SELINUX_ANDROID_RESTORECON_FORCE;
- break;
- case 'n':
- flags |= SELINUX_ANDROID_RESTORECON_NOCHANGE;
- break;
- case 'r':
- case 'R':
- flags |= SELINUX_ANDROID_RESTORECON_RECURSE;
- break;
- case 'v':
- flags |= SELINUX_ANDROID_RESTORECON_VERBOSE;
- break;
- default:
- usage();
- }
- } while (1);
-
- argc -= optind;
- argv += optind;
- if (!argc)
- usage();
-
- for (i = 0; i < argc; i++) {
- rc = selinux_android_restorecon(argv[i], flags);
- if (rc < 0)
- fprintf(stderr, "Could not restorecon %s: %s\n", argv[i],
- strerror(errno));
- }
-
- return 0;
-}
diff --git a/toolbox/rmmod.c b/toolbox/rmmod.c
deleted file mode 100644
index c7e0d6a..0000000
--- a/toolbox/rmmod.c
+++ /dev/null
@@ -1,53 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <malloc.h>
-#include <errno.h>
-#include <asm/unistd.h>
-
-extern int delete_module(const char *, unsigned int);
-
-int rmmod_main(int argc, char **argv)
-{
- int ret, i;
- char *modname, *dot;
-
- /* make sure we've got an argument */
- if (argc < 2) {
- fprintf(stderr, "usage: rmmod <module>\n");
- return -1;
- }
-
- /* if given /foo/bar/blah.ko, make a weak attempt
- * to convert to "blah", just for convenience
- */
- modname = strrchr(argv[1], '/');
- if (!modname)
- modname = argv[1];
- else modname++;
-
- dot = strchr(argv[1], '.');
- if (dot)
- *dot = '\0';
-
- /* Replace "-" with "_". This would keep rmmod
- * compatible with module-init-tools version of
- * rmmod
- */
- for (i = 0; modname[i] != '\0'; i++) {
- if (modname[i] == '-')
- modname[i] = '_';
- }
-
- /* pass it to the kernel */
- ret = delete_module(modname, O_NONBLOCK | O_EXCL);
- if (ret != 0) {
- fprintf(stderr, "rmmod: delete_module '%s' failed (errno %d)\n",
- modname, errno);
- return -1;
- }
-
- return 0;
-}
-
diff --git a/toolbox/rotatefb.c b/toolbox/rotatefb.c
deleted file mode 100644
index 2ff4127..0000000
--- a/toolbox/rotatefb.c
+++ /dev/null
@@ -1,71 +0,0 @@
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-#include <errno.h>
-#include <linux/fb.h>
-
-
-int rotatefb_main(int argc, char *argv[])
-{
- int c;
- char *fbdev = "/dev/graphics/fb0";
- int rotation = 0;
- int fd;
- int res;
- struct fb_var_screeninfo fbinfo;
-
- do {
- c = getopt(argc, argv, "d:");
- if (c == EOF)
- break;
- switch (c) {
- case 'd':
- fbdev = optarg;
- break;
- case '?':
- fprintf(stderr, "%s: invalid option -%c\n",
- argv[0], optopt);
- exit(1);
- }
- } while (1);
-
- if(optind + 1 != argc) {
- fprintf(stderr, "%s: specify rotation\n", argv[0]);
- exit(1);
- }
- rotation = atoi(argv[optind]);
-
- fd = open(fbdev, O_RDWR);
- if(fd < 0) {
- fprintf(stderr, "cannot open %s\n", fbdev);
- return 1;
- }
-
- res = ioctl(fd, FBIOGET_VSCREENINFO, &fbinfo);
- if(res < 0) {
- fprintf(stderr, "failed to get fbinfo: %s\n", strerror(errno));
- return 1;
- }
- if((fbinfo.rotate ^ rotation) & 1) {
- unsigned int xres = fbinfo.yres;
- fbinfo.yres = fbinfo.xres;
- fbinfo.xres = xres;
- fbinfo.xres_virtual = fbinfo.xres;
- fbinfo.yres_virtual = fbinfo.yres * 2;
- if(fbinfo.yoffset == xres)
- fbinfo.yoffset = fbinfo.yres;
- }
- fbinfo.rotate = rotation;
- res = ioctl(fd, FBIOPUT_VSCREENINFO, &fbinfo);
- if(res < 0) {
- fprintf(stderr, "failed to set fbinfo: %s\n", strerror(errno));
- return 1;
- }
-
- return 0;
-}
diff --git a/toolbox/route.c b/toolbox/route.c
deleted file mode 100644
index 3e10014..0000000
--- a/toolbox/route.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (c) 2009, The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <linux/route.h>
-
-static inline int set_address(const char *address, struct sockaddr *sa) {
- return inet_aton(address, &((struct sockaddr_in *)sa)->sin_addr);
-}
-
-/* current support the following routing entries */
-/* route add default dev wlan0 */
-/* route add default gw 192.168.1.1 dev wlan0 */
-/* route add -net 192.168.1.2 netmask 255.255.255.0 gw 192.168.1.1 */
-
-int route_main(int argc, char *argv[])
-{
- struct rtentry rt = {
- .rt_dst = {.sa_family = AF_INET},
- .rt_genmask = {.sa_family = AF_INET},
- .rt_gateway = {.sa_family = AF_INET},
- };
-
- errno = EINVAL;
- if (argc > 2 && !strcmp(argv[1], "add")) {
- if (!strcmp(argv[2], "default")) {
- /* route add default dev wlan0 */
- if (argc > 4 && !strcmp(argv[3], "dev")) {
- rt.rt_flags = RTF_UP;
- rt.rt_dev = argv[4];
- errno = 0;
- goto apply;
- }
-
- /* route add default gw 192.168.1.1 dev wlan0 */
- if (argc > 6 && !strcmp(argv[3], "gw") && !strcmp(argv[5], "dev")) {
- rt.rt_flags = RTF_UP | RTF_GATEWAY;
- rt.rt_dev = argv[6];
- if (set_address(argv[4], &rt.rt_gateway)) {
- errno = 0;
- }
- goto apply;
- }
- }
-
- /* route add -net 192.168.1.2 netmask 255.255.255.0 gw 192.168.1.1 */
- if (argc > 7 && !strcmp(argv[2], "-net") &&
- !strcmp(argv[4], "netmask")) {
- if (!strcmp(argv[6], "gw")) {
- rt.rt_flags = RTF_UP | RTF_GATEWAY;
- if (set_address(argv[3], &rt.rt_dst) &&
- set_address(argv[5], &rt.rt_genmask) &&
- set_address(argv[7], &rt.rt_gateway)) {
- errno = 0;
- }
- goto apply;
- } else if (!strcmp(argv[6], "dev")) {
- rt.rt_flags = RTF_UP;
- rt.rt_dev = argv[7];
- if (set_address(argv[3], &rt.rt_dst) &&
- set_address(argv[5], &rt.rt_genmask)) {
- errno = 0;
- }
- goto apply;
- }
- }
- }
-
-apply:
- if (!errno) {
- int s = socket(AF_INET, SOCK_DGRAM, 0);
- if (s != -1 && (ioctl(s, SIOCADDRT, &rt) != -1 || errno == EEXIST)) {
- return 0;
- }
- }
- puts(strerror(errno));
- return errno;
-}
diff --git a/toolbox/runcon.c b/toolbox/runcon.c
deleted file mode 100644
index 4a57bf3..0000000
--- a/toolbox/runcon.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <selinux/selinux.h>
-
-int runcon_main(int argc, char **argv)
-{
- int rc;
-
- if (argc < 3) {
- fprintf(stderr, "usage: %s context program args...\n", argv[0]);
- exit(1);
- }
-
- rc = setexeccon(argv[1]);
- if (rc < 0) {
- fprintf(stderr, "Could not set context to %s: %s\n", argv[1], strerror(errno));
- exit(2);
- }
-
- argv += 2;
- argc -= 2;
- execvp(argv[0], argv);
- fprintf(stderr, "Could not exec %s: %s\n", argv[0], strerror(errno));
- exit(3);
-}
diff --git a/toolbox/schedtop.c b/toolbox/schedtop.c
deleted file mode 100644
index 2fccd2e..0000000
--- a/toolbox/schedtop.c
+++ /dev/null
@@ -1,330 +0,0 @@
-#include <ctype.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-struct thread_info {
- int pid;
- int tid;
- char name[64];
- unsigned long long exec_time;
- unsigned long long delay_time;
- unsigned long long run_count;
-};
-
-struct thread_table {
- size_t allocated;
- size_t active;
- struct thread_info *data;
-};
-
-enum {
- FLAG_BATCH = 1U << 0,
- FLAG_HIDE_IDLE = 1U << 1,
- FLAG_SHOW_THREADS = 1U << 2,
- FLAG_USE_ALTERNATE_SCREEN = 1U << 3,
-};
-
-static int time_dp = 9;
-static int time_div = 1;
-#define NS_TO_S_D(ns) \
- (uint32_t)((ns) / 1000000000), time_dp, ((uint32_t)((ns) % 1000000000) / time_div)
-
-struct thread_table processes;
-struct thread_table last_processes;
-struct thread_table threads;
-struct thread_table last_threads;
-
-static void grow_table(struct thread_table *table)
-{
- size_t size = table->allocated;
- struct thread_info *new_table;
- if (size < 128)
- size = 128;
- else
- size *= 2;
-
- new_table = realloc(table->data, size * sizeof(*table->data));
- if (new_table == NULL) {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
- table->data = new_table;
- table->allocated = size;
-}
-
-static struct thread_info *get_item(struct thread_table *table)
-{
- if (table->active >= table->allocated)
- grow_table(table);
- return table->data + table->active;
-}
-
-static void commit_item(struct thread_table *table)
-{
- table->active++;
-}
-
-static int read_line(char *line, size_t line_size)
-{
- int fd;
- int len;
- fd = open(line, O_RDONLY);
- if(fd == 0)
- return -1;
- len = read(fd, line, line_size - 1);
- close(fd);
- if (len <= 0)
- return -1;
- line[len] = '\0';
- return 0;
-}
-
-static void add_thread(int pid, int tid, struct thread_info *proc_info)
-{
- char line[1024];
- char *name, *name_end;
- size_t name_len;
- struct thread_info *info;
- if(tid == 0)
- info = get_item(&processes);
- else
- info = get_item(&threads);
- info->pid = pid;
- info->tid = tid;
-
- if(tid)
- sprintf(line, "/proc/%d/task/%d/schedstat", pid, tid);
- else
- sprintf(line, "/proc/%d/schedstat", pid);
- if (read_line(line, sizeof(line)))
- return;
- if(sscanf(line, "%llu %llu %llu",
- &info->exec_time, &info->delay_time, &info->run_count) != 3)
- return;
- if (proc_info) {
- proc_info->exec_time += info->exec_time;
- proc_info->delay_time += info->delay_time;
- proc_info->run_count += info->run_count;
- }
-
- name = NULL;
- if (!tid) {
- sprintf(line, "/proc/%d/cmdline", pid);
- if (read_line(line, sizeof(line)) == 0 && line[0]) {
- name = line;
- name_len = strlen(name);
- }
- }
- if (!name) {
- if (tid)
- sprintf(line, "/proc/%d/task/%d/stat", pid, tid);
- else
- sprintf(line, "/proc/%d/stat", pid);
- if (read_line(line, sizeof(line)))
- return;
- name = strchr(line, '(');
- if (name == NULL)
- return;
- name_end = strchr(name, ')');
- if (name_end == NULL)
- return;
- name++;
- name_len = name_end - name;
- }
- if (name_len >= sizeof(info->name))
- name_len = sizeof(info->name) - 1;
- memcpy(info->name, name, name_len);
- info->name[name_len] = '\0';
- if(tid == 0)
- commit_item(&processes);
- else
- commit_item(&threads);
-}
-
-static void add_threads(int pid, struct thread_info *proc_info)
-{
- char path[1024];
- DIR *d;
- struct dirent *de;
- sprintf(path, "/proc/%d/task", pid);
- d = opendir(path);
- if(d == 0) return;
- while((de = readdir(d)) != 0){
- if(isdigit(de->d_name[0])){
- int tid = atoi(de->d_name);
- add_thread(pid, tid, proc_info);
- }
- }
- closedir(d);
-}
-
-static void print_threads(int pid, uint32_t flags)
-{
- size_t i, j;
- for (i = 0; i < last_threads.active; i++) {
- int epid = last_threads.data[i].pid;
- int tid = last_threads.data[i].tid;
- if (epid != pid)
- continue;
- for (j = 0; j < threads.active; j++)
- if (tid == threads.data[j].tid)
- break;
- if (j == threads.active)
- printf(" %5u died\n", tid);
- else if (!(flags & FLAG_HIDE_IDLE) || threads.data[j].run_count - last_threads.data[i].run_count)
- printf(" %5u %2u.%0*u %2u.%0*u %5llu %5u.%0*u %5u.%0*u %7llu %s\n", tid,
- NS_TO_S_D(threads.data[j].exec_time - last_threads.data[i].exec_time),
- NS_TO_S_D(threads.data[j].delay_time - last_threads.data[i].delay_time),
- threads.data[j].run_count - last_threads.data[i].run_count,
- NS_TO_S_D(threads.data[j].exec_time), NS_TO_S_D(threads.data[j].delay_time),
- threads.data[j].run_count, threads.data[j].name);
- }
-}
-
-static void update_table(DIR *d, uint32_t flags)
-{
- size_t i, j;
- struct dirent *de;
-
- rewinddir(d);
- while((de = readdir(d)) != 0){
- if(isdigit(de->d_name[0])){
- int pid = atoi(de->d_name);
- struct thread_info *proc_info;
- add_thread(pid, 0, NULL);
- proc_info = &processes.data[processes.active - 1];
- proc_info->exec_time = 0;
- proc_info->delay_time = 0;
- proc_info->run_count = 0;
- add_threads(pid, proc_info);
- }
- }
- if (!(flags & FLAG_BATCH))
- printf("\e[H\e[0J");
- printf("Processes: %zu, Threads %zu\n", processes.active, threads.active);
- switch (time_dp) {
- case 3:
- printf(" TID --- SINCE LAST ---- ---------- TOTAL ----------\n");
- printf(" PID EXEC_T DELAY SCHED EXEC_TIME DELAY_TIM SCHED NAME\n");
- break;
- case 6:
- printf(" TID ------ SINCE LAST ------- ------------ TOTAL -----------\n");
- printf(" PID EXEC_TIME DELAY_TIM SCHED EXEC_TIME DELAY_TIME SCHED NAME\n");
- break;
- default:
- printf(" TID -------- SINCE LAST -------- ------------- TOTAL -------------\n");
- printf(" PID EXEC_TIME DELAY_TIME SCHED EXEC_TIME DELAY_TIME SCHED NAME\n");
- break;
- }
- for (i = 0; i < last_processes.active; i++) {
- int pid = last_processes.data[i].pid;
- for (j = 0; j < processes.active; j++)
- if (pid == processes.data[j].pid)
- break;
- if (j == processes.active)
- printf("%5u died\n", pid);
- else if (!(flags & FLAG_HIDE_IDLE) || processes.data[j].run_count - last_processes.data[i].run_count) {
- printf("%5u %2u.%0*u %2u.%0*u %5llu %5u.%0*u %5u.%0*u %7llu %s\n", pid,
- NS_TO_S_D(processes.data[j].exec_time - last_processes.data[i].exec_time),
- NS_TO_S_D(processes.data[j].delay_time - last_processes.data[i].delay_time),
- processes.data[j].run_count - last_processes.data[i].run_count,
- NS_TO_S_D(processes.data[j].exec_time), NS_TO_S_D(processes.data[j].delay_time),
- processes.data[j].run_count, processes.data[j].name);
- if (flags & FLAG_SHOW_THREADS)
- print_threads(pid, flags);
- }
- }
-
- {
- struct thread_table tmp;
- tmp = last_processes;
- last_processes = processes;
- processes = tmp;
- processes.active = 0;
- tmp = last_threads;
- last_threads = threads;
- threads = tmp;
- threads.active = 0;
- }
-}
-
-void
-sig_abort(int signum)
-{
- printf("\e[?47l");
- exit(0);
-}
-
-
-int schedtop_main(int argc, char **argv)
-{
- int c;
- DIR *d;
- uint32_t flags = 0;
- int delay = 3000000;
- float delay_f;
-
- while(1) {
- c = getopt(argc, argv, "d:ibtamun");
- if (c == EOF)
- break;
- switch (c) {
- case 'd':
- delay_f = atof(optarg);
- delay = delay_f * 1000000;
- break;
- case 'b':
- flags |= FLAG_BATCH;
- break;
- case 'i':
- flags |= FLAG_HIDE_IDLE;
- break;
- case 't':
- flags |= FLAG_SHOW_THREADS;
- break;
- case 'a':
- flags |= FLAG_USE_ALTERNATE_SCREEN;
- break;
- case 'm':
- time_dp = 3;
- time_div = 1000000;
- break;
- case 'u':
- time_dp = 6;
- time_div = 1000;
- break;
- case 'n':
- time_dp = 9;
- time_div = 1;
- break;
- }
- }
-
- d = opendir("/proc");
- if(d == 0) return -1;
-
- if (!(flags & FLAG_BATCH)) {
- if(flags & FLAG_USE_ALTERNATE_SCREEN) {
- signal(SIGINT, sig_abort);
- signal(SIGPIPE, sig_abort);
- signal(SIGTERM, sig_abort);
- printf("\e7\e[?47h");
- }
- printf("\e[2J");
- }
- while (1) {
- update_table(d, flags);
- usleep(delay);
- }
- closedir(d);
- return 0;
-}
diff --git a/toolbox/sendevent.c b/toolbox/sendevent.c
index 9b813f6..4d0ca17 100644
--- a/toolbox/sendevent.c
+++ b/toolbox/sendevent.c
@@ -1,49 +1,12 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/input.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <stdint.h>
-#include <fcntl.h>
#include <sys/ioctl.h>
-//#include <linux/input.h> // this does not compile
-#include <errno.h>
-
-
-// from <linux/input.h>
-
-struct input_event {
- struct timeval time;
- __u16 type;
- __u16 code;
- __s32 value;
-};
-
-#define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */
-#define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */
-#define EVIOCGKEYCODE _IOR('E', 0x04, int[2]) /* get keycode */
-#define EVIOCSKEYCODE _IOW('E', 0x04, int[2]) /* set keycode */
-
-#define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */
-#define EVIOCGPHYS(len) _IOC(_IOC_READ, 'E', 0x07, len) /* get physical location */
-#define EVIOCGUNIQ(len) _IOC(_IOC_READ, 'E', 0x08, len) /* get unique identifier */
-
-#define EVIOCGKEY(len) _IOC(_IOC_READ, 'E', 0x18, len) /* get global keystate */
-#define EVIOCGLED(len) _IOC(_IOC_READ, 'E', 0x19, len) /* get all LEDs */
-#define EVIOCGSND(len) _IOC(_IOC_READ, 'E', 0x1a, len) /* get all sounds status */
-#define EVIOCGSW(len) _IOC(_IOC_READ, 'E', 0x1b, len) /* get all switch states */
-
-#define EVIOCGBIT(ev,len) _IOC(_IOC_READ, 'E', 0x20 + ev, len) /* get event bits */
-#define EVIOCGABS(abs) _IOR('E', 0x40 + abs, struct input_absinfo) /* get abs value/limits */
-#define EVIOCSABS(abs) _IOW('E', 0xc0 + abs, struct input_absinfo) /* set abs value/limits */
-
-#define EVIOCSFF _IOC(_IOC_WRITE, 'E', 0x80, sizeof(struct ff_effect)) /* send a force effect to a force feedback device */
-#define EVIOCRMFF _IOW('E', 0x81, int) /* Erase a force effect */
-#define EVIOCGEFFECTS _IOR('E', 0x84, int) /* Report number of effects playable at the same time */
-
-#define EVIOCGRAB _IOW('E', 0x90, int) /* Grab/Release device */
-
-// end <linux/input.h>
-
-
+#include <unistd.h>
int sendevent_main(int argc, char *argv[])
{
diff --git a/toolbox/setenforce.c b/toolbox/setenforce.c
deleted file mode 100644
index 444073d..0000000
--- a/toolbox/setenforce.c
+++ /dev/null
@@ -1,44 +0,0 @@
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-#include <strings.h>
-#include <errno.h>
-#include <selinux/selinux.h>
-
-static void usage(const char *progname)
-{
- fprintf(stderr, "usage: %s [ Enforcing | Permissive | 1 | 0 ]\n",
- progname);
- exit(1);
-}
-
-int setenforce_main(int argc, char **argv)
-{
- int rc = 0;
- if (argc != 2) {
- usage(argv[0]);
- }
-
- if (is_selinux_enabled() <= 0) {
- fprintf(stderr, "%s: SELinux is disabled\n", argv[0]);
- return 1;
- }
- if (strlen(argv[1]) == 1 && (argv[1][0] == '0' || argv[1][0] == '1')) {
- rc = security_setenforce(atoi(argv[1]));
- } else {
- if (strcasecmp(argv[1], "enforcing") == 0) {
- rc = security_setenforce(1);
- } else if (strcasecmp(argv[1], "permissive") == 0) {
- rc = security_setenforce(0);
- } else
- usage(argv[0]);
- }
- if (rc < 0) {
- fprintf(stderr, "%s: Could not set enforcing status: %s\n",
- argv[0], strerror(errno));
- return 2;
- }
- return 0;
-}
diff --git a/toolbox/setkey.c b/toolbox/setkey.c
deleted file mode 100644
index 1ff2774..0000000
--- a/toolbox/setkey.c
+++ /dev/null
@@ -1,89 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <string.h>
-#include <linux/kd.h>
-#include <linux/vt.h>
-#include <errno.h>
-
-static void setkey_usage(char *argv[])
-{
- fprintf(stderr, "%s [-t <table>] [-k <index>] [-v value] [-r] [-h]\n"
- " -t <table> Select table\n"
- " -k <index> Select key\n"
- " -v <value> Set entry\n"
- " -r Read current entry\n"
- " -h Print help\n", argv[0]);
-}
-
-#define TTYDEV "/dev/tty0"
-
-int setkey_main(int argc, char *argv[])
-{
- int fd;
- struct kbentry kbe;
- int did_something = 0;
-
- kbe.kb_table = 0;
- kbe.kb_index = -1;
- kbe.kb_value = 0;
-
- fd = open(TTYDEV, O_RDWR | O_SYNC);
- if (fd < 0) {
- fprintf(stderr, "open %s: %s\n", TTYDEV, strerror(errno));
- return 1;
- }
-
- do {
- int c, ret;
-
- c = getopt(argc, argv, "t:k:v:hr");
- if (c == EOF)
- break;
-
- switch (c) {
- case 't':
- kbe.kb_table = strtol(optarg, NULL, 0);
- break;
- case 'k':
- kbe.kb_index = strtol(optarg, NULL, 0);
- break;
- case 'v':
- kbe.kb_value = strtol(optarg, NULL, 0);
- ret = ioctl(fd, KDSKBENT, &kbe);
- if (ret < 0) {
- fprintf(stderr, "KDSKBENT %d %d %d failed: %s\n",
- kbe.kb_table, kbe.kb_index, kbe.kb_value,
- strerror(errno));
- return 1;
- }
- did_something = 1;
- break;
- case 'r':
- ret = ioctl(fd, KDGKBENT, &kbe);
- if (ret < 0) {
- fprintf(stderr, "KDGKBENT %d %d failed: %s\n",
- kbe.kb_table, kbe.kb_index, strerror(errno));
- return 1;
- }
- printf("0x%x 0x%x 0x%x\n",
- kbe.kb_table, kbe.kb_index, kbe.kb_value);
- did_something = 1;
- break;
- case 'h':
- setkey_usage(argv);
- return 1;
- case '?':
- fprintf(stderr, "%s: invalid option -%c\n",
- argv[0], optopt);
- return 1;
- }
- } while (1);
-
- if(optind != argc || !did_something) {
- setkey_usage(argv);
- return 1;
- }
-
- return 0;
-}
diff --git a/toolbox/setprop.c b/toolbox/setprop.c
deleted file mode 100644
index 63ad2b4..0000000
--- a/toolbox/setprop.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#include <stdio.h>
-
-#include <cutils/properties.h>
-
-int setprop_main(int argc, char *argv[])
-{
- if(argc != 3) {
- fprintf(stderr,"usage: setprop <key> <value>\n");
- return 1;
- }
-
- if(property_set(argv[1], argv[2])){
- fprintf(stderr,"could not set property\n");
- return 1;
- }
-
- return 0;
-}
diff --git a/toolbox/setsebool.c b/toolbox/setsebool.c
deleted file mode 100644
index f79a612..0000000
--- a/toolbox/setsebool.c
+++ /dev/null
@@ -1,46 +0,0 @@
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <selinux/selinux.h>
-#include <errno.h>
-
-static int do_setsebool(int nargs, char **args) {
- const char *name = args[1];
- const char *value = args[2];
- SELboolean b;
-
- if (is_selinux_enabled() <= 0)
- return 0;
-
- b.name = name;
- if (!strcmp(value, "1") || !strcasecmp(value, "true") || !strcasecmp(value, "on"))
- b.value = 1;
- else if (!strcmp(value, "0") || !strcasecmp(value, "false") || !strcasecmp(value, "off"))
- b.value = 0;
- else {
- fprintf(stderr, "setsebool: invalid value %s\n", value);
- return -1;
- }
-
- if (security_set_boolean_list(1, &b, 0) < 0)
- {
- fprintf(stderr, "setsebool: could not set %s to %s: %s", name, value, strerror(errno));
- return -1;
- }
-
- return 0;
-}
-
-int setsebool_main(int argc, char **argv)
-{
- if (argc != 3) {
- fprintf(stderr, "Usage: %s name value\n", argv[0]);
- exit(1);
- }
-
- return do_setsebool(argc, argv);
-}
diff --git a/toolbox/smd.c b/toolbox/smd.c
deleted file mode 100644
index 91e495c..0000000
--- a/toolbox/smd.c
+++ /dev/null
@@ -1,41 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-
-int smd_main(int argc, char **argv)
-{
- int fd, len, r, port = 0;
- char devname[32];
- argc--;
- argv++;
-
- if((argc > 0) && (argv[0][0] == '-')) {
- port = atoi(argv[0] + 1);
- argc--;
- argv++;
- }
-
- sprintf(devname,"/dev/smd%d",port);
- fd = open(devname, O_WRONLY);
- if(fd < 0) {
- fprintf(stderr,"failed to open smd0 - %s\n",
- strerror(errno));
- return -1;
- }
- while(argc > 0) {
- len = strlen(argv[0]);
- r = write(fd, argv[0], len);
- if(r != len) {
- fprintf(stderr,"failed to write smd0 (%d) %s\n",
- r, strerror(errno));
- return -1;
- }
- argc--;
- argv++;
- write(fd, argc ? " " : "\r", 1);
- }
- close(fd);
- return 0;
-}
diff --git a/toolbox/swapoff.c b/toolbox/swapoff.c
deleted file mode 100644
index d8f6a00..0000000
--- a/toolbox/swapoff.c
+++ /dev/null
@@ -1,20 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/swap.h>
-
-int swapoff_main(int argc, char **argv)
-{
- int err = 0;
-
- if (argc != 2) {
- fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
- return -EINVAL;
- }
-
- err = swapoff(argv[1]);
- if (err) {
- fprintf(stderr, "swapoff failed for %s\n", argv[1]);
- }
-
- return err;
-}
diff --git a/toolbox/swapon.c b/toolbox/swapon.c
deleted file mode 100644
index 150701a..0000000
--- a/toolbox/swapon.c
+++ /dev/null
@@ -1,66 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <sys/swap.h>
-
-static void usage(char *name)
-{
- fprintf(stderr, "Usage: %s [-p prio] <filename>\n"
- " prio must be between 0 and %d\n", name, SWAP_FLAG_PRIO_MASK);
-}
-
-static int parse_prio(char *prio_str)
-{
- unsigned long p = strtoul(prio_str, NULL, 10);
-
- return (p > SWAP_FLAG_PRIO_MASK)? -1 : (int)p;
-}
-
-int swapon_main(int argc, char **argv)
-{
- int err = 0;
- int flags = 0;
- int prio;
-
- opterr = 0;
- do {
- int c = getopt(argc, argv, "hp:");
- if (c == -1)
- break;
-
- switch (c) {
- case 'p':
- if (optarg != NULL)
- prio = parse_prio(optarg);
- else
- prio = -1;
-
- if (prio < 0) {
- usage(argv[0]);
- return -EINVAL;
- }
- flags |= SWAP_FLAG_PREFER;
- flags |= (prio << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK;
- break;
- case 'h':
- usage(argv[0]);
- return 0;
- case '?':
- fprintf(stderr, "unknown option: %c\n", optopt);
- return -EINVAL;
- }
- } while (1);
-
- if (optind != argc - 1) {
- usage(argv[0]);
- return -EINVAL;
- }
-
- err = swapon(argv[argc - 1], flags);
- if (err) {
- fprintf(stderr, "swapon failed for %s\n", argv[argc - 1]);
- }
-
- return err;
-}
diff --git a/toolbox/syren.c b/toolbox/syren.c
deleted file mode 100644
index 47c2460..0000000
--- a/toolbox/syren.c
+++ /dev/null
@@ -1,158 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <malloc.h>
-
-/* ioctl crap */
-#define SYREN_RD 101
-#define SYREN_WR 102
-#define SYREN_OLD_RD 108
-#define SYREN_OLD_WR 109
-
-struct syren_io_args {
- unsigned long page;
- unsigned long addr;
- unsigned long value;
-};
-
-typedef struct {
- u_char page;
- u_char addr;
- const char *name;
-} syren_reg;
-
-static syren_reg registers[] = {
- { 0, 0x04, "TOGBR1" },
- { 0, 0x05, "TOGBR2" },
- { 0, 0x06, "VBDCTRL" },
- { 1, 0x07, "VBUCTRL" },
- { 1, 0x08, "VBCTRL" },
- { 1, 0x09, "PWDNRG" },
- { 1, 0x0a, "VBPOP" },
- { 1, 0x0b, "VBCTRL2" },
- { 1, 0x0f, "VAUDCTRL" },
- { 1, 0x10, "VAUSCTRL" },
- { 1, 0x11, "VAUOCTRL" },
- { 1, 0x12, "VAUDPLL" },
- { 1, 0x17, "VRPCSIMR" },
- { 0, 0, 0 }
-};
-
-static syren_reg *find_reg(const char *name)
-{
- int i;
-
- for (i = 0; registers[i].name != 0; i++) {
- if (!strcasecmp(registers[i].name, name))
- return &registers[i];
- }
-
- return NULL;
-}
-
-static int usage(void)
-{
- fprintf(stderr, "usage: syren [r/w] [REGNAME | page:addr] (value)\n");
- return 1;
-}
-
-int
-syren_main(int argc, char **argv)
-{
- int cmd = -1;
- syren_reg *r;
- struct syren_io_args sio;
- char name[32];
- int fd;
-
- if (argc < 3) {
- return usage();
- }
-
- switch(argv[1][0]) {
- case 'r':
- cmd = SYREN_RD;
- break;
- case 'w':
- cmd = SYREN_WR;
- break;
- case 'R':
- cmd = SYREN_OLD_RD;
- break;
- case 'W':
- cmd = SYREN_OLD_WR;
- break;
- default:
- return usage();
- }
-
- if (cmd == SYREN_WR || cmd == SYREN_OLD_WR) {
- if (argc < 4)
- return usage();
- sio.value = strtoul(argv[3], 0, 0);
- }
-
- fd = open("/dev/eac", O_RDONLY);
- if (fd < 0) {
- fprintf(stderr, "can't open /dev/eac\n");
- return 1;
- }
-
- if (strcasecmp(argv[2], "all") == 0) {
- int i;
- if (cmd != SYREN_RD && cmd != SYREN_OLD_RD) {
- fprintf(stderr, "can only read all registers\n");
- return 1;
- }
-
- for (i = 0; registers[i].name; i++) {
- sio.page = registers[i].page;
- sio.addr = registers[i].addr;
- if (ioctl(fd, cmd, &sio) < 0) {
- fprintf(stderr, "%s: error\n", registers[i].name);
- } else {
- fprintf(stderr, "%s: %04x\n", registers[i].name, sio.value);
- }
- }
-
- close(fd);
- return 0;
- }
-
- r = find_reg(argv[2]);
- if (r == NULL) {
- if(strlen(argv[2]) >= sizeof(name)){
- fprintf(stderr, "REGNAME too long\n");
- return 0;
- }
- strlcpy(name, argv[2], sizeof(name));
- char *addr_str = strchr(argv[2], ':');
- if (addr_str == NULL)
- return usage();
- *addr_str++ = 0;
- sio.page = strtoul(argv[2], 0, 0);
- sio.addr = strtoul(addr_str, 0, 0);
- } else {
- strlcpy(name, r->name, sizeof(name));
- sio.page = r->page;
- sio.addr = r->addr;
- }
-
- if (ioctl(fd, cmd, &sio) < 0) {
- fprintf(stderr, "ioctl(%d) failed\n", cmd);
- return 1;
- }
-
- if (cmd == SYREN_RD || cmd == SYREN_OLD_RD) {
- printf("%s: %04x\n", name, sio.value);
- } else {
- printf("wrote %04x to %s\n", sio.value, name);
- }
-
- close(fd);
-
- return 0;
-}
-
diff --git a/toolbox/toolbox.c b/toolbox/toolbox.c
index 0eac390..915da44 100644
--- a/toolbox/toolbox.c
+++ b/toolbox/toolbox.c
@@ -1,6 +1,8 @@
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
int main(int, char **);
@@ -31,11 +33,24 @@ static struct
{ 0, 0 },
};
+static void SIGPIPE_handler(int signal) {
+ // Those desktop Linux tools that catch SIGPIPE seem to agree that it's
+ // a successful way to exit, not a failure. (Which makes sense --- we were
+ // told to stop by a reader, rather than failing to continue ourselves.)
+ _exit(0);
+}
+
int main(int argc, char **argv)
{
int i;
char *name = argv[0];
+ // Let's assume that none of this code handles broken pipes. At least ls,
+ // ps, and top were broken (though I'd previously added this fix locally
+ // to top). We exit rather than use SIG_IGN because tools like top will
+ // just keep on writing to nowhere forever if we don't stop them.
+ signal(SIGPIPE, SIGPIPE_handler);
+
if((argc > 1) && (argv[1][0] == '@')) {
name = argv[1] + 1;
argc--;
diff --git a/toolbox/top.c b/toolbox/top.c
index b1a275c..1e99d4c 100644
--- a/toolbox/top.c
+++ b/toolbox/top.c
@@ -109,15 +109,9 @@ static int proc_thr_cmp(const void *a, const void *b);
static int numcmp(long long a, long long b);
static void usage(char *cmd);
-static void exit_top(int signal) {
- exit(EXIT_FAILURE);
-}
-
int top_main(int argc, char *argv[]) {
num_used_procs = num_free_procs = 0;
- signal(SIGPIPE, exit_top);
-
max_procs = 0;
delay = 3;
iterations = -1;
diff --git a/toolbox/touch.c b/toolbox/touch.c
deleted file mode 100644
index 52ddf2a..0000000
--- a/toolbox/touch.c
+++ /dev/null
@@ -1,114 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <time.h>
-
-static void usage(void)
-{
- fprintf(stderr, "touch: usage: touch [-alm] [-t YYYYMMDD[.hhmmss]] <file>\n");
- exit(1);
-}
-
-static time_t parse_time(char *s)
-{
- struct tm tm;
- int day = atoi(s);
- int hour = 0;
-
- while (*s && *s != '.') {
- s++;
- }
-
- if (*s) {
- s++;
- hour = atoi(s);
- }
-
- tm.tm_year = day / 10000 - 1900;
- tm.tm_mon = (day % 10000) / 100 - 1;
- tm.tm_mday = day % 100;
- tm.tm_hour = hour / 10000;
- tm.tm_min = (hour % 10000) / 100;
- tm.tm_sec = hour % 100;
- tm.tm_isdst = -1;
-
- return mktime(&tm);
-}
-
-int touch_main(int argc, char *argv[])
-{
- int i, fd, aflag = 0, mflag = 0, debug = 0, flags = 0;
- struct timespec specified_time, times[2];
- char *file = 0;
-
- specified_time.tv_nsec = UTIME_NOW;
-
- for (i = 1; i < argc; i++) {
- if (argv[i][0] == '-') {
- /* an option */
- const char *arg = argv[i]+1;
- while (arg[0]) {
- switch (arg[0]) {
- case 'a': aflag = 1; break;
- case 'm': mflag = 1; break;
- case 't':
- if ((i+1) >= argc)
- usage();
- specified_time.tv_sec = parse_time(argv[++i]);
- if (specified_time.tv_sec == -1) {
- fprintf(stderr, "touch: invalid timestamp specified\n");
- exit(1);
- }
- specified_time.tv_nsec = 0;
- break;
- case 'l': flags |= AT_SYMLINK_NOFOLLOW; break;
- case 'd': debug = 1; break;
- default:
- usage();
- }
- arg++;
- }
- } else {
- /* not an option, and only accept one filename */
- if (i+1 != argc)
- usage();
- file = argv[i];
- }
- }
-
- if (! file) {
- fprintf(stderr, "touch: no file specified\n");
- exit(1);
- }
-
- if (access(file, F_OK))
- if ((fd=creat(file, 0666)) != -1)
- close(fd);
-
- if ((mflag == 0) && (aflag == 0))
- aflag = mflag = 1;
-
- if (aflag)
- times[0] = specified_time;
- else
- times[0].tv_nsec = UTIME_OMIT;
-
- if (mflag)
- times[1] = specified_time;
- else
- times[1].tv_nsec = UTIME_OMIT;
-
- if (debug) {
- fprintf(stderr, "file = %s\n", file);
- fprintf(stderr, "times[0].tv_sec = %ld, times[0].tv_nsec = %ld\n", times[0].tv_sec, times[0].tv_nsec);
- fprintf(stderr, "times[1].tv_sec = %ld, times[1].tv_nsec = %ld\n", times[1].tv_sec, times[1].tv_nsec);
- fprintf(stderr, "flags = 0x%8.8x\n", flags);
- }
-
- return utimensat(AT_FDCWD, file, times, flags);
-}
-
diff --git a/toolbox/umount.c b/toolbox/umount.c
deleted file mode 100644
index 3e17396..0000000
--- a/toolbox/umount.c
+++ /dev/null
@@ -1,90 +0,0 @@
-
-#include <sys/mount.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <linux/loop.h>
-#include <errno.h>
-
-#define LOOPDEV_MAXLEN 64
-#define LOOP_MAJOR 7
-
-static int is_loop(char *dev)
-{
- struct stat st;
- int ret = 0;
-
- if (stat(dev, &st) == 0) {
- if (S_ISBLK(st.st_mode) && (major(st.st_rdev) == LOOP_MAJOR)) {
- ret = 1;
- }
- }
-
- return ret;
-}
-
-static int is_loop_mount(const char* path, char *loopdev)
-{
- FILE* f;
- int count;
- char device[256];
- char mount_path[256];
- char rest[256];
- int result = 0;
-
- f = fopen("/proc/mounts", "r");
- if (!f) {
- fprintf(stdout, "could not open /proc/mounts: %s\n", strerror(errno));
- return -1;
- }
-
- do {
- count = fscanf(f, "%255s %255s %255s\n", device, mount_path, rest);
- if (count == 3) {
- if (is_loop(device) && strcmp(path, mount_path) == 0) {
- strlcpy(loopdev, device, LOOPDEV_MAXLEN);
- result = 1;
- break;
- }
- }
- } while (count == 3);
-
- fclose(f);
- return result;
-}
-
-int umount_main(int argc, char *argv[])
-{
- int loop, loop_fd;
- char loopdev[LOOPDEV_MAXLEN];
-
- if(argc != 2) {
- fprintf(stderr,"umount <path>\n");
- return 1;
- }
-
- loop = is_loop_mount(argv[1], loopdev);
- if (umount(argv[1])) {
- fprintf(stderr, "failed: %s\n", strerror(errno));
- return 1;
- }
-
- if (loop) {
- // free the loop device
- loop_fd = open(loopdev, O_RDONLY);
- if (loop_fd < 0) {
- fprintf(stderr, "open loop device failed: %s\n", strerror(errno));
- return 1;
- }
- if (ioctl(loop_fd, LOOP_CLR_FD, 0) < 0) {
- fprintf(stderr, "ioctl LOOP_CLR_FD failed: %s\n", strerror(errno));
- return 1;
- }
-
- close(loop_fd);
- }
-
- return 0;
-}
diff --git a/toolbox/upstream-netbsd/bin/cat/cat.c b/toolbox/upstream-netbsd/bin/cat/cat.c
deleted file mode 100644
index cca8cf5..0000000
--- a/toolbox/upstream-netbsd/bin/cat/cat.c
+++ /dev/null
@@ -1,329 +0,0 @@
-/* $NetBSD: cat.c,v 1.54 2013/12/08 08:32:13 spz Exp $ */
-
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kevin Fall.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if HAVE_NBTOOL_CONFIG_H
-#include "nbtool_config.h"
-#endif
-
-#include <sys/cdefs.h>
-#if !defined(lint)
-__COPYRIGHT(
-"@(#) Copyright (c) 1989, 1993\
- The Regents of the University of California. All rights reserved.");
-#if 0
-static char sccsid[] = "@(#)cat.c 8.2 (Berkeley) 4/27/95";
-#else
-__RCSID("$NetBSD: cat.c,v 1.54 2013/12/08 08:32:13 spz Exp $");
-#endif
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/stat.h>
-
-#include <ctype.h>
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <locale.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-static int bflag, eflag, fflag, lflag, nflag, sflag, tflag, vflag;
-static size_t bsize;
-static int rval;
-static const char *filename;
-
-void cook_args(char *argv[]);
-void cook_buf(FILE *);
-void raw_args(char *argv[]);
-void raw_cat(int);
-
-int
-main(int argc, char *argv[])
-{
- int ch;
- struct flock stdout_lock;
-
- setprogname(argv[0]);
- (void)setlocale(LC_ALL, "");
-
- while ((ch = getopt(argc, argv, "B:beflnstuv")) != -1)
- switch (ch) {
- case 'B':
- bsize = (size_t)strtol(optarg, NULL, 0);
- break;
- case 'b':
- bflag = nflag = 1; /* -b implies -n */
- break;
- case 'e':
- eflag = vflag = 1; /* -e implies -v */
- break;
- case 'f':
- fflag = 1;
- break;
- case 'l':
- lflag = 1;
- break;
- case 'n':
- nflag = 1;
- break;
- case 's':
- sflag = 1;
- break;
- case 't':
- tflag = vflag = 1; /* -t implies -v */
- break;
- case 'u':
- setbuf(stdout, NULL);
- break;
- case 'v':
- vflag = 1;
- break;
- default:
- case '?':
- (void)fprintf(stderr,
- "Usage: %s [-beflnstuv] [-B bsize] [-] "
- "[file ...]\n", getprogname());
- return EXIT_FAILURE;
- }
- argv += optind;
-
- if (lflag) {
- stdout_lock.l_len = 0;
- stdout_lock.l_start = 0;
- stdout_lock.l_type = F_WRLCK;
- stdout_lock.l_whence = SEEK_SET;
- if (fcntl(STDOUT_FILENO, F_SETLKW, &stdout_lock) == -1)
- err(EXIT_FAILURE, "stdout");
- }
-
- if (bflag || eflag || nflag || sflag || tflag || vflag)
- cook_args(argv);
- else
- raw_args(argv);
- if (fclose(stdout))
- err(EXIT_FAILURE, "stdout");
- return rval;
-}
-
-void
-cook_args(char **argv)
-{
- FILE *fp;
-
- fp = stdin;
- filename = "stdin";
- do {
- if (*argv) {
- if (!strcmp(*argv, "-"))
- fp = stdin;
- else if ((fp = fopen(*argv,
- fflag ? "rf" : "r")) == NULL) {
- warn("%s", *argv);
- rval = EXIT_FAILURE;
- ++argv;
- continue;
- }
- filename = *argv++;
- }
- cook_buf(fp);
- if (fp != stdin)
- (void)fclose(fp);
- else
- clearerr(fp);
- } while (*argv);
-}
-
-void
-cook_buf(FILE *fp)
-{
- int ch, gobble, line, prev;
-
- line = gobble = 0;
- for (prev = '\n'; (ch = getc(fp)) != EOF; prev = ch) {
- if (prev == '\n') {
- if (ch == '\n') {
- if (sflag) {
- if (!gobble && nflag && !bflag)
- (void)fprintf(stdout,
- "%6d\t\n", ++line);
- else if (!gobble && putchar(ch) == EOF)
- break;
- gobble = 1;
- continue;
- }
- if (nflag) {
- if (!bflag) {
- (void)fprintf(stdout,
- "%6d\t", ++line);
- if (ferror(stdout))
- break;
- } else if (eflag) {
- (void)fprintf(stdout,
- "%6s\t", "");
- if (ferror(stdout))
- break;
- }
- }
- } else if (nflag) {
- (void)fprintf(stdout, "%6d\t", ++line);
- if (ferror(stdout))
- break;
- }
- }
- gobble = 0;
- if (ch == '\n') {
- if (eflag)
- if (putchar('$') == EOF)
- break;
- } else if (ch == '\t') {
- if (tflag) {
- if (putchar('^') == EOF || putchar('I') == EOF)
- break;
- continue;
- }
- } else if (vflag) {
- if (!isascii(ch)) {
- if (putchar('M') == EOF || putchar('-') == EOF)
- break;
- ch = toascii(ch);
- }
- if (iscntrl(ch)) {
- if (putchar('^') == EOF ||
- putchar(ch == '\177' ? '?' :
- ch | 0100) == EOF)
- break;
- continue;
- }
- }
- if (putchar(ch) == EOF)
- break;
- }
- if (ferror(fp)) {
- warn("%s", filename);
- rval = EXIT_FAILURE;
- clearerr(fp);
- }
- if (ferror(stdout))
- err(EXIT_FAILURE, "stdout");
-}
-
-void
-raw_args(char **argv)
-{
- int fd;
-
- fd = fileno(stdin);
- filename = "stdin";
- do {
- if (*argv) {
- if (!strcmp(*argv, "-")) {
- fd = fileno(stdin);
- if (fd < 0)
- goto skip;
- } else if (fflag) {
- struct stat st;
- fd = open(*argv, O_RDONLY|O_NONBLOCK, 0);
- if (fd < 0)
- goto skip;
-
- if (fstat(fd, &st) == -1) {
- close(fd);
- goto skip;
- }
- if (!S_ISREG(st.st_mode)) {
- close(fd);
- warnx("%s: not a regular file", *argv);
- goto skipnomsg;
- }
- }
- else if ((fd = open(*argv, O_RDONLY, 0)) < 0) {
-skip:
- warn("%s", *argv);
-skipnomsg:
- rval = EXIT_FAILURE;
- ++argv;
- continue;
- }
- filename = *argv++;
- } else if (fd < 0) {
- err(EXIT_FAILURE, "stdin");
- }
- raw_cat(fd);
- if (fd != fileno(stdin))
- (void)close(fd);
- } while (*argv);
-}
-
-void
-raw_cat(int rfd)
-{
- static char *buf;
- static char fb_buf[BUFSIZ];
-
- ssize_t nr, nw, off;
- int wfd;
-
- wfd = fileno(stdout);
- if (wfd < 0)
- err(EXIT_FAILURE, "stdout");
- if (buf == NULL) {
- struct stat sbuf;
-
- if (bsize == 0) {
- if (fstat(wfd, &sbuf) == 0 && sbuf.st_blksize > 0 &&
- (size_t)sbuf.st_blksize > sizeof(fb_buf))
- bsize = sbuf.st_blksize;
- }
- if (bsize > sizeof(fb_buf)) {
- buf = malloc(bsize);
- if (buf == NULL)
- warnx("malloc, using %zu buffer", bsize);
- }
- if (buf == NULL) {
- bsize = sizeof(fb_buf);
- buf = fb_buf;
- }
- }
- while ((nr = read(rfd, buf, bsize)) > 0)
- for (off = 0; nr; nr -= nw, off += nw)
- if ((nw = write(wfd, buf + off, (size_t)nr)) < 0)
- err(EXIT_FAILURE, "stdout");
- if (nr < 0) {
- warn("%s", filename);
- rval = EXIT_FAILURE;
- }
-}
diff --git a/toolbox/upstream-netbsd/bin/cp/cp.c b/toolbox/upstream-netbsd/bin/cp/cp.c
deleted file mode 100644
index 4bbe1b7..0000000
--- a/toolbox/upstream-netbsd/bin/cp/cp.c
+++ /dev/null
@@ -1,548 +0,0 @@
-/* $NetBSD: cp.c,v 1.58 2012/01/04 15:58:37 christos Exp $ */
-
-/*
- * Copyright (c) 1988, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * David Hitz of Auspex Systems Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-__COPYRIGHT(
-"@(#) Copyright (c) 1988, 1993, 1994\
- The Regents of the University of California. All rights reserved.");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95";
-#else
-__RCSID("$NetBSD: cp.c,v 1.58 2012/01/04 15:58:37 christos Exp $");
-#endif
-#endif /* not lint */
-
-/*
- * Cp copies source files to target files.
- *
- * The global PATH_T structure "to" always contains the path to the
- * current target file. Since fts(3) does not change directories,
- * this path can be either absolute or dot-relative.
- *
- * The basic algorithm is to initialize "to" and use fts(3) to traverse
- * the file hierarchy rooted in the argument list. A trivial case is the
- * case of 'cp file1 file2'. The more interesting case is the case of
- * 'cp file1 file2 ... fileN dir' where the hierarchy is traversed and the
- * path (relative to the root of the traversal) is appended to dir (stored
- * in "to") to form the final target path.
- */
-
-#include <sys/param.h>
-#include <sys/stat.h>
-
-#include <assert.h>
-#include <err.h>
-#include <errno.h>
-#include <fts.h>
-#include <locale.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "extern.h"
-
-#define STRIP_TRAILING_SLASH(p) { \
- while ((p).p_end > (p).p_path + 1 && (p).p_end[-1] == '/') \
- *--(p).p_end = '\0'; \
-}
-
-static char empty[] = "";
-PATH_T to = { .p_end = to.p_path, .target_end = empty };
-
-uid_t myuid;
-int Hflag, Lflag, Rflag, Pflag, fflag, iflag, lflag, pflag, rflag, vflag, Nflag;
-mode_t myumask;
-sig_atomic_t pinfo;
-
-enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
-
-static int copy(char *[], enum op, int);
-
-static void
-progress(int sig __unused)
-{
-
- pinfo++;
-}
-
-int
-main(int argc, char *argv[])
-{
- struct stat to_stat, tmp_stat;
- enum op type;
- int ch, fts_options, r, have_trailing_slash;
- char *target, **src;
-
- setprogname(argv[0]);
- (void)setlocale(LC_ALL, "");
-
- Hflag = Lflag = Pflag = Rflag = 0;
- while ((ch = getopt(argc, argv, "HLNPRfailprv")) != -1)
- switch (ch) {
- case 'H':
- Hflag = 1;
- Lflag = Pflag = 0;
- break;
- case 'L':
- Lflag = 1;
- Hflag = Pflag = 0;
- break;
- case 'N':
- Nflag = 1;
- break;
- case 'P':
- Pflag = 1;
- Hflag = Lflag = 0;
- break;
- case 'R':
- Rflag = 1;
- break;
- case 'a':
- Pflag = 1;
- pflag = 1;
- Rflag = 1;
- Hflag = Lflag = 0;
- break;
- case 'f':
- fflag = 1;
- iflag = 0;
- break;
- case 'i':
- iflag = isatty(fileno(stdin));
- fflag = 0;
- break;
- case 'l':
- lflag = 1;
- break;
- case 'p':
- pflag = 1;
- break;
- case 'r':
- rflag = 1;
- break;
- case 'v':
- vflag = 1;
- break;
- case '?':
- default:
- usage();
- /* NOTREACHED */
- }
- argc -= optind;
- argv += optind;
-
- if (argc < 2)
- usage();
-
- fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
- if (rflag) {
- if (Rflag) {
- errx(EXIT_FAILURE,
- "the -R and -r options may not be specified together.");
- /* NOTREACHED */
- }
- if (Hflag || Lflag || Pflag) {
- errx(EXIT_FAILURE,
- "the -H, -L, and -P options may not be specified with the -r option.");
- /* NOTREACHED */
- }
- fts_options &= ~FTS_PHYSICAL;
- fts_options |= FTS_LOGICAL;
- }
-
- if (Rflag) {
- if (Hflag)
- fts_options |= FTS_COMFOLLOW;
- if (Lflag) {
- fts_options &= ~FTS_PHYSICAL;
- fts_options |= FTS_LOGICAL;
- }
- } else if (!Pflag) {
- fts_options &= ~FTS_PHYSICAL;
- fts_options |= FTS_LOGICAL | FTS_COMFOLLOW;
- }
-
- myuid = getuid();
-
- /* Copy the umask for explicit mode setting. */
- myumask = umask(0);
- (void)umask(myumask);
-
- /* Save the target base in "to". */
- target = argv[--argc];
- if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path))
- errx(EXIT_FAILURE, "%s: name too long", target);
- to.p_end = to.p_path + strlen(to.p_path);
- have_trailing_slash = (to.p_end[-1] == '/');
- if (have_trailing_slash)
- STRIP_TRAILING_SLASH(to);
- to.target_end = to.p_end;
-
- /* Set end of argument list for fts(3). */
- argv[argc] = NULL;
-
- (void)signal(SIGINFO, progress);
-
- /*
- * Cp has two distinct cases:
- *
- * cp [-R] source target
- * cp [-R] source1 ... sourceN directory
- *
- * In both cases, source can be either a file or a directory.
- *
- * In (1), the target becomes a copy of the source. That is, if the
- * source is a file, the target will be a file, and likewise for
- * directories.
- *
- * In (2), the real target is not directory, but "directory/source".
- */
- if (Pflag)
- r = lstat(to.p_path, &to_stat);
- else
- r = stat(to.p_path, &to_stat);
- if (r == -1 && errno != ENOENT) {
- err(EXIT_FAILURE, "%s", to.p_path);
- /* NOTREACHED */
- }
- if (r == -1 || !S_ISDIR(to_stat.st_mode)) {
- /*
- * Case (1). Target is not a directory.
- */
- if (argc > 1)
- usage();
- /*
- * Need to detect the case:
- * cp -R dir foo
- * Where dir is a directory and foo does not exist, where
- * we want pathname concatenations turned on but not for
- * the initial mkdir().
- */
- if (r == -1) {
- if (rflag || (Rflag && (Lflag || Hflag)))
- r = stat(*argv, &tmp_stat);
- else
- r = lstat(*argv, &tmp_stat);
- if (r == -1) {
- err(EXIT_FAILURE, "%s", *argv);
- /* NOTREACHED */
- }
-
- if (S_ISDIR(tmp_stat.st_mode) && (Rflag || rflag))
- type = DIR_TO_DNE;
- else
- type = FILE_TO_FILE;
- } else
- type = FILE_TO_FILE;
-
- if (have_trailing_slash && type == FILE_TO_FILE) {
- if (r == -1)
- errx(1, "directory %s does not exist",
- to.p_path);
- else
- errx(1, "%s is not a directory", to.p_path);
- }
- } else {
- /*
- * Case (2). Target is a directory.
- */
- type = FILE_TO_DIR;
- }
-
- /*
- * make "cp -rp src/ dst" behave like "cp -rp src dst" not
- * like "cp -rp src/. dst"
- */
- for (src = argv; *src; src++) {
- size_t len = strlen(*src);
- while (len-- > 1 && (*src)[len] == '/')
- (*src)[len] = '\0';
- }
-
- exit(copy(argv, type, fts_options));
- /* NOTREACHED */
-}
-
-static int dnestack[MAXPATHLEN]; /* unlikely we'll have more nested dirs */
-static ssize_t dnesp;
-static void
-pushdne(int dne)
-{
-
- dnestack[dnesp++] = dne;
- assert(dnesp < MAXPATHLEN);
-}
-
-static int
-popdne(void)
-{
- int rv;
-
- rv = dnestack[--dnesp];
- assert(dnesp >= 0);
- return rv;
-}
-
-static int
-copy(char *argv[], enum op type, int fts_options)
-{
- struct stat to_stat;
- FTS *ftsp;
- FTSENT *curr;
- int base, dne, sval;
- int this_failed, any_failed;
- size_t nlen;
- char *p, *target_mid;
-
- base = 0; /* XXX gcc -Wuninitialized (see comment below) */
-
- if ((ftsp = fts_open(argv, fts_options, NULL)) == NULL)
- err(EXIT_FAILURE, "%s", argv[0]);
- /* NOTREACHED */
- for (any_failed = 0; (curr = fts_read(ftsp)) != NULL;) {
- this_failed = 0;
- switch (curr->fts_info) {
- case FTS_NS:
- case FTS_DNR:
- case FTS_ERR:
- warnx("%s: %s", curr->fts_path,
- strerror(curr->fts_errno));
- this_failed = any_failed = 1;
- continue;
- case FTS_DC: /* Warn, continue. */
- warnx("%s: directory causes a cycle", curr->fts_path);
- this_failed = any_failed = 1;
- continue;
- }
-
- /*
- * If we are in case (2) or (3) above, we need to append the
- * source name to the target name.
- */
- if (type != FILE_TO_FILE) {
- if ((curr->fts_namelen +
- to.target_end - to.p_path + 1) > MAXPATHLEN) {
- warnx("%s/%s: name too long (not copied)",
- to.p_path, curr->fts_name);
- this_failed = any_failed = 1;
- continue;
- }
-
- /*
- * Need to remember the roots of traversals to create
- * correct pathnames. If there's a directory being
- * copied to a non-existent directory, e.g.
- * cp -R a/dir noexist
- * the resulting path name should be noexist/foo, not
- * noexist/dir/foo (where foo is a file in dir), which
- * is the case where the target exists.
- *
- * Also, check for "..". This is for correct path
- * concatentation for paths ending in "..", e.g.
- * cp -R .. /tmp
- * Paths ending in ".." are changed to ".". This is
- * tricky, but seems the easiest way to fix the problem.
- *
- * XXX
- * Since the first level MUST be FTS_ROOTLEVEL, base
- * is always initialized.
- */
- if (curr->fts_level == FTS_ROOTLEVEL) {
- if (type != DIR_TO_DNE) {
- p = strrchr(curr->fts_path, '/');
- base = (p == NULL) ? 0 :
- (int)(p - curr->fts_path + 1);
-
- if (!strcmp(&curr->fts_path[base],
- ".."))
- base += 1;
- } else
- base = curr->fts_pathlen;
- }
-
- p = &curr->fts_path[base];
- nlen = curr->fts_pathlen - base;
- target_mid = to.target_end;
- if (*p != '/' && target_mid[-1] != '/')
- *target_mid++ = '/';
- *target_mid = 0;
-
- if (target_mid - to.p_path + nlen >= PATH_MAX) {
- warnx("%s%s: name too long (not copied)",
- to.p_path, p);
- this_failed = any_failed = 1;
- continue;
- }
- (void)strncat(target_mid, p, nlen);
- to.p_end = target_mid + nlen;
- *to.p_end = 0;
- STRIP_TRAILING_SLASH(to);
- }
-
- sval = Pflag ? lstat(to.p_path, &to_stat) : stat(to.p_path, &to_stat);
- /* Not an error but need to remember it happened */
- if (sval == -1)
- dne = 1;
- else {
- if (to_stat.st_dev == curr->fts_statp->st_dev &&
- to_stat.st_ino == curr->fts_statp->st_ino) {
- warnx("%s and %s are identical (not copied).",
- to.p_path, curr->fts_path);
- this_failed = any_failed = 1;
- if (S_ISDIR(curr->fts_statp->st_mode))
- (void)fts_set(ftsp, curr, FTS_SKIP);
- continue;
- }
- if (!S_ISDIR(curr->fts_statp->st_mode) &&
- S_ISDIR(to_stat.st_mode)) {
- warnx("cannot overwrite directory %s with non-directory %s",
- to.p_path, curr->fts_path);
- this_failed = any_failed = 1;
- continue;
- }
- dne = 0;
- }
-
- switch (curr->fts_statp->st_mode & S_IFMT) {
- case S_IFLNK:
- /* Catch special case of a non dangling symlink */
- if((fts_options & FTS_LOGICAL) ||
- ((fts_options & FTS_COMFOLLOW) && curr->fts_level == 0)) {
- if (copy_file(curr, dne))
- this_failed = any_failed = 1;
- } else {
- if (copy_link(curr, !dne))
- this_failed = any_failed = 1;
- }
- break;
- case S_IFDIR:
- if (!Rflag && !rflag) {
- if (curr->fts_info == FTS_D)
- warnx("%s is a directory (not copied).",
- curr->fts_path);
- (void)fts_set(ftsp, curr, FTS_SKIP);
- this_failed = any_failed = 1;
- break;
- }
-
- /*
- * Directories get noticed twice:
- * In the first pass, create it if needed.
- * In the second pass, after the children have been copied, set the permissions.
- */
- if (curr->fts_info == FTS_D) /* First pass */
- {
- /*
- * If the directory doesn't exist, create the new
- * one with the from file mode plus owner RWX bits,
- * modified by the umask. Trade-off between being
- * able to write the directory (if from directory is
- * 555) and not causing a permissions race. If the
- * umask blocks owner writes, we fail..
- */
- pushdne(dne);
- if (dne) {
- if (mkdir(to.p_path,
- curr->fts_statp->st_mode | S_IRWXU) < 0)
- err(EXIT_FAILURE, "%s",
- to.p_path);
- /* NOTREACHED */
- } else if (!S_ISDIR(to_stat.st_mode)) {
- errno = ENOTDIR;
- err(EXIT_FAILURE, "%s",
- to.p_path);
- /* NOTREACHED */
- }
- }
- else if (curr->fts_info == FTS_DP) /* Second pass */
- {
- /*
- * If not -p and directory didn't exist, set it to be
- * the same as the from directory, umodified by the
- * umask; arguably wrong, but it's been that way
- * forever.
- */
- if (pflag && setfile(curr->fts_statp, 0))
- this_failed = any_failed = 1;
- else if ((dne = popdne()))
- (void)chmod(to.p_path,
- curr->fts_statp->st_mode);
- }
- else
- {
- warnx("directory %s encountered when not expected.",
- curr->fts_path);
- this_failed = any_failed = 1;
- break;
- }
-
- break;
- case S_IFBLK:
- case S_IFCHR:
- if (Rflag) {
- if (copy_special(curr->fts_statp, !dne))
- this_failed = any_failed = 1;
- } else
- if (copy_file(curr, dne))
- this_failed = any_failed = 1;
- break;
- case S_IFIFO:
- if (Rflag) {
- if (copy_fifo(curr->fts_statp, !dne))
- this_failed = any_failed = 1;
- } else
- if (copy_file(curr, dne))
- this_failed = any_failed = 1;
- break;
- default:
- if (copy_file(curr, dne))
- this_failed = any_failed = 1;
- break;
- }
- if (vflag && !this_failed)
- (void)printf("%s -> %s\n", curr->fts_path, to.p_path);
- }
- if (errno) {
- err(EXIT_FAILURE, "fts_read");
- /* NOTREACHED */
- }
- (void)fts_close(ftsp);
- return (any_failed);
-}
diff --git a/toolbox/upstream-netbsd/bin/cp/extern.h b/toolbox/upstream-netbsd/bin/cp/extern.h
deleted file mode 100644
index e393844..0000000
--- a/toolbox/upstream-netbsd/bin/cp/extern.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/* $NetBSD: extern.h,v 1.17 2012/01/04 15:58:37 christos Exp $ */
-
-/*-
- * Copyright (c) 1991, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)extern.h 8.2 (Berkeley) 4/1/94
- */
-
-#ifndef _EXTERN_H_
-#define _EXTERN_H_
-
-typedef struct {
- char *p_end; /* pointer to NULL at end of path */
- char *target_end; /* pointer to end of target base */
- char p_path[MAXPATHLEN + 1]; /* pointer to the start of a path */
-} PATH_T;
-
-extern PATH_T to;
-extern uid_t myuid;
-extern int Rflag, rflag, Hflag, Lflag, Pflag, fflag, iflag, lflag, pflag, Nflag;
-extern mode_t myumask;
-extern sig_atomic_t pinfo;
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-int copy_fifo(struct stat *, int);
-int copy_file(FTSENT *, int);
-int copy_link(FTSENT *, int);
-int copy_special(struct stat *, int);
-int set_utimes(const char *, struct stat *);
-int setfile(struct stat *, int);
-void usage(void) __attribute__((__noreturn__));
-__END_DECLS
-
-#endif /* !_EXTERN_H_ */
diff --git a/toolbox/upstream-netbsd/bin/cp/utils.c b/toolbox/upstream-netbsd/bin/cp/utils.c
deleted file mode 100644
index d8f900a..0000000
--- a/toolbox/upstream-netbsd/bin/cp/utils.c
+++ /dev/null
@@ -1,444 +0,0 @@
-/* $NetBSD: utils.c,v 1.42 2013/12/11 06:00:11 dholland Exp $ */
-
-/*-
- * Copyright (c) 1991, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94";
-#else
-__RCSID("$NetBSD: utils.c,v 1.42 2013/12/11 06:00:11 dholland Exp $");
-#endif
-#endif /* not lint */
-
-#include <sys/mman.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/extattr.h>
-
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <fts.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "extern.h"
-
-#define MMAP_MAX_SIZE (8 * 1048576)
-#define MMAP_MAX_WRITE (64 * 1024)
-
-int
-set_utimes(const char *file, struct stat *fs)
-{
- static struct timeval tv[2];
-
-#ifdef __ANDROID__
- tv[0].tv_sec = fs->st_atime;
- tv[0].tv_usec = 0;
- tv[1].tv_sec = fs->st_mtime;
- tv[1].tv_usec = 0;
-
- if (utimes(file, tv)) {
- warn("utimes: %s", file);
- return 1;
- }
-#else
- TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec);
- TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec);
-
- if (lutimes(file, tv)) {
- warn("lutimes: %s", file);
- return (1);
- }
-#endif
- return (0);
-}
-
-struct finfo {
- const char *from;
- const char *to;
- size_t size;
-};
-
-static void
-progress(const struct finfo *fi, size_t written)
-{
- int pcent = (int)((100.0 * written) / fi->size);
-
- pinfo = 0;
- (void)fprintf(stderr, "%s => %s %zu/%zu bytes %d%% written\n",
- fi->from, fi->to, written, fi->size, pcent);
-}
-
-int
-copy_file(FTSENT *entp, int dne)
-{
- static char buf[MAXBSIZE];
- struct stat to_stat, *fs;
- int ch, checkch, from_fd, rcount, rval, to_fd, tolnk, wcount;
- char *p;
- size_t ptotal = 0;
-
- if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {
- warn("%s", entp->fts_path);
- return (1);
- }
-
- to_fd = -1;
- fs = entp->fts_statp;
- tolnk = ((Rflag && !(Lflag || Hflag)) || Pflag);
-
- /*
- * If the file exists and we're interactive, verify with the user.
- * If the file DNE, set the mode to be the from file, minus setuid
- * bits, modified by the umask; arguably wrong, but it makes copying
- * executables work right and it's been that way forever. (The
- * other choice is 666 or'ed with the execute bits on the from file
- * modified by the umask.)
- */
- if (!dne) {
- struct stat sb;
- int sval;
-
- if (iflag) {
- (void)fprintf(stderr, "overwrite %s? ", to.p_path);
- checkch = ch = getchar();
- while (ch != '\n' && ch != EOF)
- ch = getchar();
- if (checkch != 'y' && checkch != 'Y') {
- (void)close(from_fd);
- return (0);
- }
- }
-
- sval = tolnk ?
- lstat(to.p_path, &sb) : stat(to.p_path, &sb);
- if (sval == -1) {
- warn("stat: %s", to.p_path);
- (void)close(from_fd);
- return (1);
- }
-
- if (!(tolnk && S_ISLNK(sb.st_mode)))
- to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
- } else
- to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
- fs->st_mode & ~(S_ISUID | S_ISGID));
-
- if (to_fd == -1 && (fflag || tolnk)) {
- /*
- * attempt to remove existing destination file name and
- * create a new file
- */
- (void)unlink(to.p_path);
- to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
- fs->st_mode & ~(S_ISUID | S_ISGID));
- }
-
- if (to_fd == -1) {
- warn("%s", to.p_path);
- (void)close(from_fd);
- return (1);
- }
-
- rval = 0;
-
- /* if hard linking then simply close the open fds, link and return */
- if (lflag) {
- (void)close(from_fd);
- (void)close(to_fd);
- (void)unlink(to.p_path);
- if (link(entp->fts_path, to.p_path)) {
- warn("%s", to.p_path);
- return (1);
- }
- return (0);
- }
-
- /*
- * There's no reason to do anything other than close the file
- * now if it's empty, so let's not bother.
- */
-#ifndef __ANDROID__ // Files in /proc report length 0. mmap will fail but we'll fall back to read.
- if (fs->st_size > 0) {
-#endif
- struct finfo fi;
-
- fi.from = entp->fts_path;
- fi.to = to.p_path;
- fi.size = (size_t)fs->st_size;
-
- /*
- * Mmap and write if less than 8M (the limit is so
- * we don't totally trash memory on big files).
- * This is really a minor hack, but it wins some CPU back.
- */
- bool use_read;
-
- use_read = true;
- if (fs->st_size <= MMAP_MAX_SIZE) {
- size_t fsize = (size_t)fs->st_size;
- p = mmap(NULL, fsize, PROT_READ, MAP_FILE|MAP_SHARED,
- from_fd, (off_t)0);
- if (p != MAP_FAILED) {
- size_t remainder;
-
- use_read = false;
-
- (void) madvise(p, (size_t)fs->st_size,
- MADV_SEQUENTIAL);
-
- /*
- * Write out the data in small chunks to
- * avoid locking the output file for a
- * long time if the reading the data from
- * the source is slow.
- */
- remainder = fsize;
- do {
- ssize_t chunk;
-
- chunk = (remainder > MMAP_MAX_WRITE) ?
- MMAP_MAX_WRITE : remainder;
- if (write(to_fd, &p[fsize - remainder],
- chunk) != chunk) {
- warn("%s", to.p_path);
- rval = 1;
- break;
- }
- remainder -= chunk;
- ptotal += chunk;
- if (pinfo)
- progress(&fi, ptotal);
- } while (remainder > 0);
-
- if (munmap(p, fsize) < 0) {
- warn("%s", entp->fts_path);
- rval = 1;
- }
- }
- }
-
- if (use_read) {
- while ((rcount = read(from_fd, buf, MAXBSIZE)) > 0) {
- wcount = write(to_fd, buf, (size_t)rcount);
- if (rcount != wcount || wcount == -1) {
- warn("%s", to.p_path);
- rval = 1;
- break;
- }
- ptotal += wcount;
- if (pinfo)
- progress(&fi, ptotal);
- }
- if (rcount < 0) {
- warn("%s", entp->fts_path);
- rval = 1;
- }
- }
-#ifndef __ANDROID__
- }
-#endif
-
-#ifndef __ANDROID__
- if (pflag && (fcpxattr(from_fd, to_fd) != 0))
- warn("%s: error copying extended attributes", to.p_path);
-#endif
-
- (void)close(from_fd);
-
- if (rval == 1) {
- (void)close(to_fd);
- return (1);
- }
-
- if (pflag && setfile(fs, to_fd))
- rval = 1;
- /*
- * If the source was setuid or setgid, lose the bits unless the
- * copy is owned by the same user and group.
- */
-#define RETAINBITS \
- (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
- if (!pflag && dne
- && fs->st_mode & (S_ISUID | S_ISGID) && fs->st_uid == myuid) {
- if (fstat(to_fd, &to_stat)) {
- warn("%s", to.p_path);
- rval = 1;
- } else if (fs->st_gid == to_stat.st_gid &&
- fchmod(to_fd, fs->st_mode & RETAINBITS & ~myumask)) {
- warn("%s", to.p_path);
- rval = 1;
- }
- }
- if (close(to_fd)) {
- warn("%s", to.p_path);
- rval = 1;
- }
- /* set the mod/access times now after close of the fd */
- if (pflag && set_utimes(to.p_path, fs)) {
- rval = 1;
- }
- return (rval);
-}
-
-int
-copy_link(FTSENT *p, int exists)
-{
- int len;
- char target[MAXPATHLEN];
-
- if ((len = readlink(p->fts_path, target, sizeof(target)-1)) == -1) {
- warn("readlink: %s", p->fts_path);
- return (1);
- }
- target[len] = '\0';
- if (exists && unlink(to.p_path)) {
- warn("unlink: %s", to.p_path);
- return (1);
- }
- if (symlink(target, to.p_path)) {
- warn("symlink: %s", target);
- return (1);
- }
- return (pflag ? setfile(p->fts_statp, 0) : 0);
-}
-
-int
-copy_fifo(struct stat *from_stat, int exists)
-{
- if (exists && unlink(to.p_path)) {
- warn("unlink: %s", to.p_path);
- return (1);
- }
- if (mkfifo(to.p_path, from_stat->st_mode)) {
- warn("mkfifo: %s", to.p_path);
- return (1);
- }
- return (pflag ? setfile(from_stat, 0) : 0);
-}
-
-int
-copy_special(struct stat *from_stat, int exists)
-{
- if (exists && unlink(to.p_path)) {
- warn("unlink: %s", to.p_path);
- return (1);
- }
- if (mknod(to.p_path, from_stat->st_mode, from_stat->st_rdev)) {
- warn("mknod: %s", to.p_path);
- return (1);
- }
- return (pflag ? setfile(from_stat, 0) : 0);
-}
-
-
-/*
- * Function: setfile
- *
- * Purpose:
- * Set the owner/group/permissions for the "to" file to the information
- * in the stat structure. If fd is zero, also call set_utimes() to set
- * the mod/access times. If fd is non-zero, the caller must do a utimes
- * itself after close(fd).
- */
-int
-setfile(struct stat *fs, int fd)
-{
- int rval, islink;
-
- rval = 0;
- islink = S_ISLNK(fs->st_mode);
- fs->st_mode &= S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO;
-
- /*
- * Changing the ownership probably won't succeed, unless we're root
- * or POSIX_CHOWN_RESTRICTED is not set. Set uid/gid before setting
- * the mode; current BSD behavior is to remove all setuid bits on
- * chown. If chown fails, lose setuid/setgid bits.
- */
- if (fd ? fchown(fd, fs->st_uid, fs->st_gid) :
- lchown(to.p_path, fs->st_uid, fs->st_gid)) {
- if (errno != EPERM) {
- warn("chown: %s", to.p_path);
- rval = 1;
- }
- fs->st_mode &= ~(S_ISUID | S_ISGID);
- }
-#ifdef __ANDROID__
- if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode)) {
-#else
- if (fd ? fchmod(fd, fs->st_mode) : lchmod(to.p_path, fs->st_mode)) {
-#endif
- warn("chmod: %s", to.p_path);
- rval = 1;
- }
-
-#ifndef __ANDROID__
- if (!islink && !Nflag) {
- unsigned long fflags = fs->st_flags;
- /*
- * XXX
- * NFS doesn't support chflags; ignore errors unless
- * there's reason to believe we're losing bits.
- * (Note, this still won't be right if the server
- * supports flags and we were trying to *remove* flags
- * on a file that we copied, i.e., that we didn't create.)
- */
- errno = 0;
- if ((fd ? fchflags(fd, fflags) :
- chflags(to.p_path, fflags)) == -1)
- if (errno != EOPNOTSUPP || fs->st_flags != 0) {
- warn("chflags: %s", to.p_path);
- rval = 1;
- }
- }
-#endif
- /* if fd is non-zero, caller must call set_utimes() after close() */
- if (fd == 0 && set_utimes(to.p_path, fs))
- rval = 1;
- return (rval);
-}
-
-void
-usage(void)
-{
- (void)fprintf(stderr,
- "usage: %s [-R [-H | -L | -P]] [-f | -i] [-alNpv] src target\n"
- " %s [-R [-H | -L | -P]] [-f | -i] [-alNpv] src1 ... srcN directory\n",
- getprogname(), getprogname());
- exit(1);
- /* NOTREACHED */
-}
diff --git a/toolbox/upstream-netbsd/bin/kill/kill.c b/toolbox/upstream-netbsd/bin/kill/kill.c
deleted file mode 100644
index 0592577..0000000
--- a/toolbox/upstream-netbsd/bin/kill/kill.c
+++ /dev/null
@@ -1,253 +0,0 @@
-/* $NetBSD: kill.c,v 1.27 2011/08/29 14:51:18 joerg Exp $ */
-
-/*
- * Copyright (c) 1988, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if !defined(lint) && !defined(SHELL)
-__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\
- The Regents of the University of California. All rights reserved.");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)kill.c 8.4 (Berkeley) 4/28/95";
-#else
-__RCSID("$NetBSD: kill.c,v 1.27 2011/08/29 14:51:18 joerg Exp $");
-#endif
-#endif /* not lint */
-
-#include <ctype.h>
-#include <err.h>
-#include <errno.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <inttypes.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-#include <locale.h>
-#include <sys/ioctl.h>
-
-#ifdef SHELL /* sh (aka ash) builtin */
-int killcmd(int, char *argv[]);
-#define main killcmd
-#include "../../bin/sh/bltin/bltin.h"
-#endif /* SHELL */
-
-__dead static void nosig(char *);
-static void printsignals(FILE *);
-static int signame_to_signum(char *);
-__dead static void usage(void);
-
-int
-main(int argc, char *argv[])
-{
- int errors;
- intmax_t numsig, pid;
- char *ep;
-
- setprogname(argv[0]);
- setlocale(LC_ALL, "");
- if (argc < 2)
- usage();
-
- numsig = SIGTERM;
-
- argc--, argv++;
- if (strcmp(*argv, "-l") == 0) {
- argc--, argv++;
- if (argc > 1)
- usage();
- if (argc == 1) {
- if (isdigit((unsigned char)**argv) == 0)
- usage();
- numsig = strtoimax(*argv, &ep, 10);
- /* check for correctly parsed number */
- if (*ep != '\0' || numsig == INTMAX_MIN || numsig == INTMAX_MAX) {
- errx(EXIT_FAILURE, "illegal signal number: %s",
- *argv);
- /* NOTREACHED */
- }
- if (numsig >= 128)
- numsig -= 128;
- /* and whether it fits into signals range */
- if (numsig <= 0 || numsig >= NSIG)
- nosig(*argv);
- printf("%s\n", sys_signame[(int) numsig]);
- exit(0);
- }
- printsignals(stdout);
- exit(0);
- }
-
- if (!strcmp(*argv, "-s")) {
- argc--, argv++;
- if (argc < 1) {
- warnx("option requires an argument -- s");
- usage();
- }
- if (strcmp(*argv, "0")) {
- if ((numsig = signame_to_signum(*argv)) < 0)
- nosig(*argv);
- } else
- numsig = 0;
- argc--, argv++;
- } else if (**argv == '-') {
- char *sn = *argv + 1;
- if (isalpha((unsigned char)*sn)) {
- if ((numsig = signame_to_signum(sn)) < 0)
- nosig(sn);
- } else if (isdigit((unsigned char)*sn)) {
- numsig = strtoimax(sn, &ep, 10);
- /* check for correctly parsed number */
- if (*ep || numsig == INTMAX_MIN || numsig == INTMAX_MAX ) {
- errx(EXIT_FAILURE, "illegal signal number: %s",
- sn);
- /* NOTREACHED */
- }
- /* and whether it fits into signals range */
- if (numsig < 0 || numsig >= NSIG)
- nosig(sn);
- } else
- nosig(sn);
- argc--, argv++;
- }
-
- if (argc == 0)
- usage();
-
- for (errors = 0; argc; argc--, argv++) {
-#ifdef SHELL
- extern int getjobpgrp(const char *);
- if (*argv[0] == '%') {
- pid = getjobpgrp(*argv);
- if (pid == 0) {
- warnx("illegal job id: %s", *argv);
- errors = 1;
- continue;
- }
- } else
-#endif
- {
- pid = strtoimax(*argv, &ep, 10);
- /* make sure the pid is a number and fits into pid_t */
- if (!**argv || *ep || pid == INTMAX_MIN ||
- pid == INTMAX_MAX || pid != (pid_t) pid) {
-
- warnx("illegal process id: %s", *argv);
- errors = 1;
- continue;
- }
- }
- if (kill((pid_t) pid, (int) numsig) == -1) {
- warn("%s", *argv);
- errors = 1;
- }
-#ifdef SHELL
- /* Wakeup the process if it was suspended, so it can
- exit without an explicit 'fg'. */
- if (numsig == SIGTERM || numsig == SIGHUP)
- kill((pid_t) pid, SIGCONT);
-#endif
- }
-
- exit(errors);
- /* NOTREACHED */
-}
-
-static int
-signame_to_signum(char *sig)
-{
- int n;
-
- if (strncasecmp(sig, "sig", 3) == 0)
- sig += 3;
- for (n = 1; n < NSIG; n++) {
- if (!strcasecmp(sys_signame[n], sig))
- return (n);
- }
- return (-1);
-}
-
-static void
-nosig(char *name)
-{
-
- warnx("unknown signal %s; valid signals:", name);
- printsignals(stderr);
- exit(1);
- /* NOTREACHED */
-}
-
-static void
-printsignals(FILE *fp)
-{
- int sig;
- int len, nl;
- const char *name;
- int termwidth = 80;
-
- if (isatty(fileno(fp))) {
- struct winsize win;
- if (ioctl(fileno(fp), TIOCGWINSZ, &win) == 0 && win.ws_col > 0)
- termwidth = win.ws_col;
- }
-
- for (len = 0, sig = 1; sig < NSIG; sig++) {
- name = sys_signame[sig];
- nl = 1 + strlen(name);
-
- if (len + nl >= termwidth) {
- fprintf(fp, "\n");
- len = 0;
- } else
- if (len != 0)
- fprintf(fp, " ");
- len += nl;
- fprintf(fp, "%s", name);
- }
- if (len != 0)
- fprintf(fp, "\n");
-}
-
-static void
-usage(void)
-{
-
- fprintf(stderr, "usage: %s [-s signal_name] pid ...\n"
- " %s -l [exit_status]\n"
- " %s -signal_name pid ...\n"
- " %s -signal_number pid ...\n",
- getprogname(), getprogname(), getprogname(), getprogname());
- exit(1);
- /* NOTREACHED */
-}
diff --git a/toolbox/upstream-netbsd/bin/ln/ln.c b/toolbox/upstream-netbsd/bin/ln/ln.c
deleted file mode 100644
index 9127477..0000000
--- a/toolbox/upstream-netbsd/bin/ln/ln.c
+++ /dev/null
@@ -1,230 +0,0 @@
-/* $NetBSD: ln.c,v 1.35 2011/08/29 14:38:30 joerg Exp $ */
-
-/*
- * Copyright (c) 1987, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994\
- The Regents of the University of California. All rights reserved.");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)ln.c 8.2 (Berkeley) 3/31/94";
-#else
-__RCSID("$NetBSD: ln.c,v 1.35 2011/08/29 14:38:30 joerg Exp $");
-#endif
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/stat.h>
-
-#include <err.h>
-#include <errno.h>
-#include <locale.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-static int fflag; /* Unlink existing files. */
-static int hflag; /* Check new name for symlink first. */
-static int iflag; /* Interactive mode. */
-static int sflag; /* Symbolic, not hard, link. */
-static int vflag; /* Verbose output */
-
- /* System link call. */
-static int (*linkf)(const char *, const char *);
-static char linkch;
-
-static int linkit(const char *, const char *, int);
-__dead static void usage(void);
-
-int
-main(int argc, char *argv[])
-{
- struct stat sb;
- int ch, exitval;
- char *sourcedir;
-
- setprogname(argv[0]);
- (void)setlocale(LC_ALL, "");
-
- while ((ch = getopt(argc, argv, "fhinsv")) != -1)
- switch (ch) {
- case 'f':
- fflag = 1;
- iflag = 0;
- break;
- case 'h':
- case 'n':
- hflag = 1;
- break;
- case 'i':
- iflag = 1;
- fflag = 0;
- break;
- case 's':
- sflag = 1;
- break;
- case 'v':
- vflag = 1;
- break;
- case '?':
- default:
- usage();
- /* NOTREACHED */
- }
-
- argv += optind;
- argc -= optind;
-
- if (sflag) {
- linkf = symlink;
- linkch = '-';
- } else {
- linkf = link;
- linkch = '=';
- }
-
- switch(argc) {
- case 0:
- usage();
- /* NOTREACHED */
- case 1: /* ln target */
- exit(linkit(argv[0], ".", 1));
- /* NOTREACHED */
- case 2: /* ln target source */
- exit(linkit(argv[0], argv[1], 0));
- /* NOTREACHED */
- }
-
- /* ln target1 target2 directory */
- sourcedir = argv[argc - 1];
- if (hflag && lstat(sourcedir, &sb) == 0 && S_ISLNK(sb.st_mode)) {
- /* we were asked not to follow symlinks, but found one at
- the target--simulate "not a directory" error */
- errno = ENOTDIR;
- err(EXIT_FAILURE, "%s", sourcedir);
- /* NOTREACHED */
- }
- if (stat(sourcedir, &sb)) {
- err(EXIT_FAILURE, "%s", sourcedir);
- /* NOTREACHED */
- }
- if (!S_ISDIR(sb.st_mode)) {
- usage();
- /* NOTREACHED */
- }
- for (exitval = 0; *argv != sourcedir; ++argv)
- exitval |= linkit(*argv, sourcedir, 1);
- exit(exitval);
- /* NOTREACHED */
-}
-
-static int
-linkit(const char *target, const char *source, int isdir)
-{
- struct stat sb;
- const char *p;
- char path[MAXPATHLEN];
- int ch, exists, first;
-
- if (!sflag) {
- /* If target doesn't exist, quit now. */
- if (stat(target, &sb)) {
- warn("%s", target);
- return (1);
- }
- }
-
- /* If the source is a directory (and not a symlink if hflag),
- append the target's name. */
- if (isdir ||
- (!lstat(source, &sb) && S_ISDIR(sb.st_mode)) ||
- (!hflag && !stat(source, &sb) && S_ISDIR(sb.st_mode))) {
- if ((p = strrchr(target, '/')) == NULL)
- p = target;
- else
- ++p;
- (void)snprintf(path, sizeof(path), "%s/%s", source, p);
- source = path;
- }
-
- exists = !lstat(source, &sb);
-
- /*
- * If the file exists, then unlink it forcibly if -f was specified
- * and interactively if -i was specified.
- */
- if (fflag && exists) {
- if (unlink(source)) {
- warn("%s", source);
- return (1);
- }
- } else if (iflag && exists) {
- fflush(stdout);
- (void)fprintf(stderr, "replace %s? ", source);
-
- first = ch = getchar();
- while (ch != '\n' && ch != EOF)
- ch = getchar();
- if (first != 'y' && first != 'Y') {
- (void)fprintf(stderr, "not replaced\n");
- return (1);
- }
-
- if (unlink(source)) {
- warn("%s", source);
- return (1);
- }
- }
-
- /* Attempt the link. */
- if ((*linkf)(target, source)) {
- warn("%s", source);
- return (1);
- }
- if (vflag)
- (void)printf("%s %c> %s\n", source, linkch, target);
-
- return (0);
-}
-
-static void
-usage(void)
-{
-
- (void)fprintf(stderr,
- "usage:\t%s [-fhinsv] file1 file2\n\t%s [-fhinsv] file ... directory\n",
- getprogname(), getprogname());
- exit(1);
- /* NOTREACHED */
-}
diff --git a/toolbox/upstream-netbsd/bin/mv/mv.c b/toolbox/upstream-netbsd/bin/mv/mv.c
deleted file mode 100644
index 4be6c30..0000000
--- a/toolbox/upstream-netbsd/bin/mv/mv.c
+++ /dev/null
@@ -1,396 +0,0 @@
-/* $NetBSD: mv.c,v 1.43 2011/08/29 14:46:54 joerg Exp $ */
-
-/*
- * Copyright (c) 1989, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Ken Smith of The State University of New York at Buffalo.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\
- The Regents of the University of California. All rights reserved.");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94";
-#else
-__RCSID("$NetBSD: mv.c,v 1.43 2011/08/29 14:46:54 joerg Exp $");
-#endif
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <sys/extattr.h>
-
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <grp.h>
-#include <locale.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "pathnames.h"
-
-static int fflg, iflg, vflg;
-static int stdin_ok;
-
-static int copy(char *, char *);
-static int do_move(char *, char *);
-static int fastcopy(char *, char *, struct stat *);
-__dead static void usage(void);
-
-int
-main(int argc, char *argv[])
-{
- int ch, len, rval;
- char *p, *endp;
- struct stat sb;
- char path[MAXPATHLEN + 1];
- size_t baselen;
-
- setprogname(argv[0]);
- (void)setlocale(LC_ALL, "");
-
- while ((ch = getopt(argc, argv, "ifv")) != -1)
- switch (ch) {
- case 'i':
- fflg = 0;
- iflg = 1;
- break;
- case 'f':
- iflg = 0;
- fflg = 1;
- break;
- case 'v':
- vflg = 1;
- break;
- default:
- usage();
- }
- argc -= optind;
- argv += optind;
-
- if (argc < 2)
- usage();
-
- stdin_ok = isatty(STDIN_FILENO);
-
- /*
- * If the stat on the target fails or the target isn't a directory,
- * try the move. More than 2 arguments is an error in this case.
- */
- if (stat(argv[argc - 1], &sb) || !S_ISDIR(sb.st_mode)) {
- if (argc > 2)
- usage();
- exit(do_move(argv[0], argv[1]));
- }
-
- /* It's a directory, move each file into it. */
- baselen = strlcpy(path, argv[argc - 1], sizeof(path));
- if (baselen >= sizeof(path))
- errx(1, "%s: destination pathname too long", argv[argc - 1]);
- endp = &path[baselen];
- if (!baselen || *(endp - 1) != '/') {
- *endp++ = '/';
- ++baselen;
- }
- for (rval = 0; --argc; ++argv) {
- p = *argv + strlen(*argv) - 1;
- while (*p == '/' && p != *argv)
- *p-- = '\0';
- if ((p = strrchr(*argv, '/')) == NULL)
- p = *argv;
- else
- ++p;
-
- if ((baselen + (len = strlen(p))) >= MAXPATHLEN) {
- warnx("%s: destination pathname too long", *argv);
- rval = 1;
- } else {
- memmove(endp, p, len + 1);
- if (do_move(*argv, path))
- rval = 1;
- }
- }
- exit(rval);
- /* NOTREACHED */
-}
-
-static int
-do_move(char *from, char *to)
-{
- struct stat sb;
- char modep[15];
-
- /*
- * (1) If the destination path exists, the -f option is not specified
- * and either of the following conditions are true:
- *
- * (a) The permissions of the destination path do not permit
- * writing and the standard input is a terminal.
- * (b) The -i option is specified.
- *
- * the mv utility shall write a prompt to standard error and
- * read a line from standard input. If the response is not
- * affirmative, mv shall do nothing more with the current
- * source file...
- */
- if (!fflg && !access(to, F_OK)) {
- int ask = 1;
- int ch;
-
- if (iflg) {
- if (access(from, F_OK)) {
- warn("rename %s", from);
- return (1);
- }
- (void)fprintf(stderr, "overwrite %s? ", to);
- } else if (stdin_ok && access(to, W_OK) && !stat(to, &sb)) {
- if (access(from, F_OK)) {
- warn("rename %s", from);
- return (1);
- }
- strmode(sb.st_mode, modep);
- (void)fprintf(stderr, "override %s%s%s/%s for %s? ",
- modep + 1, modep[9] == ' ' ? "" : " ",
- user_from_uid(sb.st_uid, 0),
- group_from_gid(sb.st_gid, 0), to);
- } else
- ask = 0;
- if (ask) {
- if ((ch = getchar()) != EOF && ch != '\n') {
- int ch2;
- while ((ch2 = getchar()) != EOF && ch2 != '\n')
- continue;
- }
- if (ch != 'y' && ch != 'Y')
- return (0);
- }
- }
-
- /*
- * (2) If rename() succeeds, mv shall do nothing more with the
- * current source file. If it fails for any other reason than
- * EXDEV, mv shall write a diagnostic message to the standard
- * error and do nothing more with the current source file.
- *
- * (3) If the destination path exists, and it is a file of type
- * directory and source_file is not a file of type directory,
- * or it is a file not of type directory, and source file is
- * a file of type directory, mv shall write a diagnostic
- * message to standard error, and do nothing more with the
- * current source file...
- */
- if (!rename(from, to)) {
- if (vflg)
- printf("%s -> %s\n", from, to);
- return (0);
- }
-
- if (errno != EXDEV) {
- warn("rename %s to %s", from, to);
- return (1);
- }
-
- /*
- * (4) If the destination path exists, mv shall attempt to remove it.
- * If this fails for any reason, mv shall write a diagnostic
- * message to the standard error and do nothing more with the
- * current source file...
- */
- if (!lstat(to, &sb)) {
- if ((S_ISDIR(sb.st_mode)) ? rmdir(to) : unlink(to)) {
- warn("can't remove %s", to);
- return (1);
- }
- }
-
- /*
- * (5) The file hierarchy rooted in source_file shall be duplicated
- * as a file hierarchy rooted in the destination path...
- */
- if (lstat(from, &sb)) {
- warn("%s", from);
- return (1);
- }
-
- return (S_ISREG(sb.st_mode) ?
- fastcopy(from, to, &sb) : copy(from, to));
-}
-
-static int
-fastcopy(char *from, char *to, struct stat *sbp)
-{
- struct timeval tval[2];
- static blksize_t blen;
- static char *bp;
- int nread, from_fd, to_fd;
-
- if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
- warn("%s", from);
- return (1);
- }
- if ((to_fd =
- open(to, O_CREAT | O_TRUNC | O_WRONLY, sbp->st_mode)) < 0) {
- warn("%s", to);
- (void)close(from_fd);
- return (1);
- }
- if (!blen && !(bp = malloc(blen = sbp->st_blksize))) {
- warn(NULL);
- blen = 0;
- (void)close(from_fd);
- (void)close(to_fd);
- return (1);
- }
- while ((nread = read(from_fd, bp, blen)) > 0)
- if (write(to_fd, bp, nread) != nread) {
- warn("%s", to);
- goto err;
- }
- if (nread < 0) {
- warn("%s", from);
-err: if (unlink(to))
- warn("%s: remove", to);
- (void)close(from_fd);
- (void)close(to_fd);
- return (1);
- }
-
-#ifndef __ANDROID__
- if (fcpxattr(from_fd, to_fd) == -1)
- warn("%s: error copying extended attributes", to);
-#endif
-
- (void)close(from_fd);
-#ifdef BSD4_4
- TIMESPEC_TO_TIMEVAL(&tval[0], &sbp->st_atimespec);
- TIMESPEC_TO_TIMEVAL(&tval[1], &sbp->st_mtimespec);
-#else
- tval[0].tv_sec = sbp->st_atime;
- tval[1].tv_sec = sbp->st_mtime;
- tval[0].tv_usec = 0;
- tval[1].tv_usec = 0;
-#endif
-#ifdef __SVR4
- if (utimes(to, tval))
-#else
- if (futimes(to_fd, tval))
-#endif
- warn("%s: set times", to);
- if (fchown(to_fd, sbp->st_uid, sbp->st_gid)) {
- if (errno != EPERM)
- warn("%s: set owner/group", to);
- sbp->st_mode &= ~(S_ISUID | S_ISGID);
- }
- if (fchmod(to_fd, sbp->st_mode))
- warn("%s: set mode", to);
-#ifndef __ANDROID__
- if (fchflags(to_fd, sbp->st_flags) && (errno != EOPNOTSUPP))
- warn("%s: set flags (was: 0%07o)", to, sbp->st_flags);
-#endif
-
- if (close(to_fd)) {
- warn("%s", to);
- return (1);
- }
-
- if (unlink(from)) {
- warn("%s: remove", from);
- return (1);
- }
-
- if (vflg)
- printf("%s -> %s\n", from, to);
-
- return (0);
-}
-
-static int
-copy(char *from, char *to)
-{
- pid_t pid;
- int status;
-
- if ((pid = vfork()) == 0) {
- execl(_PATH_CP, "mv", vflg ? "-PRpv" : "-PRp", "--", from, to, NULL);
- warn("%s", _PATH_CP);
- _exit(1);
- }
- if (waitpid(pid, &status, 0) == -1) {
- warn("%s: waitpid", _PATH_CP);
- return (1);
- }
- if (!WIFEXITED(status)) {
- warnx("%s: did not terminate normally", _PATH_CP);
- return (1);
- }
- if (WEXITSTATUS(status)) {
- warnx("%s: terminated with %d (non-zero) status",
- _PATH_CP, WEXITSTATUS(status));
- return (1);
- }
- if (!(pid = vfork())) {
- execl(_PATH_RM, "mv", "-rf", "--", from, NULL);
- warn("%s", _PATH_RM);
- _exit(1);
- }
- if (waitpid(pid, &status, 0) == -1) {
- warn("%s: waitpid", _PATH_RM);
- return (1);
- }
- if (!WIFEXITED(status)) {
- warnx("%s: did not terminate normally", _PATH_RM);
- return (1);
- }
- if (WEXITSTATUS(status)) {
- warnx("%s: terminated with %d (non-zero) status",
- _PATH_RM, WEXITSTATUS(status));
- return (1);
- }
- return (0);
-}
-
-static void
-usage(void)
-{
- (void)fprintf(stderr, "usage: %s [-fiv] source target\n"
- " %s [-fiv] source ... directory\n", getprogname(),
- getprogname());
- exit(1);
- /* NOTREACHED */
-}
diff --git a/toolbox/upstream-netbsd/bin/mv/pathnames.h b/toolbox/upstream-netbsd/bin/mv/pathnames.h
deleted file mode 100644
index 7838946..0000000
--- a/toolbox/upstream-netbsd/bin/mv/pathnames.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/* $NetBSD: pathnames.h,v 1.8 2004/08/19 22:26:07 christos Exp $ */
-
-/*
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)pathnames.h 8.1 (Berkeley) 5/31/93
- */
-
-#ifdef __ANDROID__
-#define _PATH_RM "/system/bin/rm"
-#define _PATH_CP "/system/bin/cp"
-#else
-#ifdef RESCUEDIR
-#define _PATH_RM RESCUEDIR "/rm"
-#define _PATH_CP RESCUEDIR "/cp"
-#else
-#define _PATH_RM "/bin/rm"
-#define _PATH_CP "/bin/cp"
-#endif
-#endif
diff --git a/toolbox/upstream-netbsd/bin/rm/rm.c b/toolbox/upstream-netbsd/bin/rm/rm.c
deleted file mode 100644
index f183810..0000000
--- a/toolbox/upstream-netbsd/bin/rm/rm.c
+++ /dev/null
@@ -1,625 +0,0 @@
-/* $NetBSD: rm.c,v 1.53 2013/04/26 18:43:22 christos Exp $ */
-
-/*-
- * Copyright (c) 1990, 1993, 1994, 2003
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\
- The Regents of the University of California. All rights reserved.");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)rm.c 8.8 (Berkeley) 4/27/95";
-#else
-__RCSID("$NetBSD: rm.c,v 1.53 2013/04/26 18:43:22 christos Exp $");
-#endif
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <fts.h>
-#include <grp.h>
-#include <locale.h>
-#include <pwd.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-static int dflag, eval, fflag, iflag, Pflag, stdin_ok, vflag, Wflag;
-static int xflag;
-static sig_atomic_t pinfo;
-
-static int check(char *, char *, struct stat *);
-static void checkdot(char **);
-static void progress(int);
-static void rm_file(char **);
-static int rm_overwrite(char *, struct stat *);
-static void rm_tree(char **);
-__dead static void usage(void);
-
-/*
- * For the sake of the `-f' flag, check whether an error number indicates the
- * failure of an operation due to an non-existent file, either per se (ENOENT)
- * or because its filename argument was illegal (ENAMETOOLONG, ENOTDIR).
- */
-#define NONEXISTENT(x) \
- ((x) == ENOENT || (x) == ENAMETOOLONG || (x) == ENOTDIR)
-
-/*
- * rm --
- * This rm is different from historic rm's, but is expected to match
- * POSIX 1003.2 behavior. The most visible difference is that -f
- * has two specific effects now, ignore non-existent files and force
- * file removal.
- */
-int
-main(int argc, char *argv[])
-{
- int ch, rflag;
-
- setprogname(argv[0]);
- (void)setlocale(LC_ALL, "");
-
- Pflag = rflag = xflag = 0;
- while ((ch = getopt(argc, argv, "dfiPRrvWx")) != -1)
- switch (ch) {
- case 'd':
- dflag = 1;
- break;
- case 'f':
- fflag = 1;
- iflag = 0;
- break;
- case 'i':
- fflag = 0;
- iflag = 1;
- break;
- case 'P':
- Pflag = 1;
- break;
- case 'R':
- case 'r': /* Compatibility. */
- rflag = 1;
- break;
- case 'v':
- vflag = 1;
- break;
- case 'x':
- xflag = 1;
- break;
-#ifndef __ANDROID__
- case 'W':
- Wflag = 1;
- break;
-#endif
- case '?':
- default:
- usage();
- }
- argc -= optind;
- argv += optind;
-
- if (argc < 1) {
- if (fflag)
- return 0;
- usage();
- }
-
- (void)signal(SIGINFO, progress);
-
- checkdot(argv);
-
- if (*argv) {
- stdin_ok = isatty(STDIN_FILENO);
-
- if (rflag)
- rm_tree(argv);
- else
- rm_file(argv);
- }
-
- exit(eval);
- /* NOTREACHED */
-}
-
-static void
-rm_tree(char **argv)
-{
- FTS *fts;
- FTSENT *p;
- int flags, needstat, rval;
-
- /*
- * Remove a file hierarchy. If forcing removal (-f), or interactive
- * (-i) or can't ask anyway (stdin_ok), don't stat the file.
- */
- needstat = !fflag && !iflag && stdin_ok;
-
- /*
- * If the -i option is specified, the user can skip on the pre-order
- * visit. The fts_number field flags skipped directories.
- */
-#define SKIPPED 1
-
- flags = FTS_PHYSICAL;
- if (!needstat)
- flags |= FTS_NOSTAT;
-#ifndef __ANDROID__
- if (Wflag)
- flags |= FTS_WHITEOUT;
-#endif
- if (xflag)
- flags |= FTS_XDEV;
- if ((fts = fts_open(argv, flags, NULL)) == NULL)
- err(1, "fts_open failed");
- while ((p = fts_read(fts)) != NULL) {
-
- switch (p->fts_info) {
- case FTS_DNR:
- if (!fflag || p->fts_errno != ENOENT) {
- warnx("%s: %s", p->fts_path,
- strerror(p->fts_errno));
- eval = 1;
- }
- continue;
- case FTS_ERR:
- errx(EXIT_FAILURE, "%s: %s", p->fts_path,
- strerror(p->fts_errno));
- /* NOTREACHED */
- case FTS_NS:
- /*
- * FTS_NS: assume that if can't stat the file, it
- * can't be unlinked.
- */
- if (fflag && NONEXISTENT(p->fts_errno))
- continue;
- if (needstat) {
- warnx("%s: %s", p->fts_path,
- strerror(p->fts_errno));
- eval = 1;
- continue;
- }
- break;
- case FTS_D:
- /* Pre-order: give user chance to skip. */
- if (!fflag && !check(p->fts_path, p->fts_accpath,
- p->fts_statp)) {
- (void)fts_set(fts, p, FTS_SKIP);
- p->fts_number = SKIPPED;
- }
- continue;
- case FTS_DP:
- /* Post-order: see if user skipped. */
- if (p->fts_number == SKIPPED)
- continue;
- break;
- default:
- if (!fflag &&
- !check(p->fts_path, p->fts_accpath, p->fts_statp))
- continue;
- }
-
- rval = 0;
- /*
- * If we can't read or search the directory, may still be
- * able to remove it. Don't print out the un{read,search}able
- * message unless the remove fails.
- */
- switch (p->fts_info) {
- case FTS_DP:
- case FTS_DNR:
- rval = rmdir(p->fts_accpath);
- if (rval != 0 && fflag && errno == ENOENT)
- continue;
- break;
-
-#ifndef __ANDROID__
- case FTS_W:
- rval = undelete(p->fts_accpath);
- if (rval != 0 && fflag && errno == ENOENT)
- continue;
- break;
-#endif
-
- default:
- if (Pflag) {
- if (rm_overwrite(p->fts_accpath, NULL))
- continue;
- }
- rval = unlink(p->fts_accpath);
- if (rval != 0 && fflag && NONEXISTENT(errno))
- continue;
- break;
- }
- if (rval != 0) {
- warn("%s", p->fts_path);
- eval = 1;
- } else if (vflag || pinfo) {
- pinfo = 0;
- (void)printf("%s\n", p->fts_path);
- }
- }
- if (errno)
- err(1, "fts_read");
- fts_close(fts);
-}
-
-static void
-rm_file(char **argv)
-{
- struct stat sb;
- int rval;
- char *f;
-
- /*
- * Remove a file. POSIX 1003.2 states that, by default, attempting
- * to remove a directory is an error, so must always stat the file.
- */
- while ((f = *argv++) != NULL) {
- /* Assume if can't stat the file, can't unlink it. */
- if (lstat(f, &sb)) {
-#ifndef __ANDROID__
- if (Wflag) {
- sb.st_mode = S_IFWHT|S_IWUSR|S_IRUSR;
- } else {
-#endif
- if (!fflag || !NONEXISTENT(errno)) {
- warn("%s", f);
- eval = 1;
- }
- continue;
-#ifndef __ANDROID__
- }
- } else if (Wflag) {
- warnx("%s: %s", f, strerror(EEXIST));
- eval = 1;
- continue;
-#endif
- }
-
- if (S_ISDIR(sb.st_mode) && !dflag) {
- warnx("%s: is a directory", f);
- eval = 1;
- continue;
- }
- if (!fflag && !S_ISWHT(sb.st_mode) && !check(f, f, &sb))
- continue;
-#ifndef __ANDROID__
- if (S_ISWHT(sb.st_mode))
- rval = undelete(f);
- else if (S_ISDIR(sb.st_mode))
-#else
- if (S_ISDIR(sb.st_mode))
-#endif
- rval = rmdir(f);
- else {
- if (Pflag) {
- if (rm_overwrite(f, &sb))
- continue;
- }
- rval = unlink(f);
- }
- if (rval && (!fflag || !NONEXISTENT(errno))) {
- warn("%s", f);
- eval = 1;
- }
- if (vflag && rval == 0)
- (void)printf("%s\n", f);
- }
-}
-
-/*
- * rm_overwrite --
- * Overwrite the file 3 times with varying bit patterns.
- *
- * This is an expensive way to keep people from recovering files from your
- * non-snapshotted FFS filesystems using fsdb(8). Really. No more. Only
- * regular files are deleted, directories (and therefore names) will remain.
- * Also, this assumes a fixed-block file system (like FFS, or a V7 or a
- * System V file system). In a logging file system, you'll have to have
- * kernel support.
- *
- * A note on standards: U.S. DoD 5220.22-M "National Industrial Security
- * Program Operating Manual" ("NISPOM") is often cited as a reference
- * for clearing and sanitizing magnetic media. In fact, a matrix of
- * "clearing" and "sanitization" methods for various media was given in
- * Chapter 8 of the original 1995 version of NISPOM. However, that
- * matrix was *removed from the document* when Chapter 8 was rewritten
- * in Change 2 to the document in 2001. Recently, the Defense Security
- * Service has made a revised clearing and sanitization matrix available
- * in Microsoft Word format on the DSS web site. The standardization
- * status of this matrix is unclear. Furthermore, one must be very
- * careful when referring to this matrix: it is intended for the "clearing"
- * prior to reuse or "sanitization" prior to disposal of *entire media*,
- * not individual files and the only non-physically-destructive method of
- * "sanitization" that is permitted for magnetic disks of any kind is
- * specifically noted to be prohibited for media that have contained
- * Top Secret data.
- *
- * It is impossible to actually conform to the exact procedure given in
- * the matrix if one is overwriting a file, not an entire disk, because
- * the procedure requires examination and comparison of the disk's defect
- * lists. Any program that claims to securely erase *files* while
- * conforming to the standard, then, is not correct. We do as much of
- * what the standard requires as can actually be done when erasing a
- * file, rather than an entire disk; but that does not make us conformant.
- *
- * Furthermore, the presence of track caches, disk and controller write
- * caches, and so forth make it extremely difficult to ensure that data
- * have actually been written to the disk, particularly when one tries
- * to repeatedly overwrite the same sectors in quick succession. We call
- * fsync(), but controllers with nonvolatile cache, as well as IDE disks
- * that just plain lie about the stable storage of data, will defeat this.
- *
- * Finally, widely respected research suggests that the given procedure
- * is nowhere near sufficient to prevent the recovery of data using special
- * forensic equipment and techniques that are well-known. This is
- * presumably one reason that the matrix requires physical media destruction,
- * rather than any technique of the sort attempted here, for secret data.
- *
- * Caveat Emptor.
- *
- * rm_overwrite will return 0 on success.
- */
-
-static int
-rm_overwrite(char *file, struct stat *sbp)
-{
- struct stat sb, sb2;
- int fd, randint;
- char randchar;
-
- fd = -1;
- if (sbp == NULL) {
- if (lstat(file, &sb))
- goto err;
- sbp = &sb;
- }
- if (!S_ISREG(sbp->st_mode))
- return 0;
-
- /* flags to try to defeat hidden caching by forcing seeks */
- if ((fd = open(file, O_RDWR|O_SYNC|O_RSYNC|O_NOFOLLOW, 0)) == -1)
- goto err;
-
- if (fstat(fd, &sb2)) {
- goto err;
- }
-
- if (sb2.st_dev != sbp->st_dev || sb2.st_ino != sbp->st_ino ||
- !S_ISREG(sb2.st_mode)) {
- errno = EPERM;
- goto err;
- }
-
-#define RAND_BYTES 1
-#define THIS_BYTE 0
-
-#define WRITE_PASS(mode, byte) do { \
- off_t len; \
- size_t wlen, i; \
- char buf[8 * 1024]; \
- \
- if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET)) \
- goto err; \
- \
- if (mode == THIS_BYTE) \
- memset(buf, byte, sizeof(buf)); \
- for (len = sbp->st_size; len > 0; len -= wlen) { \
- if (mode == RAND_BYTES) { \
- for (i = 0; i < sizeof(buf); \
- i+= sizeof(u_int32_t)) \
- *(int *)(buf + i) = arc4random(); \
- } \
- wlen = len < (off_t)sizeof(buf) ? (size_t)len : sizeof(buf); \
- if ((size_t)write(fd, buf, wlen) != wlen) \
- goto err; \
- } \
- sync(); /* another poke at hidden caches */ \
-} while (/* CONSTCOND */ 0)
-
-#define READ_PASS(byte) do { \
- off_t len; \
- size_t rlen; \
- char pattern[8 * 1024]; \
- char buf[8 * 1024]; \
- \
- if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET)) \
- goto err; \
- \
- memset(pattern, byte, sizeof(pattern)); \
- for(len = sbp->st_size; len > 0; len -= rlen) { \
- rlen = len < (off_t)sizeof(buf) ? (size_t)len : sizeof(buf); \
- if((size_t)read(fd, buf, rlen) != rlen) \
- goto err; \
- if(memcmp(buf, pattern, rlen)) \
- goto err; \
- } \
- sync(); /* another poke at hidden caches */ \
-} while (/* CONSTCOND */ 0)
-
- /*
- * DSS sanitization matrix "clear" for magnetic disks:
- * option 'c' "Overwrite all addressable locations with a single
- * character."
- */
- randint = arc4random();
- randchar = *(char *)&randint;
- WRITE_PASS(THIS_BYTE, randchar);
-
- /*
- * DSS sanitization matrix "sanitize" for magnetic disks:
- * option 'd', sub 2 "Overwrite all addressable locations with a
- * character, then its complement. Verify "complement" character
- * was written successfully to all addressable locations, then
- * overwrite all addressable locations with random characters; or
- * verify third overwrite of random characters." The rest of the
- * text in d-sub-2 specifies requirements for overwriting spared
- * sectors; we cannot conform to it when erasing only a file, thus
- * we do not conform to the standard.
- */
-
- /* 1. "a character" */
- WRITE_PASS(THIS_BYTE, 0xff);
-
- /* 2. "its complement" */
- WRITE_PASS(THIS_BYTE, 0x00);
-
- /* 3. "Verify 'complement' character" */
- READ_PASS(0x00);
-
- /* 4. "overwrite all addressable locations with random characters" */
-
- WRITE_PASS(RAND_BYTES, 0x00);
-
- /*
- * As the file might be huge, and we note that this revision of
- * the matrix says "random characters", not "a random character"
- * as the original did, we do not verify the random-character
- * write; the "or" in the standard allows this.
- */
-
- if (close(fd) == -1) {
- fd = -1;
- goto err;
- }
-
- return 0;
-
-err: eval = 1;
- warn("%s", file);
- if (fd != -1)
- close(fd);
- return 1;
-}
-
-static int
-check(char *path, char *name, struct stat *sp)
-{
- int ch, first;
- char modep[15];
-
- /* Check -i first. */
- if (iflag)
- (void)fprintf(stderr, "remove '%s'? ", path);
- else {
- /*
- * If it's not a symbolic link and it's unwritable and we're
- * talking to a terminal, ask. Symbolic links are excluded
- * because their permissions are meaningless. Check stdin_ok
- * first because we may not have stat'ed the file.
- */
- if (!stdin_ok || S_ISLNK(sp->st_mode) ||
- !(access(name, W_OK) && (errno != ETXTBSY)))
- return (1);
- strmode(sp->st_mode, modep);
- if (Pflag) {
- warnx(
- "%s: -P was specified but file could not"
- " be overwritten", path);
- return 0;
- }
- (void)fprintf(stderr, "override %s%s%s:%s for '%s'? ",
- modep + 1, modep[9] == ' ' ? "" : " ",
- user_from_uid(sp->st_uid, 0),
- group_from_gid(sp->st_gid, 0), path);
- }
- (void)fflush(stderr);
-
- first = ch = getchar();
- while (ch != '\n' && ch != EOF)
- ch = getchar();
- return (first == 'y' || first == 'Y');
-}
-
-/*
- * POSIX.2 requires that if "." or ".." are specified as the basename
- * portion of an operand, a diagnostic message be written to standard
- * error and nothing more be done with such operands.
- *
- * Since POSIX.2 defines basename as the final portion of a path after
- * trailing slashes have been removed, we'll remove them here.
- */
-#define ISDOT(a) ((a)[0] == '.' && (!(a)[1] || ((a)[1] == '.' && !(a)[2])))
-static void
-checkdot(char **argv)
-{
- char *p, **save, **t;
- int complained;
-
- complained = 0;
- for (t = argv; *t;) {
- /* strip trailing slashes */
- p = strrchr(*t, '\0');
- while (--p > *t && *p == '/')
- *p = '\0';
-
- /* extract basename */
- if ((p = strrchr(*t, '/')) != NULL)
- ++p;
- else
- p = *t;
-
- if (ISDOT(p)) {
- if (!complained++)
- warnx("\".\" and \"..\" may not be removed");
- eval = 1;
- for (save = t; (t[0] = t[1]) != NULL; ++t)
- continue;
- t = save;
- } else
- ++t;
- }
-}
-
-static void
-usage(void)
-{
-
- (void)fprintf(stderr, "usage: %s [-f|-i] [-dPRrvWx] file ...\n",
- getprogname());
- exit(1);
- /* NOTREACHED */
-}
-
-static void
-progress(int sig __unused)
-{
-
- pinfo++;
-}
diff --git a/toolbox/upstream-netbsd/bin/rmdir/rmdir.c b/toolbox/upstream-netbsd/bin/rmdir/rmdir.c
deleted file mode 100644
index 03261ce..0000000
--- a/toolbox/upstream-netbsd/bin/rmdir/rmdir.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/* $NetBSD: rmdir.c,v 1.26 2011/08/29 14:49:38 joerg Exp $ */
-
-/*-
- * Copyright (c) 1992, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\
- The Regents of the University of California. All rights reserved.");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)rmdir.c 8.3 (Berkeley) 4/2/94";
-#else
-__RCSID("$NetBSD: rmdir.c,v 1.26 2011/08/29 14:49:38 joerg Exp $");
-#endif
-#endif /* not lint */
-
-#include <sys/param.h>
-
-#include <err.h>
-#include <locale.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-static int rm_path(char *);
-__dead static void usage(void);
-
-int
-main(int argc, char *argv[])
-{
- int ch, errors, pflag;
-
- setprogname(argv[0]);
- (void)setlocale(LC_ALL, "");
-
- pflag = 0;
- while ((ch = getopt(argc, argv, "p")) != -1)
- switch(ch) {
- case 'p':
- pflag = 1;
- break;
- case '?':
- default:
- usage();
- }
- argc -= optind;
- argv += optind;
-
- if (argc == 0)
- usage();
-
- for (errors = 0; *argv; argv++) {
- /* We rely on the kernel to ignore trailing '/' characters. */
- if (rmdir(*argv) < 0) {
- warn("%s", *argv);
- errors = 1;
- } else if (pflag)
- errors |= rm_path(*argv);
- }
-
- exit(errors);
- /* NOTREACHED */
-}
-
-static int
-rm_path(char *path)
-{
- char *p;
-
- while ((p = strrchr(path, '/')) != NULL) {
- *p = 0;
- if (p[1] == 0)
- /* Ignore trailing '/' on deleted name */
- continue;
-
- if (rmdir(path) < 0) {
- warn("%s", path);
- return (1);
- }
- }
-
- return (0);
-}
-
-static void
-usage(void)
-{
- (void)fprintf(stderr, "usage: %s [-p] directory ...\n", getprogname());
- exit(1);
- /* NOTREACHED */
-}
diff --git a/toolbox/upstream-netbsd/bin/sleep/sleep.c b/toolbox/upstream-netbsd/bin/sleep/sleep.c
deleted file mode 100644
index 4349af4..0000000
--- a/toolbox/upstream-netbsd/bin/sleep/sleep.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/* $NetBSD: sleep.c,v 1.24 2011/08/29 14:51:19 joerg Exp $ */
-
-/*
- * Copyright (c) 1988, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\
- The Regents of the University of California. All rights reserved.");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)sleep.c 8.3 (Berkeley) 4/2/94";
-#else
-__RCSID("$NetBSD: sleep.c,v 1.24 2011/08/29 14:51:19 joerg Exp $");
-#endif
-#endif /* not lint */
-
-#include <ctype.h>
-#include <err.h>
-#include <locale.h>
-#include <math.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <unistd.h>
-
-__dead static void alarmhandle(int);
-__dead static void usage(void);
-
-static volatile sig_atomic_t report_requested;
-static void
-report_request(int signo __unused)
-{
-
- report_requested = 1;
-}
-
-int
-main(int argc, char *argv[])
-{
- char *arg, *temp;
- double fval, ival, val;
- struct timespec ntime;
- time_t original;
- int ch, fracflag, rv;
-
- setprogname(argv[0]);
- (void)setlocale(LC_ALL, "");
-
- (void)signal(SIGALRM, alarmhandle);
-
- while ((ch = getopt(argc, argv, "")) != -1)
- switch(ch) {
- default:
- usage();
- }
- argc -= optind;
- argv += optind;
-
- if (argc != 1)
- usage();
-
- /*
- * Okay, why not just use atof for everything? Why bother
- * checking if there is a fraction in use? Because the old
- * sleep handled the full range of integers, that's why, and a
- * double can't handle a large long. This is fairly useless
- * given how large a number a double can hold on most
- * machines, but now we won't ever have trouble. If you want
- * 1000000000.9 seconds of sleep, well, that's your
- * problem. Why use an isdigit() check instead of checking for
- * a period? Because doing it this way means locales will be
- * handled transparently by the atof code.
- */
- fracflag = 0;
- arg = *argv;
- for (temp = arg; *temp != '\0'; temp++)
- if (!isdigit((unsigned char)*temp))
- fracflag++;
-
- if (fracflag) {
- val = atof(arg);
- if (val <= 0)
- usage();
- ival = floor(val);
- fval = (1000000000 * (val-ival));
- ntime.tv_sec = ival;
- ntime.tv_nsec = fval;
- }
- else {
- ntime.tv_sec = atol(arg);
- if (ntime.tv_sec <= 0)
- return EXIT_SUCCESS;
- ntime.tv_nsec = 0;
- }
-
- original = ntime.tv_sec;
- signal(SIGINFO, report_request);
- while ((rv = nanosleep(&ntime, &ntime)) != 0) {
- if (report_requested) {
- /* Reporting does not bother with nanoseconds. */
- warnx("about %d second(s) left out of the original %d",
- (int)ntime.tv_sec, (int)original);
- report_requested = 0;
- } else
- break;
- }
-
- if (rv == -1)
- err(EXIT_FAILURE, "nanosleep failed");
-
- return EXIT_SUCCESS;
- /* NOTREACHED */
-}
-
-static void
-usage(void)
-{
- (void)fprintf(stderr, "usage: %s seconds\n", getprogname());
- exit(EXIT_FAILURE);
- /* NOTREACHED */
-}
-
-/* ARGSUSED */
-static void
-alarmhandle(int i)
-{
- _exit(EXIT_SUCCESS);
- /* NOTREACHED */
-}
diff --git a/toolbox/upstream-netbsd/bin/sync/sync.c b/toolbox/upstream-netbsd/bin/sync/sync.c
deleted file mode 100644
index 2b9c367..0000000
--- a/toolbox/upstream-netbsd/bin/sync/sync.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/* $NetBSD: sync.c,v 1.13 2008/07/20 00:52:40 lukem Exp $ */
-
-/*
- * Copyright (c) 1987, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1987, 1993\
- The Regents of the University of California. All rights reserved.");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)sync.c 8.1 (Berkeley) 5/31/93";
-#else
-__RCSID("$NetBSD: sync.c,v 1.13 2008/07/20 00:52:40 lukem Exp $");
-#endif
-#endif /* not lint */
-
-#include <stdlib.h>
-#include <unistd.h>
-
-int main(int, char *[]);
-
-/* ARGSUSED */
-int
-main(int argc, char *argv[])
-{
- setprogname(argv[0]);
- sync();
- exit(0);
- /* NOTREACHED */
-}
diff --git a/toolbox/upstream-netbsd/sbin/chown/chown.c b/toolbox/upstream-netbsd/sbin/chown/chown.c
deleted file mode 100644
index ee46eee..0000000
--- a/toolbox/upstream-netbsd/sbin/chown/chown.c
+++ /dev/null
@@ -1,302 +0,0 @@
-/* $NetBSD: chown.c,v 1.8 2012/10/24 01:12:51 enami Exp $ */
-
-/*
- * Copyright (c) 1988, 1993, 1994, 2003
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994, 2003\
- The Regents of the University of California. All rights reserved.");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)chown.c 8.8 (Berkeley) 4/4/94";
-#else
-__RCSID("$NetBSD: chown.c,v 1.8 2012/10/24 01:12:51 enami Exp $");
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <ctype.h>
-#include <dirent.h>
-#include <err.h>
-#include <errno.h>
-#include <locale.h>
-#include <fts.h>
-#include <grp.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <getopt.h>
-
-static void a_gid(const char *);
-static void a_uid(const char *);
-static id_t id(const char *, const char *);
-__dead static void usage(void);
-
-static uid_t uid;
-static gid_t gid;
-static int ischown;
-static const char *myname;
-
-struct option chown_longopts[] = {
- { "reference", required_argument, 0,
- 1 },
- { NULL, 0, 0,
- 0 },
-};
-
-int
-main(int argc, char **argv)
-{
- FTS *ftsp;
- FTSENT *p;
- int Hflag, Lflag, Rflag, ch, fflag, fts_options, hflag, rval, vflag;
- char *cp, *reference;
- int (*change_owner)(const char *, uid_t, gid_t);
-
- setprogname(*argv);
-
- (void)setlocale(LC_ALL, "");
-
- myname = getprogname();
- ischown = (myname[2] == 'o');
- reference = NULL;
-
- Hflag = Lflag = Rflag = fflag = hflag = vflag = 0;
- while ((ch = getopt_long(argc, argv, "HLPRfhv",
- chown_longopts, NULL)) != -1)
- switch (ch) {
- case 1:
- reference = optarg;
- break;
- case 'H':
- Hflag = 1;
- Lflag = 0;
- break;
- case 'L':
- Lflag = 1;
- Hflag = 0;
- break;
- case 'P':
- Hflag = Lflag = 0;
- break;
- case 'R':
- Rflag = 1;
- break;
- case 'f':
- fflag = 1;
- break;
- case 'h':
- /*
- * In System V the -h option causes chown/chgrp to
- * change the owner/group of the symbolic link.
- * 4.4BSD's symbolic links didn't have owners/groups,
- * so it was an undocumented noop.
- * In NetBSD 1.3, lchown(2) is introduced.
- */
- hflag = 1;
- break;
- case 'v':
- vflag = 1;
- break;
- case '?':
- default:
- usage();
- }
- argv += optind;
- argc -= optind;
-
- if (argc == 0 || (argc == 1 && reference == NULL))
- usage();
-
- fts_options = FTS_PHYSICAL;
- if (Rflag) {
- if (Hflag)
- fts_options |= FTS_COMFOLLOW;
- if (Lflag) {
- if (hflag)
- errx(EXIT_FAILURE,
- "the -L and -h options "
- "may not be specified together.");
- fts_options &= ~FTS_PHYSICAL;
- fts_options |= FTS_LOGICAL;
- }
- } else if (!hflag)
- fts_options |= FTS_COMFOLLOW;
-
- uid = (uid_t)-1;
- gid = (gid_t)-1;
- if (reference == NULL) {
- if (ischown) {
- if ((cp = strchr(*argv, ':')) != NULL) {
- *cp++ = '\0';
- a_gid(cp);
- }
-#ifdef SUPPORT_DOT
- else if ((cp = strrchr(*argv, '.')) != NULL) {
- if (uid_from_user(*argv, &uid) == -1) {
- *cp++ = '\0';
- a_gid(cp);
- }
- }
-#endif
- a_uid(*argv);
- } else
- a_gid(*argv);
- argv++;
- } else {
- struct stat st;
-
- if (stat(reference, &st) == -1)
- err(EXIT_FAILURE, "Cannot stat `%s'", reference);
- if (ischown)
- uid = st.st_uid;
- gid = st.st_gid;
- }
-
- if ((ftsp = fts_open(argv, fts_options, NULL)) == NULL)
- err(EXIT_FAILURE, "fts_open");
-
- for (rval = EXIT_SUCCESS; (p = fts_read(ftsp)) != NULL;) {
- change_owner = chown;
- switch (p->fts_info) {
- case FTS_D:
- if (!Rflag) /* Change it at FTS_DP. */
- fts_set(ftsp, p, FTS_SKIP);
- continue;
- case FTS_DNR: /* Warn, chown, continue. */
- warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
- rval = EXIT_FAILURE;
- break;
- case FTS_ERR: /* Warn, continue. */
- case FTS_NS:
- warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
- rval = EXIT_FAILURE;
- continue;
- case FTS_SL: /* Ignore unless -h. */
- /*
- * All symlinks we found while doing a physical
- * walk end up here.
- */
- if (!hflag)
- continue;
- /*
- * Note that if we follow a symlink, fts_info is
- * not FTS_SL but FTS_F or whatever. And we should
- * use lchown only for FTS_SL and should use chown
- * for others.
- */
- change_owner = lchown;
- break;
- case FTS_SLNONE: /* Ignore. */
- /*
- * The only symlinks that end up here are ones that
- * don't point to anything. Note that if we are
- * doing a phisycal walk, we never reach here unless
- * we asked to follow explicitly.
- */
- continue;
- default:
- break;
- }
-
- if ((*change_owner)(p->fts_accpath, uid, gid) && !fflag) {
- warn("%s", p->fts_path);
- rval = EXIT_FAILURE;
- } else {
- if (vflag)
- printf("%s\n", p->fts_path);
- }
- }
- if (errno)
- err(EXIT_FAILURE, "fts_read");
- exit(rval);
- /* NOTREACHED */
-}
-
-static void
-a_gid(const char *s)
-{
- struct group *gr;
-
- if (*s == '\0') /* Argument was "uid[:.]". */
- return;
- gr = *s == '#' ? NULL : getgrnam(s);
- if (gr == NULL)
- gid = id(s, "group");
- else
- gid = gr->gr_gid;
- return;
-}
-
-static void
-a_uid(const char *s)
-{
- if (*s == '\0') /* Argument was "[:.]gid". */
- return;
- if (*s == '#' || uid_from_user(s, &uid) == -1) {
- uid = id(s, "user");
- }
- return;
-}
-
-static id_t
-id(const char *name, const char *type)
-{
- id_t val;
- char *ep;
-
- errno = 0;
- if (*name == '#')
- name++;
- val = (id_t)strtoul(name, &ep, 10);
- if (errno)
- err(EXIT_FAILURE, "%s", name);
- if (*ep != '\0')
- errx(EXIT_FAILURE, "%s: invalid %s name", name, type);
- return (val);
-}
-
-static void
-usage(void)
-{
-
- (void)fprintf(stderr,
- "Usage: %s [-R [-H | -L | -P]] [-fhv] %s file ...\n"
- "\t%s [-R [-H | -L | -P]] [-fhv] --reference=rfile file ...\n",
- myname, ischown ? "owner:group|owner|:group" : "group",
- myname);
- exit(EXIT_FAILURE);
-}
diff --git a/toolbox/upstream-netbsd/usr.bin/grep/file.c b/toolbox/upstream-netbsd/usr.bin/grep/file.c
index da03d71..cf4a0fa 100644
--- a/toolbox/upstream-netbsd/usr.bin/grep/file.c
+++ b/toolbox/upstream-netbsd/usr.bin/grep/file.c
@@ -78,7 +78,9 @@ static inline int
grep_refill(struct file *f)
{
ssize_t nr;
+#ifndef __ANDROID__
int bzerr;
+#endif
bufpos = buffer;
bufrem = 0;
diff --git a/toolbox/upstream-netbsd/usr.bin/printenv/printenv.c b/toolbox/upstream-netbsd/usr.bin/printenv/printenv.c
deleted file mode 100644
index e15384f..0000000
--- a/toolbox/upstream-netbsd/usr.bin/printenv/printenv.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/* $NetBSD: printenv.c,v 1.12 2011/09/06 18:26:55 joerg Exp $ */
-
-/*
- * Copyright (c) 1987, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1987, 1993\
- The Regents of the University of California. All rights reserved.");
-#endif /* not lint */
-
-#ifndef lint
-/*static char sccsid[] = "from: @(#)printenv.c 8.2 (Berkeley) 5/4/95";*/
-__RCSID("$NetBSD: printenv.c,v 1.12 2011/09/06 18:26:55 joerg Exp $");
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <err.h>
-
-__dead static void usage(void);
-
-/*
- * printenv
- *
- * Bill Joy, UCB
- * February, 1979
- */
-int
-main(int argc, char *argv[])
-{
- extern char **environ;
- char *cp, **ep;
- size_t len;
- int ch;
-
- while ((ch = getopt(argc, argv, "")) != -1)
- switch(ch) {
- case '?':
- default:
- usage();
- }
- argc -= optind;
- argv += optind;
-
- if (argc == 0) {
- for (ep = environ; *ep; ep++)
- (void)printf("%s\n", *ep);
- exit(0);
- }
- if (argc != 1)
- usage();
- if (strchr(*argv, '=') != NULL)
- errx(1, "Invalid environment variable %s", *argv);
- len = strlen(*argv);
- for (ep = environ; *ep; ep++)
- if (!memcmp(*ep, *argv, len)) {
- cp = *ep + len;
- if (!*cp || *cp == '=') {
- (void)printf("%s\n", *cp ? cp + 1 : cp);
- exit(0);
- }
- }
- exit(1);
-}
-
-static void
-usage(void)
-{
- (void)fprintf(stderr, "Usage: printenv [name]\n");
- exit(1);
-}
diff --git a/toolbox/uptime.c b/toolbox/uptime.c
index 3fb4606..ebfb15e 100644
--- a/toolbox/uptime.c
+++ b/toolbox/uptime.c
@@ -29,71 +29,33 @@
* SUCH DAMAGE.
*/
-#include <sys/time.h>
-#include <linux/ioctl.h>
-#include <linux/rtc.h>
-#include <linux/android_alarm.h>
-#include <fcntl.h>
+#include <errno.h>
#include <stdio.h>
+#include <string.h>
#include <time.h>
-
static void format_time(int time, char* buffer) {
- int seconds, minutes, hours, days;
-
- seconds = time % 60;
+ int seconds = time % 60;
time /= 60;
- minutes = time % 60;
+ int minutes = time % 60;
time /= 60;
- hours = time % 24;
- days = time / 24;
+ int hours = time % 24;
+ int days = time / 24;
- if (days > 0)
- sprintf(buffer, "%d days, %02d:%02d:%02d", days, hours, minutes, seconds);
- else
+ if (days > 0) {
+ sprintf(buffer, "%d day%s, %02d:%02d:%02d", days, (days == 1) ? "" : "s", hours, minutes, seconds);
+ } else {
sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
+ }
}
-static int elapsedRealtimeAlarm(struct timespec *ts)
-{
- int fd, result;
-
- fd = open("/dev/alarm", O_RDONLY);
- if (fd < 0)
- return fd;
-
- result = ioctl(fd, ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), ts);
- close(fd);
-
- return result;
-}
-
-int64_t elapsedRealtime()
-{
- struct timespec ts;
-
- int result = elapsedRealtimeAlarm(&ts);
- if (result < 0)
- result = clock_gettime(CLOCK_BOOTTIME, &ts);
-
- if (result == 0)
- return ts.tv_sec;
- return -1;
-}
-
-int uptime_main(int argc __attribute__((unused)),
- char *argv[] __attribute__((unused)))
-{
- float up_time, idle_time;
- char up_string[100], idle_string[100], sleep_string[100];
- int elapsed;
- struct timespec up_timespec;
-
+int uptime_main(int argc __attribute__((unused)), char *argv[] __attribute__((unused))) {
FILE* file = fopen("/proc/uptime", "r");
if (!file) {
fprintf(stderr, "Could not open /proc/uptime\n");
return -1;
}
+ float idle_time;
if (fscanf(file, "%*f %f", &idle_time) != 1) {
fprintf(stderr, "Could not parse /proc/uptime\n");
fclose(file);
@@ -101,18 +63,21 @@ int uptime_main(int argc __attribute__((unused)),
}
fclose(file);
- if (clock_gettime(CLOCK_MONOTONIC, &up_timespec) < 0) {
- fprintf(stderr, "Could not get monotonic time\n");
+ struct timespec up_timespec;
+ if (clock_gettime(CLOCK_MONOTONIC, &up_timespec) == -1) {
+ fprintf(stderr, "Could not get monotonic time: %s\n", strerror(errno));
return -1;
}
- up_time = up_timespec.tv_sec + up_timespec.tv_nsec / 1e9;
+ float up_time = up_timespec.tv_sec + up_timespec.tv_nsec / 1e9;
- elapsed = elapsedRealtime();
- if (elapsed < 0) {
- fprintf(stderr, "elapsedRealtime failed\n");
+ struct timespec elapsed_timespec;
+ if (clock_gettime(CLOCK_BOOTTIME, &elapsed_timespec) == -1) {
+ fprintf(stderr, "Could not get boot time: %s\n", strerror(errno));
return -1;
}
+ int elapsed = elapsed_timespec.tv_sec;
+ char up_string[100], idle_string[100], sleep_string[100];
format_time(elapsed, up_string);
format_time((int)idle_time, idle_string);
format_time((int)(elapsed - up_time), sleep_string);
diff --git a/toolbox/vmstat.c b/toolbox/vmstat.c
deleted file mode 100644
index 4086ed0..0000000
--- a/toolbox/vmstat.c
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * Copyright (c) 2008, The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/param.h>
-#include <unistd.h>
-
-struct state {
- long procs_r;
- long procs_b;
-
- long mem_free;
- long mem_mapped;
- long mem_anon;
- long mem_slab;
-
- long sys_in;
- long sys_cs;
- long sys_flt;
-
- long cpu_us;
- long cpu_ni;
- long cpu_sy;
- long cpu_id;
- long cpu_wa;
- long cpu_ir;
- long cpu_si;
-};
-
-#define MAX_LINE 256
-
-char line[MAX_LINE];
-
-static void read_state(struct state *s);
-static int read_meminfo(struct state *s);
-static int read_stat(struct state *s);
-static int read_vmstat(struct state *s);
-static void print_header(void);
-static void print_line(struct state *old, struct state *new);
-static void usage(char *cmd);
-
-int vmstat_main(int argc, char *argv[]) {
- struct state s[2];
- int iterations, delay, header_interval;
- int toggle, count;
- int i;
-
- iterations = -1;
- delay = 1;
- header_interval = 20;
-
- for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "-n")) {
- if (i >= argc - 1) {
- fprintf(stderr, "Option -n requires an argument.\n");
- exit(EXIT_FAILURE);
- }
- iterations = atoi(argv[++i]);
- continue;
- }
- if (!strcmp(argv[i], "-d")) {
- if (i >= argc - 1) {
- fprintf(stderr, "Option -d requires an argument.\n");
- exit(EXIT_FAILURE);
- }
- delay = atoi(argv[++i]);
- continue;
- }
- if (!strcmp(argv[i], "-r")) {
- if (i >= argc - 1) {
- fprintf(stderr, "Option -r requires an argument.\n");
- exit(EXIT_FAILURE);
- }
- header_interval = atoi(argv[++i]);
- continue;
- }
- if (!strcmp(argv[i], "-h")) {
- usage(argv[0]);
- exit(EXIT_SUCCESS);
- }
- fprintf(stderr, "Invalid argument \"%s\".\n", argv[i]);
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
-
- toggle = 0;
- count = 0;
-
- if (!header_interval)
- print_header();
- read_state(&s[1 - toggle]);
- while ((iterations < 0) || (iterations-- > 0)) {
- sleep(delay);
- read_state(&s[toggle]);
- if (header_interval) {
- if (count == 0)
- print_header();
- count = (count + 1) % header_interval;
- }
- print_line(&s[1 - toggle], &s[toggle]);
- toggle = 1 - toggle;
- }
-
- return 0;
-}
-
-static void read_state(struct state *s) {
- int error;
-
- error = read_meminfo(s);
- if (error) {
- fprintf(stderr, "vmstat: could not read /proc/meminfo: %s\n", strerror(error));
- exit(EXIT_FAILURE);
- }
-
- error = read_stat(s);
- if (error) {
- fprintf(stderr, "vmstat: could not read /proc/stat: %s\n", strerror(error));
- exit(EXIT_FAILURE);
- }
-
- error = read_vmstat(s);
- if (error) {
- fprintf(stderr, "vmstat: could not read /proc/vmstat: %s\n", strerror(error));
- exit(EXIT_FAILURE);
- }
-}
-
-static int read_meminfo(struct state *s) {
- FILE *f;
-
- f = fopen("/proc/meminfo", "r");
- if (!f) return errno;
-
- while (fgets(line, MAX_LINE, f)) {
- sscanf(line, "MemFree: %ld kB", &s->mem_free);
- sscanf(line, "AnonPages: %ld kB", &s->mem_anon);
- sscanf(line, "Mapped: %ld kB", &s->mem_mapped);
- sscanf(line, "Slab: %ld kB", &s->mem_slab);
- }
-
- fclose(f);
-
- return 0;
-}
-
-static int read_stat(struct state *s) {
- FILE *f;
-
- f = fopen("/proc/stat", "r");
- if (!f) return errno;
-
- while (fgets(line, MAX_LINE, f)) {
- if (!strncmp(line, "cpu ", 4)) {
- sscanf(line, "cpu %ld %ld %ld %ld %ld %ld %ld",
- &s->cpu_us, &s->cpu_ni, &s->cpu_sy, &s->cpu_id, &s->cpu_wa,
- &s->cpu_ir, &s->cpu_si);
- }
- sscanf(line, "intr %ld", &s->sys_in);
- sscanf(line, "ctxt %ld", &s->sys_cs);
- sscanf(line, "procs_running %ld", &s->procs_r);
- sscanf(line, "procs_blocked %ld", &s->procs_b);
- }
-
- fclose(f);
-
- return 0;
-}
-
-static int read_vmstat(struct state *s) {
- FILE *f;
-
- f = fopen("/proc/vmstat", "r");
- if (!f) return errno;
-
- while (fgets(line, MAX_LINE, f)) {
- sscanf(line, "pgmajfault %ld", &s->sys_flt);
- }
-
- fclose(f);
-
- return 0;
-}
-
-static void print_header(void) {
- printf("%-5s %-27s %-14s %-17s\n", "procs", "memory", "system", "cpu");
- printf("%2s %2s %6s %6s %6s %6s %4s %4s %4s %2s %2s %2s %2s %2s %2s\n", "r", "b", "free", "mapped", "anon", "slab", "in", "cs", "flt", "us", "ni", "sy", "id", "wa", "ir");
-}
-
-/* Jiffies to percent conversion */
-#define JP(jif) ((jif) * 100 / (HZ))
-#define NORM(var) ((var) = (((var) > 99) ? (99) : (var)))
-
-static void print_line(struct state *old, struct state *new) {
- int us, ni, sy, id, wa, ir;
- us = JP(new->cpu_us - old->cpu_us); NORM(us);
- ni = JP(new->cpu_ni - old->cpu_ni); NORM(ni);
- sy = JP(new->cpu_sy - old->cpu_sy); NORM(sy);
- id = JP(new->cpu_id - old->cpu_id); NORM(id);
- wa = JP(new->cpu_wa - old->cpu_wa); NORM(wa);
- ir = JP(new->cpu_ir - old->cpu_ir); NORM(ir);
- printf("%2ld %2ld %6ld %6ld %6ld %6ld %4ld %4ld %4ld %2d %2d %2d %2d %2d %2d\n",
- new->procs_r ? (new->procs_r - 1) : 0, new->procs_b,
- new->mem_free, new->mem_mapped, new->mem_anon, new->mem_slab,
- new->sys_in - old->sys_in, new->sys_cs - old->sys_cs, new->sys_flt - old->sys_flt,
- us, ni, sy, id, wa, ir);
-}
-
-static void usage(char *cmd) {
- fprintf(stderr, "Usage: %s [ -h ] [ -n iterations ] [ -d delay ] [ -r header_repeat ]\n"
- " -n iterations How many rows of data to print.\n"
- " -d delay How long to sleep between rows.\n"
- " -r header_repeat How many rows to print before repeating\n"
- " the header. Zero means never repeat.\n"
- " -h Displays this help screen.\n",
- cmd);
-}
diff --git a/toolbox/watchprops.c b/toolbox/watchprops.c
index 0d05aba..cd62922 100644
--- a/toolbox/watchprops.c
+++ b/toolbox/watchprops.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <time.h>
#include <errno.h>
diff --git a/toolbox/wipe.c b/toolbox/wipe.c
deleted file mode 100644
index 650a0d6..0000000
--- a/toolbox/wipe.c
+++ /dev/null
@@ -1,176 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <cutils/android_reboot.h>
-#include <sys/stat.h>
-
-#ifndef PATH_MAX
-#define PATH_MAX 4096
-#endif
-
-
-/* Directories created by init defined in system/rootdir/init.rc */
-static char *INIT_DIRS[] = {
- "/system/etc/ppp",
- "/data/misc",
- "/data/local",
- "/data/local/tmp",
- "/data/data",
- "/data/app_private",
- "/data/app",
- NULL
-};
-
-static void wipe (const char *path);
-
-static int usage()
-{
- fprintf(stderr, "wipe <system|data|all>\n\n"
- "system means '/system'\n"
- "data means '/data'\n");
-
- return -1;
-}
-
-int wipe_main (int argc, char *argv[])
-{
- char *whatToWipe;
-
- if (argc != 2) return usage();
-
- whatToWipe = argv[1];
-
- if (0 == strcmp (whatToWipe, "system")) {
- fprintf(stdout, "Wiping /system\n");
- wipe ("/system");
- fprintf(stdout, "Done wiping /android\n");
- } else if (0 == strcmp (whatToWipe, "data")) {
- fprintf(stdout, "Wiping /data\n");
- wipe ("/data");
- fprintf(stdout, "Done wiping /data\n");
- } else if (0 == strcmp (whatToWipe, "all")) {
- fprintf(stdout, "Wiping /system and /data\n");
- wipe ("/system");
- wipe ("/data");
- fprintf(stdout, "Done wiping /system and /data\n");
- } else if (0 == strcmp(whatToWipe, "nuke")) {
- int ret;
- fprintf(stdout, "Nuking the device...\n");
- wipe ("/system");
- wipe ("/data");
- fprintf(stdout, "Device nuked! Rebooting...\n");
- ret = android_reboot(ANDROID_RB_RESTART, 0, 0);
- if (ret < 0) {
- fprintf(stderr, "Reboot failed, %s\n", strerror(errno));
- return 1;
- }
- } else {
- return usage();
- }
-
- return 0;
-}
-
-static char nameBuffer[PATH_MAX];
-static struct stat statBuffer;
-
-static void wipe (const char *path)
-{
- DIR *dir;
- struct dirent *de;
- int ret;
-
- dir = opendir(path);
-
- if (dir == NULL) {
- fprintf (stderr, "Error opendir'ing %s '%s'\n",
- path, strerror(errno));
- return;
- }
-
- char *filenameOffset;
-
- strcpy(nameBuffer, path);
- strcat(nameBuffer, "/");
-
- filenameOffset = nameBuffer + strlen(nameBuffer);
-
- for (;;) {
- de = readdir(dir);
-
- if (de == NULL) {
- break;
- }
-
- if (0 == strcmp(de->d_name, ".")
- || 0 == strcmp(de->d_name, "..")
- || 0 == strcmp(de->d_name, "lost+found")
- ) {
- continue;
- }
-
- strcpy(filenameOffset, de->d_name);
-
- ret = lstat (nameBuffer, &statBuffer);
-
- if (ret != 0) {
- fprintf(stderr, "stat() error on '%s' '%s'\n",
- nameBuffer, strerror(errno));
- }
-
- if(S_ISDIR(statBuffer.st_mode)) {
- int i;
- char *newpath;
-
-#if 0
- closedir(dir);
-#endif
-
- newpath = strdup(nameBuffer);
- wipe(newpath);
-
- /* Leave directories created by init, they have special permissions. */
- for (i = 0; INIT_DIRS[i]; i++) {
- if (strcmp(INIT_DIRS[i], newpath) == 0) {
- break;
- }
- }
- if (INIT_DIRS[i] == NULL) {
- ret = rmdir(newpath);
- if (ret != 0) {
- fprintf(stderr, "rmdir() error on '%s' '%s'\n",
- newpath, strerror(errno));
- }
- }
-
- free(newpath);
-
-#if 0
- dir = opendir(path);
- if (dir == NULL) {
- fprintf (stderr, "Error opendir'ing %s '%s'\n",
- path, strerror(errno));
- return;
- }
-#endif
-
- strcpy(nameBuffer, path);
- strcat(nameBuffer, "/");
-
- } else {
- ret = unlink(nameBuffer);
-
- if (ret != 0) {
- fprintf(stderr, "unlink() error on '%s' '%s'\n",
- nameBuffer, strerror(errno));
- }
- }
- }
-
- closedir(dir);
-
-}