Merge "init: Add option to run a service in a new PID/mount namespace."
diff --git a/adb/adb.cpp b/adb/adb.cpp
index c3f1a96..725aa91 100644
--- a/adb/adb.cpp
+++ b/adb/adb.cpp
@@ -46,8 +46,6 @@
#include "adb_utils.h"
#include "transport.h"
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
-
#if !ADB_HOST
#include <cutils/properties.h>
#include <sys/capability.h>
diff --git a/fastboot/engine.cpp b/fastboot/engine.cpp
index a245e49..728dcb8 100644
--- a/fastboot/engine.cpp
+++ b/fastboot/engine.cpp
@@ -38,8 +38,6 @@
#include <sys/types.h>
#include <unistd.h>
-#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
-
#define OP_DOWNLOAD 1
#define OP_COMMAND 2
#define OP_QUERY 3
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 1839d25..665b9d0 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -47,6 +47,7 @@
#include <utility>
#include <vector>
+#include <android-base/macros.h>
#include <android-base/parseint.h>
#include <android-base/parsenetaddress.h>
#include <android-base/stringprintf.h>
@@ -67,8 +68,6 @@
#define O_BINARY 0
#endif
-#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a)))
-
char cur_product[FB_RESPONSE_SZ + 1];
static const char* serial = nullptr;
@@ -926,7 +925,7 @@
setup_requirements(reinterpret_cast<char*>(data), sz);
- for (size_t i = 0; i < ARRAY_SIZE(images); ++i) {
+ for (size_t i = 0; i < arraysize(images); ++i) {
int fd = unzip_to_file(zip, images[i].img_name);
if (fd == -1) {
if (images[i].is_optional) {
@@ -988,7 +987,7 @@
setup_requirements(reinterpret_cast<char*>(data), sz);
- for (size_t i = 0; i < ARRAY_SIZE(images); i++) {
+ for (size_t i = 0; i < arraysize(images); i++) {
fname = find_item(images[i].part_name, product);
fastboot_buffer buf;
if (!load_buf(transport, fname.c_str(), &buf)) {
diff --git a/libcutils/tests/PropertiesTest.cpp b/libcutils/tests/PropertiesTest.cpp
index 5f2396b..f66590b 100644
--- a/libcutils/tests/PropertiesTest.cpp
+++ b/libcutils/tests/PropertiesTest.cpp
@@ -24,11 +24,12 @@
#include <sstream>
#include <iostream>
+#include <android-base/macros.h>
+
namespace android {
#define STRINGIFY_INNER(x) #x
#define STRINGIFY(x) STRINGIFY_INNER(x)
-#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
#define ASSERT_OK(x) ASSERT_EQ(0, (x))
#define EXPECT_OK(x) EXPECT_EQ(0, (x))
@@ -85,7 +86,7 @@
}
void ResetValue(unsigned char c = 0xFF) {
- for (size_t i = 0; i < ARRAY_SIZE(mValue); ++i) {
+ for (size_t i = 0; i < arraysize(mValue); ++i) {
mValue[i] = (char) c;
}
}
@@ -177,7 +178,7 @@
* TRUE
*/
const char *valuesTrue[] = { "1", "true", "y", "yes", "on", };
- for (size_t i = 0; i < ARRAY_SIZE(valuesTrue); ++i) {
+ for (size_t i = 0; i < arraysize(valuesTrue); ++i) {
ASSERT_OK(property_set(PROPERTY_TEST_KEY, valuesTrue[i]));
bool val = property_get_bool(PROPERTY_TEST_KEY, /*default_value*/false);
EXPECT_TRUE(val) << "Property should've been TRUE for value: '" << valuesTrue[i] << "'";
@@ -187,7 +188,7 @@
* FALSE
*/
const char *valuesFalse[] = { "0", "false", "n", "no", "off", };
- for (size_t i = 0; i < ARRAY_SIZE(valuesFalse); ++i) {
+ for (size_t i = 0; i < arraysize(valuesFalse); ++i) {
ASSERT_OK(property_set(PROPERTY_TEST_KEY, valuesFalse[i]));
bool val = property_get_bool(PROPERTY_TEST_KEY, /*default_value*/true);
EXPECT_FALSE(val) << "Property shoud've been FALSE For string value: '" << valuesFalse[i] << "'";
@@ -200,7 +201,7 @@
"+1", " 1 ", " true", " true ", " y ", " yes", "yes ",
"+0", "-0", "00", " 00 ", " false", "false ",
};
- for (size_t i = 0; i < ARRAY_SIZE(valuesNeither); ++i) {
+ for (size_t i = 0; i < arraysize(valuesNeither); ++i) {
ASSERT_OK(property_set(PROPERTY_TEST_KEY, valuesNeither[i]));
// The default value should always be used
@@ -249,9 +250,9 @@
DEFAULT_VALUE, DEFAULT_VALUE,
};
- ASSERT_EQ(ARRAY_SIZE(setValues), ARRAY_SIZE(getValues));
+ ASSERT_EQ(arraysize(setValues), arraysize(getValues));
- for (size_t i = 0; i < ARRAY_SIZE(setValues); ++i) {
+ for (size_t i = 0; i < arraysize(setValues); ++i) {
ASSERT_OK(property_set(PROPERTY_TEST_KEY, setValues[i]));
int64_t val = property_get_int64(PROPERTY_TEST_KEY, DEFAULT_VALUE);
@@ -296,9 +297,9 @@
DEFAULT_VALUE, DEFAULT_VALUE,
};
- ASSERT_EQ(ARRAY_SIZE(setValues), ARRAY_SIZE(getValues));
+ ASSERT_EQ(arraysize(setValues), arraysize(getValues));
- for (size_t i = 0; i < ARRAY_SIZE(setValues); ++i) {
+ for (size_t i = 0; i < arraysize(setValues); ++i) {
ASSERT_OK(property_set(PROPERTY_TEST_KEY, setValues[i]));
int32_t val = property_get_int32(PROPERTY_TEST_KEY, DEFAULT_VALUE);
diff --git a/libmemunreachable/Allocator.cpp b/libmemunreachable/Allocator.cpp
index 68f654c..6fe67a4 100644
--- a/libmemunreachable/Allocator.cpp
+++ b/libmemunreachable/Allocator.cpp
@@ -52,8 +52,6 @@
return (x + y - 1) / y;
}
-#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
-
static constexpr size_t kPageSize = 4096;
static constexpr size_t kChunkSize = 256 * 1024;
static constexpr size_t kUsableChunkSize = kChunkSize - kPageSize;
@@ -258,7 +256,7 @@
unsigned int i = first_free_bitmap_;
while (free_bitmap_[i] == 0)
i++;
- assert(i < ARRAY_SIZE(free_bitmap_));
+ assert(i < arraysize(free_bitmap_));
unsigned int bit = __builtin_ffs(free_bitmap_[i]) - 1;
assert(free_bitmap_[i] & (1U << bit));
free_bitmap_[i] &= ~(1U << bit);
@@ -266,7 +264,7 @@
assert(n < max_allocations_);
unsigned int page = n * allocation_size_ / kPageSize;
- assert(page / 32 < ARRAY_SIZE(dirty_pages_));
+ assert(page / 32 < arraysize(dirty_pages_));
dirty_pages_[page / 32] |= 1U << (page % 32);
free_count_--;
@@ -285,7 +283,7 @@
unsigned int i = n / 32;
unsigned int bit = n % 32;
- assert(i < ARRAY_SIZE(free_bitmap_));
+ assert(i < arraysize(free_bitmap_));
assert(!(free_bitmap_[i] & (1U << bit)));
free_bitmap_[i] |= 1U << bit;
free_count_++;
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index 23af1f9..c7b6d4c0 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -34,13 +34,10 @@
getevent \
newfs_msdos \
sendevent \
- start \
- stop \
ALL_TOOLS = $(BSD_TOOLS) $(OUR_TOOLS)
LOCAL_SRC_FILES := \
- start_stop.cpp \
toolbox.c \
$(patsubst %,%.c,$(OUR_TOOLS)) \
diff --git a/toolbox/start.c b/toolbox/start.c
deleted file mode 100644
index cca5fef..0000000
--- a/toolbox/start.c
+++ /dev/null
@@ -1 +0,0 @@
-/* Needed by Android.mk. Actual code in start_stop.cpp. */
diff --git a/toolbox/start_stop.cpp b/toolbox/start_stop.cpp
deleted file mode 100644
index dc48c0c..0000000
--- a/toolbox/start_stop.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-#include <error.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <cutils/properties.h>
-
-static const char* services[] = {
- "netd",
- "surfaceflinger",
- "zygote",
- "zygote_secondary",
-};
-
-static int start_stop(bool start, int argc, char* argv[]) {
- if (getuid() != 0) error(1, 0, "must be root");
- const char* property = start ? "ctl.start" : "ctl.stop";
- if (argc > 2) {
- error(1, 0, "usage: %s [SERVICE]\n", argv[0]);
- } else if (argc == 2) {
- property_set(property, argv[1]);
- } else {
- if (start) {
- for (size_t i = 0; i < sizeof(services)/sizeof(services[0]); ++i) {
- property_set(property, services[i]);
- }
- } else {
- for (int i = sizeof(services)/sizeof(services[0]) - 1; i >= 0; --i) {
- property_set(property, services[i]);
- }
- }
- }
- return 0;
-}
-
-extern "C" int start_main(int argc, char* argv[]) {
- return start_stop(true, argc, argv);
-}
-
-extern "C" int stop_main(int argc, char* argv[]) {
- return start_stop(false, argc, argv);
-}
diff --git a/toolbox/stop.c b/toolbox/stop.c
deleted file mode 100644
index cca5fef..0000000
--- a/toolbox/stop.c
+++ /dev/null
@@ -1 +0,0 @@
-/* Needed by Android.mk. Actual code in start_stop.cpp. */