Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7bb56606 authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Refresh toolbox.

Use more upstream NetBSD, and update those things that were already NetBSD.

Note that unlike bionic, the upstream-netbsd directory isn't pristine; we have
changes marked by __ANDROID__.

Bug: 16493461

(cherry picked from commit fd4c6b0a)

Change-Id: I53267edaac0b92ad062a5df0f3201e3952eb084e
parent eb49dd79
Loading
Loading
Loading
Loading
+194 −88
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)


common_cflags := \
    -std=gnu99 \
    -Werror -Wno-unused-parameter \
    -I$(LOCAL_PATH)/upstream-netbsd/include/ \
    -include bsd-compatibility.h \


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
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
@@ -13,19 +71,81 @@ 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)

TOOLS := \
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 \
	chown \
    clear \
    cmp \
    date \
	dd \
    df \
    dmesg \
	du \
    getenforce \
    getevent \
    getprop \
@@ -37,7 +157,6 @@ TOOLS := \
    insmod \
    ioctl \
    ionice \
	ln \
    load_policy \
    log \
    ls \
@@ -48,19 +167,15 @@ TOOLS := \
    mknod \
    mkswap \
    mount \
	mv \
    nandread \
    netstat \
    newfs_msdos \
    nohup \
    notify \
	printenv \
    ps \
    readlink \
    renice \
    restorecon \
	rm \
	rmdir \
    rmmod \
    route \
    runcon \
@@ -69,13 +184,11 @@ TOOLS := \
    setenforce \
    setprop \
    setsebool \
	sleep \
    smd \
    start \
    stop \
    swapoff \
    swapon \
	sync \
    top \
    touch \
    umount \
@@ -85,27 +198,21 @@ TOOLS := \
    wipe \

ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
TOOLS += r
OUR_TOOLS += r
endif

ALL_TOOLS = $(TOOLS)
ALL_TOOLS += \
	cp \
	grep \
	kill \
ALL_TOOLS = $(BSD_TOOLS) $(OUR_TOOLS)

LOCAL_SRC_FILES := \
	cp/cp.c \
	cp/utils.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 \
    dynarray.c \
	grep/fastgrep.c \
	grep/file.c \
	grep/grep.c \
	grep/queue.c \
	grep/util.c \
	$(patsubst %,%.c,$(TOOLS)) \
    pwcache.c \
    $(patsubst %,%.c,$(OUR_TOOLS)) \
    toolbox.c \
	uid_from_user.c \

LOCAL_CFLAGS += $(common_cflags)

@@ -121,8 +228,7 @@ LOCAL_SHARED_LIBRARIES := \
LOCAL_STATIC_LIBRARIES := \
    libusbhost \

LOCAL_WHOLE_STATIC_LIBRARIES := \
    libtoolbox_kill \
LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))

LOCAL_MODULE := toolbox
LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
+897 −103

File changed.

Preview size limit exceeded, changes collapsed.

+52 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
 * SUCH DAMAGE.
 */

#include <stdbool.h>
#include <sys/types.h>

/* We want chown to support user.group as well as user:group. */
@@ -34,8 +35,58 @@
/* We don't localize /system/bin! */
#define WITHOUT_NLS

// NetBSD uses _DIAGASSERT to null-check arguments and the like.
#include <assert.h>
#define _DIAGASSERT(e) ((e) ? (void) 0 : __assert2(__FILE__, __LINE__, __func__, #e))

// TODO: update our <sys/cdefs.h> to support this properly.
#define __type_fit(t, a) (0 == 0)

// TODO: should this be in our <sys/cdefs.h>?
#define __arraycount(a) (sizeof(a) / sizeof(a[0]))

// This at least matches GNU dd(1) behavior.
#define SIGINFO SIGUSR1

#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

extern int uid_from_user(const char* name, uid_t* uid);
/* 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
#define HN_B                    0x04
#define HN_DIVISOR_1000         0x08
#define HN_GETSCALE             0x10
#define HN_AUTOSCALE            0x20
int	humanize_number(char *, size_t, int64_t, const char *, int, int);
int	dehumanize_number(const char *, int64_t *);
char	*getbsize(int *, long *);
long long strsuftoll(const char *, const char *, long long, long long);
long long strsuftollx(const char *, const char *, long long, long long,
			char *, size_t);

/* From NetBSD <string.h>. */
void strmode(mode_t, char*);

/* From NetBSD <sys/param.h>. */
#define MAXBSIZE 65536

/* From NetBSD <sys/stat.h>. */
#define DEFFILEMODE (S_IRUSR | S_IWUSR)

/* From NetBSD <unistd.h>. */
void	swab(const void * __restrict, void * __restrict, ssize_t);

/* From NetBSD <util.h>. */
int		raise_default_signal(int);

__END_DECLS

toolbox/ln.c

deleted100644 → 0
+0 −34
Original line number Diff line number Diff line
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

static int usage()
{
    fprintf(stderr,"ln [-s] <target> <name>\n");
    return -1;
}

int ln_main(int argc, char *argv[])
{
    int symbolic = 0;
    int ret;
    if(argc < 2) return usage();
    
    if(!strcmp(argv[1],"-s")) {
        symbolic = 1;
        argc--;
        argv++;
    }

    if(argc < 3) return usage();

    if(symbolic) {
        ret = symlink(argv[1], argv[2]);
    } else {
        ret = link(argv[1], argv[2]);
    }
    if(ret < 0)
        fprintf(stderr, "link failed %s\n", strerror(errno));
    return ret;
}
+4 −4
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@
// fwd
static int listpath(const char *name, int flags);

static char mode2kind(unsigned mode)
static char mode2kind(mode_t mode)
{
    switch(mode & S_IFMT){
    case S_IFSOCK: return 's';
@@ -47,7 +47,7 @@ static char mode2kind(unsigned mode)
    }
}

static void mode2str(unsigned mode, char *out)
void strmode(mode_t mode, char *out)
{
    *out++ = mode2kind(mode);

@@ -180,7 +180,7 @@ static int listfile_long(const char *path, struct stat *s, int flags)
        name++;
    }

    mode2str(s->st_mode, mode);
    strmode(s->st_mode, mode);
    if (flags & LIST_LONG_NUMERIC) {
        snprintf(user, sizeof(user), "%u", s->st_uid);
        snprintf(group, sizeof(group), "%u", s->st_gid);
@@ -260,7 +260,7 @@ static int listfile_maclabel(const char *path, struct stat *s)
        return -1;
    }

    mode2str(s->st_mode, mode);
    strmode(s->st_mode, mode);
    user2str(s->st_uid, user, sizeof(user));
    group2str(s->st_gid, group, sizeof(group));

Loading