aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2019-06-07 10:38:36 -0700
committerRob Landley <rob@landley.net>2019-06-07 21:53:50 -0500
commit61ef1dccec4e6bf1c56384ed1cd45f93dcb6bd4c (patch)
tree5466c8b6204c8cb8cc22ad9dd2df97f79cb139ab
parent7771204cf7bc161822eb636ff6fb30a1579b622d (diff)
downloadtoybox-61ef1dccec4e6bf1c56384ed1cd45f93dcb6bd4c.tar.gz
Remove getprop, setprop, start, and stop from toybox
These are Android specific, so not really helping the outside community, and are getting more and more Android dependencies to work correctly, so let's drop these from toybox and build them within Android. Change-Id: Ic6022f1f506e10868c61f55d64fa4e7c1b14eba2
-rw-r--r--lib/portability.h6
-rw-r--r--toys/android/getprop.c119
-rw-r--r--toys/android/setprop.c44
-rw-r--r--toys/android/start.c59
4 files changed, 0 insertions, 228 deletions
diff --git a/lib/portability.h b/lib/portability.h
index f5f8352a..f57eb026 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -251,7 +251,6 @@ pid_t xfork(void);
// use toybox before they're ready to switch to host bionic.
#ifdef __BIONIC__
#include <android/log.h>
-#include <sys/system_properties.h>
#else
typedef enum android_LogPriority {
ANDROID_LOG_UNKNOWN = 0,
@@ -268,11 +267,6 @@ static inline int __android_log_write(int pri, const char *tag, const char *msg)
{
return -1;
}
-#define PROP_VALUE_MAX 92
-static inline int __system_property_set(const char *key, const char *value)
-{
- return -1;
-}
#endif
// libprocessgroup is an Android platform library not included in the NDK.
diff --git a/toys/android/getprop.c b/toys/android/getprop.c
deleted file mode 100644
index 51ef7f6b..00000000
--- a/toys/android/getprop.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/* getprop.c - Get an Android system property
- *
- * Copyright 2015 The Android Open Source Project
-
-USE_GETPROP(NEWTOY(getprop, ">2Z", TOYFLAG_USR|TOYFLAG_SBIN))
-
-config GETPROP
- bool "getprop"
- default y
- depends on TOYBOX_ON_ANDROID && TOYBOX_SELINUX
- help
- usage: getprop [NAME [DEFAULT]]
-
- Gets an Android system property, or lists them all.
-*/
-
-#define FOR_getprop
-#include "toys.h"
-
-#include <sys/system_properties.h>
-
-#include <selinux/android.h>
-#include <selinux/label.h>
-#include <selinux/selinux.h>
-
-GLOBALS(
- size_t size;
- char **nv; // name/value pairs: even=name, odd=value
- struct selabel_handle *handle;
-)
-
-static char *get_property_context(const char *property)
-{
- char *context = NULL;
-
- if (selabel_lookup(TT.handle, &context, property, 1)) {
- perror_exit("unable to lookup label for \"%s\"", property);
- }
- return context;
-}
-
-static void read_callback(void *unused, const char *name, const char *value,
- unsigned serial)
-{
- if (!(TT.size&31)) TT.nv = xrealloc(TT.nv, (TT.size+32)*2*sizeof(char *));
-
- TT.nv[2*TT.size] = xstrdup((char *)name);
- if (toys.optflags & FLAG_Z) {
- TT.nv[1+2*TT.size++] = get_property_context(name);
- } else {
- TT.nv[1+2*TT.size++] = xstrdup((char *)value);
- }
-}
-
-static void add_property(const prop_info *pi, void *unused)
-{
- __system_property_read_callback(pi, read_callback, NULL);
-}
-
-static void print_callback(void *unused, const char *unused_name, const char *value,
- unsigned unused_serial)
-{
- puts(value);
-}
-
-// Needed to supress extraneous "Loaded property_contexts from" message
-static int selinux_log_callback_local(int type, const char *fmt, ...)
-{
- va_list ap;
-
- if (type == SELINUX_INFO) return 0;
- va_start(ap, fmt);
- verror_msg((char *)fmt, 0, ap);
- va_end(ap);
- return 0;
-}
-
-void getprop_main(void)
-{
- if (toys.optflags & FLAG_Z) {
- union selinux_callback cb;
-
- cb.func_log = selinux_log_callback_local;
- selinux_set_callback(SELINUX_CB_LOG, cb);
- TT.handle = selinux_android_prop_context_handle();
- if (!TT.handle) error_exit("unable to get selinux property context handle");
- }
-
- if (*toys.optargs) {
- if (toys.optflags & FLAG_Z) {
- char *context = get_property_context(*toys.optargs);
-
- puts(context);
- if (CFG_TOYBOX_FREE) free(context);
- } else {
- const prop_info* pi = __system_property_find(*toys.optargs);
- if (pi == NULL) {
- puts(toys.optargs[1] ? toys.optargs[1] : "");
- } else {
- __system_property_read_callback(pi, print_callback, NULL);
- }
- }
- } else {
- size_t i;
-
- if (__system_property_foreach(add_property, NULL))
- error_exit("property_list");
- qsort(TT.nv, TT.size, 2*sizeof(char *), qstrcmp);
- for (i = 0; i<TT.size; i++) printf("[%s]: [%s]\n", TT.nv[i*2],TT.nv[1+i*2]);
- if (CFG_TOYBOX_FREE) {
- for (i = 0; i<TT.size; i++) {
- free(TT.nv[i*2]);
- free(TT.nv[1+i*2]);
- }
- free(TT.nv);
- }
- }
- if (CFG_TOYBOX_FREE && (toys.optflags & FLAG_Z)) selabel_close(TT.handle);
-}
diff --git a/toys/android/setprop.c b/toys/android/setprop.c
deleted file mode 100644
index cda34a5d..00000000
--- a/toys/android/setprop.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/* setprop.c - Set an Android system property
- *
- * Copyright 2015 The Android Open Source Project
-
-USE_SETPROP(NEWTOY(setprop, "<2>2", TOYFLAG_USR|TOYFLAG_SBIN))
-
-config SETPROP
- bool "setprop"
- default y
- depends on TOYBOX_ON_ANDROID
- help
- usage: setprop NAME VALUE
-
- Sets an Android system property.
-*/
-
-#define FOR_setprop
-#include "toys.h"
-
-void setprop_main(void)
-{
- char *name = toys.optargs[0], *value = toys.optargs[1];
- char *p;
- size_t name_len = strlen(name), value_len = strlen(value);
-
- // property_set doesn't tell us why it failed, and actually can't
- // recognize most failures (because it doesn't wait for init), so
- // we duplicate all of init's checks here to help the user.
-
- if (value_len >= PROP_VALUE_MAX && !strncmp(value, "ro.", 3))
- error_exit("value '%s' too long; try '%.*s'",
- value, PROP_VALUE_MAX - 1, value);
-
- if (*name == '.' || name[name_len - 1] == '.')
- error_exit("property names must not start or end with '.'");
- if (strstr(name, ".."))
- error_exit("'..' is not allowed in a property name");
- for (p = name; *p; ++p)
- if (!isalnum(*p) && !strchr(":@_.-", *p))
- error_exit("invalid character '%c' in name '%s'", *p, name);
-
- if (__system_property_set(name, value))
- error_msg("failed to set property '%s' to '%s'", name, value);
-}
diff --git a/toys/android/start.c b/toys/android/start.c
deleted file mode 100644
index 5df847a9..00000000
--- a/toys/android/start.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/* start.c - Start/stop system services.
- *
- * Copyright 2016 The Android Open Source Project
-
-USE_START(NEWTOY(start, "", TOYFLAG_USR|TOYFLAG_SBIN))
-USE_STOP(NEWTOY(stop, "", TOYFLAG_USR|TOYFLAG_SBIN))
-
-config START
- bool "start"
- depends on TOYBOX_ON_ANDROID
- default y
- help
- usage: start [SERVICE...]
-
- Starts the given system service, or netd/surfaceflinger/zygotes.
-
-config STOP
- bool "stop"
- depends on TOYBOX_ON_ANDROID
- default y
- help
- usage: stop [SERVICE...]
-
- Stop the given system service, or netd/surfaceflinger/zygotes.
-*/
-
-#define FOR_start
-#include "toys.h"
-
-static void start_stop(int start)
-{
- char *property = start ? "ctl.start" : "ctl.stop";
- // null terminated in both directions
- char *services[] = {0,"netd","surfaceflinger","zygote","zygote_secondary",0},
- **ss = toys.optargs;
- int direction = 1;
-
- if (getuid()) error_exit("must be root");
-
- if (!*ss) {
- // If we don't have optargs, iterate through services forward/backward.
- ss = services+1;
- if (!start) ss = services+ARRAY_LEN(services)-2, direction = -1;
- }
-
- for (; *ss; ss += direction)
- if (__system_property_set(property, *ss))
- error_exit("failed to set property '%s' to '%s'", property, *ss);
-}
-
-void start_main(void)
-{
- start_stop(1);
-}
-
-void stop_main(void)
-{
- start_stop(0);
-}