Change-Id: I6d2c6ba7b520c583254ea84c9b6d5438f77a7bb5
---
 toys/android/getprop.c | 27 ++++++++++++---------------
 toys/android/setprop.c | 14 ++------------
 toys/android/start.c   |  4 ++--
 3 files changed, 16 insertions(+), 29 deletions(-)
From 31e934994507071d4e008b04e815d5443bf73629 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Mon, 26 Dec 2016 12:12:23 -0800
Subject: [PATCH] Switch to bionic <sys/system_properties.h>.

Change-Id: I6d2c6ba7b520c583254ea84c9b6d5438f77a7bb5
---
 toys/android/getprop.c | 27 ++++++++++++---------------
 toys/android/setprop.c | 14 ++------------
 toys/android/start.c   |  4 ++--
 3 files changed, 16 insertions(+), 29 deletions(-)

diff --git a/toys/android/getprop.c b/toys/android/getprop.c
index 9675d9f..305a7a9 100644
--- a/toys/android/getprop.c
+++ b/toys/android/getprop.c
@@ -17,9 +17,7 @@ config GETPROP
 #define FOR_getprop
 #include "toys.h"
 
-#if defined(__ANDROID__)
-
-#include <cutils/properties.h>
+#include <sys/system_properties.h>
 
 #include <selinux/android.h>
 #include <selinux/label.h>
@@ -41,8 +39,13 @@ static char *get_property_context(char *property)
   return context;
 }
 
-static void add_property(char *name, char *value, void *unused)
+static void add_property(const prop_info *pi, void *unused)
 {
+  char name[PROP_NAME_MAX];
+  char value[PROP_VALUE_MAX];
+
+  __system_property_read(pi, name, value);
+
   if (!(TT.size&31)) TT.nv = xrealloc(TT.nv, (TT.size+32)*2*sizeof(char *));
 
   TT.nv[2*TT.size] = xstrdup(name);
@@ -60,7 +63,7 @@ static int selinux_log_callback_local(int type, const char *fmt, ...)
 
   if (type == SELINUX_INFO) return 0;
   va_start(ap, fmt);
-  verror_msg(fmt, 0, ap);
+  verror_msg((char *)fmt, 0, ap);
   va_end(ap);
   return 0;
 }
@@ -83,13 +86,15 @@ void getprop_main(void)
       puts(context);
       if (CFG_TOYBOX_FREE) free(context);
     } else {
-      property_get(*toys.optargs, toybuf, toys.optargs[1] ? toys.optargs[1] : "");
+      if (__system_property_get(*toys.optargs, toybuf) <= 0)
+        strcpy(toybuf, toys.optargs[1] ? toys.optargs[1] : "");
       puts(toybuf);
     }
   } else {
     size_t i;
 
-    if (property_list((void *)add_property, 0)) error_exit("property_list");
+    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) {
@@ -102,11 +107,3 @@ void getprop_main(void)
   }
   if (CFG_TOYBOX_FREE && (toys.optflags & FLAG_Z)) selabel_close(TT.handle);
 }
-
-#else
-
-void getprop_main(void)
-{
-}
-
-#endif
diff --git a/toys/android/setprop.c b/toys/android/setprop.c
index 72bd7bd..2af314a 100644
--- a/toys/android/setprop.c
+++ b/toys/android/setprop.c
@@ -17,9 +17,7 @@ config SETPROP
 #define FOR_setprop
 #include "toys.h"
 
-#if defined(__ANDROID__)
-
-#include <cutils/properties.h>
+#include <sys/system_properties.h>
 
 void setprop_main(void)
 {
@@ -46,14 +44,6 @@ void setprop_main(void)
     if (!isalnum(*p) && !strchr("@_.-", *p))
       error_exit("invalid character '%c' in name '%s'", *p, name);
 
-  if (property_set(name, value))
+  if (__system_property_set(name, value))
     error_msg("failed to set property '%s' to '%s'", name, value);
 }
-
-#else
-
-void setprop_main(void)
-{
-}
-
-#endif
diff --git a/toys/android/start.c b/toys/android/start.c
index 20fa2b9..f6b3c37 100644
--- a/toys/android/start.c
+++ b/toys/android/start.c
@@ -27,7 +27,7 @@ config STOP
 #define FOR_start
 #include "toys.h"
 
-#include <cutils/properties.h>
+#include <sys/system_properties.h>
 
 static void start_stop(int start)
 {
@@ -46,7 +46,7 @@ static void start_stop(int start)
   }
 
   for (; *ss; ss += direction)
-    if (property_set(property, *ss))
+    if (__system_property_set(property, *ss))
       error_exit("failed to set property '%s' to '%s'", property, *ss);
 }
 
-- 
2.8.0.rc3.226.g39d4020

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to