Using swupd_code as return code of main functions

All exit codes that get propagated to the end user should be defined in
the swupd_exit_codes.h file. This commit changes the type of data
returned by those functions which the user interacts with so instead of
returning an int we return a swupd_code. This way it'll be easier to
identify what functions only return a documented code. If a function
returns an integer value not in swupd_exit_code.h then it should use int
instead.

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit is contained in:
Castulo Martinez
2019-01-24 15:23:15 -08:00
committed by Otavio Pontes
parent a723c0bc4a
commit 8f7f0b15ee
22 changed files with 65 additions and 65 deletions
+1 -1
View File
@@ -107,7 +107,7 @@ static int system_command(const char *cmd)
return ret;
}
int autoupdate_main(int argc, char **argv)
enum swupd_code autoupdate_main(int argc, char **argv)
{
if (!parse_options(argc, argv)) {
return SWUPD_INVALID_OPTION;
+8 -8
View File
@@ -43,7 +43,7 @@
* Parse the full manifest for the current version of the OS and print
* all available bundles.
*/
swupd_code list_installable_bundles()
enum swupd_code list_installable_bundles()
{
char *name;
struct list *list;
@@ -138,7 +138,7 @@ bool is_tracked_bundle(const char *bundle_name)
* bundles, this function search for bundle_name into subs
* struct and if it found then free it from the list.
*/
static swupd_code unload_tracked_bundle(const char *bundle_name, struct list **subs)
static enum swupd_code unload_tracked_bundle(const char *bundle_name, struct list **subs)
{
struct list *bundles;
struct list *cur_item;
@@ -193,7 +193,7 @@ static void required_by(struct list **reqd_by, const char *bundle_name, struct m
}
}
/* Return recursive list of included bundles */
swupd_code show_included_bundles(char *bundle_name)
enum swupd_code show_included_bundles(char *bundle_name)
{
int ret = 0;
int current_version = CURRENT_OS_VERSION;
@@ -286,7 +286,7 @@ out:
return ret;
}
swupd_code show_bundle_reqd_by(const char *bundle_name, bool server)
enum swupd_code show_bundle_reqd_by(const char *bundle_name, bool server)
{
int ret = 0;
int version = CURRENT_OS_VERSION;
@@ -482,7 +482,7 @@ out:
* performing a unlink(2) for each filename.
* 6) Done.
*/
swupd_code remove_bundles(char **bundles)
enum swupd_code remove_bundles(char **bundles)
{
int ret = SWUPD_OK;
int ret_code = 0;
@@ -734,7 +734,7 @@ out:
return ret;
}
static swupd_code install_bundles(struct list *bundles, struct list **subs, struct manifest *mom)
static enum swupd_code install_bundles(struct list *bundles, struct list **subs, struct manifest *mom)
{
int ret;
int bundles_failed = 0;
@@ -1051,7 +1051,7 @@ out:
/* Bundle install one ore more bundles passed in bundles
* param as a null terminated array of strings
*/
int install_bundles_frontend(char **bundles)
enum swupd_code install_bundles_frontend(char **bundles)
{
int ret = 0;
int current_version;
@@ -1131,7 +1131,7 @@ clean_and_exit:
* /usr/share/clear/bundles/), get the list of local bundles and print
* them sorted.
*/
swupd_code list_local_bundles()
enum swupd_code list_local_bundles()
{
char *name;
char *path = NULL;
+2 -2
View File
@@ -42,7 +42,7 @@ static void print_help(void)
}
/* Return 0 if there is an update available, nonzero if not */
static swupd_code check_update()
static enum swupd_code check_update()
{
int current_version, server_version;
int ret;
@@ -100,7 +100,7 @@ static bool parse_options(int argc, char **argv)
}
/* return 0 if update available, non-zero if not */
int check_update_main(int argc, char **argv)
enum swupd_code check_update_main(int argc, char **argv)
{
int ret;
+4 -4
View File
@@ -86,7 +86,7 @@ typedef bool(remove_predicate_func)(const char *dir, const struct dirent *entry)
/* Remove files from path for which pred returns true.
* Currently it doesn't recursively remove directories.
*/
static swupd_code remove_if(const char *path, bool dry_run, remove_predicate_func pred)
static enum swupd_code remove_if(const char *path, bool dry_run, remove_predicate_func pred)
{
int ret = SWUPD_OK;
DIR *dir;
@@ -280,7 +280,7 @@ end:
return contents;
}
static swupd_code clean_staged_manifests(const char *path, bool dry_run, bool all)
static enum swupd_code clean_staged_manifests(const char *path, bool dry_run, bool all)
{
DIR *dir;
@@ -377,7 +377,7 @@ static void clean_deinit(void)
v_lockfile();
}
int clean_main(int argc, char **argv)
enum swupd_code clean_main(int argc, char **argv)
{
if (!parse_options(argc, argv)) {
print_help();
@@ -425,7 +425,7 @@ end:
* /var/lib/swupd). It will remove all files except relevant manifests unless
* all is set to true. Setting dry_run to true will print the files that would
* be removed but will not actually remove them. */
int clean_statedir(bool dry_run, bool all)
enum swupd_code clean_statedir(bool dry_run, bool all)
{
char *staged_dir = NULL;
+1 -1
View File
@@ -94,7 +94,7 @@ static bool parse_options(int argc, char **argv)
return true;
}
int bundle_add_main(int argc, char **argv)
enum swupd_code bundle_add_main(int argc, char **argv)
{
if (!parse_options(argc, argv)) {
print_help();
+1 -1
View File
@@ -111,7 +111,7 @@ static bool parse_options(int argc, char **argv)
return true;
}
int bundle_list_main(int argc, char **argv)
enum swupd_code bundle_list_main(int argc, char **argv)
{
int ret;
+1 -1
View File
@@ -76,7 +76,7 @@ static bool parse_options(int argc, char **argv)
return true;
}
int bundle_remove_main(int argc, char **argv)
enum swupd_code bundle_remove_main(int argc, char **argv)
{
if (!parse_options(argc, argv)) {
print_help();
+1 -1
View File
@@ -115,7 +115,7 @@ static bool handle(const char *filename, bool is_dir, bool fix)
}
/* expect the start to end in /usr and be the absolute path to the root */
swupd_code walk_tree(struct manifest *manifest, const char *start, bool fix, const regex_t *whitelist, struct file_counts *counts)
enum swupd_code walk_tree(struct manifest *manifest, const char *start, bool fix, const regex_t *whitelist, struct file_counts *counts)
{
/* Walk the tree, */
int rc;
+1 -1
View File
@@ -157,7 +157,7 @@ int compute_hash_lazy(struct file *file, char *filename)
* a "0000000..." hash is returned as is our convention in the manifest
* for deleted files. Otherwise file->hash is set to a non-zero hash. */
/* TODO: how should we properly handle compute_hash() failures? */
swupd_code compute_hash(struct file *file, char *filename)
enum swupd_code compute_hash(struct file *file, char *filename)
{
int ret;
char key[SWUPD_HASH_LEN];
+1 -1
View File
@@ -55,7 +55,7 @@ static void usage(const char *name)
fprintf(stderr, "\n");
}
int hashdump_main(int argc, char **argv)
enum swupd_code hashdump_main(int argc, char **argv)
{
struct file file = { 0 };
char *fullname = NULL;
+2 -2
View File
@@ -530,7 +530,7 @@ void swupd_deinit(void)
* - Initialize curl
* - Initialize signature checking
*/
swupd_code swupd_init(void)
enum swupd_code swupd_init(void)
{
int ret = SWUPD_OK;
@@ -715,7 +715,7 @@ static void free_path_data(void *data)
* by breaking it into sub-paths and fixing them top down.
* Here, target_MoM is the consolidated manifest for the version you are trying to update/verify.
*/
swupd_code verify_fix_path(char *targetpath, struct manifest *target_MoM)
enum swupd_code verify_fix_path(char *targetpath, struct manifest *target_MoM)
{
struct list *path_list = NULL; /* path_list contains the subparts in the path */
char *path;
+1 -1
View File
@@ -30,7 +30,7 @@ void print_update_conf_info()
printf("Content URL: %s\n", content_url);
}
int info_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
enum swupd_code info_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
{
if (!init_globals()) {
return SWUPD_INIT_GLOBALS_FAILED;
+1 -1
View File
@@ -31,7 +31,7 @@
struct subcmd {
char *name;
char *doc;
int (*mainfunc)(int, char **);
enum swupd_code (*mainfunc)(int, char **);
};
static struct subcmd commands[] = {
+3 -3
View File
@@ -127,7 +127,7 @@ out:
return ret;
}
static swupd_code write_to_path(char *content, char *path)
static enum swupd_code write_to_path(char *content, char *path)
{
char *dir, *tmp = NULL;
struct stat dirstat;
@@ -182,7 +182,7 @@ out:
return ret;
}
static swupd_code set_mirror_url(char *url)
static enum swupd_code set_mirror_url(char *url)
{
char *content_path;
char *version_path;
@@ -258,7 +258,7 @@ out:
}
/* return 0 if update available, non-zero if not */
int mirror_main(int argc, char **argv)
enum swupd_code mirror_main(int argc, char **argv)
{
int ret = SWUPD_OK;
if (!parse_options(argc, argv)) {
+2 -2
View File
@@ -718,7 +718,7 @@ static double query_total_download_size(struct list *list)
* Description: To search Clear bundles for a particular entry, a complete set of
* manifests must be downloaded. This function does so, asynchronously, using
* the curl_multi interface */
static swupd_code download_manifests(struct manifest **MoM)
static enum swupd_code download_manifests(struct manifest **MoM)
{
struct list *list = NULL;
struct file *file = NULL;
@@ -807,7 +807,7 @@ static swupd_code download_manifests(struct manifest **MoM)
return ret;
}
int search_main(int argc, char **argv)
enum swupd_code search_main(int argc, char **argv)
{
int ret = SWUPD_OK;
struct manifest *MoM = NULL;
+1 -1
View File
@@ -62,7 +62,7 @@ static int create_staging_renamedir(char *rename_tmpdir)
//TODO: "do_staging is currently not able to be run in parallel"
/* Consider adding a remove_leftovers() that runs in verify/fix in order to
* allow this function to mkdtemp create folders for parallel build */
swupd_code do_staging(struct file *file, struct manifest *MoM)
enum swupd_code do_staging(struct file *file, struct manifest *MoM)
{
char *statfile = NULL, *tmp = NULL, *tmp2 = NULL;
char *dir, *base, *rel_dir;
+14 -14
View File
@@ -200,11 +200,11 @@ extern void increment_retries(int *retries, int *timeout);
extern int add_included_manifests(struct manifest *mom, struct list **subs);
extern int main_verify(int current_version);
extern swupd_code walk_tree(struct manifest *, const char *, bool, const regex_t *, struct file_counts *);
extern enum swupd_code walk_tree(struct manifest *, const char *, bool, const regex_t *, struct file_counts *);
extern int get_latest_version(char *v_url);
extern swupd_code read_versions(int *current_version, int *server_version, char *path_prefix);
extern swupd_code check_versions(int *current_version, int *server_version, int requested_version, char *path_prefix);
extern enum swupd_code read_versions(int *current_version, int *server_version, char *path_prefix);
extern enum swupd_code check_versions(int *current_version, int *server_version, int requested_version, char *path_prefix);
extern int get_current_version(char *path_prefix);
extern bool ignore(struct file *file);
@@ -281,7 +281,7 @@ extern int download_subscribed_packs(struct list *subs, struct manifest *mom, bo
extern void apply_deltas(struct manifest *current_manifest);
extern int untar_full_download(void *data);
extern swupd_code do_staging(struct file *file, struct manifest *manifest);
extern enum swupd_code do_staging(struct file *file, struct manifest *manifest);
extern int rename_all_files_to_final(struct list *updates);
extern int rename_staged_file_to_final(struct file *file);
@@ -298,7 +298,7 @@ extern void hash_assign(const char *src, char *dest);
extern bool hash_equal(const char *hash1, const char *hash2);
extern bool hash_is_zeros(char *hash);
extern int compute_hash_lazy(struct file *file, char *filename);
extern swupd_code compute_hash(struct file *file, char *filename) __attribute__((warn_unused_result));
extern enum swupd_code compute_hash(struct file *file, char *filename) __attribute__((warn_unused_result));
/* manifest.c */
/* Calculate the total contentsize of a manifest list */
@@ -341,13 +341,13 @@ extern int swupd_rm(const char *path);
extern int rm_bundle_file(const char *bundle);
extern void print_manifest_files(struct manifest *m);
extern void swupd_deinit(void);
extern swupd_code swupd_init(void);
extern enum swupd_code swupd_init(void);
extern int strtoi_err(const char *str, int *value);
extern int strtoi_err_endptr(const char *str, char **endptr, int *value);
void update_motd(int new_release);
void delete_motd(void);
extern int get_dirfd_path(const char *fullname);
extern swupd_code verify_fix_path(char *targetpath, struct manifest *manifest);
extern enum swupd_code verify_fix_path(char *targetpath, struct manifest *manifest);
extern struct list *files_from_bundles(struct list *bundles);
extern bool version_files_consistent(void);
extern bool string_in_list(char *string_to_check, struct list *list_to_check);
@@ -364,13 +364,13 @@ extern void create_and_append_subscription(struct list **subs, const char *compo
/* bundle.c */
extern bool is_tracked_bundle(const char *bundle_name);
extern swupd_code remove_bundles(char **bundles);
extern swupd_code show_bundle_reqd_by(const char *bundle_name, bool server);
extern swupd_code show_included_bundles(char *bundle_name);
extern swupd_code list_installable_bundles();
extern int install_bundles_frontend(char **bundles);
extern enum swupd_code remove_bundles(char **bundles);
extern enum swupd_code show_bundle_reqd_by(const char *bundle_name, bool server);
extern enum swupd_code show_included_bundles(char *bundle_name);
extern enum swupd_code list_installable_bundles();
extern enum swupd_code install_bundles_frontend(char **bundles);
extern int add_subscriptions(struct list *bundles, struct list **subs, struct manifest *mom, bool find_all, int recursion);
swupd_code list_local_bundles();
enum swupd_code list_local_bundles();
extern int link_or_rename(const char *orig, const char *dest);
/* telemetry.c */
@@ -395,7 +395,7 @@ extern void print_update_conf_info(void);
extern void handle_mirror_if_stale(void);
extern int clean_statedir(bool all, bool dry_run);
extern enum swupd_code clean_statedir(bool all, bool dry_run);
/* Parameter parsing in global.c */
extern struct global_const global;
+2 -2
View File
@@ -6,7 +6,7 @@
* Always add new codes last
*/
typedef enum {
enum swupd_code {
SWUPD_OK = 0, /* 0 success */
SWUPD_NO, /* 1 used by swupd to respond "No" in different situations:
@@ -48,6 +48,6 @@ typedef enum {
SWUPD_OUT_OF_MEMORY, /* 35 swupd ran out of memory */
SWUPD_VERIFY_FAILED /* 36 verify could not fix/replace/delete one or more files */
} swupd_code;
} ;
#endif
+12 -12
View File
@@ -1,17 +1,17 @@
#ifndef __INCLUDE_GUARD_SWUPD_INTERNAL_H
#define __INCLUDE_GUARD_SWUPD_INTERNAL_H
extern int autoupdate_main(int argc, char **argv);
extern int bundle_add_main(int argc, char **argv);
extern int bundle_remove_main(int argc, char **argv);
extern int bundle_list_main(int argc, char **argv);
extern int hashdump_main(int argc, char **argv);
extern int update_main(int argc, char **argv);
extern int verify_main(int argc, char **argv);
extern int check_update_main(int argc, char **argv);
extern int search_main(int argc, char **argv);
extern int info_main(int argc, char **argv);
extern int clean_main(int argc, char **argv);
extern int mirror_main(int argc, char **argv);
extern enum swupd_code autoupdate_main(int argc, char **argv);
extern enum swupd_code bundle_add_main(int argc, char **argv);
extern enum swupd_code bundle_remove_main(int argc, char **argv);
extern enum swupd_code bundle_list_main(int argc, char **argv);
extern enum swupd_code hashdump_main(int argc, char **argv);
extern enum swupd_code update_main(int argc, char **argv);
extern enum swupd_code verify_main(int argc, char **argv);
extern enum swupd_code check_update_main(int argc, char **argv);
extern enum swupd_code search_main(int argc, char **argv);
extern enum swupd_code info_main(int argc, char **argv);
extern enum swupd_code clean_main(int argc, char **argv);
extern enum swupd_code mirror_main(int argc, char **argv);
#endif
+3 -3
View File
@@ -205,7 +205,7 @@ static bool need_new_upstream(int server)
return false;
}
static swupd_code main_update()
static enum swupd_code main_update()
{
int current_version = -1, server_version = -1;
int mix_current_version = -1, mix_server_version = -1;
@@ -663,7 +663,7 @@ static bool parse_options(int argc, char **argv)
* 1 if the current_version is current or ahead
* a code > 1 if one or more versions can't be found
*/
static swupd_code print_versions()
static enum swupd_code print_versions()
{
int current_version, server_version, ret = 0;
@@ -696,7 +696,7 @@ static swupd_code print_versions()
return ret;
}
int update_main(int argc, char **argv)
enum swupd_code update_main(int argc, char **argv)
{
int ret = SWUPD_OK;
+1 -1
View File
@@ -611,7 +611,7 @@ static bool parse_options(int argc, char **argv)
* found to not match the manifest. This is notably different from update,
* which attempts to atomically (or nearly atomically) activate a set of
* pre-computed and validated staged changes as a group. */
int verify_main(int argc, char **argv)
enum swupd_code verify_main(int argc, char **argv)
{
struct manifest *official_manifest = NULL;
int ret;
+2 -2
View File
@@ -136,7 +136,7 @@ int get_current_version(char *path_prefix)
return v;
}
swupd_code read_versions(int *current_version, int *server_version, char *path_prefix)
enum swupd_code read_versions(int *current_version, int *server_version, char *path_prefix)
{
*current_version = get_current_version(path_prefix);
*server_version = get_latest_version(NULL);
@@ -153,7 +153,7 @@ swupd_code read_versions(int *current_version, int *server_version, char *path_p
return SWUPD_OK;
}
swupd_code check_versions(int *current_version, int *server_version, int requested_version, char *path_prefix)
enum swupd_code check_versions(int *current_version, int *server_version, int requested_version, char *path_prefix)
{
int ret;