diff options
Diffstat (limited to 'twinstall.cpp')
-rw-r--r-- | twinstall.cpp | 62 |
1 files changed, 48 insertions, 14 deletions
diff --git a/twinstall.cpp b/twinstall.cpp index b3b9b774b..5b3242756 100644 --- a/twinstall.cpp +++ b/twinstall.cpp @@ -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; |