From 2cab05ea21962226aaa23cff20ad3c5be46a76fe Mon Sep 17 00:00:00 2001 From: Otavio Pontes Date: Wed, 17 Jul 2019 13:48:05 -0700 Subject: [PATCH] globals: Group globals functions and variables in a header file To make it easier to document and to read, group global related functions and variables in an exclusive header file Signed-off-by: Otavio Pontes --- Makefile.am | 1 + src/alias.c | 4 +- src/bundle.c | 74 +++++++++++----------- src/check_update.c | 2 +- src/clean.c | 14 ++--- src/clr_bundle_add.c | 4 +- src/curl.c | 23 +++---- src/curl_async.c | 6 +- src/delta.c | 6 +- src/extra_files.c | 4 +- src/fullfile.c | 12 ++-- src/globals.c | 145 ++++++++++++++++++------------------------- src/globals.h | 85 +++++++++++++++++++++++++ src/hash.c | 10 +-- src/hashdump.c | 4 +- src/helpers.c | 88 +++++++++++++------------- src/heuristics.c | 8 +-- src/info.c | 8 +-- src/lock.c | 2 +- src/manifest.c | 52 ++++++++-------- src/mirror.c | 20 +++--- src/os_install.c | 4 +- src/packs.c | 10 +-- src/scripts.c | 32 +++++----- src/search.c | 6 +- src/staging.c | 28 ++++----- src/subscriptions.c | 2 +- src/swupd.h | 57 +---------------- src/telemetry.c | 4 +- src/update.c | 76 ++++++++++++----------- src/verify.c | 70 ++++++++++----------- src/version.c | 8 +-- 32 files changed, 438 insertions(+), 431 deletions(-) create mode 100644 src/globals.h diff --git a/Makefile.am b/Makefile.am index 6f626984..f6bc935e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -51,6 +51,7 @@ swupd_SOURCES = \ src/filedesc.c \ src/fullfile.c \ src/globals.c \ + src/globals.h \ src/hash.c \ src/hashdump.c \ src/helpers.c \ diff --git a/src/alias.c b/src/alias.c index 1ca4aa46..bcb8871b 100644 --- a/src/alias.c +++ b/src/alias.c @@ -156,11 +156,11 @@ struct list *get_alias_definitions(void) struct list *user_alias_files = NULL; /* get sorted system and user filenames */ - string_or_die(&path, "%s/%s", path_prefix, SYSTEM_ALIAS_PATH); + string_or_die(&path, "%s/%s", globals.path_prefix, SYSTEM_ALIAS_PATH); system_alias_files = get_dir_files_sorted(path); free(path); - string_or_die(&path, "%s/%s", path_prefix, USER_ALIAS_PATH); + string_or_die(&path, "%s/%s", globals.path_prefix, USER_ALIAS_PATH); user_alias_files = get_dir_files_sorted(path); free(path); diff --git a/src/bundle.c b/src/bundle.c index e4789d4a..a4e9ebe2 100644 --- a/src/bundle.c +++ b/src/bundle.c @@ -52,7 +52,7 @@ enum swupd_code list_installable_bundles() int current_version; bool mix_exists; - current_version = get_current_version(path_prefix); + current_version = get_current_version(globals.path_prefix); if (current_version < 0) { error("Unable to determine current OS version\n"); return SWUPD_CURRENT_VERSION_UNKNOWN; @@ -122,7 +122,7 @@ bool is_installed_bundle(const char *bundle_name) char *filename = NULL; bool ret = true; - string_or_die(&filename, "%s/%s/%s", path_prefix, BUNDLES_DIR, bundle_name); + string_or_die(&filename, "%s/%s/%s", globals.path_prefix, BUNDLES_DIR, bundle_name); if (stat(filename, &statb) == -1) { ret = false; @@ -201,7 +201,7 @@ enum swupd_code show_included_bundles(char *bundle_name) struct list *deps = NULL; struct manifest *mom = NULL; - current_version = get_current_version(path_prefix); + current_version = get_current_version(globals.path_prefix); if (current_version < 0) { error("Unable to determine current OS version\n"); ret = SWUPD_CURRENT_VERSION_UNKNOWN; @@ -301,7 +301,7 @@ enum swupd_code show_bundle_reqd_by(const char *bundle_name, bool server) goto out; } - version = get_current_version(path_prefix); + version = get_current_version(globals.path_prefix); if (version < 0) { error("Unable to determine current OS version\n"); ret = SWUPD_CURRENT_VERSION_UNKNOWN; @@ -397,7 +397,7 @@ out: static char *tracking_dir(void) { - return mk_full_filename(state_dir, "bundles"); + return mk_full_filename(globals.state_dir, "bundles"); } /* @@ -441,12 +441,12 @@ static void track_installed(const char *bundle_name) if (ret) { goto out; } - src = mk_full_filename(path_prefix, "/usr/share/clear/bundles"); + src = mk_full_filename(globals.path_prefix, "/usr/share/clear/bundles"); /* at the point this function is called is already * installed on the system and therefore has a tracking file under * /usr/share/clear/bundles. A simple cp -a of that directory will * accurately track that bundle as manually installed. */ - ret = copy_all(src, state_dir); + ret = copy_all(src, globals.state_dir); free_string(&src); if (ret) { goto out; @@ -514,7 +514,7 @@ enum swupd_code remove_bundles(char **bundles) return ret; } - current_version = get_current_version(path_prefix); + current_version = get_current_version(globals.path_prefix); if (current_version < 0) { error("Unable to determine current OS version\n"); ret = SWUPD_CURRENT_VERSION_UNKNOWN; @@ -740,7 +740,7 @@ int add_subscriptions(struct list *bundles, struct list **subs, struct manifest ret |= r; /* merge in recursive call results */ } - if (!skip_optional_bundles && manifest->optional) { + if (!globals.skip_optional_bundles && manifest->optional) { int r = add_subscriptions(manifest->optional, subs, mom, find_all, recursion + 1); if (r & add_sub_ERR) { free_manifest(manifest); @@ -775,7 +775,7 @@ static enum swupd_code install_bundles(struct list *bundles, struct list **subs, /* step 1: get subscriptions for bundles to be installed */ info("Loading required manifests...\n"); - timelist_timer_start(global_times, "Add bundles and recurse"); + timelist_timer_start(globals.global_times, "Add bundles and recurse"); progress_set_step(1, "load_manifests"); ret = add_subscriptions(bundles, subs, mom, false, 0); @@ -842,10 +842,10 @@ static enum swupd_code install_bundles(struct list *bundles, struct list **subs, mom->submanifests = installed_bundles; progress_complete_step(); - timelist_timer_stop(global_times); // closing: Add bundles and recurse + timelist_timer_stop(globals.global_times); // closing: Add bundles and recurse /* Step 2: Get a list with all files needed to be installed for the requested bundles */ - timelist_timer_start(global_times, "Consolidate files from bundles"); + timelist_timer_start(globals.global_times, "Consolidate files from bundles"); progress_set_step(2, "consolidate_files"); /* get all files already installed in the target system */ @@ -863,16 +863,16 @@ static enum swupd_code install_bundles(struct list *bundles, struct list **subs, to_install_files = filter_out_existing_files(to_install_files, installed_files); progress_complete_step(); - timelist_timer_stop(global_times); // closing: Consolidate files from bundles + timelist_timer_stop(globals.global_times); // closing: Consolidate files from bundles /* Step 3: Check if we have enough space */ progress_set_step(3, "check_disk_space_availability"); - if (!skip_diskspace_check) { - timelist_timer_start(global_times, "Check disk space availability"); + if (!globals.skip_diskspace_check) { + timelist_timer_start(globals.global_times, "Check disk space availability"); char *filepath = NULL; bundle_size = get_manifest_list_contentsize(to_install_bundles); - filepath = mk_full_filename(path_prefix, "/usr/"); + filepath = mk_full_filename(globals.path_prefix, "/usr/"); /* Calculate free space on filepath */ fs_free = get_available_space(filepath); @@ -895,12 +895,12 @@ static enum swupd_code install_bundles(struct list *bundles, struct list **subs, goto out; } - timelist_timer_stop(global_times); // closing: Check disk space availability + timelist_timer_stop(globals.global_times); // closing: Check disk space availability } progress_complete_step(); /* step 4: download necessary packs */ - timelist_timer_start(global_times, "Download packs"); + timelist_timer_start(globals.global_times, "Download packs"); progress_set_step(4, "download_packs"); (void)rm_staging_dir_contents("download"); @@ -914,10 +914,10 @@ static enum swupd_code install_bundles(struct list *bundles, struct list **subs, info("No packs need to be downloaded\n"); progress_complete_step(); } - timelist_timer_stop(global_times); // closing: Download packs + timelist_timer_stop(globals.global_times); // closing: Download packs /* step 5: Download missing files */ - timelist_timer_start(global_times, "Download missing files"); + timelist_timer_start(globals.global_times, "Download missing files"); progress_set_step(5, "download_fullfiles"); ret = download_fullfiles(to_install_files, NULL); if (ret) { @@ -926,10 +926,10 @@ static enum swupd_code install_bundles(struct list *bundles, struct list **subs, error("Could not download some files from bundles, aborting bundle installation\n"); goto out; } - timelist_timer_stop(global_times); // closing: Download missing files + timelist_timer_stop(globals.global_times); // closing: Download missing files /* step 6: Install all bundle(s) files into the fs */ - timelist_timer_start(global_times, "Installing bundle(s) files onto filesystem"); + timelist_timer_start(globals.global_times, "Installing bundle(s) files onto filesystem"); progress_set_step(6, "install_files"); info("Installing bundle(s) files...\n"); @@ -942,7 +942,7 @@ static enum swupd_code install_bundles(struct list *bundles, struct list **subs, file = iter->data; iter = iter->next; - string_or_die(&hashpath, "%s/staged/%s", state_dir, file->hash); + string_or_die(&hashpath, "%s/staged/%s", globals.state_dir, file->hash); if (access(hashpath, F_OK) < 0) { /* the file does not exist in the staged directory, it will need @@ -1037,13 +1037,13 @@ static enum swupd_code install_bundles(struct list *bundles, struct list **subs, progress_report(complete, list_length); } sync(); - timelist_timer_stop(global_times); // closing: Installing bundle(s) files onto filesystem + timelist_timer_stop(globals.global_times); // closing: Installing bundle(s) files onto filesystem /* step 7: Run any scripts that are needed to complete update */ - timelist_timer_start(global_times, "Run Scripts"); + timelist_timer_start(globals.global_times, "Run Scripts"); progress_set_step(7, "run_scripts"); - scripts_run_post_update(wait_for_scripts); - timelist_timer_stop(global_times); // closing: Run Scripts + scripts_run_post_update(globals.wait_for_scripts); + timelist_timer_stop(globals.global_times); // closing: Run Scripts progress_complete_step(); ret = SWUPD_OK; @@ -1119,8 +1119,8 @@ enum swupd_code install_bundles_frontend(char **bundles) return ret; } - timelist_timer_start(global_times, "Load MoM"); - current_version = get_current_version(path_prefix); + timelist_timer_start(globals.global_times, "Load MoM"); + current_version = get_current_version(globals.path_prefix); if (current_version < 0) { error("Unable to determine current OS version\n"); ret = SWUPD_CURRENT_VERSION_UNKNOWN; @@ -1135,9 +1135,9 @@ enum swupd_code install_bundles_frontend(char **bundles) ret = SWUPD_COULDNT_LOAD_MOM; goto clean_and_exit; } - timelist_timer_stop(global_times); // closing: Load MoM + timelist_timer_stop(globals.global_times); // closing: Load MoM - timelist_timer_start(global_times, "Prepend bundles to list"); + timelist_timer_start(globals.global_times, "Prepend bundles to list"); aliases = get_alias_definitions(); for (; *bundles; ++bundles) { struct list *alias_bundles = get_alias_bundles(aliases, *bundles); @@ -1150,13 +1150,13 @@ enum swupd_code install_bundles_frontend(char **bundles) bundles_list = list_concat(alias_bundles, bundles_list); } list_free_list_and_data(aliases, free_alias_lookup); - timelist_timer_stop(global_times); // closing: Prepend bundles to list + timelist_timer_stop(globals.global_times); // closing: Prepend bundles to list - timelist_timer_start(global_times, "Install bundles"); + timelist_timer_start(globals.global_times, "Install bundles"); ret = install_bundles(bundles_list, &subs, mom); - timelist_timer_stop(global_times); // closing: Install bundles + timelist_timer_stop(globals.global_times); // closing: Install bundles - timelist_print_stats(global_times); + timelist_print_stats(globals.global_times); free_manifest(mom); clean_and_exit: @@ -1196,7 +1196,7 @@ enum swupd_code list_local_bundles() int current_version; bool mix_exists; - current_version = get_current_version(path_prefix); + current_version = get_current_version(globals.path_prefix); if (current_version < 0) { goto skip_mom; } @@ -1208,7 +1208,7 @@ enum swupd_code list_local_bundles() } skip_mom: - string_or_die(&path, "%s/%s", path_prefix, BUNDLES_DIR); + string_or_die(&path, "%s/%s", globals.path_prefix, BUNDLES_DIR); errno = 0; bundles = get_dir_files_sorted(path); diff --git a/src/check_update.c b/src/check_update.c index fdc1034f..235fb7ed 100644 --- a/src/check_update.c +++ b/src/check_update.c @@ -47,7 +47,7 @@ enum swupd_code check_update() int current_version, server_version; enum swupd_code ret; - ret = read_versions(¤t_version, &server_version, path_prefix); + ret = read_versions(¤t_version, &server_version, globals.path_prefix); if (current_version > 0) { info("Current OS version: %d\n", current_version); diff --git a/src/clean.c b/src/clean.c index 93f60b61..e8fd013f 100644 --- a/src/clean.c +++ b/src/clean.c @@ -262,7 +262,7 @@ static bool is_manifest_delta(const char UNUSED_PARAM *dir, const struct dirent static char *read_mom_contents(int version) { char *mom_path = NULL; - string_or_die(&mom_path, "%s/%d/Manifest.MoM", state_dir, version); + string_or_die(&mom_path, "%s/%d/Manifest.MoM", globals.state_dir, version); FILE *f = fopen(mom_path, "r"); free_string(&mom_path); if (!f) { @@ -315,7 +315,7 @@ static enum swupd_code clean_staged_manifests(const char *path, bool dry_run, bo * ensures that a regular 'clean' won't make 'search' redownload files. */ char *mom_contents = NULL; if (!all) { - int current_version = get_current_version(path_prefix); + int current_version = get_current_version(globals.path_prefix); if (current_version < 0) { warn("Unable to determine current OS version\n"); } else { @@ -345,7 +345,7 @@ static enum swupd_code clean_staged_manifests(const char *path, bool dry_run, bo } char *version_dir; - string_or_die(&version_dir, "%s/%s", state_dir, name); + string_or_die(&version_dir, "%s/%s", globals.state_dir, name); /* This is not precise: it may keep Manifest files that we don't use, and * also will keep the previous version. If that extra precision is @@ -430,7 +430,7 @@ enum swupd_code clean_statedir(bool dry_run, bool all) { char *staged_dir = NULL; - string_or_die(&staged_dir, "%s/staged", state_dir); + string_or_die(&staged_dir, "%s/staged", globals.state_dir); int ret = remove_if(staged_dir, dry_run, is_fullfile); free_string(&staged_dir); if (ret != 0) { @@ -438,18 +438,18 @@ enum swupd_code clean_statedir(bool dry_run, bool all) } /* Pack presence indicator files. */ - ret = remove_if(state_dir, dry_run, is_pack_indicator); + ret = remove_if(globals.state_dir, dry_run, is_pack_indicator); if (ret != 0) { return ret; } /* Manifest delta files. */ - ret = remove_if(state_dir, dry_run, is_manifest_delta); + ret = remove_if(globals.state_dir, dry_run, is_manifest_delta); if (ret != 0) { return ret; } /* NOTE: do not clean the state_dir/bundles directory */ - return clean_staged_manifests(state_dir, dry_run, all); + return clean_staged_manifests(globals.state_dir, dry_run, all); } diff --git a/src/clr_bundle_add.c b/src/clr_bundle_add.c index b184abb7..bdaed5d8 100644 --- a/src/clr_bundle_add.c +++ b/src/clr_bundle_add.c @@ -64,10 +64,10 @@ static bool parse_opt(int opt, UNUSED_PARAM char *optarg) { switch (opt) { case FLAG_SKIP_OPTIONAL: - skip_optional_bundles = true; + globals.skip_optional_bundles = true; return true; case FLAG_SKIP_DISKSPACE_CHECK: - skip_diskspace_check = true; + globals.skip_diskspace_check = true; return true; default: return false; diff --git a/src/curl.c b/src/curl.c index 735dc224..548480bb 100644 --- a/src/curl.c +++ b/src/curl.c @@ -83,7 +83,7 @@ CURLcode swupd_curl_set_optional_client_cert(CURL *curl) CURLcode curl_ret = CURLE_OK; char *client_cert_path; - client_cert_path = mk_full_filename(path_prefix, SSL_CLIENT_CERT); + client_cert_path = mk_full_filename(globals.path_prefix, SSL_CLIENT_CERT); if (access(client_cert_path, F_OK) == 0) { curl_ret = curl_easy_setopt(curl, CURLOPT_SSLCERT, client_cert_path); if (curl_ret != CURLE_OK) { @@ -209,8 +209,9 @@ int swupd_curl_init(char *url) } /* enforce the use of https or file */ - if (!is_url_allowed(version_url) || - (strcmp(content_url, version_url) != 0 && !is_url_allowed(content_url))) { + if (!is_url_allowed(globals.version_url) || + (strcmp(globals.content_url, globals.version_url) != 0 && + !is_url_allowed(globals.content_url))) { swupd_curl_deinit(); return -1; } @@ -247,7 +248,7 @@ int swupd_curl_init(char *url) exit: if (ret != 0) { /* curl failed to initialize */ - error("Failed to connect to update server: %s\n", version_url); + error("Failed to connect to update server: %s\n", globals.version_url); info("Possible solutions for this problem are:\n" "\tCheck if your network connection is working\n" "\tFix the system clock\n" @@ -476,7 +477,7 @@ enum download_status process_curl_error_codes(int curl_ret, CURL *curl_handle) return DOWNLOAD_STATUS_ERROR; case CURLE_WRITE_ERROR: error("Curl - Error downloading to local file - '%s'\n", url); - error("Curl - Check free space for %s?\n", state_dir); + error("Curl - Check free space for %s?\n", globals.state_dir); return DOWNLOAD_STATUS_WRITE_ERROR; case CURLE_OPERATION_TIMEDOUT: error("Curl - Communicating with server timed out - '%s'\n", url); @@ -606,7 +607,7 @@ exit: static enum retry_strategy determine_strategy(int status) { /* we don't need to retry if the content URL is local */ - if (content_url_is_local) { + if (globals.content_url_is_local) { return DONT_RETRY; } @@ -630,7 +631,7 @@ static int retry_download_loop(const char *url, char *filename, struct curl_file { int current_retry = 0; - int sleep_time = retry_delay; + int sleep_time = globals.retry_delay; int strategy; int ret; @@ -662,8 +663,8 @@ static int retry_download_loop(const char *url, char *filename, struct curl_file if (strategy == RETRY_NOW) { sleep_time = 0; } - if (max_retries) { - if (current_retry <= max_retries) { + if (globals.max_retries) { + if (current_retry <= globals.max_retries) { if (sleep_time) { info("Waiting %d seconds before retrying the download\n", sleep_time); } @@ -768,8 +769,8 @@ CURLcode swupd_curl_set_basic_options(CURL *curl, const char *url, bool fail_on_ curl_easy_setopt(curl, CURLOPT_USERAGENT, PACKAGE "/" VERSION); // No error checking needed, this is not critical information - if (update_server_port > 0) { - curl_ret = curl_easy_setopt(curl, CURLOPT_PORT, update_server_port); + if (globals.update_server_port > 0) { + curl_ret = curl_easy_setopt(curl, CURLOPT_PORT, globals.update_server_port); if (curl_ret != CURLE_OK) { goto exit; } diff --git a/src/curl_async.c b/src/curl_async.c index c942ae2a..ee2cc95c 100644 --- a/src/curl_async.c +++ b/src/curl_async.c @@ -206,7 +206,7 @@ struct swupd_curl_parallel_handle *swupd_curl_parallel_download_start(size_t max h->max_xfer = max_xfer; h->curl_hashmap = hashmap_new(SWUPD_CURL_HASH_BUCKETS, file_hash_cmp, file_hash_value); - h->retry_delay = retry_delay; + h->retry_delay = globals.retry_delay; return h; error: @@ -288,7 +288,7 @@ static int perform_curl_io_and_complete(struct swupd_curl_parallel_handle *h, in //Check if user can handle errors if (!h->error_cb || h->error_cb(file->status, file->data)) { // Don't retry download if error was handled - file->retries = max_retries; + file->retries = globals.max_retries; file->cb_retval = true; h->failed = list_prepend_data(h->failed, file); } else { @@ -577,7 +577,7 @@ int swupd_curl_parallel_download_end(struct swupd_curl_parallel_handle *h, int * for (l = h->failed; l;) { struct multi_curl_file *file = l->data; - if (file->retries < max_retries && + if (file->retries < globals.max_retries && file->status != DOWNLOAD_STATUS_WRITE_ERROR) { struct list *next; diff --git a/src/delta.c b/src/delta.c index 2d6188b5..2ea6b6e2 100644 --- a/src/delta.c +++ b/src/delta.c @@ -115,7 +115,7 @@ static bool check_delta_filename(const char *delta_name, char *from, char *to) void apply_deltas(struct manifest *current_manifest) { char *delta_dir; - string_or_die(&delta_dir, "%s/delta", state_dir); + string_or_die(&delta_dir, "%s/delta", globals.state_dir); DIR *dir = opendir(delta_dir); if (!dir) { @@ -142,7 +142,7 @@ void apply_deltas(struct manifest *current_manifest) goto next; } - string_or_die(&to_staged, "%s/staged/%s", state_dir, to); + string_or_die(&to_staged, "%s/staged/%s", globals.state_dir, to); /* If 'to' file already exists, no need to apply delta. */ struct stat stat; @@ -166,7 +166,7 @@ void apply_deltas(struct manifest *current_manifest) /* Verify the actual file in the disk matches our expectations. */ char hash[SWUPD_HASH_LEN]; char *filename; - string_or_die(&filename, "%s/%s", path_prefix, file->filename); + string_or_die(&filename, "%s/%s", globals.path_prefix, file->filename); if (!compute_hash_from_file(filename, hash) || !hash_equal(file->hash, hash)) { free_string(&filename); diff --git a/src/extra_files.c b/src/extra_files.c index 9f2c20ea..a51238f3 100644 --- a/src/extra_files.c +++ b/src/extra_files.c @@ -97,7 +97,7 @@ static bool handle(const char *filename, bool is_dir, bool fix) bool ret = true; if (fix) { - string_or_die(&temp, "%s%s", path_prefix, filename); + string_or_die(&temp, "%s%s", globals.path_prefix, filename); print(" -> Extra file: %s%s", filename, is_dir ? "/" : ""); if (remove(temp)) { warn(" -> Failed to remove %s (%i: %s)\n", temp, errno, strerror(errno)); @@ -126,7 +126,7 @@ enum swupd_code walk_tree(struct manifest *manifest, const char *start, bool fix return SWUPD_COULDNT_LIST_DIR; } - path_prefix_len = strlen(path_prefix); + path_prefix_len = strlen(globals.path_prefix); path_whitelist = whitelist; rc = nftw(start, &record_filename, 0, FTW_ACTIONRETVAL | FTW_PHYS | FTW_MOUNT); const char *skip_dir = NULL; /* Skip files below this in printout */ diff --git a/src/fullfile.c b/src/fullfile.c index c0c9dad4..387c127c 100644 --- a/src/fullfile.c +++ b/src/fullfile.c @@ -35,7 +35,7 @@ static void download_mix_file(struct file *file) char *url, *filename; string_or_die(&url, "%s/%i/files/%s.tar", MIX_STATE_DIR, file->last_change, file->hash); - string_or_die(&filename, "%s/download/.%s.tar", state_dir, file->hash); + string_or_die(&filename, "%s/download/.%s.tar", globals.state_dir, file->hash); /* Mix content is local, so don't queue files up for curl downloads */ if (link_or_rename(url, filename) == 0) { @@ -52,8 +52,8 @@ static void download_file(struct swupd_curl_parallel_handle *download_handle, st { char *url, *filename; - string_or_die(&filename, "%s/download/.%s.tar", state_dir, file->hash); - string_or_die(&url, "%s/%i/files/%s.tar", content_url, file->last_change, file->hash); + string_or_die(&filename, "%s/download/.%s.tar", globals.state_dir, file->hash); + string_or_die(&url, "%s/%i/files/%s.tar", globals.content_url, file->last_change, file->hash); swupd_curl_parallel_download_enqueue(download_handle, url, filename, file->hash, file); free_string(&url); free_string(&filename); @@ -72,7 +72,7 @@ static bool download_successful(void *data) if (untar_full_download(data) != 0) { warn("Error for %s tarfile extraction, (check free space for %s?)\n", - ((struct file *)data)->hash, state_dir); + ((struct file *)data)->hash, globals.state_dir); } return true; } @@ -94,7 +94,7 @@ static double fullfile_query_total_download_size(struct list *files) continue; } - string_or_die(&url, "%s/%i/files/%s.tar", content_url, file->last_change, file->hash); + string_or_die(&url, "%s/%i/files/%s.tar", globals.content_url, file->last_change, file->hash); size = swupd_curl_query_content_size(url); if (size != -1) { total_size += size; @@ -145,7 +145,7 @@ int download_fullfiles(struct list *files, int *num_downloads) continue; } - string_or_die(&targetfile, "%s/staged/%s", state_dir, file->hash); + string_or_die(&targetfile, "%s/staged/%s", globals.state_dir, file->hash); if (lstat(targetfile, &stat) != 0 || !verify_file(file, targetfile)) { need_download = list_append_data(need_download, file); } diff --git a/src/globals.c b/src/globals.c index 4b03743b..6c15323f 100644 --- a/src/globals.c +++ b/src/globals.c @@ -44,33 +44,13 @@ #define optarg_to_bool(_optarg) (_optarg ? strtobool(_optarg) : true) -bool allow_insecure_http = false; -bool allow_mix_collisions = false; -bool migrate = false; -bool sigcheck = true; -bool timecheck = true; -bool no_scripts = false; -bool no_boot_update = false; -bool verify_esp_only; -bool verify_bundles_only = false; -int update_count = 0; -int update_skip = 0; -bool need_update_boot = false; -bool need_update_bootloader = false; -bool need_systemd_reexec = false; -bool update_complete = false; -char *format_string = NULL; -char *path_prefix = NULL; /* must always end in '/' */ -char *mounted_dirs = NULL; -char *bundle_to_add = NULL; -char *state_dir = NULL; -bool skip_diskspace_check = false; -bool skip_optional_bundles = false; -bool keepcache = false; -timelist *global_times = NULL; -int max_retries = 3; -int retry_delay = 10; -bool wait_for_scripts = false; +struct globals globals = { + .sigcheck = true, + .timecheck = true, + .max_retries = DEFAULT_MAX_RETRIES, + .retry_delay = DEFAULT_RETRY_DELAY, + .update_server_port = -1, +}; /* NOTE: Today the content and version server urls are the same in * all cases. It is highly likely these will eventually differ, eg: @@ -78,27 +58,21 @@ bool wait_for_scripts = false; * different quality of server and control of the servers */ static bool verbose_time = false; -char *version_url = NULL; -char *content_url = NULL; -bool content_url_is_local = false; -char *cert_path = NULL; -int update_server_port = -1; static int max_parallel_downloads = -1; static int log_level = LOG_INFO; static bool quiet = false; static bool debug = false; -char **swupd_argv = NULL; /* Sets the content_url global variable */ static void set_content_url(char *url) { - if (content_url) { - free_string(&content_url); + if (globals.content_url) { + free_string(&globals.content_url); } - content_url = strdup_or_die(url); - remove_trailing_slash(content_url); - content_url_is_local = strncmp(content_url, "file://", 7) == 0; + globals.content_url = strdup_or_die(url); + remove_trailing_slash(globals.content_url); + globals.content_url_is_local = strncmp(globals.content_url, "file://", 7) == 0; } /* Initializes the content_url global variable with the default value, @@ -142,12 +116,12 @@ found: /* Sets the version_url global variable */ static void set_version_url(char *url) { - if (version_url) { - free_string(&version_url); + if (globals.version_url) { + free_string(&globals.version_url); } - version_url = strdup_or_die(url); - remove_trailing_slash(version_url); + globals.version_url = strdup_or_die(url); + remove_trailing_slash(globals.version_url); } /* Initializes the version_url global variable with the default value, @@ -227,15 +201,15 @@ static bool set_state_dir(char *path) return false; } - free_string(&state_dir); - string_or_die(&state_dir, "%s", path); + free_string(&globals.state_dir); + string_or_die(&globals.state_dir, "%s", path); return true; } static void set_default_state_dir() { - string_or_die(&state_dir, "%s", STATE_DIR); + string_or_die(&globals.state_dir, "%s", STATE_DIR); } static bool set_format_string(char *format) @@ -248,11 +222,11 @@ static bool set_format_string(char *format) return false; } - if (format_string) { - free_string(&format_string); + if (globals.format_string) { + free_string(&globals.format_string); } - format_string = strdup_or_die(format); + globals.format_string = strdup_or_die(format); return true; } @@ -322,30 +296,30 @@ bool set_path_prefix(char *path) free(tmp); } - free(path_prefix); - path_prefix = new_path; + free(globals.path_prefix); + globals.path_prefix = new_path; return true; error: error("Bad path_prefix %s (%s), cannot continue\n", - path_prefix, strerror(errno)); + globals.path_prefix, strerror(errno)); free(new_path); return false; } void set_default_path_prefix() { - free(path_prefix); - path_prefix = strdup_or_die("/"); + free(globals.path_prefix); + globals.path_prefix = strdup_or_die("/"); } static void set_cert_path(char *path) { - if (cert_path) { - free_string(&cert_path); + if (globals.cert_path) { + free_string(&globals.cert_path); } - cert_path = strdup_or_die(path); + globals.cert_path = strdup_or_die(path); } static void set_default_cert_path() @@ -358,37 +332,37 @@ static void set_default_cert_path() } } -bool init_globals(void) +bool globals_init(void) { - if (!state_dir) { + if (!globals.state_dir) { set_default_state_dir(); } - if (!path_prefix) { + if (!globals.path_prefix) { set_default_path_prefix(); } - if (!format_string && !set_default_format_string()) { + if (!globals.format_string && !set_default_format_string()) { error("Unable to determine format id. Use the -F option instead\n"); return false; } - if (!version_url && !set_default_version_url()) { + if (!globals.version_url && !set_default_version_url()) { error("Default version URL not found. Use the -v option instead\n"); return false; } - if (!content_url && !set_default_content_url()) { + if (!globals.content_url && !set_default_content_url()) { error("Default content URL not found. Use the -c option instead\n"); return false; } - if (!cert_path) { + if (!globals.cert_path) { set_default_cert_path(); } if (verbose_time) { - global_times = timelist_new(); + globals.global_times = timelist_new(); } return true; @@ -399,20 +373,19 @@ void globals_deinit(void) /* freeing all globals and set ALL them to NULL (via free_string) * to avoid memory corruption on multiple calls * to swupd_init() */ - free_string(&content_url); - free_string(&version_url); - free_string(&path_prefix); - free_string(&format_string); - free_string(&mounted_dirs); - free_string(&state_dir); - free_string(&bundle_to_add); - timelist_free(global_times); - global_times = NULL; + free_string(&globals.content_url); + free_string(&globals.version_url); + free_string(&globals.path_prefix); + free_string(&globals.format_string); + free_string(&globals.mounted_dirs); + free_string(&globals.state_dir); + timelist_free(globals.global_times); + globals.global_times = NULL; } void save_cmd(char **argv) { - swupd_argv = argv; + globals.swupd_argv = argv; } size_t get_max_xfer(size_t default_max_xfer) @@ -470,8 +443,8 @@ static bool global_parse_opt(int opt, char *optarg) set_content_url(optarg); return true; case 'P': - err = strtoi_err(optarg, &update_server_port); - if (err < 0 || update_server_port < 0) { + err = strtoi_err(optarg, &globals.update_server_port); + if (err < 0 || globals.update_server_port < 0) { error("Invalid --port argument: %s\n\n", optarg); return false; } @@ -495,19 +468,19 @@ static bool global_parse_opt(int opt, char *optarg) } return true; case 'n': - sigcheck = !optarg_to_bool(optarg); + globals.sigcheck = !optarg_to_bool(optarg); return true; case 'I': - timecheck = !optarg_to_bool(optarg); + globals.timecheck = !optarg_to_bool(optarg); return true; case 't': verbose_time = optarg_to_bool(optarg); return true; case 'N': - no_scripts = optarg_to_bool(optarg); + globals.no_scripts = optarg_to_bool(optarg); return true; case 'b': - no_boot_update = optarg_to_bool(optarg); + globals.no_boot_update = optarg_to_bool(optarg); return true; case 'C': set_cert_path(optarg); @@ -520,15 +493,15 @@ static bool global_parse_opt(int opt, char *optarg) } return true; case 'r': - err = strtoi_err(optarg, &max_retries); - if (err < 0 || max_retries < 0) { + err = strtoi_err(optarg, &globals.max_retries); + if (err < 0 || globals.max_retries < 0) { error("Invalid --max-retries argument: %s\n\n", optarg); return false; } return true; case 'd': - err = strtoi_err(optarg, &retry_delay); - if (err < 0 || retry_delay < 0 || retry_delay > 60) { + err = strtoi_err(optarg, &globals.retry_delay); + if (err < 0 || globals.retry_delay < 0 || globals.retry_delay > 60) { error("Invalid --retry-delay argument: %s (should be between 0 - %d seconds)\n\n", optarg, MAX_DELAY); return false; } @@ -540,7 +513,7 @@ static bool global_parse_opt(int opt, char *optarg) progress_disable(optarg_to_bool(optarg)); return true; case FLAG_WAIT_FOR_SCRIPTS: - wait_for_scripts = optarg_to_bool(optarg); + globals.wait_for_scripts = optarg_to_bool(optarg); return true; case FLAG_QUIET: quiet = optarg_to_bool(optarg); @@ -549,7 +522,7 @@ static bool global_parse_opt(int opt, char *optarg) debug = optarg_to_bool(optarg); return true; case FLAG_ALLOW_INSECURE_HTTP: - allow_insecure_http = optarg_to_bool(optarg); + globals.allow_insecure_http = optarg_to_bool(optarg); return true; default: return false; diff --git a/src/globals.h b/src/globals.h new file mode 100644 index 00000000..c64a38dd --- /dev/null +++ b/src/globals.h @@ -0,0 +1,85 @@ +#ifndef SWUPD_GLOBALS +#define SWUPD_GLOBALS + +#define DEFAULT_MAX_RETRIES 3 +#define DEFAULT_RETRY_DELAY 10 + +/** + * @file + * @brief Keep global variables for swupd flag and other values needed all over + * swupd, as well as functions to handle them. + */ + +#include "timelist.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Global variables + */ +extern struct globals { + bool allow_insecure_http; + bool content_url_is_local; + bool migrate; + bool need_systemd_reexec; + bool need_update_boot; + bool need_update_bootloader; + bool no_boot_update; + bool no_scripts; + bool sigcheck; + bool timecheck; + bool wait_for_scripts; + char **swupd_argv; + char *cert_path; + char *content_url; + char *format_string; + char *mounted_dirs; + char *path_prefix; + char *state_dir; + char *version_url; + int max_retries; + int retry_delay; + int skip_diskspace_check; + int skip_optional_bundles; + int update_count; + int update_server_port; + int update_skip; + timelist *global_times; +} globals; + +struct global_options { + const struct option *longopts; + const int longopts_len; + bool (*parse_opt)(int opt, char *optarg); + void (*print_help)(void); +}; + +/** + * @brief Parse command line options in argv calling the appropriate method in + * opts. + * + * @param argc The number of elements in argv + * @param argv A list of strings with the parameters to parse. + * @param opts A struct global_options filled with information on how to handle + * the flags in command line. + */ +int global_parse_options(int argc, char **argv, const struct global_options *opts); + +bool globals_init(void); +void globals_deinit(void); +void global_print_help(void); + +size_t get_max_xfer(size_t default_max_xfer); +void save_cmd(char **argv); + +bool set_path_prefix(char *path); +bool set_default_content_url(void); +bool set_default_version_url(void); +void set_default_path_prefix(void); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/hash.c b/src/hash.c index 484f3fc7..17bb5c54 100644 --- a/src/hash.c +++ b/src/hash.c @@ -275,10 +275,10 @@ int verify_bundle_hash(struct manifest *manifest, struct file *bundle) continue; } - string_or_die(&cached, "%s/%i/Manifest.%s.%s", state_dir, + string_or_die(&cached, "%s/%i/Manifest.%s.%s", globals.state_dir, current->last_change, current->filename, bundle->hash); - string_or_die(&local, "%s/%i/Manifest.%s", state_dir, + string_or_die(&local, "%s/%i/Manifest.%s", globals.state_dir, current->last_change, current->filename); /* *NOTE* If the file is changed after being hardlinked, the hash will be different, @@ -298,9 +298,9 @@ int verify_bundle_hash(struct manifest *manifest, struct file *bundle) warn("Downloading missing manifest for bundle %s version %d\n", current->filename, current->last_change); - string_or_die(&filename, "%s/%i/Manifest.%s", state_dir, + string_or_die(&filename, "%s/%i/Manifest.%s", globals.state_dir, current->last_change, current->filename); - string_or_die(&url, "%s/%i/Manifest.%s.tar", content_url, + string_or_die(&url, "%s/%i/Manifest.%s.tar", globals.content_url, current->last_change, current->filename); ret = swupd_curl_get_file(url, filename); free_string(&url); @@ -313,7 +313,7 @@ int verify_bundle_hash(struct manifest *manifest, struct file *bundle) } char *outputdir; - string_or_die(&outputdir, "%s/%i", state_dir, current->last_change); + string_or_die(&outputdir, "%s/%i", globals.state_dir, current->last_change); ret = archives_extract_to(filename, outputdir); free_string(&outputdir); free_string(&filename); diff --git a/src/hashdump.c b/src/hashdump.c index d8c6284b..728d4138 100644 --- a/src/hashdump.c +++ b/src/hashdump.c @@ -108,14 +108,14 @@ enum swupd_code hashdump_main(int argc, char **argv) return SWUPD_INVALID_OPTION; } - if (!path_prefix) { + if (!globals.path_prefix) { set_default_path_prefix(); } file.filename = strdup_or_die(argv[optind]); // Accept relative paths if no path_prefix set on command line if (use_prefix) { - fullname = mk_full_filename(path_prefix, file.filename); + fullname = mk_full_filename(globals.path_prefix, file.filename); } else { fullname = strdup_or_die(file.filename); } diff --git a/src/helpers.c b/src/helpers.c index 8e2f592a..8cae150c 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -64,7 +64,7 @@ int rm_staging_dir_contents(const char *rel_path) char *abs_path; int ret = 0; - string_or_die(&abs_path, "%s/%s", state_dir, rel_path); + string_or_die(&abs_path, "%s/%s", globals.state_dir, rel_path); dir = opendir(abs_path); if (dir == NULL) { @@ -110,15 +110,15 @@ static void unlink_all_staged_content(struct file *file) char *filename; /* downloaded tar file */ - string_or_die(&filename, "%s/download/%s.tar", state_dir, file->hash); + string_or_die(&filename, "%s/download/%s.tar", globals.state_dir, file->hash); unlink(filename); free_string(&filename); - string_or_die(&filename, "%s/download/.%s.tar", state_dir, file->hash); + string_or_die(&filename, "%s/download/.%s.tar", globals.state_dir, file->hash); unlink(filename); free_string(&filename); /* downloaded and un-tar'd file */ - string_or_die(&filename, "%s/staged/%s", state_dir, file->hash); + string_or_die(&filename, "%s/staged/%s", globals.state_dir, file->hash); (void)remove(filename); free_string(&filename); } @@ -185,16 +185,16 @@ static int create_required_dirs(void) const char *state_dirs[] = { "delta", "staged", "download", "telemetry" }; // check for existence - if (ensure_root_owned_dir(state_dir)) { + if (ensure_root_owned_dir(globals.state_dir)) { //state dir doesn't exist - if (mkdir_p(state_dir) != 0 || chmod(state_dir, S_IRWXU) != 0) { - error("failed to create %s\n", state_dir); + if (mkdir_p(globals.state_dir) != 0 || chmod(globals.state_dir, S_IRWXU) != 0) { + error("failed to create %s\n", globals.state_dir); return -1; } } for (i = 0; i < STATE_DIR_COUNT; i++) { - string_or_die(&dir, "%s/%s", state_dir, state_dirs[i]); + string_or_die(&dir, "%s/%s", globals.state_dir, state_dirs[i]); ret = ensure_root_owned_dir(dir); if (ret) { ret = mkdir(dir, S_IRWXU); @@ -207,12 +207,12 @@ static int create_required_dirs(void) } /* Do a final check to make sure that the top level dir wasn't * tampered with whilst we were creating the dirs */ - return ensure_root_owned_dir(state_dir); + return ensure_root_owned_dir(globals.state_dir); } /** * store a colon separated list of current mountpoint into - * variable mounted_dirs, this function do not return a value. + * variable globals.mounted_dirs, this function do not return a value. * * e.g: :/proc:/mnt/acct: */ @@ -253,11 +253,11 @@ static void get_mounted_directories(void) break; } - if (mounted_dirs == NULL) { - string_or_die(&mounted_dirs, "%s", ":"); + if (globals.mounted_dirs == NULL) { + string_or_die(&globals.mounted_dirs, "%s", ":"); } - tmp = mounted_dirs; - string_or_die(&mounted_dirs, "%s%s:", tmp, mnt); + tmp = globals.mounted_dirs; + string_or_die(&globals.mounted_dirs, "%s%s:", tmp, mnt); free_string(&tmp); break; } @@ -306,15 +306,15 @@ bool is_directory_mounted(const char *filename) bool ret = false; char *tmp; - if (mounted_dirs == NULL) { + if (globals.mounted_dirs == NULL) { return false; } - tmp = mk_full_filename(path_prefix, filename); + tmp = mk_full_filename(globals.path_prefix, filename); string_or_die(&fname, ":%s:", tmp); free_string(&tmp); - if (strstr(mounted_dirs, fname)) { + if (strstr(globals.mounted_dirs, fname)) { ret = true; } @@ -334,17 +334,17 @@ bool is_under_mounted_directory(const char *filename) char *fname; char *tmp; - if (mounted_dirs == NULL) { + if (globals.mounted_dirs == NULL) { return false; } - dir = strdup_or_die(mounted_dirs); + dir = strdup_or_die(globals.mounted_dirs); token = strtok(dir + 1, ":"); while (token != NULL) { string_or_die(&mountpoint, "%s/", token); - tmp = mk_full_filename(path_prefix, filename); + tmp = mk_full_filename(globals.path_prefix, filename); string_or_die(&fname, ":%s:", tmp); free_string(&tmp); @@ -468,7 +468,7 @@ int rm_bundle_file(const char *bundle) int ret = 0; struct stat statb; - string_or_die(&filename, "%s/%s/%s", path_prefix, BUNDLES_DIR, bundle); + string_or_die(&filename, "%s/%s/%s", globals.path_prefix, BUNDLES_DIR, bundle); if (stat(filename, &statb) == -1) { goto out; @@ -544,7 +544,7 @@ enum swupd_code swupd_init(enum swupd_init_config config) record_fds(); - if (!init_globals()) { + if (!globals_init()) { ret = SWUPD_INIT_GLOBALS_FAILED; goto out_fds; } @@ -556,8 +556,8 @@ enum swupd_code swupd_init(enum swupd_init_config config) /* Check that our system time is reasonably valid before continuing, * or the certificate verification will fail with invalid time */ - if ((config & SWUPD_NO_TIMECHECK) == 0 && timecheck) { - if (!verify_time(path_prefix)) { + if ((config & SWUPD_NO_TIMECHECK) == 0 && globals.timecheck) { + if (!verify_time(globals.path_prefix)) { /* in the case we are doing an installation to an empty directory * using swupd verify --install, we won't have a valid versionstamp * in path_prefix, so try searching without the path_prefix */ @@ -578,9 +578,9 @@ enum swupd_code swupd_init(enum swupd_init_config config) goto out_fds; } - if (sigcheck) { + if (globals.sigcheck) { /* If --nosigcheck, we do not attempt any signature checking */ - if (!signature_init(cert_path, NULL)) { + if (!signature_init(globals.cert_path, NULL)) { ret = SWUPD_SIGNATURE_VERIFICATION_FAILED; signature_deinit(); goto out_close_lock; @@ -589,7 +589,7 @@ enum swupd_code swupd_init(enum swupd_init_config config) } if ((config & SWUPD_NO_NETWORK) == 0) { - if (swupd_curl_init(version_url) != 0) { + if (swupd_curl_init(globals.version_url) != 0) { ret = SWUPD_CURL_INIT_FAILED; goto out_close_lock; } @@ -710,14 +710,14 @@ enum swupd_code verify_fix_path(char *targetpath, struct manifest *target_MoM) free_string(&tar_dotfile); free_string(&url); - target = mk_full_filename(path_prefix, path); + target = mk_full_filename(globals.path_prefix, path); /* Search for the file in the manifest, to get the hash for the file */ file = search_file_in_manifest(target_MoM, path); if (file == NULL) { error("Path %s not found in any of the subscribed manifests" "in verify_fix_path for path_prefix %s\n", - path, path_prefix); + path, globals.path_prefix); ret = SWUPD_PATH_NOT_IN_MANIFEST; goto end; } @@ -750,8 +750,8 @@ enum swupd_code verify_fix_path(char *targetpath, struct manifest *target_MoM) unlink_all_staged_content(file); /* download the fullfile for the missing path */ - string_or_die(&tar_dotfile, "%s/download/.%s.tar", state_dir, file->hash); - string_or_die(&url, "%s/%i/files/%s.tar", content_url, file->last_change, file->hash); + string_or_die(&tar_dotfile, "%s/download/.%s.tar", globals.state_dir, file->hash); + string_or_die(&url, "%s/%i/files/%s.tar", globals.content_url, file->last_change, file->hash); ret = swupd_curl_get_file(url, tar_dotfile); if (ret != 0) { error("Failed to download file %s in verify_fix_path\n", file->filename); @@ -815,8 +815,8 @@ bool version_files_consistent(void) int state_v = -1; char *state_v_path; - string_or_die(&state_v_path, "%s/version", state_dir); - os_release_v = get_current_version(path_prefix); + string_or_die(&state_v_path, "%s/version", globals.state_dir); + os_release_v = get_current_version(globals.path_prefix); state_v = get_version_from_path(state_v_path); free_string(&state_v_path); @@ -849,17 +849,17 @@ bool string_in_list(char *string_to_check, struct list *list_to_check) * never appears in a manifest, it is skipped. */ bool is_compatible_format(int format_num) { - if (strcmp(format_string, "staging") == 0) { + if (strcmp(globals.format_string, "staging") == 0) { return true; } char *format_manifest = NULL; string_or_die(&format_manifest, "%d", format_num); - size_t len = strlen(format_string); + size_t len = strlen(globals.format_string); bool ret; - if (strncmp(format_string, format_manifest, len) == 0) { + if (strncmp(globals.format_string, format_manifest, len) == 0) { ret = true; } else { ret = false; @@ -876,7 +876,7 @@ bool is_current_version(int version) return false; } - return (version == get_current_version(path_prefix)); + return (version == get_current_version(globals.path_prefix)); } /* Check if the format at default_format_path has changed from the beginning @@ -930,9 +930,9 @@ int untar_full_download(void *data) struct stat stat; int err; - string_or_die(&tar_dotfile, "%s/download/.%s.tar", state_dir, file->hash); - string_or_die(&tarfile, "%s/download/%s.tar", state_dir, file->hash); - string_or_die(&targetfile, "%s/staged/%s", state_dir, file->hash); + string_or_die(&tar_dotfile, "%s/download/.%s.tar", globals.state_dir, file->hash); + string_or_die(&tarfile, "%s/download/%s.tar", globals.state_dir, file->hash); + string_or_die(&targetfile, "%s/staged/%s", globals.state_dir, file->hash); /* If valid target file already exists, we're done. * NOTE: this should NEVER happen given the checking that happens @@ -968,7 +968,7 @@ int untar_full_download(void *data) /* modern tar will automatically determine the compression type used */ char *outputdir; - string_or_die(&outputdir, "%s/staged", state_dir); + string_or_die(&outputdir, "%s/staged", globals.state_dir); err = archives_extract_to(tarfile, outputdir); free_string(&outputdir); if (err) { @@ -1029,7 +1029,7 @@ void print_regexp_error(int errcode, regex_t *regexp) bool is_url_allowed(char *url) { if (strncasecmp(url, "http://", 7) == 0) { - if (allow_insecure_http) { + if (globals.allow_insecure_http) { warn("This is an insecure connection\n"); info("The --allow-insecure-http flag was used, be aware that this poses a threat to the system\n\n"); } else { @@ -1077,7 +1077,7 @@ int get_value_from_path(char **contents, const char *path, bool is_abs_path) if (is_abs_path) { string_or_die(&rel_path, path); } else { - string_or_die(&rel_path, "%s%s", path_prefix, path); + string_or_die(&rel_path, "%s%s", globals.path_prefix, path); } file = fopen(rel_path, "r"); @@ -1124,7 +1124,7 @@ bool check_mix_exists(void) { char *fullpath; bool ret; - string_or_die(&fullpath, "%s%s/.valid-mix", path_prefix, MIX_DIR); + string_or_die(&fullpath, "%s%s/.valid-mix", globals.path_prefix, MIX_DIR); ret = access(fullpath, F_OK) == 0; free_string(&fullpath); return ret; diff --git a/src/heuristics.c b/src/heuristics.c index 9f3d5fa0..5cd9e012 100644 --- a/src/heuristics.c +++ b/src/heuristics.c @@ -102,11 +102,11 @@ static void boot_file_heuristics(struct file *file) if (strncmp(file->filename, "/usr/lib/kernel/", 16) == 0) { file->is_boot = 1; - need_update_boot = true; + globals.need_update_boot = true; } if (strcmp(file->filename, "/usr/lib/systemd/systemd") == 0) { - need_systemd_reexec = true; + globals.need_systemd_reexec = true; } if ((strncmp(file->filename, "/usr/lib/gummiboot", 18) == 0) || @@ -114,7 +114,7 @@ static void boot_file_heuristics(struct file *file) (strncmp(file->filename, "/usr/bin/bootctl", 16) == 0) || (strncmp(file->filename, "/usr/lib/systemd/boot", 21) == 0)) { file->is_boot = 1; - need_update_bootloader = true; + globals.need_update_bootloader = true; } } @@ -140,7 +140,7 @@ bool ignore(struct file *file) (file->is_boot && file->is_deleted) || (file->is_orphan) || (file->is_ghosted)) { - update_skip++; + globals.update_skip++; file->do_not_update = 1; return true; } diff --git a/src/info.c b/src/info.c index 7325db28..7bbc5cc2 100644 --- a/src/info.c +++ b/src/info.c @@ -26,8 +26,8 @@ enum swupd_code print_update_conf_info() { enum swupd_code ret = SWUPD_OK; char dist_string[LINE_MAX]; - int current_version = get_current_version(path_prefix); - bool dist_string_found = get_distribution_string(path_prefix, dist_string); + int current_version = get_current_version(globals.path_prefix); + bool dist_string_found = get_distribution_string(globals.path_prefix, dist_string); // Set distribution string 'unknown' when not found. info("Distribution: %s\n", dist_string_found ? dist_string : "unknown"); @@ -39,8 +39,8 @@ enum swupd_code print_update_conf_info() } else { info("Installed version: %d\n", current_version); } - info("Version URL: %s\n", version_url); - info("Content URL: %s\n", content_url); + info("Version URL: %s\n", globals.version_url); + info("Content URL: %s\n", globals.content_url); return ret; } diff --git a/src/lock.c b/src/lock.c index 06121f57..5b77ae67 100644 --- a/src/lock.c +++ b/src/lock.c @@ -61,7 +61,7 @@ int p_lockfile(void) }; char *lockfile; - string_or_die(&lockfile, "%s/swupd_lock", state_dir); + string_or_die(&lockfile, "%s/swupd_lock", globals.state_dir); /* open lock file */ lock_fd = open(lockfile, O_RDWR | O_CREAT | O_CLOEXEC, 0600); diff --git a/src/manifest.c b/src/manifest.c index 853d0fde..f4299a58 100644 --- a/src/manifest.c +++ b/src/manifest.c @@ -96,7 +96,7 @@ static struct manifest *manifest_from_file(int version, char *component, bool he struct manifest *manifest; if (!is_mix) { - basedir = state_dir; + basedir = globals.state_dir; } else { basedir = MIX_STATE_DIR; } @@ -156,13 +156,13 @@ static int try_manifest_delta_download(int from, int to, char *component) return -1; } - string_or_die(&from_manifest, "%s/%i/Manifest.%s", state_dir, from, component); - string_or_die(&to_manifest, "%s/%i/Manifest.%s", state_dir, to, component); - string_or_die(&manifest_delta, "%s/Manifest-%s-delta-from-%i-to-%i", state_dir, component, from, to); - string_or_die(&to_dir, "%s/%i", state_dir, to); + string_or_die(&from_manifest, "%s/%i/Manifest.%s", globals.state_dir, from, component); + string_or_die(&to_manifest, "%s/%i/Manifest.%s", globals.state_dir, to, component); + string_or_die(&manifest_delta, "%s/Manifest-%s-delta-from-%i-to-%i", globals.state_dir, component, from, to); + string_or_die(&to_dir, "%s/%i", globals.state_dir, to); if (!file_exists(manifest_delta)) { - string_or_die(&url, "%s/%i/Manifest-%s-delta-from-%i", content_url, to, component, from); + string_or_die(&url, "%s/%i/Manifest-%s-delta-from-%i", globals.content_url, to, component, from); ret = swupd_curl_get_file(url, manifest_delta); free_string(&url); if (ret != 0) { @@ -205,13 +205,13 @@ static int retrieve_manifest(int previous_version, int version, char *component, struct stat sb; if (!is_mix) { - basedir = state_dir; + basedir = globals.state_dir; } else { basedir = MIX_STATE_DIR; } /* Check for fullfile only, we will not be keeping the .tar around */ - string_or_die(&filename, "%s/%i/Manifest.%s", state_dir, version, component); + string_or_die(&filename, "%s/%i/Manifest.%s", globals.state_dir, version, component); if (stat(filename, &sb) == 0) { ret = 0; goto out; @@ -223,7 +223,7 @@ static int retrieve_manifest(int previous_version, int version, char *component, goto out; } - string_or_die(&dir, "%s/%i", state_dir, version); + string_or_die(&dir, "%s/%i", globals.state_dir, version); ret = mkdir(dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); if ((ret != 0) && (errno != EEXIST)) { goto out; @@ -231,7 +231,7 @@ static int retrieve_manifest(int previous_version, int version, char *component, /* If it's mix content just hardlink instead of curl download */ if (is_mix) { - string_or_die(&filename, "%s/%i/Manifest.%s.tar", state_dir, version, component); + string_or_die(&filename, "%s/%i/Manifest.%s.tar", globals.state_dir, version, component); string_or_die(&url, "%s/%i/Manifest.%s.tar", basedir, version, component); ret = link_or_rename(url, filename); /* If rename fails, we try again below with curl to the contenurl */ @@ -243,8 +243,8 @@ static int retrieve_manifest(int previous_version, int version, char *component, } /* Either we're not on mix or it failed, try curl-ing the file if link didn't work */ - string_or_die(&filename, "%s/%i/Manifest.%s.tar", state_dir, version, component); - string_or_die(&url, "%s/%i/Manifest.%s.tar", content_url, version, component); + string_or_die(&filename, "%s/%i/Manifest.%s.tar", globals.state_dir, version, component); + string_or_die(&url, "%s/%i/Manifest.%s.tar", globals.content_url, version, component); ret = swupd_curl_get_file(url, filename); if (ret) { @@ -293,17 +293,17 @@ static void remove_manifest_files(char *filename, int version, char *hash) char *file; warn("Removing corrupt Manifest.%s artifacts and re-downloading...\n", filename); - string_or_die(&file, "%s/%i/Manifest.%s", state_dir, version, filename); + string_or_die(&file, "%s/%i/Manifest.%s", globals.state_dir, version, filename); unlink(file); free_string(&file); - string_or_die(&file, "%s/%i/Manifest.%s.tar", state_dir, version, filename); + string_or_die(&file, "%s/%i/Manifest.%s.tar", globals.state_dir, version, filename); unlink(file); free_string(&file); - string_or_die(&file, "%s/%i/Manifest.%s.sig", state_dir, version, filename); + string_or_die(&file, "%s/%i/Manifest.%s.sig", globals.state_dir, version, filename); unlink(file); free_string(&file); if (hash != NULL) { - string_or_die(&file, "%s/%i/Manifest.%s.%s", state_dir, version, filename, hash); + string_or_die(&file, "%s/%i/Manifest.%s.%s", globals.state_dir, version, filename, hash); unlink(file); free_string(&file); } @@ -373,7 +373,7 @@ struct manifest *load_mom(int version, bool latest, bool mix_exists, int *err) char *filename; char *url; bool retried = false; - bool needs_sig_verification = !(migrate && mix_exists); + bool needs_sig_verification = !(globals.migrate && mix_exists); retry_load: ret = retrieve_manifest(0, version, "MoM", mix_exists); @@ -400,10 +400,10 @@ retry_load: return NULL; } - string_or_die(&filename, "%s/%i/Manifest.MoM", state_dir, version); - string_or_die(&url, "%s/%i/Manifest.MoM", content_url, version); + string_or_die(&filename, "%s/%i/Manifest.MoM", globals.state_dir, version); + string_or_die(&url, "%s/%i/Manifest.MoM", globals.content_url, version); - if (!sigcheck) { + if (!globals.sigcheck) { warn("FAILED TO VERIFY SIGNATURE OF Manifest.MoM. Operation proceeding due to\n" " --nosigcheck, but system security may be compromised\n"); journal_log_error("swupd security notice: --nosigcheck used to bypass MoM signature verification failure"); @@ -436,7 +436,7 @@ retry_load: char *momdir; char *momfile; - string_or_die(&momdir, "%s/var/tmp/swupd", path_prefix); + string_or_die(&momdir, "%s/var/tmp/swupd", globals.path_prefix); string_or_die(&momfile, "%s/Manifest.MoM", momdir); swupd_rm(momfile); mkdir_p(momdir); @@ -543,7 +543,7 @@ static bool is_installed_and_verified(struct file *file) return false; } - char *fullname = mk_full_filename(path_prefix, file->filename); + char *fullname = mk_full_filename(globals.path_prefix, file->filename); if (verify_file(file, fullname)) { free_string(&fullname); @@ -561,8 +561,8 @@ struct list *create_update_list(struct manifest *server) struct list *output = NULL; struct list *list; - update_count = 0; - update_skip = 0; + globals.update_count = 0; + globals.update_skip = 0; list = list_head(server->files); while (list) { struct file *file; @@ -604,7 +604,7 @@ struct list *create_update_list(struct manifest *server) continue; } } - update_count = list_len(output) - update_skip; + globals.update_count = list_len(output) - globals.update_skip; return output; } @@ -1037,7 +1037,7 @@ void remove_files_in_manifest_from_fs(struct manifest *m) while (iter) { file = iter->data; iter = iter->next; - string_or_die(&fullfile, "%s/%s", path_prefix, file->filename); + string_or_die(&fullfile, "%s/%s", globals.path_prefix, file->filename); if (swupd_rm(fullfile) == -1) { /* if a -1 is returned it means there was an issue deleting the * file or directory, in that case decrease the counter of deleted diff --git a/src/mirror.c b/src/mirror.c index d663637e..74e865c2 100644 --- a/src/mirror.c +++ b/src/mirror.c @@ -104,8 +104,8 @@ static int unset_mirror_url() char *content_path; char *version_path; int ret = 0; - content_path = mk_full_filename(path_prefix, MIRROR_CONTENT_URL_PATH); - version_path = mk_full_filename(path_prefix, MIRROR_VERSION_URL_PATH); + content_path = mk_full_filename(globals.path_prefix, MIRROR_CONTENT_URL_PATH); + version_path = mk_full_filename(globals.path_prefix, MIRROR_VERSION_URL_PATH); if ((ret = swupd_rm(content_path))) { goto out; @@ -116,8 +116,8 @@ static int unset_mirror_url() /* we need to also unset the mirror urls from the cache and set it to * the central version */ - free_string(&version_url); - free_string(&content_url); + free_string(&globals.version_url); + free_string(&globals.content_url); set_default_version_url(); set_default_content_url(); get_latest_version(""); @@ -192,8 +192,8 @@ static enum swupd_code set_mirror_url(char *url) /* concatenate path_prefix and configuration paths if necessary * if path_prefix is NULL the second argument will be returned */ - content_path = mk_full_filename(path_prefix, MIRROR_CONTENT_URL_PATH); - version_path = mk_full_filename(path_prefix, MIRROR_VERSION_URL_PATH); + content_path = mk_full_filename(globals.path_prefix, MIRROR_CONTENT_URL_PATH); + version_path = mk_full_filename(globals.path_prefix, MIRROR_VERSION_URL_PATH); /* write url to path_prefix/MIRROR_CONTENT_URL_PATH */ ret = write_to_path(url, content_path); @@ -228,8 +228,8 @@ static bool mirror_is_set(void) char *version_path; char *content_path; - version_path = mk_full_filename(path_prefix, MIRROR_VERSION_URL_PATH); - content_path = mk_full_filename(path_prefix, MIRROR_CONTENT_URL_PATH); + version_path = mk_full_filename(globals.path_prefix, MIRROR_VERSION_URL_PATH); + content_path = mk_full_filename(globals.path_prefix, MIRROR_CONTENT_URL_PATH); mirror_set = file_exists(version_path) && file_exists(content_path); free_string(&version_path); @@ -250,7 +250,7 @@ void handle_mirror_if_stale(void) info("Checking mirror status\n"); - fullpath = mk_full_filename(path_prefix, DEFAULT_VERSION_URL_PATH); + fullpath = mk_full_filename(globals.path_prefix, DEFAULT_VERSION_URL_PATH); int ret = get_value_from_path(&ret_str, fullpath, true); if (ret != 0 || ret_str == NULL) { /* no versionurl file here, might not exist under --path argument */ @@ -258,7 +258,7 @@ void handle_mirror_if_stale(void) } /* before trying to get the latest version let's make sure the central version is up */ - if (!content_url_is_local && !check_connection(NULL, ret_str) != 0) { + if (!globals.content_url_is_local && !check_connection(NULL, ret_str) != 0) { warn("Upstream server %s not responding, cannot determine upstream version\n", ret_str); warn("Unable to determine if the mirror is up to date\n"); goto out; diff --git a/src/os_install.c b/src/os_install.c index e4a58aae..426c30af 100644 --- a/src/os_install.c +++ b/src/os_install.c @@ -110,12 +110,12 @@ static bool parse_options(int argc, char **argv) /* users need to specify a PATH for the installation as mandatory argument * either explicitly or using the --path global argument */ - if ((argc == optind) && (path_prefix == NULL)) { + if ((argc == optind) && (globals.path_prefix == NULL)) { error("the path where the OS will be installed needs to be specified\n\n"); return false; } else if (argc > optind) { path = *(argv + optind); - if (path_prefix) { + if (globals.path_prefix) { error("cannot specify a PATH and use the --path option at the same time\n\n"); return false; } diff --git a/src/packs.c b/src/packs.c index b374a97c..fe657547 100644 --- a/src/packs.c +++ b/src/packs.c @@ -58,7 +58,7 @@ static int finalize_pack_download(const char *module, int newversion, const char int err; debug("\nExtracting %s pack for version %i\n", module, newversion); - err = archives_extract_to(filename, state_dir); + err = archives_extract_to(filename, globals.state_dir); unlink(filename); @@ -119,7 +119,7 @@ static int download_pack(struct swupd_curl_parallel_handle *download_handle, int int err = -1; char *filename; - string_or_die(&filename, "%s/pack-%s-from-%i-to-%i.tar", state_dir, module, oldversion, newversion); + string_or_die(&filename, "%s/pack-%s-from-%i-to-%i.tar", globals.state_dir, module, oldversion, newversion); if (is_mix) { string_or_die(&url, "%s/%i/pack-%s-from-%i.tar", MIX_STATE_DIR, newversion, module, oldversion); @@ -137,7 +137,7 @@ static int download_pack(struct swupd_curl_parallel_handle *download_handle, int } else { struct pack_data *pack_data; - string_or_die(&url, "%s/%i/pack-%s-from-%i.tar", content_url, newversion, module, oldversion); + string_or_die(&url, "%s/%i/pack-%s-from-%i.tar", globals.content_url, newversion, module, oldversion); pack_data = calloc(1, sizeof(struct pack_data)); ON_NULL_ABORT(pack_data); @@ -176,7 +176,7 @@ static double packs_query_total_download_size(struct list *subs, struct manifest continue; } - string_or_die(&url, "%s/%i/pack-%s-from-%i.tar", content_url, sub->version, sub->component, sub->oldversion); + string_or_die(&url, "%s/%i/pack-%s-from-%i.tar", globals.content_url, sub->version, sub->component, sub->oldversion); size = swupd_curl_query_content_size(url); if (size != -1) { total_size += size; @@ -235,7 +235,7 @@ int download_subscribed_packs(struct list *subs, struct manifest *mom, bool requ } /* make sure the file is not already in the client system */ - string_or_die(&targetfile, "%s/pack-%s-from-%i-to-%i.tar", state_dir, sub->component, sub->oldversion, sub->version); + string_or_die(&targetfile, "%s/pack-%s-from-%i-to-%i.tar", globals.state_dir, sub->component, sub->oldversion, sub->version); if (lstat(targetfile, &stat) != 0 || stat.st_size != 0) { need_download = list_append_data(need_download, sub); } diff --git a/src/scripts.c b/src/scripts.c index 1b301603..40c2175a 100644 --- a/src/scripts.c +++ b/src/scripts.c @@ -51,15 +51,15 @@ static void update_boot(void) char *scriptname; /* Don't run clr-boot-manager update in a container on the rootfs */ - if (strcmp("/", path_prefix) == 0 && systemd_in_container()) { + if (strcmp("/", globals.path_prefix) == 0 && systemd_in_container()) { return; } - if (strcmp("/", path_prefix) == 0) { + if (strcmp("/", globals.path_prefix) == 0) { run_script_if_exists("/usr/bin/clr-boot-manager", "update", NULL); } else { - string_or_die(&scriptname, "%s/usr/bin/clr-boot-manager", path_prefix); - run_script_if_exists(scriptname, "update", "--path", path_prefix, NULL); + string_or_die(&scriptname, "%s/usr/bin/clr-boot-manager", globals.path_prefix); + run_script_if_exists(scriptname, "update", "--path", globals.path_prefix, NULL); free_string(&scriptname); } } @@ -71,13 +71,13 @@ void exec_post_update_script(bool reexec, bool block) int i = 0; bool has_path_prefix; - has_path_prefix = strcmp("/", path_prefix) != 0; + has_path_prefix = strcmp("/", globals.path_prefix) != 0; - params[i++] = str_or_die("%s%s", has_path_prefix ? path_prefix : "", + params[i++] = str_or_die("%s%s", has_path_prefix ? globals.path_prefix : "", POST_UPDATE); if (has_path_prefix) { - params[i++] = path_prefix; + params[i++] = globals.path_prefix; } if (block) { @@ -99,7 +99,7 @@ static void update_triggers(bool block) if (strlen(POST_UPDATE) == 0) { /* fall back to systemd if path prefix is not the rootfs * and the POST_UPDATE trigger wasn't specified */ - if (strcmp("/", path_prefix) != 0) { + if (strcmp("/", globals.path_prefix) != 0) { return; } @@ -110,7 +110,7 @@ static void update_triggers(bool block) } /* These must block so that new update triggers are executed after */ - if (need_systemd_reexec) { + if (globals.need_systemd_reexec) { systemctl_daemon_reexec(); } else { systemctl_daemon_reload(); @@ -129,13 +129,13 @@ static void update_triggers(bool block) } else { /* These must block so that new update triggers are executed after */ - exec_post_update_script(need_systemd_reexec, block); + exec_post_update_script(globals.need_systemd_reexec, block); } } void scripts_run_post_update(bool block) { - if (no_scripts) { + if (globals.no_scripts) { warn("post-update helper scripts skipped due to " "--no-scripts argument\n"); return; @@ -143,8 +143,8 @@ void scripts_run_post_update(bool block) info("Calling post-update helper scripts\n"); - if (need_update_boot || need_update_bootloader) { - if (no_boot_update) { + if (globals.need_update_boot || globals.need_update_bootloader) { + if (globals.no_boot_update) { warn("boot files update skipped due to " "--no-boot-update argument\n"); } else { @@ -157,10 +157,10 @@ void scripts_run_post_update(bool block) static void exec_pre_update_script(const char *script) { - if (strlen(PRE_UPDATE) == 0 || strcmp("/", path_prefix) == 0) { + if (strlen(PRE_UPDATE) == 0 || strcmp("/", globals.path_prefix) == 0) { run_script_if_exists(script, NULL); } else { - run_script_if_exists(script, path_prefix, NULL); + run_script_if_exists(script, globals.path_prefix, NULL); } } @@ -173,7 +173,7 @@ void scripts_run_pre_update(struct manifest *manifest) if (strlen(PRE_UPDATE) == 0) { string_or_die(&script, "/usr/bin/clr_pre_update.sh"); } else { - string_or_die(&script, "%s/%s", path_prefix, PRE_UPDATE); + string_or_die(&script, "%s/%s", globals.path_prefix, PRE_UPDATE); } if (!file_exists(script)) { diff --git a/src/search.c b/src/search.c index 72af17a6..c1c41fb1 100644 --- a/src/search.c +++ b/src/search.c @@ -401,12 +401,12 @@ static double query_total_download_size(struct list *list) file = list->data; list = list->next; - string_or_die(&untard_file, "%s/%i/Manifest.%s", state_dir, file->last_change, + string_or_die(&untard_file, "%s/%i/Manifest.%s", globals.state_dir, file->last_change, file->filename); if (access(untard_file, F_OK) == -1) { /* Does not exist client-side. Must download */ - string_or_die(&url, "%s/%i/Manifest.%s.tar", content_url, + string_or_die(&url, "%s/%i/Manifest.%s.tar", globals.content_url, file->last_change, file->filename); ret = swupd_curl_query_content_size(url); @@ -618,7 +618,7 @@ enum swupd_code search_main(int argc, char **argv) } progress_set_step(1, "get_versions"); - current_version = get_current_version(path_prefix); + current_version = get_current_version(globals.path_prefix); if (current_version < 0) { error("Unable to determine current OS version\n"); return SWUPD_CURRENT_VERSION_UNKNOWN; diff --git a/src/staging.c b/src/staging.c index f906dd1b..03444cae 100644 --- a/src/staging.c +++ b/src/staging.c @@ -89,11 +89,11 @@ enum swupd_code do_staging(struct file *file, struct manifest *MoM) rel_dir = dir + 1; } - string_or_die(&original, "%s/staged/%s", state_dir, file->hash); + string_or_die(&original, "%s/staged/%s", globals.state_dir, file->hash); /* make sure the directory where the file should be copied to exists * and is in deed a directory */ - string_or_die(&targetpath, "%s%s", path_prefix, rel_dir); + string_or_die(&targetpath, "%s%s", globals.path_prefix, rel_dir); ret = stat(targetpath, &s); if ((ret == -1) && (errno == ENOENT)) { if (MoM) { @@ -111,7 +111,7 @@ enum swupd_code do_staging(struct file *file, struct manifest *MoM) * it will end up here */ ret = SWUPD_COULDNT_CREATE_DIR; goto out; - } else if (strcmp(path_prefix, targetpath) != 0 && + } else if (strcmp(globals.path_prefix, targetpath) != 0 && strcmp(targetpath, real_path) != 0) { /* * targetpath and real_path should always be equal but @@ -125,7 +125,7 @@ enum swupd_code do_staging(struct file *file, struct manifest *MoM) } /* remove a pre-existing .update file in the destination if it exists */ - string_or_die(&target, "%s%s/.update.%s", path_prefix, rel_dir, base); + string_or_die(&target, "%s%s/.update.%s", globals.path_prefix, rel_dir, base); ret = swupd_rm(target); if (ret < 0 && ret != -ENOENT) { error("Failed to remove %s\n", target); @@ -133,7 +133,7 @@ enum swupd_code do_staging(struct file *file, struct manifest *MoM) /* if the file already exists in the final destination, check to see * if it is of the same type */ - string_or_die(&statfile, "%s%s", path_prefix, file->filename); + string_or_die(&statfile, "%s%s", globals.path_prefix, file->filename); memset(&s, 0, sizeof(struct stat)); ret = lstat(statfile, &s); if (ret == 0) { @@ -165,7 +165,7 @@ enum swupd_code do_staging(struct file *file, struct manifest *MoM) * pre-existing: */ /* In order to avoid tar transforms with directories, rename * the directory before and after the tar command */ - string_or_die(&rename_tmpdir, "%s/tmprenamedir", state_dir); + string_or_die(&rename_tmpdir, "%s/tmprenamedir", globals.state_dir); ret = create_staging_renamedir(rename_tmpdir); if (ret) { ret = SWUPD_COULDNT_CREATE_DIR; @@ -177,7 +177,7 @@ enum swupd_code do_staging(struct file *file, struct manifest *MoM) goto out; } string_or_die(&tarcommand, TAR_COMMAND " -C '%s' " TAR_PERM_ATTR_ARGS " -cf - './%s' 2> /dev/null | " TAR_COMMAND " -C '%s%s' " TAR_PERM_ATTR_ARGS " -xf - 2> /dev/null", - rename_tmpdir, base, path_prefix, rel_dir); + rename_tmpdir, base, globals.path_prefix, rel_dir); ret = system(tarcommand); if (ret == -1) { ret = SWUPD_SUBPROCESS_ERROR; @@ -210,14 +210,14 @@ enum swupd_code do_staging(struct file *file, struct manifest *MoM) /* either the hardlink failed, or it was undesirable (config), do a tar-tar dance */ /* In order to avoid tar transforms, rename the file * before and after the tar command */ - string_or_die(&rename_target, "%s/staged/.update.%s", state_dir, base); + string_or_die(&rename_target, "%s/staged/.update.%s", globals.state_dir, base); ret = rename(original, rename_target); if (ret) { ret = SWUPD_COULDNT_RENAME_FILE; goto out; } string_or_die(&tarcommand, TAR_COMMAND " -C '%s/staged' " TAR_PERM_ATTR_ARGS " -cf - '.update.%s' 2> /dev/null | " TAR_COMMAND " -C '%s%s' " TAR_PERM_ATTR_ARGS " -xf - 2> /dev/null", - state_dir, base, path_prefix, rel_dir); + globals.state_dir, base, globals.path_prefix, rel_dir); ret = system(tarcommand); if (ret == -1) { ret = SWUPD_SUBPROCESS_ERROR; @@ -234,7 +234,7 @@ enum swupd_code do_staging(struct file *file, struct manifest *MoM) } free_string(&file->staging); - string_or_die(&file->staging, "%s%s/.update.%s", path_prefix, rel_dir, base); + string_or_die(&file->staging, "%s%s/.update.%s", globals.path_prefix, rel_dir, base); err = lstat(file->staging, &buf); if (err != 0) { free_string(&file->staging); @@ -261,7 +261,7 @@ int rename_staged_file_to_final(struct file *file) int ret; char *target; - string_or_die(&target, "%s%s", path_prefix, file->filename); + string_or_die(&target, "%s%s", globals.path_prefix, file->filename); if (!file->staging && !file->is_deleted && !file->is_dir) { free_string(&target); @@ -294,7 +294,7 @@ int rename_staged_file_to_final(struct file *file) char *lostnfound; char *base; - string_or_die(&lostnfound, "%slost+found", path_prefix); + string_or_die(&lostnfound, "%slost+found", globals.path_prefix); ret = mkdir(lostnfound, S_IRWXU); if ((ret != 0) && (errno != EEXIST)) { free_string(&lostnfound); @@ -304,7 +304,7 @@ int rename_staged_file_to_final(struct file *file) free_string(&lostnfound); base = basename(file->filename); - string_or_die(&lostnfound, "%slost+found/%s", path_prefix, base); + string_or_die(&lostnfound, "%slost+found/%s", globals.path_prefix, base); /* this will fail if the directory was not already emptied */ ret = rename(target, lostnfound); if (ret < 0 && errno != ENOTEMPTY && errno != EEXIST) { @@ -357,5 +357,5 @@ int rename_all_files_to_final(struct list *updates) progress_report(complete, list_length); } - return update_count - update_good - update_errs - (update_skip - skip); + return globals.update_count - update_good - update_errs - (globals.update_skip - skip); } diff --git a/src/subscriptions.c b/src/subscriptions.c index d1c48776..b6cc3cf0 100644 --- a/src/subscriptions.c +++ b/src/subscriptions.c @@ -79,7 +79,7 @@ void read_subscriptions(struct list **subs) DIR *dir; struct dirent *ent; - string_or_die(&path, "%s/%s", path_prefix, BUNDLES_DIR); + string_or_die(&path, "%s/%s", globals.path_prefix, BUNDLES_DIR); dir = opendir(path); if (dir) { diff --git a/src/swupd.h b/src/swupd.h index fe2ee851..e60db773 100644 --- a/src/swupd.h +++ b/src/swupd.h @@ -11,6 +11,7 @@ #include #include "config_loader.h" +#include "globals.h" #include "lib/archives.h" #include "lib/config_parser.h" #include "lib/formatter_json.h" @@ -91,19 +92,6 @@ enum swupd_init_config { struct header; -extern bool allow_insecure_http; -extern bool allow_mix_collisions; -extern bool migrate; -extern bool sigcheck; -extern bool timecheck; -extern int update_count; -extern int update_skip; -extern bool update_complete; -extern bool need_update_boot; -extern bool need_update_bootloader; -extern bool need_systemd_reexec; -extern bool keepcache; - extern uint64_t total_curl_sz; struct update_stat { @@ -166,37 +154,6 @@ struct file_counts { int picky_extraneous; }; -extern bool verify_esp_only; -extern bool have_network; -extern bool verify_bundles_only; -extern bool no_scripts; -extern bool no_boot_update; -extern bool wait_for_scripts; -extern char *format_string; -extern char *path_prefix; -extern bool init_globals(void); -extern void globals_deinit(void); -extern void save_cmd(char **argv); -extern char **swupd_argv; -extern char *bundle_to_add; -extern char *state_dir; -extern bool skip_diskspace_check; -extern bool skip_optional_bundles; -extern timelist *global_times; -extern int max_retries; -extern int retry_delay; - -extern char *version_url; -extern char *content_url; -extern bool content_url_is_local; -extern char *cert_path; -extern int update_server_port; -extern char *default_format_path; -extern bool set_path_prefix(char *path); -extern bool set_default_content_url(void); -extern bool set_default_version_url(void); -extern void set_default_path_prefix(void); - extern void check_root(void); extern int add_included_manifests(struct manifest *mom, struct list **subs); @@ -286,8 +243,6 @@ extern int rename_staged_file_to_final(struct file *file); extern int update_device_latest_version(int version); -extern size_t get_max_xfer(size_t default_max_xfer); - extern void free_subscriptions(struct list **subs); extern void read_subscriptions(struct list **subs); extern bool component_subscribed(struct list *subs, char *component); @@ -318,7 +273,6 @@ void deduplicate_files_from_manifest(struct manifest **m1, struct manifest *m2); extern struct file *search_bundle_in_manifest(struct manifest *manifest, const char *bundlename); extern struct file *search_file_in_manifest(struct manifest *manifest, const char *filename); -extern char *mounted_dirs; extern char *mk_full_filename(const char *prefix, const char *path); extern bool is_directory_mounted(const char *filename); extern bool is_under_mounted_directory(const char *filename); @@ -412,15 +366,6 @@ extern enum swupd_code clean_statedir(bool all, bool dry_run); /* Parameter parsing in global.c */ extern struct global_const global; -struct global_options { - const struct option *longopts; - const int longopts_len; - bool (*parse_opt)(int opt, char *optarg); - void (*print_help)(void); -}; - -void global_print_help(void); -int global_parse_options(int argc, char **argv, const struct global_options *opts); enum swupd_code check_update(); diff --git a/src/telemetry.c b/src/telemetry.c index 2fc246bc..a8fce2d6 100644 --- a/src/telemetry.c +++ b/src/telemetry.c @@ -40,7 +40,7 @@ void telemetry(telem_prio_t level, const char *class, const char *fmt, ...) char *newname; int fd; - string_or_die(&filename, "%s/%d.%s.%d.XXXXXX", state_dir, + string_or_die(&filename, "%s/%d.%s.%d.XXXXXX", globals.state_dir, RECORD_VERSION, class, level); fd = mkstemp(filename); @@ -64,7 +64,7 @@ void telemetry(telem_prio_t level, const char *class, const char *fmt, ...) return; } - string_or_die(&newname, "%s/telemetry/%s", state_dir, filename_n); + string_or_die(&newname, "%s/telemetry/%s", globals.state_dir, filename_n); rename(filename, newname); free_string(&filename); diff --git a/src/update.c b/src/update.c index 8328411f..6ddfa1b3 100644 --- a/src/update.c +++ b/src/update.c @@ -39,8 +39,10 @@ #define FLAG_DOWNLOAD_ONLY 2000 +static bool allow_mix_collisions = false; static int requested_version = -1; static bool download_only = false; +static bool keepcache = false; int nonpack; @@ -178,7 +180,7 @@ int add_included_manifests(struct manifest *mom, struct list **subs) static bool need_new_upstream(int server) { if (!access(MIX_DIR "upstreamversion", R_OK)) { - int version = read_mix_version_file(MIX_DIR "upstreamversion", path_prefix); + int version = read_mix_version_file(MIX_DIR "upstreamversion", globals.path_prefix); if (version < server) { return true; } @@ -231,7 +233,7 @@ static enum swupd_code main_update() clock_gettime(CLOCK_MONOTONIC_RAW, &ts_start); /* Step 1: Preparation steps */ - timelist_timer_start(global_times, "Prepare for update"); + timelist_timer_start(globals.global_times, "Prepare for update"); progress_set_step(1, "prepare_for_update"); info("Update started\n"); @@ -241,19 +243,19 @@ static enum swupd_code main_update() handle_mirror_if_stale(); progress_complete_step(); - timelist_timer_stop(global_times); // closing: Prepare for update + timelist_timer_stop(globals.global_times); // closing: Prepare for update /* Step 2: get versions */ - timelist_timer_start(global_times, "Get versions"); + timelist_timer_start(globals.global_times, "Get versions"); progress_set_step(2, "get_versions"); version_check: - ret = check_versions(¤t_version, &server_version, requested_version, path_prefix); + ret = check_versions(¤t_version, &server_version, requested_version, globals.path_prefix); if (ret != SWUPD_OK) { goto clean_curl; } if (mix_exists) { - check_mix_versions(&mix_current_version, &mix_server_version, path_prefix); + check_mix_versions(&mix_current_version, &mix_server_version, globals.path_prefix); if (mix_current_version == -1 || mix_server_version == -1) { ret = SWUPD_CURRENT_VERSION_UNKNOWN; goto clean_curl; @@ -277,7 +279,7 @@ version_check: } // new mix version - check_mix_versions(&mix_current_version, &mix_server_version, path_prefix); + check_mix_versions(&mix_current_version, &mix_server_version, globals.path_prefix); ret = check_manifests_uniqueness(server_version, mix_server_version); if (ret > 0) { info("\n"); @@ -310,10 +312,10 @@ version_check: info("Preparing to update from %i to %i\n", current_version, server_version); progress_complete_step(); - timelist_timer_stop(global_times); // closing: Get versions + timelist_timer_stop(globals.global_times); // closing: Get versions /* Step 3: housekeeping */ - timelist_timer_start(global_times, "Clean up download directory"); + timelist_timer_start(globals.global_times, "Clean up download directory"); progress_set_step(3, "cleanup_download_dir"); if (rm_staging_dir_contents("download")) { error("There was a problem cleaning download directory\n"); @@ -321,12 +323,12 @@ version_check: goto clean_curl; } progress_complete_step(); - timelist_timer_stop(global_times); // closing: Clean up download directory + timelist_timer_stop(globals.global_times); // closing: Clean up download directory /* Step 4: setup manifests */ - timelist_timer_start(global_times, "Load manifests"); + timelist_timer_start(globals.global_times, "Load manifests"); progress_set_step(4, "load_manifests"); - timelist_timer_start(global_times, "Load MoM manifests"); + timelist_timer_start(globals.global_times, "Load MoM manifests"); int manifest_err; /* get the from/to MoM manifests */ @@ -347,9 +349,9 @@ version_check: ret = SWUPD_COULDNT_LOAD_MOM; goto clean_exit; } - timelist_timer_stop(global_times); // closing: Load MoM manifests + timelist_timer_stop(globals.global_times); // closing: Load MoM manifests - timelist_timer_start(global_times, "Recurse and consolidate bundle manifests"); + timelist_timer_start(globals.global_times, "Recurse and consolidate bundle manifests"); /* Read the current collective of manifests that we are subscribed to. * First load up the old (current) manifests. Statedir could have been cleared * or corrupt, so don't assume things are already there. Updating subscribed @@ -370,7 +372,7 @@ version_check: /* The new subscription is seeded from the list of currently installed bundles * This calls add_subscriptions which recurses for new includes */ - timelist_timer_start(global_times, "Add included bundle manifests"); + timelist_timer_start(globals.global_times, "Add included bundle manifests"); ret = add_included_manifests(server_manifest, &latest_subs); if (ret) { if (ret == -add_sub_BADNAME) { @@ -382,7 +384,7 @@ version_check: goto clean_exit; } } - timelist_timer_stop(global_times); // closing: Add included bundle manifests + timelist_timer_stop(globals.global_times); // closing: Add included bundle manifests /* read the new collective of manifests that we are subscribed to in the new MoM */ server_manifest->submanifests = recurse_manifest(server_manifest, latest_subs, NULL, false, &manifest_err); @@ -400,44 +402,44 @@ version_check: /* prepare for an update process based on comparing two in memory manifests */ link_manifests(current_manifest, server_manifest); - timelist_timer_stop(global_times); // closing: Recurse and consolidate bundle manifests + timelist_timer_stop(globals.global_times); // closing: Recurse and consolidate bundle manifests progress_complete_step(); - timelist_timer_stop(global_times); // closing: Load manifests + timelist_timer_stop(globals.global_times); // closing: Load manifests /* Step 5: check disk state before attempting update */ - timelist_timer_start(global_times, "Run pre-update scripts"); + timelist_timer_start(globals.global_times, "Run pre-update scripts"); progress_set_step(5, "run_preupdate_scripts"); scripts_run_pre_update(server_manifest); progress_complete_step(); - timelist_timer_stop(global_times); // closing: Run pre-update scripts + timelist_timer_stop(globals.global_times); // closing: Run pre-update scripts /* Step 6: get the packs and untar */ - timelist_timer_start(global_times, "Download packs"); + timelist_timer_start(globals.global_times, "Download packs"); progress_set_step(6, "download_packs"); download_subscribed_packs(latest_subs, server_manifest, false); - timelist_timer_stop(global_times); // closing: Download packs + timelist_timer_stop(globals.global_times); // closing: Download packs /* Step 7: apply deltas */ - timelist_timer_start(global_times, "Apply deltas"); + timelist_timer_start(globals.global_times, "Apply deltas"); progress_set_step(7, "apply_deltas"); apply_deltas(current_manifest); progress_complete_step(); - timelist_timer_stop(global_times); // closing: Apply deltas + timelist_timer_stop(globals.global_times); // closing: Apply deltas /* Step 8: some more housekeeping */ /* TODO: consider trying to do less sorting of manifests */ - timelist_timer_start(global_times, "Create update list"); + timelist_timer_start(globals.global_times, "Create update list"); progress_set_step(8, "create_update_list"); updates = create_update_list(server_manifest); print_statistics(current_version, server_version); progress_complete_step(); - timelist_timer_stop(global_times); // closing: Create update list + timelist_timer_stop(globals.global_times); // closing: Create update list /* Steps 9 & 10: downloading and applying updates */ /* need update list in filename order to insure directories are * created before their contents */ - timelist_timer_start(global_times, "Update loop"); + timelist_timer_start(globals.global_times, "Update loop"); /* two steps are part of this stage, so only pass the * initial step number and we will update the description * from within the update_loop function */ @@ -457,20 +459,20 @@ version_check: } delete_motd(); - timelist_timer_stop(global_times); // closing: Update loop + timelist_timer_stop(globals.global_times); // closing: Update loop /* Step 11: Run any scripts that are needed to complete update */ - timelist_timer_start(global_times, "Run post-update scripts"); + timelist_timer_start(globals.global_times, "Run post-update scripts"); progress_set_step(11, "run_postupdate_scripts"); /* Determine if another update is needed so the scripts block */ - int new_current_version = get_current_version(path_prefix); + int new_current_version = get_current_version(globals.path_prefix); if (on_new_format() && (requested_version == -1 || (requested_version > new_current_version))) { re_update = true; } - scripts_run_post_update(re_update || wait_for_scripts); + scripts_run_post_update(re_update || globals.wait_for_scripts); progress_complete_step(); - timelist_timer_stop(global_times); // closing: Run post-update scripts + timelist_timer_stop(globals.global_times); // closing: Run post-update scripts /* Create the state file that will tell swupd it's on a mix on future runs */ if (mix_exists && !system_on_mix()) { @@ -507,7 +509,7 @@ clean_curl: info("Update took %0.1f seconds, %ld MB transferred\n", delta, total_curl_sz / 1000 / 1000); } - timelist_print_stats(global_times); + timelist_print_stats(globals.global_times); /* version_files_match must be done before swupd_deinit to use globals */ if (re_update) { @@ -548,7 +550,7 @@ clean_curl: return SWUPD_CURRENT_VERSION_UNKNOWN; } - if (!swupd_argv) { + if (!globals.swupd_argv) { error("Unable to determine re-update command, exiting now\n"); return SWUPD_INVALID_BINARY; } @@ -565,7 +567,7 @@ clean_curl: swupd_binary[path_length] = '\0'; /* Run the swupd_argv saved from main */ - return execv(swupd_binary, swupd_argv); + return execv(swupd_binary, globals.swupd_argv); } return ret; @@ -630,7 +632,7 @@ static bool parse_opt(int opt, char *optarg) cmd_line_status = true; return true; case 'T': - migrate = true; + globals.migrate = true; error("Attempting to migrate to your mix content...\n\n"); return true; case 'k': @@ -696,7 +698,7 @@ enum swupd_code update_main(int argc, char **argv) } /* Update should always ignore optional bundles */ - skip_optional_bundles = true; + globals.skip_optional_bundles = true; progress_init_steps("update", steps_in_update); ret = swupd_init(SWUPD_ALL); diff --git a/src/verify.c b/src/verify.c index 5f130511..d2add847 100644 --- a/src/verify.c +++ b/src/verify.c @@ -215,7 +215,7 @@ static int check_files_hash(struct list *files) goto progress; } - fullname = mk_full_filename(path_prefix, f->filename); + fullname = mk_full_filename(globals.path_prefix, f->filename); valid = cmdline_option_quick ? verify_file_lazy(fullname) : verify_file(f, fullname); free_string(&fullname); if (valid) { @@ -280,8 +280,8 @@ static void check_warn_freespace(const struct file *file) goto out; } - string_or_die(&original, "%s/staged/%s", state_dir, file->hash); - fs_free = get_available_space(path_prefix); + string_or_die(&original, "%s/staged/%s", globals.state_dir, file->hash); + fs_free = get_available_space(globals.path_prefix); if (fs_free < 0 || stat(original, &st) != 0) { warn("Unable to determine free space on filesystem\n"); goto out; @@ -322,7 +322,7 @@ static void add_missing_files(struct manifest *official_manifest, bool repair) goto progress; } - fullname = mk_full_filename(path_prefix, file->filename); + fullname = mk_full_filename(globals.path_prefix, file->filename); memset(&local, 0, sizeof(struct file)); local.filename = file->filename; populate_file_struct(&local, fullname); @@ -392,7 +392,7 @@ static void check_and_fix_one(struct file *file, struct manifest *official_manif } /* compare the hash and report mismatch */ - fullname = mk_full_filename(path_prefix, file->filename); + fullname = mk_full_filename(globals.path_prefix, file->filename); if (verify_file(file, fullname)) { goto end; } @@ -488,7 +488,7 @@ static void remove_orphaned_files(struct manifest *official_manifest, bool repai goto progress; } - fullname = mk_full_filename(path_prefix, file->filename); + fullname = mk_full_filename(globals.path_prefix, file->filename); if (lstat(fullname, &sb) != 0) { /* correctly, the file is not present */ @@ -698,7 +698,7 @@ static bool parse_options(int argc, char **argv) error("--install option requires -m version option\n"); return false; } - if (path_prefix == NULL) { + if (globals.path_prefix == NULL) { error("--install option requires --path option\n"); return false; } @@ -727,7 +727,7 @@ static enum swupd_code deal_with_extra_files(struct manifest *manifest, bool fix { enum swupd_code ret; - char *start = mk_full_filename(path_prefix, cmdline_option_picky_tree); + char *start = mk_full_filename(globals.path_prefix, cmdline_option_picky_tree); info("\n%s extra files under %s\n", fix ? "Removing" : "Checking for", start); ret = walk_tree(manifest, start, fix, picky_whitelist, &counts); free_string(&start); @@ -794,13 +794,13 @@ enum swupd_code verify_main(void) /* Unless we are installing a new bundle we shoudn't include optional * bundles to the bundle list */ if (!cmdline_option_install) { - skip_optional_bundles = true; + globals.skip_optional_bundles = true; } /* Get the current system version and the version to verify against */ - timelist_timer_start(global_times, "Get versions"); + timelist_timer_start(globals.global_times, "Get versions"); progress_set_step(1, "get_versions"); - int sys_version = get_current_version(path_prefix); + int sys_version = get_current_version(globals.path_prefix); if (!version) { if (sys_version < 0) { error("Unable to determine current OS version\n"); @@ -821,7 +821,7 @@ enum swupd_code verify_main(void) } } progress_complete_step(); - timelist_timer_stop(global_times); // closing: Get versions + timelist_timer_stop(globals.global_times); // closing: Get versions if (cmdline_option_install) { info("Installing OS version %i%s\n", version, use_latest ? " (latest)" : ""); @@ -842,7 +842,7 @@ enum swupd_code verify_main(void) * FIXME: We need a command line option to override this in case the * certificate is hosed and the admin knows it and wants to recover. */ - timelist_timer_start(global_times, "Clean up download directory"); + timelist_timer_start(globals.global_times, "Clean up download directory"); progress_set_step(2, "cleanup_download_dir"); ret = rm_staging_dir_contents("download"); if (ret != 0) { @@ -850,9 +850,9 @@ enum swupd_code verify_main(void) warn("Failed to remove prior downloads, carrying on anyway\n"); } progress_complete_step(); - timelist_timer_stop(global_times); // closing: Clean up download directory + timelist_timer_stop(globals.global_times); // closing: Clean up download directory - timelist_timer_start(global_times, "Load manifests"); + timelist_timer_start(globals.global_times, "Load manifests"); progress_set_step(3, "load_manifests"); /* Gather current manifests */ @@ -887,7 +887,7 @@ enum swupd_code verify_main(void) error("Mismatching formats detected when %s %d" " (expected: %s; actual: %d)\n", cmdline_command_verify ? "verifying" : "diagnosing", - version, format_string, official_manifest->manifest_version); + version, globals.format_string, official_manifest->manifest_version); int latest = get_latest_version(NULL); if (latest > 0) { info("Latest supported version to %s: %d\n", @@ -958,14 +958,14 @@ enum swupd_code verify_main(void) goto clean_and_exit; } progress_complete_step(); - timelist_timer_stop(global_times); // closing: Load manifests + timelist_timer_stop(globals.global_times); // closing: Load manifests - timelist_timer_start(global_times, "Consolidate files from bundles"); + timelist_timer_start(globals.global_times, "Consolidate files from bundles"); progress_set_step(4, "consolidate_files"); official_manifest->files = files_from_bundles(official_manifest->submanifests); official_manifest->files = consolidate_files(official_manifest->files); progress_complete_step(); - timelist_timer_stop(global_times); + timelist_timer_stop(globals.global_times); if (cmdline_extra_files_only) { /* user wants to deal only with the extra files, so skip everything else */ @@ -973,7 +973,7 @@ enum swupd_code verify_main(void) } /* steps 5, 6 & 7 are executed within the get_required_files function */ - timelist_timer_start(global_times, "Get required files"); + timelist_timer_start(globals.global_times, "Get required files"); /* get the initial number of files to be inspected */ counts.checked = list_len(official_manifest->files); @@ -986,7 +986,7 @@ enum swupd_code verify_main(void) goto clean_and_exit; } } - timelist_timer_stop(global_times); + timelist_timer_stop(globals.global_times); /* preparation work complete. */ @@ -1009,7 +1009,7 @@ enum swupd_code verify_main(void) * is already there. It's also the most safe operation, adding files rarely * has unintended side effect. So lets do the safest thing first. */ - timelist_timer_start(global_times, "Add missing files"); + timelist_timer_start(globals.global_times, "Add missing files"); progress_set_next_step("add_missing_files"); if (cmdline_option_install) { info("\nInstalling base OS and selected bundles\n"); @@ -1019,7 +1019,7 @@ enum swupd_code verify_main(void) info("\nChecking for missing files\n"); } add_missing_files(official_manifest, cmdline_option_fix || cmdline_option_install); - timelist_timer_stop(global_times); + timelist_timer_stop(globals.global_times); if (cmdline_option_quick) { /* quick only replaces missing files, so it is done here */ @@ -1027,28 +1027,28 @@ enum swupd_code verify_main(void) } /* repair corrupt files */ - timelist_timer_start(global_times, "Fixing modified files"); + timelist_timer_start(globals.global_times, "Fixing modified files"); progress_set_next_step("fix_files"); deal_with_hash_mismatches(official_manifest, cmdline_option_fix); - timelist_timer_stop(global_times); + timelist_timer_stop(globals.global_times); /* remove orphaned files, removing files could be * risky, so only do it if the prior phases had no problems */ - timelist_timer_start(global_times, "Removing orphaned files"); + timelist_timer_start(globals.global_times, "Removing orphaned files"); if ((counts.not_fixed == 0) && (counts.not_replaced == 0)) { progress_set_next_step("remove_extraneous_files"); remove_orphaned_files(official_manifest, cmdline_option_fix); } - timelist_timer_stop(global_times); + timelist_timer_stop(globals.global_times); /* remove extra files */ extra_files: if (cmdline_option_picky || cmdline_extra_files_only) { - timelist_timer_start(global_times, "Removing extra files"); + timelist_timer_start(globals.global_times, "Removing extra files"); progress_set_next_step("remove_extra_files"); deal_with_extra_files(official_manifest, cmdline_option_fix); progress_complete_step(); - timelist_timer_stop(global_times); + timelist_timer_stop(globals.global_times); } brick_the_system_and_clean_curl: @@ -1087,12 +1087,12 @@ brick_the_system_and_clean_curl: if (cmdline_option_fix || cmdline_option_install) { // always run in a fix or install case - need_update_boot = true; - need_update_bootloader = true; - timelist_timer_start(global_times, "Run Scripts"); + globals.need_update_boot = true; + globals.need_update_bootloader = true; + timelist_timer_start(globals.global_times, "Run Scripts"); info("\n"); - scripts_run_post_update(wait_for_scripts); - timelist_timer_stop(global_times); + scripts_run_post_update(globals.wait_for_scripts); + timelist_timer_stop(globals.global_times); } sync(); @@ -1185,7 +1185,7 @@ clean_and_exit: } } - timelist_print_stats(global_times); + timelist_print_stats(globals.global_times); free_subscriptions(&subs); swupd_deinit(); diff --git a/src/version.c b/src/version.c index 393b980d..a44d9283 100644 --- a/src/version.c +++ b/src/version.c @@ -59,10 +59,10 @@ int get_latest_version(char *v_url) } if (v_url == NULL || strcmp(v_url, "") == 0) { - v_url = version_url; + v_url = globals.version_url; } - string_or_die(&url, "%s/version/format%s/latest", v_url, format_string); + string_or_die(&url, "%s/version/format%s/latest", v_url, globals.format_string); ret = swupd_curl_get_file_memory(url, &tmp_version); if (ret) { @@ -233,7 +233,7 @@ void check_mix_versions(int *current_version, int *server_version, char *path_pr { *current_version = read_mix_version_file("/usr/share/clear/version", path_prefix); char *format_file; - string_or_die(&format_file, MIX_STATE_DIR "version/format%s/latest", format_string); + string_or_die(&format_file, MIX_STATE_DIR "version/format%s/latest", globals.format_string); *server_version = read_mix_version_file(format_file, path_prefix); free_string(&format_file); } @@ -243,7 +243,7 @@ int update_device_latest_version(int version) FILE *file = NULL; char *path = NULL; - string_or_die(&path, "%s/version", state_dir); + string_or_die(&path, "%s/version", globals.state_dir); file = fopen(path, "w"); if (!file) { free_string(&path);