Add basic error checking to legacy property init

Let init and rename funcitons return success or failure values.

Change-Id: Ieed86cac8a0dcfd770a89dacc57fd306e7a6ad8d
This commit is contained in:
Matt Mower
2014-03-27 14:38:48 -05:00
parent 02a6453b75
commit cdd3b339fc
4 changed files with 59 additions and 23 deletions

View File

@@ -63,7 +63,7 @@ struct prop_info {
char value[PROP_VALUE_MAX];
};
struct prop_msg
struct prop_msg
{
unsigned cmd;
char name[PROP_NAME_MAX];
@@ -71,7 +71,7 @@ struct prop_msg
};
#define PROP_MSG_SETPROP 1
/*
** Rules:
**

View File

@@ -33,13 +33,11 @@
#include <sys/atomics.h>
#include "legacy_property_service.h"
static int persistent_properties_loaded = 0;
static int property_area_inited = 0;
static int property_set_fd = -1;
typedef struct {
void *data;
size_t size;
@@ -203,9 +201,13 @@ static void copy_property_to_legacy(const char *key, const char *value, void *co
legacy_property_set(key, value);
}
void legacy_properties_init()
int legacy_properties_init()
{
init_property_area();
property_list(copy_property_to_legacy, 0);
}
if(init_property_area() != 0)
return -1;
if(property_list(copy_property_to_legacy, 0) != 0)
return -1;
return 0;
}

View File

@@ -20,6 +20,6 @@
#include <stdbool.h>
void legacy_get_property_workspace(int *fd, int *sz);
void legacy_properties_init();
int legacy_properties_init();
#endif /* _LEGACY_PROPERTY_H */

View File

@@ -53,29 +53,48 @@ extern "C" {
static const char* properties_path = "/dev/__properties__";
static const char* properties_path_renamed = "/dev/__properties_kk__";
static bool legacy_props_env_initd = false;
static bool legacy_props_path_modified = false;
static void switch_to_legacy_properties()
static int switch_to_legacy_properties()
{
char tmp[32];
int propfd, propsz;
legacy_properties_init();
legacy_get_property_workspace(&propfd, &propsz);
sprintf(tmp, "%d,%d", dup(propfd), propsz);
setenv("ANDROID_PROPERTY_WORKSPACE", tmp, 1);
if (!legacy_props_env_initd) {
if (legacy_properties_init() != 0)
return -1;
char tmp[32];
int propfd, propsz;
legacy_get_property_workspace(&propfd, &propsz);
sprintf(tmp, "%d,%d", dup(propfd), propsz);
setenv("ANDROID_PROPERTY_WORKSPACE", tmp, 1);
legacy_props_env_initd = true;
}
if (TWFunc::Path_Exists(properties_path)) {
// hide real properties so that the updater uses the envvar to find the legacy format properties
if (rename(properties_path, properties_path_renamed) != 0)
LOGERR("Renaming properties failed: %s (assertions in old installers may fail)\n", strerror(errno));
if (rename(properties_path, properties_path_renamed) != 0) {
LOGERR("Renaming %s failed: %s\n", properties_path, strerror(errno));
return -1;
} else {
legacy_props_path_modified = true;
}
}
return 0;
}
static void switch_to_new_properties()
static int switch_to_new_properties()
{
if (TWFunc::Path_Exists(properties_path_renamed)) {
if (rename(properties_path_renamed, properties_path) != 0)
LOGERR("Restoring properties failed: %s\n", strerror(errno));
if (rename(properties_path_renamed, properties_path) != 0) {
LOGERR("Renaming %s failed: %s\n", properties_path_renamed, strerror(errno));
return -1;
} else {
legacy_props_path_modified = false;
}
}
return 0;
}
static int Run_Update_Binary(const char *path, ZipArchive *Zip, int* wipe_cache) {
@@ -143,6 +162,13 @@ static int Run_Update_Binary(const char *path, ZipArchive *Zip, int* wipe_cache)
}
mzCloseZipArchive(Zip);
/* Set legacy properties */
if (switch_to_legacy_properties() != 0) {
LOGERR("Legacy property environment did not initialize successfully. Properties may not be detected.\n");
} else {
LOGINFO("Legacy property environment initialized.\n");
}
pipe(pipe_fd);
args[0] = Temp_Binary.c_str();
@@ -155,7 +181,6 @@ static int Run_Update_Binary(const char *path, ZipArchive *Zip, int* wipe_cache)
pid_t pid = fork();
if (pid == 0) {
switch_to_legacy_properties();
close(pipe_fd[0]);
execve(Temp_Binary.c_str(), (char* const*)args, environ);
printf("E:Can't execute '%s'\n", Temp_Binary.c_str());
@@ -204,7 +229,16 @@ static int Run_Update_Binary(const char *path, ZipArchive *Zip, int* wipe_cache)
fclose(child_data);
waitpid(pid, &status, 0);
switch_to_new_properties();
/* Unset legacy properties */
if (legacy_props_path_modified) {
if (switch_to_new_properties() != 0) {
LOGERR("Legacy property environment did not disable successfully. Legacy properties may still be in use.\n");
} else {
LOGINFO("Legacy property environment disabled.\n");
}
}
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
LOGERR("Error executing updater binary in zip '%s'\n", path);
return INSTALL_ERROR;