Loading debuggerd/libdebuggerd/test/sys/system_properties.h +0 −1 Original line number Original line Diff line number Diff line Loading @@ -32,7 +32,6 @@ // This is just enough to get the property code to compile on // This is just enough to get the property code to compile on // the host. // the host. #define PROP_NAME_MAX 32 #define PROP_VALUE_MAX 92 #define PROP_VALUE_MAX 92 #endif // _DEBUGGERD_TEST_SYS_SYSTEM_PROPERTIES_H #endif // _DEBUGGERD_TEST_SYS_SYSTEM_PROPERTIES_H init/service.cpp +5 −7 Original line number Original line Diff line number Diff line Loading @@ -180,12 +180,6 @@ void Service::NotifyStateChange(const std::string& new_state) const { } } std::string prop_name = StringPrintf("init.svc.%s", name_.c_str()); std::string prop_name = StringPrintf("init.svc.%s", name_.c_str()); if (prop_name.length() >= PROP_NAME_MAX) { // If the property name would be too long, we can't set it. LOG(ERROR) << "Property name \"init.svc." << name_ << "\" too long; not setting to " << new_state; return; } property_set(prop_name.c_str(), new_state.c_str()); property_set(prop_name.c_str(), new_state.c_str()); if (new_state == "running") { if (new_state == "running") { Loading Loading @@ -1040,5 +1034,9 @@ void ServiceParser::EndSection() { } } bool ServiceParser::IsValidName(const std::string& name) const { bool ServiceParser::IsValidName(const std::string& name) const { return is_legal_property_name("init.svc." + name); // Property names can be any length, but may only contain certain characters. // Property values can contain any characters, but may only be a certain length. // (The latter restriction is needed because `start` and `stop` work by writing // the service name to the "ctl.start" and "ctl.stop" properties.) return is_legal_property_name("init.svc." + name) && name.size() <= PROP_VALUE_MAX; } } libsysutils/Android.mk +1 −1 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ LOCAL_MODULE:= libsysutils LOCAL_CFLAGS := -Werror LOCAL_CFLAGS := -Werror LOCAL_SHARED_LIBRARIES := \ LOCAL_SHARED_LIBRARIES := \ libbase \ libcutils \ libcutils \ liblog \ liblog \ libnl libnl Loading @@ -24,4 +25,3 @@ LOCAL_SHARED_LIBRARIES := \ LOCAL_EXPORT_C_INCLUDE_DIRS := system/core/libsysutils/include LOCAL_EXPORT_C_INCLUDE_DIRS := system/core/libsysutils/include include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY) libsysutils/src/ServiceManager.cpp +15 −37 Original line number Original line Diff line number Diff line Loading @@ -19,34 +19,23 @@ #include <errno.h> #include <errno.h> #include <stdio.h> #include <stdio.h> #include <string.h> #include <string.h> #include <sys/system_properties.h> #include <unistd.h> #include <unistd.h> #include <cutils/properties.h> #include <android-base/properties.h> #include <android-base/stringprintf.h> #include <log/log.h> #include <log/log.h> #include <sysutils/ServiceManager.h> #include <sysutils/ServiceManager.h> ServiceManager::ServiceManager() { ServiceManager::ServiceManager() { } } /* The service name should not exceed SERVICE_NAME_MAX to avoid // The length of a service name should not exceed SERVICE_NAME_MAX. Starting * some weird things. This is due to the fact that: // a service is done by writing its name to the "ctl.start" system property * // and stopping a service is done by writing its name to "ctl.stop". If a * - Starting a service is done by writing its name to the "ctl.start" // service name is too long to fit in a property, you won't be able to start * system property. This triggers the init daemon to actually start // or stop it. * the service for us. static constexpr size_t SERVICE_NAME_MAX = PROP_VALUE_MAX; * * - Stopping the service is done by writing its name to "ctl.stop" * in a similar way. * * - Reading the status of a service is done by reading the property * named "init.svc.<name>" * * If strlen(<name>) > (PROPERTY_KEY_MAX-1)-9, then you can start/stop * the service by writing to ctl.start/stop, but you won't be able to * read its state due to the truncation of "init.svc.<name>" into a * zero-terminated buffer of PROPERTY_KEY_MAX characters. */ #define SERVICE_NAME_MAX (PROPERTY_KEY_MAX-10) /* The maximum amount of time to wait for a service to start or stop, /* The maximum amount of time to wait for a service to start or stop, * in micro-seconds (really an approximation) */ * in micro-seconds (really an approximation) */ Loading @@ -61,13 +50,14 @@ int ServiceManager::start(const char *name) { SLOGE("Service name '%s' is too long", name); SLOGE("Service name '%s' is too long", name); return 0; return 0; } } if (isRunning(name)) { if (isRunning(name)) { SLOGW("Service '%s' is already running", name); SLOGW("Service '%s' is already running", name); return 0; return 0; } } SLOGD("Starting service '%s'", name); SLOGD("Starting service '%s'", name); property_set("ctl.start", name); android::base::SetProperty("ctl.start", name); int count = SLEEP_MAX_USEC; int count = SLEEP_MAX_USEC; while(count > 0) { while(count > 0) { Loading @@ -90,13 +80,14 @@ int ServiceManager::stop(const char *name) { SLOGE("Service name '%s' is too long", name); SLOGE("Service name '%s' is too long", name); return 0; return 0; } } if (!isRunning(name)) { if (!isRunning(name)) { SLOGW("Service '%s' is already stopped", name); SLOGW("Service '%s' is already stopped", name); return 0; return 0; } } SLOGD("Stopping service '%s'", name); SLOGD("Stopping service '%s'", name); property_set("ctl.stop", name); android::base::SetProperty("ctl.stop", name); int count = SLEEP_MAX_USEC; int count = SLEEP_MAX_USEC; while(count > 0) { while(count > 0) { Loading @@ -116,19 +107,6 @@ int ServiceManager::stop(const char *name) { } } bool ServiceManager::isRunning(const char *name) { bool ServiceManager::isRunning(const char *name) { char propVal[PROPERTY_VALUE_MAX]; std::string property_name = android::base::StringPrintf("init.svc.%s", name); char propName[PROPERTY_KEY_MAX]; return (android::base::GetProperty(property_name, "") == "running"); int ret; ret = snprintf(propName, sizeof(propName), "init.svc.%s", name); if (ret > (int)sizeof(propName)-1) { SLOGD("Service name '%s' is too long", name); return false; } if (property_get(propName, propVal, NULL)) { if (!strcmp(propVal, "running")) return true; } return false; } } Loading
debuggerd/libdebuggerd/test/sys/system_properties.h +0 −1 Original line number Original line Diff line number Diff line Loading @@ -32,7 +32,6 @@ // This is just enough to get the property code to compile on // This is just enough to get the property code to compile on // the host. // the host. #define PROP_NAME_MAX 32 #define PROP_VALUE_MAX 92 #define PROP_VALUE_MAX 92 #endif // _DEBUGGERD_TEST_SYS_SYSTEM_PROPERTIES_H #endif // _DEBUGGERD_TEST_SYS_SYSTEM_PROPERTIES_H
init/service.cpp +5 −7 Original line number Original line Diff line number Diff line Loading @@ -180,12 +180,6 @@ void Service::NotifyStateChange(const std::string& new_state) const { } } std::string prop_name = StringPrintf("init.svc.%s", name_.c_str()); std::string prop_name = StringPrintf("init.svc.%s", name_.c_str()); if (prop_name.length() >= PROP_NAME_MAX) { // If the property name would be too long, we can't set it. LOG(ERROR) << "Property name \"init.svc." << name_ << "\" too long; not setting to " << new_state; return; } property_set(prop_name.c_str(), new_state.c_str()); property_set(prop_name.c_str(), new_state.c_str()); if (new_state == "running") { if (new_state == "running") { Loading Loading @@ -1040,5 +1034,9 @@ void ServiceParser::EndSection() { } } bool ServiceParser::IsValidName(const std::string& name) const { bool ServiceParser::IsValidName(const std::string& name) const { return is_legal_property_name("init.svc." + name); // Property names can be any length, but may only contain certain characters. // Property values can contain any characters, but may only be a certain length. // (The latter restriction is needed because `start` and `stop` work by writing // the service name to the "ctl.start" and "ctl.stop" properties.) return is_legal_property_name("init.svc." + name) && name.size() <= PROP_VALUE_MAX; } }
libsysutils/Android.mk +1 −1 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ LOCAL_MODULE:= libsysutils LOCAL_CFLAGS := -Werror LOCAL_CFLAGS := -Werror LOCAL_SHARED_LIBRARIES := \ LOCAL_SHARED_LIBRARIES := \ libbase \ libcutils \ libcutils \ liblog \ liblog \ libnl libnl Loading @@ -24,4 +25,3 @@ LOCAL_SHARED_LIBRARIES := \ LOCAL_EXPORT_C_INCLUDE_DIRS := system/core/libsysutils/include LOCAL_EXPORT_C_INCLUDE_DIRS := system/core/libsysutils/include include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)
libsysutils/src/ServiceManager.cpp +15 −37 Original line number Original line Diff line number Diff line Loading @@ -19,34 +19,23 @@ #include <errno.h> #include <errno.h> #include <stdio.h> #include <stdio.h> #include <string.h> #include <string.h> #include <sys/system_properties.h> #include <unistd.h> #include <unistd.h> #include <cutils/properties.h> #include <android-base/properties.h> #include <android-base/stringprintf.h> #include <log/log.h> #include <log/log.h> #include <sysutils/ServiceManager.h> #include <sysutils/ServiceManager.h> ServiceManager::ServiceManager() { ServiceManager::ServiceManager() { } } /* The service name should not exceed SERVICE_NAME_MAX to avoid // The length of a service name should not exceed SERVICE_NAME_MAX. Starting * some weird things. This is due to the fact that: // a service is done by writing its name to the "ctl.start" system property * // and stopping a service is done by writing its name to "ctl.stop". If a * - Starting a service is done by writing its name to the "ctl.start" // service name is too long to fit in a property, you won't be able to start * system property. This triggers the init daemon to actually start // or stop it. * the service for us. static constexpr size_t SERVICE_NAME_MAX = PROP_VALUE_MAX; * * - Stopping the service is done by writing its name to "ctl.stop" * in a similar way. * * - Reading the status of a service is done by reading the property * named "init.svc.<name>" * * If strlen(<name>) > (PROPERTY_KEY_MAX-1)-9, then you can start/stop * the service by writing to ctl.start/stop, but you won't be able to * read its state due to the truncation of "init.svc.<name>" into a * zero-terminated buffer of PROPERTY_KEY_MAX characters. */ #define SERVICE_NAME_MAX (PROPERTY_KEY_MAX-10) /* The maximum amount of time to wait for a service to start or stop, /* The maximum amount of time to wait for a service to start or stop, * in micro-seconds (really an approximation) */ * in micro-seconds (really an approximation) */ Loading @@ -61,13 +50,14 @@ int ServiceManager::start(const char *name) { SLOGE("Service name '%s' is too long", name); SLOGE("Service name '%s' is too long", name); return 0; return 0; } } if (isRunning(name)) { if (isRunning(name)) { SLOGW("Service '%s' is already running", name); SLOGW("Service '%s' is already running", name); return 0; return 0; } } SLOGD("Starting service '%s'", name); SLOGD("Starting service '%s'", name); property_set("ctl.start", name); android::base::SetProperty("ctl.start", name); int count = SLEEP_MAX_USEC; int count = SLEEP_MAX_USEC; while(count > 0) { while(count > 0) { Loading @@ -90,13 +80,14 @@ int ServiceManager::stop(const char *name) { SLOGE("Service name '%s' is too long", name); SLOGE("Service name '%s' is too long", name); return 0; return 0; } } if (!isRunning(name)) { if (!isRunning(name)) { SLOGW("Service '%s' is already stopped", name); SLOGW("Service '%s' is already stopped", name); return 0; return 0; } } SLOGD("Stopping service '%s'", name); SLOGD("Stopping service '%s'", name); property_set("ctl.stop", name); android::base::SetProperty("ctl.stop", name); int count = SLEEP_MAX_USEC; int count = SLEEP_MAX_USEC; while(count > 0) { while(count > 0) { Loading @@ -116,19 +107,6 @@ int ServiceManager::stop(const char *name) { } } bool ServiceManager::isRunning(const char *name) { bool ServiceManager::isRunning(const char *name) { char propVal[PROPERTY_VALUE_MAX]; std::string property_name = android::base::StringPrintf("init.svc.%s", name); char propName[PROPERTY_KEY_MAX]; return (android::base::GetProperty(property_name, "") == "running"); int ret; ret = snprintf(propName, sizeof(propName), "init.svc.%s", name); if (ret > (int)sizeof(propName)-1) { SLOGD("Service name '%s' is too long", name); return false; } if (property_get(propName, propVal, NULL)) { if (!strcmp(propVal, "running")) return true; } return false; } }