diff options
Diffstat (limited to 'toolbox')
42 files changed, 810 insertions, 406 deletions
diff --git a/toolbox/Android.mk b/toolbox/Android.mk index 4fff9f5..c53f17d 100644 --- a/toolbox/Android.mk +++ b/toolbox/Android.mk @@ -2,73 +2,75 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) TOOLS := \ - ls \ - mount \ cat \ - ps \ - kill \ - ln \ - insmod \ - rmmod \ - lsmod \ - ifconfig \ - rm \ - mkdir \ - rmdir \ - getevent \ - sendevent \ - date \ - wipe \ - sync \ - umount \ - start \ - stop \ - notify \ + chcon \ + chmod \ + chown \ + clear \ cmp \ - dmesg \ - route \ - hd \ + date \ dd \ df \ + dmesg \ + du \ + getenforce \ + getevent \ getprop \ - setprop \ - watchprops \ - log \ - sleep \ - renice \ - printenv \ - smd \ - chmod \ - chown \ - newfs_msdos \ - netstat \ - ioctl \ - mv \ - schedtop \ - top \ - iftop \ + getsebool \ + hd \ id \ - uptime \ - vmstat \ - nandread \ + ifconfig \ + iftop \ + insmod \ + ioctl \ ionice \ - touch \ + kill \ + ln \ + load_policy \ + log \ + ls \ + lsmod \ lsof \ - du \ md5 \ - clear \ - getenforce \ - setenforce \ - chcon \ + mkdir \ + mknod \ + mkswap \ + mount \ + mv \ + nandread \ + netstat \ + newfs_msdos \ + nohup \ + notify \ + printenv \ + ps \ + readlink \ + renice \ restorecon \ + rm \ + rmdir \ + rmmod \ + route \ runcon \ - getsebool \ + schedtop \ + sendevent \ + setenforce \ + setprop \ setsebool \ - load_policy \ - swapon \ + sleep \ + smd \ + start \ + stop \ swapoff \ - mkswap \ - readlink + swapon \ + sync \ + top \ + touch \ + umount \ + uptime \ + vmstat \ + watchprops \ + wipe \ ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) TOOLS += r @@ -80,24 +82,37 @@ ALL_TOOLS += \ grep LOCAL_SRC_FILES := \ + cp/cp.c \ + cp/utils.c \ dynarray.c \ - toolbox.c \ + grep/fastgrep.c \ + grep/file.c \ + grep/grep.c \ + grep/queue.c \ + grep/util.c \ $(patsubst %,%.c,$(TOOLS)) \ - cp/cp.c cp/utils.c \ - grep/grep.c grep/fastgrep.c grep/file.c grep/queue.c grep/util.c + toolbox.c \ + uid_from_user.c \ -LOCAL_C_INCLUDES := bionic/libc/bionic +LOCAL_CFLAGS += \ + -std=gnu99 \ + -Werror -Wno-unused-parameter \ + -include bsd-compatibility.h \ -LOCAL_CFLAGS += -Wno-unused-parameter +LOCAL_C_INCLUDES += external/openssl/include LOCAL_SHARED_LIBRARIES := \ - libcutils \ - liblog \ - libc \ - libusbhost \ - libselinux + 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_MODULE := toolbox +LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk # Including this will define $(intermediates). # diff --git a/toolbox/bsd-compatibility.h b/toolbox/bsd-compatibility.h new file mode 100644 index 0000000..a304631 --- /dev/null +++ b/toolbox/bsd-compatibility.h @@ -0,0 +1,38 @@ +/* + * 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 <sys/types.h> + +/* We want chown to support user.group as well as user:group. */ +#define SUPPORT_DOT + +__BEGIN_DECLS + +extern int uid_from_user(const char* name, uid_t* uid); + +__END_DECLS diff --git a/toolbox/chown.c b/toolbox/chown.c index 92efee6..6ac2233 100644 --- a/toolbox/chown.c +++ b/toolbox/chown.c @@ -1,73 +1,302 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> +/* $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 <pwd.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 <time.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 chown_main(int argc, char **argv) +int +chown_main(int argc, char **argv) { - int i; - - if (argc < 3) { - fprintf(stderr, "Usage: chown <USER>[:GROUP] <FILE1> [FILE2] ...\n"); - return 10; - } - - // Copy argv[1] to 'user' so we can truncate it at the period - // if a group id specified. - char user[32]; - char *group = NULL; - strncpy(user, argv[1], sizeof(user)); - if ((group = strchr(user, ':')) != NULL) { - *group++ = '\0'; - } else if ((group = strchr(user, '.')) != NULL) { - *group++ = '\0'; - } - - // Lookup uid (and gid if specified) - struct passwd *pw; - struct group *grp = NULL; - uid_t uid; - gid_t gid = -1; // passing -1 to chown preserves current group - - pw = getpwnam(user); - if (pw != NULL) { - uid = pw->pw_uid; - } else { - char* endptr; - uid = (int) strtoul(user, &endptr, 0); - if (endptr == user) { // no conversion - fprintf(stderr, "No such user '%s'\n", user); - return 10; - } - } - - if (group != NULL) { - grp = getgrnam(group); - if (grp != NULL) { - gid = grp->gr_gid; - } else { - char* endptr; - gid = (int) strtoul(group, &endptr, 0); - if (endptr == group) { // no conversion - fprintf(stderr, "No such group '%s'\n", group); - return 10; - } - } - } - - for (i = 2; i < argc; i++) { - if (chown(argv[i], uid, gid) < 0) { - fprintf(stderr, "Unable to chown %s: %s\n", argv[i], strerror(errno)); - return 10; - } - } - - return 0; + 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/cp/cp.c b/toolbox/cp/cp.c index bd3c70e..e666453 100644 --- a/toolbox/cp/cp.c +++ b/toolbox/cp/cp.c @@ -95,12 +95,14 @@ enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE }; static int copy(char *[], enum op, int); +#ifndef ANDROID static void progress(int sig __unused) { pinfo++; } +#endif int cp_main(int argc, char *argv[]) diff --git a/toolbox/cp/utils.c b/toolbox/cp/utils.c index b682bbe..9d0390f 100644 --- a/toolbox/cp/utils.c +++ b/toolbox/cp/utils.c @@ -380,10 +380,11 @@ copy_special(struct stat *from_stat, int exists) int setfile(struct stat *fs, int fd) { - int rval, islink; + int rval = 0; +#ifndef ANDROID + int islink = S_ISLNK(fs->st_mode); +#endif - rval = 0; - islink = S_ISLNK(fs->st_mode); fs->st_mode &= S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO; /* @@ -401,13 +402,13 @@ setfile(struct stat *fs, int fd) fs->st_mode &= ~(S_ISUID | S_ISGID); } #ifdef ANDROID - if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode)) { + 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)) { + if (fd ? fchmod(fd, fs->st_mode) : lchmod(to.p_path, fs->st_mode)) { #endif - warn("chmod: %s", to.p_path); - rval = 1; - } + warn("chmod: %s", to.p_path); + rval = 1; + } #ifndef ANDROID if (!islink && !Nflag) { diff --git a/toolbox/date.c b/toolbox/date.c index d6c9052..70ce1d5 100644 --- a/toolbox/date.c +++ b/toolbox/date.c @@ -1,10 +1,13 @@ +#include <ctype.h> +#include <errno.h> +#include <fcntl.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> #include <string.h> -#include <errno.h> #include <time.h> +#include <unistd.h> + #include <linux/android_alarm.h> #include <linux/rtc.h> #include <sys/ioctl.h> @@ -108,16 +111,41 @@ static void settime(char *s) { 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 c; int res; - struct tm tm; - time_t t; - struct timeval tv; - struct timespec ts; - char strbuf[260]; - int fd; + struct tm tm; + time_t t; + struct timeval tv; + char strbuf[260]; int useutc = 0; @@ -147,7 +175,6 @@ int date_main(int argc, char *argv[]) int hasfmt = argc == optind + 1 && argv[optind][0] == '+'; if(optind == argc || hasfmt) { - char buf[2000]; time(&t); if (useutc) { gmtime_r(&t, &tm); @@ -181,7 +208,7 @@ int date_main(int argc, char *argv[]) //strptime(argv[optind], NULL, &tm); //tv.tv_sec = mktime(&tm); //tv.tv_usec = 0; - strtotimeval(argv[optind], &tv); + 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) diff --git a/toolbox/dd.c b/toolbox/dd.c index 6b61ffb..408a496 100644 --- a/toolbox/dd.c +++ b/toolbox/dd.c @@ -356,7 +356,7 @@ dd_in(void) ++st.in_full; /* Handle full input blocks. */ - } else if (n == in.dbsz) { + } else if (n == (int64_t)in.dbsz) { in.dbcnt += in.dbrcnt = n; ++st.in_full; @@ -521,7 +521,7 @@ dd_out(int force) outp += nw; st.bytes += nw; if (nw == n) { - if (n != out.dbsz) + if (n != (int64_t)out.dbsz) ++st.out_part; else ++st.out_full; @@ -649,8 +649,8 @@ pos_in(void) void pos_out(void) { -// struct mtop t_op; - int cnt, n; +/* struct mtop t_op; */ + int64_t cnt, n; /* * If not a tape, try seeking on the file. Seeking on a pipe is @@ -681,7 +681,7 @@ pos_out(void) } /* Read it. */ - for (cnt = 0; cnt < out.offset; ++cnt) { + for (cnt = 0; cnt < (int64_t)out.offset; ++cnt) { if ((n = read(out.fd, out.db, out.dbsz)) > 0) continue; @@ -705,8 +705,8 @@ pos_out(void) /* NOTREACHED */ } - while (cnt++ < out.offset) - if ((n = bwrite(out.fd, out.db, out.dbsz)) != out.dbsz) { + while (cnt++ < (int64_t)out.offset) + if ((n = bwrite(out.fd, out.db, out.dbsz)) != (int64_t)out.dbsz) { fprintf(stderr, "%s: cannot position " "by writing: %s\n", out.name, strerror(errno)); @@ -1153,7 +1153,7 @@ c_arg(const void *a, const void *b) ((const struct arg *)b)->name)); } -static long long strsuftoll(const char* name, const char* arg, int def, unsigned int max) +static long long strsuftoll(const char* name, const char* arg, int def, unsigned long long max) { long long result; @@ -1180,7 +1180,7 @@ static void f_count(char *arg) { - cpy_cnt = strsuftoll("block count", arg, 0, LLONG_MAX); + cpy_cnt = (uint64_t)strsuftoll("block count", arg, 0, 0xFFFFFFFFFFFFFFFFULL); if (!cpy_cnt) terminate(0); } @@ -1228,14 +1228,14 @@ static void f_seek(char *arg) { - out.offset = strsuftoll("seek blocks", arg, 0, LLONG_MAX); + out.offset = (uint64_t)strsuftoll("seek blocks", arg, 0, 0xFFFFFFFFFFFFFFFFULL); } static void f_skip(char *arg) { - in.offset = strsuftoll("skip blocks", arg, 0, LLONG_MAX); + in.offset = (uint64_t)strsuftoll("skip blocks", arg, 0, 0xFFFFFFFFFFFFFFFFULL); } static void diff --git a/toolbox/du.c b/toolbox/du.c index fc7c943..c8beba5 100644 --- a/toolbox/du.c +++ b/toolbox/du.c @@ -76,7 +76,7 @@ du_main(int argc, char *argv[]) int64_t totalblocks; int ftsoptions, listfiles; int depth; - int Hflag, Lflag, aflag, ch, cflag, dflag, gkmflag, nflag, rval, sflag; + int Hflag, Lflag, aflag, ch, cflag, dflag, gkmflag, rval, sflag; const char *noargv[2]; Hflag = Lflag = aflag = cflag = dflag = gkmflag = sflag = 0; diff --git a/toolbox/getevent.c b/toolbox/getevent.c index ed381f5..da83ec3 100644 --- a/toolbox/getevent.c +++ b/toolbox/getevent.c @@ -295,6 +295,7 @@ static int open_device(const char *device, int print_flags) { int version; int fd; + int clkid = CLOCK_MONOTONIC; struct pollfd *new_ufds; char **new_device_names; char name[80]; @@ -335,6 +336,11 @@ static int open_device(const char *device, int print_flags) idstr[0] = '\0'; } + if (ioctl(fd, EVIOCSCLOCKID, &clkid) != 0) { + fprintf(stderr, "Can't enable monotonic clock reporting: %s\n", strerror(errno)); + // a non-fatal error + } + new_ufds = realloc(ufds, sizeof(ufds[0]) * (nfds + 1)); if(new_ufds == NULL) { fprintf(stderr, "out of memory\n"); @@ -470,9 +476,9 @@ static int scan_dir(const char *dirname, int print_flags) return 0; } -static void usage(int argc, char *argv[]) +static void usage(char *name) { - fprintf(stderr, "Usage: %s [-t] [-n] [-s switchmask] [-S] [-v [mask]] [-d] [-p] [-i] [-l] [-q] [-c count] [-r] [device]\n", argv[0]); + fprintf(stderr, "Usage: %s [-t] [-n] [-s switchmask] [-S] [-v [mask]] [-d] [-p] [-i] [-l] [-q] [-c count] [-r] [device]\n", name); fprintf(stderr, " -t: show time stamps\n"); fprintf(stderr, " -n: don't print newlines\n"); fprintf(stderr, " -s: print switch states for given bits\n"); @@ -492,13 +498,11 @@ int getevent_main(int argc, char *argv[]) int c; int i; int res; - int pollres; int get_time = 0; int print_device = 0; char *newline = "\n"; uint16_t get_switch = 0; struct input_event event; - int version; int print_flags = 0; int print_flags_set = 0; int dont_block = -1; @@ -570,7 +574,7 @@ int getevent_main(int argc, char *argv[]) fprintf(stderr, "%s: invalid option -%c\n", argv[0], optopt); case 'h': - usage(argc, argv); + usage(argv[0]); exit(1); } } while (1); @@ -582,7 +586,7 @@ int getevent_main(int argc, char *argv[]) optind++; } if (optind != argc) { - usage(argc, argv); + usage(argv[0]); exit(1); } nfds = 1; @@ -629,7 +633,8 @@ int getevent_main(int argc, char *argv[]) return 0; while(1) { - pollres = poll(ufds, nfds, -1); + //int pollres = + poll(ufds, nfds, -1); //printf("poll %d, returned %d\n", nfds, pollres); if(ufds[0].revents & POLLIN) { read_notify(device_path, ufds[0].fd, print_flags); diff --git a/toolbox/getevent.h b/toolbox/getevent.h index 2b76209..0482d04 100644 --- a/toolbox/getevent.h +++ b/toolbox/getevent.h @@ -652,6 +652,7 @@ static struct label snd_labels[] = { LABEL_END, }; +#if 0 static struct label id_labels[] = { LABEL(ID_BUS), LABEL(ID_VENDOR), @@ -682,6 +683,7 @@ static struct label bus_labels[] = { LABEL(BUS_SPI), LABEL_END, }; +#endif static struct label mt_tool_labels[] = { LABEL(MT_TOOL_FINGER), diff --git a/toolbox/getprop.c b/toolbox/getprop.c index c001fda..dcc0ea0 100644 --- a/toolbox/getprop.c +++ b/toolbox/getprop.c @@ -3,7 +3,6 @@ #include <cutils/properties.h> -#include <sys/system_properties.h> #include "dynarray.h" static void record_prop(const char* key, const char* name, void* opaque) @@ -31,12 +30,8 @@ static void list_properties(void) strlist_done(list); } -int __system_property_wait(prop_info *pi); - int getprop_main(int argc, char *argv[]) { - int n = 0; - if (argc == 1) { list_properties(); } else { diff --git a/toolbox/grep/file.c b/toolbox/grep/file.c index 86b7658..d28dff5 100644 --- a/toolbox/grep/file.c +++ b/toolbox/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/grep/grep.c b/toolbox/grep/grep.c index b5bb2ef..7b2c487 100644 --- a/toolbox/grep/grep.c +++ b/toolbox/grep/grep.c @@ -294,10 +294,8 @@ read_patterns(const char *fn) err(2, "%s", fn); line = NULL; len = 0; -#ifndef ANDROID while ((rlen = getline(&line, &len, f)) != -1) add_pattern(line, *line == '\n' ? 0 : (size_t)rlen); -#endif free(line); if (ferror(f)) err(2, "%s", fn); @@ -405,7 +403,7 @@ grep_main(int argc, char *argv[]) Aflag = 0; else if (Aflag > LLONG_MAX / 10) { errno = ERANGE; - err(2, NULL); + err(2, "%llu", Aflag); } Aflag = Bflag = (Aflag * 10) + (c - '0'); break; @@ -422,10 +420,10 @@ grep_main(int argc, char *argv[]) l = strtoull(optarg, &ep, 10); if (((errno == ERANGE) && (l == ULLONG_MAX)) || ((errno == EINVAL) && (l == 0))) - err(2, NULL); + err(2, "strtoull"); else if (ep[0] != '\0') { errno = EINVAL; - err(2, NULL); + err(2, "empty"); } if (c == 'A') Aflag = l; @@ -511,10 +509,10 @@ grep_main(int argc, char *argv[]) mcount = strtoull(optarg, &ep, 10); if (((errno == ERANGE) && (mcount == ULLONG_MAX)) || ((errno == EINVAL) && (mcount == 0))) - err(2, NULL); + err(2, "strtoull"); else if (ep[0] != '\0') { errno = EINVAL; - err(2, NULL); + err(2, "empty"); } break; case 'n': diff --git a/toolbox/grep/util.c b/toolbox/grep/util.c index 497db06..5712fee 100644 --- a/toolbox/grep/util.c +++ b/toolbox/grep/util.c @@ -273,7 +273,7 @@ procfile(const char *fn) return (c); } -#define iswword(x) (iswalnum((x)) || (x) == L'_') +#define iswword(x) (iswalnum((wint_t)(x)) || (x) == L'_') /* * Processes a line comparing it with the specified patterns. Each pattern @@ -323,7 +323,7 @@ procline(struct str *l, int nottext) continue; /* Check for whole word match */ if (fg_pattern[i].word && pmatch.rm_so != 0) { - wint_t wbegin, wend; + wchar_t wbegin, wend; wbegin = wend = L' '; if (pmatch.rm_so != 0 && diff --git a/toolbox/hd.c b/toolbox/hd.c index 0d2f96a..7c9998e 100644 --- a/toolbox/hd.c +++ b/toolbox/hd.c @@ -14,7 +14,6 @@ int hd_main(int argc, char *argv[]) unsigned char buf[4096]; int res; int read_len; - int rv = 0; int i; int filepos = 0; int sum; diff --git a/toolbox/ifconfig.c b/toolbox/ifconfig.c index 80c0e5c..b953176 100644 --- a/toolbox/ifconfig.c +++ b/toolbox/ifconfig.c @@ -61,11 +61,11 @@ int ifconfig_main(int argc, char *argv[]) { struct ifreq ifr; int s; - unsigned int addr, mask, flags; + unsigned int flags; char astring[20]; char mstring[20]; char *updown, *brdcst, *loopbk, *ppp, *running, *multi; - + argc--; argv++; @@ -85,13 +85,17 @@ int ifconfig_main(int argc, char *argv[]) perror(ifr.ifr_name); return -1; } else - addr = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr; + 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 - mask = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr; + strlcpy(mstring, + inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr), + sizeof(mstring)); if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0) { perror(ifr.ifr_name); @@ -99,16 +103,6 @@ int ifconfig_main(int argc, char *argv[]) } else flags = ifr.ifr_flags; - sprintf(astring, "%d.%d.%d.%d", - addr & 0xff, - ((addr >> 8) & 0xff), - ((addr >> 16) & 0xff), - ((addr >> 24) & 0xff)); - sprintf(mstring, "%d.%d.%d.%d", - mask & 0xff, - ((mask >> 8) & 0xff), - ((mask >> 16) & 0xff), - ((mask >> 24) & 0xff)); printf("%s: ip %s mask %s flags [", ifr.ifr_name, astring, mstring diff --git a/toolbox/insmod.c b/toolbox/insmod.c index fb1448b..d252433 100644 --- a/toolbox/insmod.c +++ b/toolbox/insmod.c @@ -73,7 +73,7 @@ int insmod_main(int argc, char **argv) char *ptr = opts; for (i = 2; (i < argc) && (ptr < end); i++) { - len = MIN(strlen(argv[i]), end - ptr); + len = MIN(strlen(argv[i]), (size_t)(end - ptr)); memcpy(ptr, argv[i], len); ptr += len; *ptr++ = ' '; diff --git a/toolbox/ioctl.c b/toolbox/ioctl.c index fb555d2..17fabff 100644 --- a/toolbox/ioctl.c +++ b/toolbox/ioctl.c @@ -21,9 +21,9 @@ int ioctl_main(int argc, char *argv[]) int arg_size = 4; int direct_arg = 0; uint32_t ioctl_nr; - void *ioctl_args; + void *ioctl_args = NULL; uint8_t *ioctl_argp; - uint8_t *ioctl_argp_save; + uint8_t *ioctl_argp_save = NULL; int rem; do { @@ -112,6 +112,7 @@ int ioctl_main(int argc, char *argv[]) else 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; } @@ -124,5 +125,6 @@ int ioctl_main(int argc, char *argv[]) } printf("\n"); } + free(ioctl_args); return 0; } diff --git a/toolbox/load_policy.c b/toolbox/load_policy.c index eb5aba6..90d48c4 100644 --- a/toolbox/load_policy.c +++ b/toolbox/load_policy.c @@ -10,7 +10,7 @@ int load_policy_main(int argc, char **argv) { - int fd, rc, vers; + int fd, rc; struct stat sb; void *map; const char *path; diff --git a/toolbox/ls.c b/toolbox/ls.c index 3cc5bb2..011f7b5 100644 --- a/toolbox/ls.c +++ b/toolbox/ls.c @@ -137,7 +137,7 @@ static int listfile_size(const char *path, const char *filename, struct stat *s, /* blocks are 512 bytes, we want output to be KB */ if ((flags & LIST_SIZE) != 0) { - printf("%lld ", s->st_blocks / 2); + printf("%lld ", (long long)s->st_blocks / 2); } if ((flags & LIST_CLASSIFY) != 0) { @@ -205,7 +205,7 @@ static int listfile_long(const char *path, struct stat *s, int flags) break; case S_IFREG: printf("%s %-8s %-8s %8lld %s %s\n", - mode, user, group, s->st_size, date, name); + mode, user, group, (long long)s->st_size, date, name); break; case S_IFLNK: { char linkto[256]; @@ -321,7 +321,7 @@ static int listfile(const char *dirname, const char *filename, int flags) } if(flags & LIST_INODE) { - printf("%8llu ", s.st_ino); + printf("%8llu ", (unsigned long long)s.st_ino); } if ((flags & LIST_MACLABEL) != 0) { @@ -443,7 +443,6 @@ static int listpath(const char *name, int flags) int ls_main(int argc, char **argv) { int flags = 0; - int listed = 0; if(argc > 1) { int i; diff --git a/toolbox/lsof.c b/toolbox/lsof.c index 113c120..bee981d 100644 --- a/toolbox/lsof.c +++ b/toolbox/lsof.c @@ -99,10 +99,7 @@ out: static void print_maps(struct pid_info_t* info) { FILE *maps; - char buffer[PATH_MAX + 100]; - size_t offset; - int major, minor; char device[10]; long int inode; char file[PATH_MAX]; @@ -113,7 +110,7 @@ static void print_maps(struct pid_info_t* info) if (!maps) goto out; - while (fscanf(maps, "%*x-%*x %*s %zx %5s %ld %s\n", &offset, device, &inode, + while (fscanf(maps, "%*x-%*x %*s %zx %s %ld %s\n", &offset, device, &inode, file) == 4) { // We don't care about non-file maps if (inode == 0 || !strcmp(device, "00:00")) diff --git a/toolbox/md5.c b/toolbox/md5.c index 2fb8b05..5de4d9e 100644 --- a/toolbox/md5.c +++ b/toolbox/md5.c @@ -4,12 +4,7 @@ #include <unistd.h> #include <sys/stat.h> #include <sys/types.h> -#include <md5.h> - -/* When this was written, bionic's md5.h did not define this. */ -#ifndef MD5_DIGEST_LENGTH -#define MD5_DIGEST_LENGTH 16 -#endif +#include <openssl/md5.h> static int usage() { @@ -30,7 +25,6 @@ static int do_md5(const char *path) return -1; } - /* Note that bionic's MD5_* functions return void. */ MD5_Init(&md5_ctx); while (1) { diff --git a/toolbox/mkdir.c b/toolbox/mkdir.c index 656970a..398d350 100644 --- a/toolbox/mkdir.c +++ b/toolbox/mkdir.c @@ -15,7 +15,6 @@ static int usage() int mkdir_main(int argc, char *argv[]) { - int symbolic = 0; int ret; if(argc < 2 || strcmp(argv[1], "--help") == 0) { return usage(); diff --git a/toolbox/mknod.c b/toolbox/mknod.c new file mode 100644 index 0000000..0fedece --- /dev/null +++ b/toolbox/mknod.c @@ -0,0 +1,95 @@ +/* + * 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 index 1710ef6..0904152 100644 --- a/toolbox/mkswap.c +++ b/toolbox/mkswap.c @@ -1,6 +1,5 @@ #include <stdio.h> #include <unistd.h> -#include <asm/page.h> #include <sys/swap.h> #include <sys/types.h> #include <sys/stat.h> diff --git a/toolbox/nandread.c b/toolbox/nandread.c index d43b2fe..bd19942 100644 --- a/toolbox/nandread.c +++ b/toolbox/nandread.c @@ -1,9 +1,10 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> #include <ctype.h> #include <errno.h> #include <fcntl.h> +#include <inttypes.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <unistd.h> #include <mtd/mtd-user.h> @@ -177,11 +178,7 @@ int nandread_main(int argc, char **argv) if (rawmode) { rawmode = mtdinfo.oobsize; -#if !defined(MTD_STUPID_LOCK) /* using uapi kernel headers */ ret = ioctl(fd, MTDFILEMODE, MTD_FILE_MODE_RAW); -#else /* still using old kernel headers */ - ret = ioctl(fd, MTDFILEMODE, MTD_MODE_RAW); -#endif if (ret) { fprintf(stderr, "failed set raw mode for %s, %s\n", devname, strerror(errno)); @@ -193,18 +190,18 @@ int nandread_main(int argc, char **argv) for (pos = start, opos = 0; pos < end; pos += mtdinfo.writesize) { bad_block = 0; if (verbose > 3) - printf("reading at %llx\n", pos); + printf("reading at %" PRIx64 "\n", pos); lseek64(fd, pos, SEEK_SET); ret = read(fd, buffer, mtdinfo.writesize + rawmode); if (ret < (int)mtdinfo.writesize) { - fprintf(stderr, "short read at %llx, %d\n", pos, ret); + fprintf(stderr, "short read at %" PRIx64 ", %d\n", pos, ret); bad_block = 2; } if (!rawmode) { oobbuf.start = pos; ret = ioctl(fd, MEMREADOOB, &oobbuf); if (ret) { - fprintf(stderr, "failed to read oob data at %llx, %d\n", pos, ret); + fprintf(stderr, "failed to read oob data at %" PRIx64 ", %d\n", pos, ret); bad_block = 2; } } @@ -217,17 +214,17 @@ int nandread_main(int argc, char **argv) bpos = pos / mtdinfo.erasesize * mtdinfo.erasesize; ret = ioctl(fd, MEMGETBADBLOCK, &bpos); if (ret && errno != EOPNOTSUPP) { - printf("badblock at %llx\n", pos); + printf("badblock at %" PRIx64 "\n", pos); bad_block = 1; } if (ecc.corrected != last_ecc.corrected) - printf("ecc corrected, %u, at %llx\n", ecc.corrected - last_ecc.corrected, pos); + printf("ecc corrected, %u, at %" PRIx64 "\n", ecc.corrected - last_ecc.corrected, pos); if (ecc.failed != last_ecc.failed) - printf("ecc failed, %u, at %llx\n", ecc.failed - last_ecc.failed, pos); + printf("ecc failed, %u, at %" PRIx64 "\n", ecc.failed - last_ecc.failed, pos); if (ecc.badblocks != last_ecc.badblocks) - printf("ecc badblocks, %u, at %llx\n", ecc.badblocks - last_ecc.badblocks, pos); + printf("ecc badblocks, %u, at %" PRIx64 "\n", ecc.badblocks - last_ecc.badblocks, pos); if (ecc.bbtblocks != last_ecc.bbtblocks) - printf("ecc bbtblocks, %u, at %llx\n", ecc.bbtblocks - last_ecc.bbtblocks, pos); + printf("ecc bbtblocks, %u, at %" PRIx64 "\n", ecc.bbtblocks - last_ecc.bbtblocks, pos); if (!rawmode) { oob_fixed = (uint8_t *)oob_data; @@ -245,18 +242,18 @@ int nandread_main(int argc, char **argv) if (outfd >= 0) { ret = write(outfd, buffer, mtdinfo.writesize + spare_size); if (ret < (int)(mtdinfo.writesize + spare_size)) { - fprintf(stderr, "short write at %llx, %d\n", pos, ret); + fprintf(stderr, "short write at %" PRIx64 ", %d\n", pos, ret); close(outfd); outfd = -1; } if (ecc.corrected != last_ecc.corrected) - fprintf(statusfile, "%08llx: ecc corrected\n", opos); + fprintf(statusfile, "%08" PRIx64 ": ecc corrected\n", opos); if (ecc.failed != last_ecc.failed) - fprintf(statusfile, "%08llx: ecc failed\n", opos); + fprintf(statusfile, "%08" PRIx64 ": ecc failed\n", opos); if (bad_block == 1) - fprintf(statusfile, "%08llx: badblock\n", opos); + fprintf(statusfile, "%08" PRIx64 ": badblock\n", opos); if (bad_block == 2) - fprintf(statusfile, "%08llx: read error\n", opos); + fprintf(statusfile, "%08" PRIx64 ": read error\n", opos); opos += mtdinfo.writesize + spare_size; } @@ -265,7 +262,7 @@ int nandread_main(int argc, char **argv) if (test_empty(buffer, mtdinfo.writesize + mtdinfo.oobsize + spare_size)) empty_pages++; else if (verbose > 2 || (verbose > 1 && !(pos & (mtdinfo.erasesize - 1)))) - printf("page at %llx (%d oobbytes): %08x %08x %08x %08x " + printf("page at %" PRIx64 " (%d oobbytes): %08x %08x %08x %08x " "%08x %08x %08x %08x\n", pos, oobbuf.start, oob_data[0], oob_data[1], oob_data[2], oob_data[3], oob_data[4], oob_data[5], oob_data[6], oob_data[7]); diff --git a/toolbox/newfs_msdos.c b/toolbox/newfs_msdos.c index 27dca42..30b9f77 100644 --- a/toolbox/newfs_msdos.c +++ b/toolbox/newfs_msdos.c @@ -360,7 +360,7 @@ newfs_msdos_main(int argc, char *argv[]) if (!opt_create && !strchr(fname, '/')) { snprintf(buf, sizeof(buf), "%s%s", _PATH_DEV, fname); if (!(fname = strdup(buf))) - err(1, NULL); + err(1, "%s", buf); } dtype = *argv; if (opt_create) { @@ -493,7 +493,7 @@ newfs_msdos_main(int argc, char *argv[]) if (!strchr(bname, '/')) { snprintf(buf, sizeof(buf), "/boot/%s", bname); if (!(bname = strdup(buf))) - err(1, NULL); + err(1, "%s", buf); } if ((fd1 = open(bname, O_RDONLY)) == -1 || fstat(fd1, &sb)) err(1, "%s", bname); @@ -611,7 +611,7 @@ newfs_msdos_main(int argc, char *argv[]) now = tv.tv_sec; tm = localtime(&now); if (!(img = malloc(bpb.bps))) - err(1, NULL); + err(1, "%u", bpb.bps); dir = bpb.res + (bpb.spf ? bpb.spf : bpb.bspf) * bpb.nft; for (lsn = 0; lsn < dir + (fat == 32 ? bpb.spc : rds); lsn++) { x = lsn; @@ -728,14 +728,14 @@ newfs_msdos_main(int argc, char *argv[]) static void check_mounted(const char *fname, mode_t mode) { +#ifdef ANDROID + warnx("Skipping mount checks"); +#else struct statfs *mp; const char *s1, *s2; size_t len; int n, r; -#ifdef ANDROID - warnx("Skipping mount checks"); -#else if (!(n = getmntinfo(&mp, MNT_NOWAIT))) err(1, "getmntinfo"); len = strlen(_PATH_DEV); diff --git a/toolbox/nohup.c b/toolbox/nohup.c new file mode 100644 index 0000000..363999d --- /dev/null +++ b/toolbox/nohup.c @@ -0,0 +1,26 @@ +#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/ps.c b/toolbox/ps.c index 7c35ccb..57b4280 100644 --- a/toolbox/ps.c +++ b/toolbox/ps.c @@ -28,9 +28,12 @@ static char *nexttok(char **strp) #define SHOW_POLICY 4 #define SHOW_CPU 8 #define SHOW_MACLABEL 16 +#define SHOW_ABI 32 static int display_flags = 0; +static void print_exe_abi(int pid); + static int ps_line(int pid, int tid, char *namefilter) { char statline[1024]; @@ -40,7 +43,7 @@ static int ps_line(int pid, int tid, char *namefilter) struct stat stats; int fd, r; char *ptr, *name, *state; - int ppid, tty; + int ppid; unsigned wchan, rss, vss, eip; unsigned utime, stime; int prio, nice, rtprio, sched, psr; @@ -88,7 +91,7 @@ static int ps_line(int pid, int tid, char *namefilter) ppid = atoi(nexttok(&ptr)); nexttok(&ptr); // pgrp nexttok(&ptr); // sid - tty = atoi(nexttok(&ptr)); + nexttok(&ptr); // tty nexttok(&ptr); // tpgid nexttok(&ptr); // flags @@ -130,7 +133,7 @@ static int ps_line(int pid, int tid, char *namefilter) rtprio = atoi(nexttok(&ptr)); // rt_priority sched = atoi(nexttok(&ptr)); // scheduling policy - tty = atoi(nexttok(&ptr)); + nexttok(&ptr); // tty if(tid != 0) { ppid = pid; @@ -170,7 +173,11 @@ static int ps_line(int pid, int tid, char *namefilter) else printf(" %.2s ", get_sched_policy_name(p)); } - printf(" %08x %08x %s %s", wchan, eip, state, cmdline[0] ? cmdline : name); + printf(" %08x %08x %s ", wchan, eip, state); + if (display_flags & SHOW_ABI) { + print_exe_abi(pid); + } + printf("%s", cmdline[0] ? cmdline : name); if(display_flags&SHOW_TIME) printf(" (u:%d, s:%d)", utime, stime); @@ -179,6 +186,39 @@ static int ps_line(int pid, int tid, char *namefilter) return 0; } +static void print_exe_abi(int pid) +{ + int fd, r; + char exeline[1024]; + + sprintf(exeline, "/proc/%d/exe", pid); + fd = open(exeline, O_RDONLY); + if(fd == 0) { + printf(" "); + return; + } + r = read(fd, exeline, 5 /* 4 byte ELFMAG + 1 byte EI_CLASS */); + close(fd); + if(r < 0) { + printf(" "); + return; + } + if (memcmp("\177ELF", exeline, 4) != 0) { + printf("?? "); + return; + } + switch (exeline[4]) { + case 1: + printf("32 "); + return; + case 2: + printf("64 "); + return; + default: + printf("?? "); + return; + } +} void ps_threads(int pid, char *namefilter) { @@ -224,7 +264,9 @@ int ps_main(int argc, char **argv) display_flags |= SHOW_PRIO; } else if(!strcmp(argv[1],"-c")) { display_flags |= SHOW_CPU; - } else if(isdigit(argv[1][0])){ + } else if(!strcmp(argv[1],"--abi")) { + display_flags |= SHOW_ABI; + } else if(isdigit(argv[1][0])){ pidfilter = atoi(argv[1]); } else { namefilter = argv[1]; @@ -236,10 +278,11 @@ int ps_main(int argc, char **argv) if (display_flags & SHOW_MACLABEL) { printf("LABEL USER PID PPID NAME\n"); } else { - printf("USER PID PPID VSIZE RSS %s%s %s WCHAN PC NAME\n", + printf("USER PID PPID VSIZE RSS %s%s %s WCHAN PC %sNAME\n", (display_flags&SHOW_CPU)?"CPU ":"", (display_flags&SHOW_PRIO)?"PRIO NICE RTPRI SCHED ":"", - (display_flags&SHOW_POLICY)?"PCY " : ""); + (display_flags&SHOW_POLICY)?"PCY " : "", + (display_flags&SHOW_ABI)?"ABI " : ""); } while((de = readdir(d)) != 0){ if(isdigit(de->d_name[0])){ diff --git a/toolbox/restorecon.c b/toolbox/restorecon.c index f9f604f..3568625 100644 --- a/toolbox/restorecon.c +++ b/toolbox/restorecon.c @@ -2,76 +2,44 @@ #include <stdio.h> #include <stdlib.h> #include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fts.h> #include <selinux/selinux.h> -#include <selinux/label.h> #include <selinux/android.h> -static struct selabel_handle *sehandle; static const char *progname; -static int nochange; -static int verbose; static void usage(void) { - fprintf(stderr, "usage: %s [-nrRv] pathname...\n", progname); + fprintf(stderr, "usage: %s [-DFnrRv] pathname...\n", progname); exit(1); } -static int restore(const char *pathname, const struct stat *sb) -{ - char *oldcontext, *newcontext; - - if (lgetfilecon(pathname, &oldcontext) < 0) { - fprintf(stderr, "Could not get context of %s: %s\n", - pathname, strerror(errno)); - return -1; - } - if (selabel_lookup(sehandle, &newcontext, pathname, sb->st_mode) < 0) { - fprintf(stderr, "Could not lookup context for %s: %s\n", pathname, - strerror(errno)); - return -1; - } - if (strcmp(newcontext, "<<none>>") && - strcmp(oldcontext, newcontext)) { - if (verbose) - printf("Relabeling %s from %s to %s.\n", pathname, oldcontext, newcontext); - if (!nochange) { - if (lsetfilecon(pathname, newcontext) < 0) { - fprintf(stderr, "Could not label %s with %s: %s\n", - pathname, newcontext, strerror(errno)); - return -1; - } - } - } - freecon(oldcontext); - freecon(newcontext); - return 0; -} - int restorecon_main(int argc, char **argv) { - int ch, recurse = 0, ftsflags = FTS_PHYSICAL; - int i = 0; + int ch, i, rc; + unsigned int flags = 0; progname = argv[0]; do { - ch = getopt(argc, argv, "nrRv"); + 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': - nochange = 1; + flags |= SELINUX_ANDROID_RESTORECON_NOCHANGE; break; case 'r': case 'R': - recurse = 1; + flags |= SELINUX_ANDROID_RESTORECON_RECURSE; break; case 'v': - verbose = 1; + flags |= SELINUX_ANDROID_RESTORECON_VERBOSE; break; default: usage(); @@ -83,53 +51,11 @@ int restorecon_main(int argc, char **argv) if (!argc) usage(); - sehandle = selinux_android_file_context_handle(); - - if (!sehandle) { - fprintf(stderr, "Could not load file_contexts: %s\n", - strerror(errno)); - return -1; - } - - if (recurse) { - FTS *fts; - FTSENT *ftsent; - fts = fts_open(argv, ftsflags, NULL); - if (!fts) { - fprintf(stderr, "Could not traverse filesystems (first was %s): %s\n", - argv[0], strerror(errno)); - return -1; - } - while ((ftsent = fts_read(fts))) { - switch (ftsent->fts_info) { - case FTS_DP: - break; - case FTS_DNR: - case FTS_ERR: - case FTS_NS: - fprintf(stderr, "Could not access %s: %s\n", ftsent->fts_path, - strerror(errno)); - fts_set(fts, ftsent, FTS_SKIP); - break; - default: - if (restore(ftsent->fts_path, ftsent->fts_statp) < 0) - fts_set(fts, ftsent, FTS_SKIP); - break; - } - } - } else { - int i, rc; - struct stat sb; - - for (i = 0; i < argc; i++) { - rc = lstat(argv[i], &sb); - if (rc < 0) { - fprintf(stderr, "Could not stat %s: %s\n", argv[i], - strerror(errno)); - continue; - } - restore(argv[i], &sb); - } + 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/rmdir.c b/toolbox/rmdir.c index 06f3df2..749fec8 100644 --- a/toolbox/rmdir.c +++ b/toolbox/rmdir.c @@ -11,7 +11,6 @@ static int usage() int rmdir_main(int argc, char *argv[]) { - int symbolic = 0; int ret; if(argc < 2) return usage(); diff --git a/toolbox/schedtop.c b/toolbox/schedtop.c index a76f968..2fccd2e 100644 --- a/toolbox/schedtop.c +++ b/toolbox/schedtop.c @@ -1,26 +1,23 @@ -#include <stdio.h> -#include <stdlib.h> #include <ctype.h> +#include <dirent.h> #include <fcntl.h> -#include <unistd.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 <dirent.h> -#include <signal.h> - -#include <pwd.h> +#include <unistd.h> struct thread_info { int pid; int tid; char name[64]; - uint64_t exec_time; - uint64_t delay_time; - uint32_t run_count; + unsigned long long exec_time; + unsigned long long delay_time; + unsigned long long run_count; }; struct thread_table { @@ -110,7 +107,8 @@ static void add_thread(int pid, int tid, struct thread_info *proc_info) sprintf(line, "/proc/%d/schedstat", pid); if (read_line(line, sizeof(line))) return; - if(sscanf(line, "%llu %llu %u", &info->exec_time, &info->delay_time, &info->run_count) != 3) + 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; @@ -183,7 +181,7 @@ static void print_threads(int pid, uint32_t flags) 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 %5u %5u.%0*u %5u.%0*u %7u %s\n", tid, + 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, @@ -229,14 +227,13 @@ static void update_table(DIR *d, uint32_t flags) } for (i = 0; i < last_processes.active; i++) { int pid = last_processes.data[i].pid; - int tid = last_processes.data[i].tid; 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 %5u %5u.%0*u %5u.%0*u %7u %s\n", pid, + 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, @@ -272,9 +269,6 @@ int schedtop_main(int argc, char **argv) { int c; DIR *d; - struct dirent *de; - char *namefilter = 0; - int pidfilter = 0; uint32_t flags = 0; int delay = 3000000; float delay_f; diff --git a/toolbox/sendevent.c b/toolbox/sendevent.c index 1608e6c..9b813f6 100644 --- a/toolbox/sendevent.c +++ b/toolbox/sendevent.c @@ -47,9 +47,8 @@ struct input_event { int sendevent_main(int argc, char *argv[]) { - int i; int fd; - int ret; + ssize_t ret; int version; struct input_event event; @@ -72,7 +71,7 @@ int sendevent_main(int argc, char *argv[]) event.code = atoi(argv[3]); event.value = atoi(argv[4]); ret = write(fd, &event, sizeof(event)); - if(ret < sizeof(event)) { + if(ret < (ssize_t) sizeof(event)) { fprintf(stderr, "write event failed, %s\n", strerror(errno)); return -1; } diff --git a/toolbox/start.c b/toolbox/start.c index 665a941..0941e64 100644 --- a/toolbox/start.c +++ b/toolbox/start.c @@ -7,14 +7,13 @@ int start_main(int argc, char *argv[]) { - char buf[1024]; - if(argc > 1) { property_set("ctl.start", argv[1]); } else { /* defaults to starting the common services stopped by stop.c */ property_set("ctl.start", "surfaceflinger"); property_set("ctl.start", "zygote"); + property_set("ctl.start", "zygote_secondary"); } return 0; diff --git a/toolbox/stop.c b/toolbox/stop.c index 460f377..ed9a293 100644 --- a/toolbox/stop.c +++ b/toolbox/stop.c @@ -5,12 +5,11 @@ int stop_main(int argc, char *argv[]) { - char buf[1024]; - if(argc > 1) { property_set("ctl.stop", argv[1]); } else{ /* defaults to stopping the common services */ + property_set("ctl.stop", "zygote_secondary"); property_set("ctl.stop", "zygote"); property_set("ctl.stop", "surfaceflinger"); } diff --git a/toolbox/swapoff.c b/toolbox/swapoff.c index 8f14158..d8f6a00 100644 --- a/toolbox/swapoff.c +++ b/toolbox/swapoff.c @@ -1,6 +1,5 @@ #include <stdio.h> #include <unistd.h> -#include <asm/page.h> #include <sys/swap.h> int swapoff_main(int argc, char **argv) diff --git a/toolbox/swapon.c b/toolbox/swapon.c index a810b3d..21d2287 100644 --- a/toolbox/swapon.c +++ b/toolbox/swapon.c @@ -2,7 +2,6 @@ #include <stdlib.h> #include <unistd.h> #include <getopt.h> -#include <asm/page.h> #include <sys/swap.h> void usage(char *name) diff --git a/toolbox/syren.c b/toolbox/syren.c index 06e329e..47c2460 100644 --- a/toolbox/syren.c +++ b/toolbox/syren.c @@ -123,7 +123,11 @@ syren_main(int argc, char **argv) r = find_reg(argv[2]); if (r == NULL) { - strcpy(name, argv[2]); + 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(); @@ -131,7 +135,7 @@ syren_main(int argc, char **argv) sio.page = strtoul(argv[2], 0, 0); sio.addr = strtoul(addr_str, 0, 0); } else { - strcpy(name, r->name); + strlcpy(name, r->name, sizeof(name)); sio.page = r->page; sio.addr = r->addr; } diff --git a/toolbox/top.c b/toolbox/top.c index 7642522..280a032 100644 --- a/toolbox/top.c +++ b/toolbox/top.c @@ -9,7 +9,7 @@ * 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 + * 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 @@ -22,7 +22,7 @@ * 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 + * 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 @@ -108,16 +108,20 @@ 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); -int top_main(int argc, char *argv[]) { - int i; +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; proc_cmp = &proc_cpu_cmp; - for (i = 1; i < argc; i++) { + for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "-m")) { if (i + 1 >= argc) { fprintf(stderr, "Option -m expects an argument.\n"); @@ -249,9 +253,9 @@ static void read_procs(void) { continue; pid = atoi(pid_dir->d_name); - + struct proc_info cur_proc; - + if (!threads) { proc = alloc_proc(); @@ -275,7 +279,7 @@ static void read_procs(void) { sprintf(filename, "/proc/%d/status", pid); read_status(filename, &cur_proc); - + proc = NULL; } @@ -310,7 +314,7 @@ static void read_procs(void) { } closedir(task_dir); - + if (!threads) add_proc(proc_num++, proc); } @@ -324,7 +328,6 @@ static void read_procs(void) { static int read_stat(char *filename, struct proc_info *proc) { FILE *file; char buf[MAX_LINE], *open_paren, *close_paren; - int res, idx; file = fopen(filename, "r"); if (!file) return 1; @@ -339,7 +342,7 @@ static int read_stat(char *filename, struct proc_info *proc) { *open_paren = *close_paren = '\0'; strncpy(proc->tname, open_paren + 1, THREAD_NAME_LEN); proc->tname[THREAD_NAME_LEN-1] = 0; - + /* Scan rest of string. */ sscanf(close_paren + 1, " %c %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d " "%lu %lu %*d %*d %*d %*d %*d %*d %*d %lu %ld " @@ -410,9 +413,7 @@ static void print_procs(void) { struct proc_info *old_proc, *proc; long unsigned total_delta_time; struct passwd *user; - struct group *group; char *user_str, user_buf[20]; - char *group_str, group_buf[20]; for (i = 0; i < num_new_procs; i++) { if (new_procs[i]) { @@ -452,7 +453,7 @@ static void print_procs(void) { new_cpu.sirqtime - old_cpu.sirqtime, total_delta_time); printf("\n"); - if (!threads) + if (!threads) printf("%5s %2s %4s %1s %5s %7s %7s %3s %-8s %s\n", "PID", "PR", "CPU%", "S", "#THR", "VSS", "RSS", "PCY", "UID", "Name"); else printf("%5s %5s %2s %4s %1s %7s %7s %3s %-8s %-15s %s\n", "PID", "TID", "PR", "CPU%", "S", "VSS", "RSS", "PCY", "UID", "Thread", "Proc"); @@ -463,20 +464,13 @@ static void print_procs(void) { if (!proc || (max_procs && (i >= max_procs))) break; user = getpwuid(proc->uid); - group = getgrgid(proc->gid); if (user && user->pw_name) { user_str = user->pw_name; } else { snprintf(user_buf, 20, "%d", proc->uid); user_str = user_buf; } - if (group && group->gr_name) { - group_str = group->gr_name; - } else { - snprintf(group_buf, 20, "%d", proc->gid); - group_str = group_buf; - } - if (!threads) + if (!threads) printf("%5d %2d %3ld%% %c %5d %6ldK %6ldK %3s %-8.8s %s\n", proc->pid, proc->prs, proc->delta_time * 100 / total_delta_time, proc->state, proc->num_threads, proc->vss / 1024, proc->rss * getpagesize() / 1024, proc->policy, user_str, proc->name[0] != 0 ? proc->name : proc->tname); else diff --git a/toolbox/uid_from_user.c b/toolbox/uid_from_user.c new file mode 100644 index 0000000..fd48d3c --- /dev/null +++ b/toolbox/uid_from_user.c @@ -0,0 +1,39 @@ +/* + * 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 <pwd.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; +} diff --git a/toolbox/umount.c b/toolbox/umount.c index 890e870..3e17396 100644 --- a/toolbox/umount.c +++ b/toolbox/umount.c @@ -33,7 +33,6 @@ static int is_loop_mount(const char* path, char *loopdev) char mount_path[256]; char rest[256]; int result = 0; - int path_length = strlen(path); f = fopen("/proc/mounts", "r"); if (!f) { diff --git a/toolbox/watchprops.c b/toolbox/watchprops.c index bf82882..0d05aba 100644 --- a/toolbox/watchprops.c +++ b/toolbox/watchprops.c @@ -6,8 +6,6 @@ #include <cutils/properties.h> #include <cutils/hashmap.h> -#include <sys/atomics.h> - #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include <sys/_system_properties.h> @@ -23,9 +21,9 @@ static bool str_equals(void *keyA, void *keyB) static void announce(char *name, char *value) { - char *x; + unsigned char *x; - for(x = value; *x; x++) { + for(x = (unsigned char *)value; *x; x++) { if((*x < 32) || (*x > 127)) *x = '.'; } @@ -77,9 +75,7 @@ static void update_watchlist(const prop_info *pi, void *cookie) int watchprops_main(int argc, char *argv[]) { - unsigned serial = 0; - unsigned count = 0; - unsigned n; + unsigned serial; Hashmap *watchlist = hashmapCreate(1024, str_hash, str_equals); if (!watchlist) @@ -87,7 +83,7 @@ int watchprops_main(int argc, char *argv[]) __system_property_foreach(populate_watchlist, watchlist); - for(;;) { + for(serial = 0;;) { serial = __system_property_wait_any(serial); __system_property_foreach(update_watchlist, watchlist); } |