mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-10-03 23:38:25 +00:00
update: Save swupd binary path before executing any update process
On updates swupd binary can be replaced so readlink will fail to get the swudp binary path. In this case we should run that before running any update process. And besides that hardcode /usr/bin/swupd as the default swupd path in the case there's something wrong with readlink Fixes #1067 Fixes #1068 Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
This commit is contained in:
+17
-11
@@ -45,9 +45,24 @@ static int requested_version = -1;
|
||||
static bool download_only = false;
|
||||
static bool update_search_file_index = false;
|
||||
static bool keepcache = false;
|
||||
static char swupd_binary[LINE_MAX] = { 0 };
|
||||
|
||||
int nonpack;
|
||||
|
||||
static void save_swupd_binary_path()
|
||||
{
|
||||
/* we need to resolve the whole path to swupd first, proc/self/exe
|
||||
* is a symbolic link to the executable that is running the current process */
|
||||
int path_length;
|
||||
path_length = readlink("/proc/self/exe", swupd_binary, sizeof(swupd_binary));
|
||||
if (path_length <= 0 || path_length >= LINE_MAX) {
|
||||
// On errors fallback to default location
|
||||
strncpy(swupd_binary, "/usr/bin/swupd", sizeof(swupd_binary));
|
||||
} else {
|
||||
swupd_binary[path_length] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/* This loads the upstream Clear Manifest.Full and local
|
||||
* Manifest.full, and then checks that there are no conflicts between
|
||||
* the files they both include */
|
||||
@@ -243,6 +258,8 @@ static enum swupd_code main_update()
|
||||
/* start the timer used to report the total time to telemetry */
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &ts_start);
|
||||
|
||||
save_swupd_binary_path();
|
||||
|
||||
/* Step 1: Preparation steps */
|
||||
timelist_timer_start(globals.global_times, "Prepare for update");
|
||||
progress_set_step(1, "prepare_for_update");
|
||||
@@ -572,17 +589,6 @@ clean_curl:
|
||||
return SWUPD_INVALID_BINARY;
|
||||
}
|
||||
|
||||
/* we need to resolve the whole path to swupd first, proc/self/exe
|
||||
* is a symbolic link to the executable that is running the current process */
|
||||
char swupd_binary[LINE_MAX];
|
||||
int path_length;
|
||||
path_length = readlink("/proc/self/exe", swupd_binary, sizeof(swupd_binary));
|
||||
if (path_length <= 0 || path_length >= LINE_MAX) {
|
||||
error("Could not determine the swupd path\n");
|
||||
return -1;
|
||||
}
|
||||
swupd_binary[path_length] = '\0';
|
||||
|
||||
/* Run the swupd_argv saved from main */
|
||||
return execv(swupd_binary, globals.swupd_argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user