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

Commit db3f267c authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Clean up property setting code.

In particular, ensure that all property_set failures are reported.

Change-Id: Iab94a28bcba2346868c0f39bcfe26e55a2c55562
parent 1b8dbe74
Loading
Loading
Loading
Loading
+22 −45
Original line number Diff line number Diff line
@@ -14,31 +14,31 @@
 * limitations under the License.
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <net/if.h>
#include <stdio.h>
#include <linux/kd.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/if.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/mount.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <linux/loop.h>
#include <cutils/partition_utils.h>
#include <cutils/android_reboot.h>
#include <fs_mgr.h>

#include <selinux/selinux.h>
#include <selinux/label.h>

#include <fs_mgr.h>
#include <base/stringprintf.h>
#include <cutils/partition_utils.h>
#include <cutils/android_reboot.h>
#include <private/android_filesystem_config.h>

#include "init.h"
#include "keywords.h"
#include "property_service.h"
@@ -47,8 +47,6 @@
#include "util.h"
#include "log.h"

#include <private/android_filesystem_config.h>

#define chmod DO_NOT_USE_CHMOD_USE_FCHMODAT_SYMLINK_NOFOLLOW

int add_environment(const char *name, const char *value);
@@ -674,42 +672,21 @@ int do_sysclktz(int nargs, char **args)
}

int do_verity_load_state(int nargs, char **args) {
    if (nargs == 1) {
    int mode = -1;
    int rc = fs_mgr_load_verity_state(&mode);

    if (rc == 0 && mode == VERITY_MODE_LOGGING) {
        action_for_each_trigger("verity-logging", action_add_queue_tail);
    }

    return rc;
}
    return -1;
}

static void verity_update_property(struct fstab_rec *fstab,
                    const char *mount_point, int status) {
    char key[PROP_NAME_MAX];
    int ret;

    ret = snprintf(key, PROP_NAME_MAX, "partition.%s.verified", mount_point);
    if (ret >= PROP_NAME_MAX) {
        ERROR("Error setting verified property for %s: name too long\n",
            mount_point);
        return;
    }

    ret = property_set(key, "1");
    if (ret < 0)
        ERROR("Error setting verified property %s: %d\n", key, ret);
static void verity_update_property(fstab_rec *fstab, const char *mount_point, int status) {
    property_set(android::base::StringPrintf("partition.%s.verified", mount_point).c_str(), "1");
}

int do_verity_update_state(int nargs, char** args) {
    if (nargs == 1) {
    return fs_mgr_update_verity_state(verity_update_property);
}
    return -1;
}

int do_write(int nargs, char **args)
{
+1 −3
Original line number Diff line number Diff line
@@ -807,9 +807,7 @@ static void process_kernel_dt(void)
        std::replace(dt_file.begin(), dt_file.end(), ',', '.');

        std::string property_name = android::base::StringPrintf("ro.boot.%s", dp->d_name);
        if (property_set(property_name.c_str(), dt_file.c_str())) {
            ERROR("Could not set property %s to value %s", property_name.c_str(), dt_file.c_str());
        }
        property_set(property_name.c_str(), dt_file.c_str());
    }
}

+2 −2
Original line number Diff line number Diff line
@@ -89,8 +89,8 @@ enum {
    KEYWORD(symlink,     COMMAND, 1, do_symlink)
    KEYWORD(sysclktz,    COMMAND, 1, do_sysclktz)
    KEYWORD(user,        OPTION,  0, 0)
    KEYWORD(verity_load_state,      COMMAND, 0, do_verity_load_state)
    KEYWORD(verity_update_state,    COMMAND, 0, do_verity_update_state)
    KEYWORD(verity_load_state,      COMMAND, 1, do_verity_load_state)
    KEYWORD(verity_update_state,    COMMAND, 1, do_verity_update_state)
    KEYWORD(wait,        COMMAND, 1, do_wait)
    KEYWORD(write,       COMMAND, 2, do_write)
    KEYWORD(copy,        COMMAND, 2, do_copy)
+13 −10
Original line number Diff line number Diff line
@@ -199,18 +199,14 @@ static bool is_legal_property_name(const char* name, size_t namelen)
    return true;
}

int property_set(const char *name, const char *value)
{
    prop_info *pi;
    int ret;

static int property_set_impl(const char* name, const char* value) {
    size_t namelen = strlen(name);
    size_t valuelen = strlen(value);

    if (!is_legal_property_name(name, namelen)) return -1;
    if (valuelen >= PROP_VALUE_MAX) return -1;

    pi = (prop_info*) __system_property_find(name);
    prop_info* pi = (prop_info*) __system_property_find(name);

    if(pi != 0) {
        /* ro.* properties may NEVER be modified once set */
@@ -218,10 +214,9 @@ int property_set(const char *name, const char *value)

        __system_property_update(pi, value, valuelen);
    } else {
        ret = __system_property_add(name, namelen, value, valuelen);
        if (ret < 0) {
            ERROR("Failed to set '%s'='%s'\n", name, value);
            return ret;
        int rc = __system_property_add(name, namelen, value, valuelen);
        if (rc < 0) {
            return rc;
        }
    }
    /* If name starts with "net." treat as a DNS property. */
@@ -250,6 +245,14 @@ int property_set(const char *name, const char *value)
    return 0;
}

int property_set(const char* name, const char* value) {
    int rc = property_set_impl(name, value);
    if (rc == -1) {
        ERROR("property_set(\"%s\", \"%s\" failed\n", name, value);
    }
    return rc;
}

void handle_property_set_fd()
{
    prop_msg msg;