Skip to content

Commit

Permalink
authselect: document exit codes
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrezina committed Feb 14, 2018
1 parent 5f70046 commit 44fe562
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
15 changes: 12 additions & 3 deletions src/cli/cli_tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,18 @@ int cli_tool_main(int argc, const char **argv,
cli_tool_common_opts(&argc, argv);

ret = cli_tool_route(argc, argv, commands);
if (ret != EOK) {
return EXIT_FAILURE;

switch (ret) {
case EOK:
return 0;
case ENOENT:
return 2;
case EBADF:
return 3;
case EEXIST:
return 4;
}

return EXIT_SUCCESS;
/* Generic error. */
return 1;
}
23 changes: 13 additions & 10 deletions src/cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ static errno_t activate(struct cli_cmdline *cmdline)

ret = authselect_activate(profile_id, features, enforce);
free(features);
if (ret == AUTHSELECT_ERR_FORCE_REQUIRED) {
if (ret == EEXIST) {
fprintf(stderr, _("\nSome unexpected changes to the configuration were "
"detected.\nUse --force parameter if you want to overwrite "
"these changes.\n"));
return EINVAL;
return ret;
} else if (ret != EOK) {
fprintf(stderr, _("Unable to activate profile [%d]: %s\n"),
ret, strerror(ret));
Expand All @@ -134,7 +134,7 @@ static errno_t current(struct cli_cmdline *cmdline)
ret = authselect_current_configuration(&profile_id, &features);
if (ret == ENOENT) {
printf(_("No existing configuration detected.\n"));
return EOK;
return ret;
} else if (ret != EOK) {
ERROR("Unable to get current configuration [%d]: %s",
ret, strerror(ret));
Expand All @@ -156,7 +156,7 @@ static errno_t current(struct cli_cmdline *cmdline)
free(profile_id);
authselect_array_free(features);

return ret;
return EOK;
}

static errno_t check(struct cli_cmdline *cmdline)
Expand All @@ -178,14 +178,17 @@ static errno_t check(struct cli_cmdline *cmdline)
return ret;
}

if (is_valid) {
puts(_("Current configuration is valid."));
} else {
if (!is_valid) {
puts(_("Current configuration is not valid. "
"It was probably modified outside authselect."));
return EBADF;
}

return EOK;
puts(_("Current configuration is valid."));

/* EOK = existing configuration is valid,
* ENOENT = non-existing configuration is valid */
return ret;
}

static errno_t list(struct cli_cmdline *cmdline)
Expand Down Expand Up @@ -432,13 +435,13 @@ int main(int argc, const char **argv)
ret = setup_gettext();
if (ret != EOK) {
fprintf(stderr, _("Unable to setup gettext!\n"));
return EXIT_FAILURE;
return 1;
}

uid = getuid();
if (uid != 0) {
fprintf(stderr, _("Authselect can only be run as root!\n"));
return EXIT_FAILURE;
return 1;
}

return cli_tool_main(argc, argv, commands, NULL);
Expand Down
10 changes: 10 additions & 0 deletions src/man/authselect.8.txt.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ These options are available with all commands.
the program execution but may indicate some undesired situations
(e.g. unexpected file in a profile directory).

RETURN CODES
------------
The *authselect* can return these exit codes:

* 0: Success.
* 1: Generic error.
* 2: Profile or configuration was not found.
* 3: Current configuration is not valid, it was edited without authselect.
* 4: System configuration must be overwritten to activate an authselect profile, --force parameter is needed.

GENERATED FILES
---------------
Authselect creates and maintains the following files to configure system
Expand Down

0 comments on commit 44fe562

Please sign in to comment.