aboutsummaryrefslogtreecommitdiffstats
path: root/src/ck.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2018-09-22 12:58:22 +0300
committergramanas <anastasis.gramm2@gmail.com>2018-09-22 12:58:22 +0300
commit405afc36e0929d887188be09a5886f79ff0ea1c4 (patch)
treef31d36ad4229f207e7e7bfbfe679516295e82952 /src/ck.c
parentfe7c216a75ad1a5890c329df73f1d5ab461a1257 (diff)
downloadck-405afc36e0929d887188be09a5886f79ff0ea1c4.tar.gz
ck-405afc36e0929d887188be09a5886f79ff0ea1c4.tar.bz2
ck-405afc36e0929d887188be09a5886f79ff0ea1c4.zip
Standarize error codes
Diffstat (limited to 'src/ck.c')
-rw-r--r--src/ck.c27
1 files changed, 8 insertions, 19 deletions
diff --git a/src/ck.c b/src/ck.c
index 0d093d3..b2119e7 100644
--- a/src/ck.c
+++ b/src/ck.c
@@ -33,45 +33,32 @@
#include "cklist.h"
#include "ckutil.h"
-void free_res(UserOpt *opt, Conf *conf) {
- if (opt) {
- free_user_opt(opt);
- }
- if (conf) {
- free_conf(conf);
- }
-}
-
int main(int argc, char *argv[]) {
UserOpt opt;
+ Conf conf = {.VC_dir = NULL, .SCRT_dir = NULL};
/* get user opt */
switch(parse_action(argc, argv, &opt)) {
case APR_HELP:
- free_res(&opt, NULL);
print_parser_help();
- return 0;
+ goto error;
case APR_ERR:
print_parser_error(&opt);
- free_res(&opt, NULL);
- return 1;
+ goto error;
case APR_OK:
break;
}
- Conf conf = {.VC_dir = NULL, .SCRT_dir = NULL};
/* If the action is init don't load the config, skip to running init*/
if (opt.action != CKA_INIT) {
/* If the db doesn't exist ck is not initialized in the config
* location specified in opt */
if (!db_exists(&opt)) {
printf("ck is not initialized in %s.\nRun ck init first.\n", opt.confDir);
- free_res(&opt, NULL);
- return 1;
+ goto error;
}
/* Finally parse the config file and exit on error */
if (!config_file_parse(&conf, &opt)) {
- free_res(&opt, &conf);
- return 1;
+ goto error;
}
}
@@ -86,6 +73,8 @@ int main(int argc, char *argv[]) {
default:
break;
}
- free_res(&opt, &conf);
+ error:
+ free_user_opt(&opt);
+ free_conf(&conf);
return 0;
}