Commit fe58f0f sssctl: move check for version error to correct place

1 file Authored by pbrezina 2 months ago , Committed by jhrozek 2 months ago ,
sssctl: move check for version error to correct place

This check was added here:

284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 490) int sss_tool_main(int argc, const char **argv,
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 491)                   struct sss_route_cmd *commands,
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 492)                   void *pvt)
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 493) {
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 494)     struct sss_tool_ctx *tool_ctx;
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 495)     uid_t uid;
e98ccef2 (Pavel Březina   2016-06-09 16:13:34 +0200 496)     errno_t ret;
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 497)
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 498)     uid = getuid();
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 499)     if (uid != 0) {
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 500)         DEBUG(SSSDBG_CRIT_FAILURE, "Running under %d, must be root\n", uid);
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 501)         ERROR("%1$s must be run as root\n", argv[0]);
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 502)         return EXIT_FAILURE;
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 503)     }
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 504)
a0b824ac (Jakub Hrozek    2016-07-01 13:26:38 +0200 505)     ret = sss_tool_init(NULL, &argc, argv, &tool_ctx);
a0b824ac (Jakub Hrozek    2016-07-01 13:26:38 +0200 506)     if (ret == ERR_SYSDB_VERSION_TOO_OLD) {
a0b824ac (Jakub Hrozek    2016-07-01 13:26:38 +0200 507)         tool_ctx->init_err = ret;
a0b824ac (Jakub Hrozek    2016-07-01 13:26:38 +0200 508)     } else if (ret != EOK) {
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 509)         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create tool context\n");
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 510)         return EXIT_FAILURE;
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 511)     }

But then the initialization code was moved from sss_tool_init to tool_cmd_init which is called from sss_tool_route.

a0b824ac (Jakub Hrozek    2016-07-01 13:26:38 +0200 328)             if (!sss_tools_handles_init_error(&commands[i], tool_ctx->init_err)) {
a0b824ac (Jakub Hrozek    2016-07-01 13:26:38 +0200 329)                 DEBUG(SSSDBG_FATAL_FAILURE,
a0b824ac (Jakub Hrozek    2016-07-01 13:26:38 +0200 330)                       "Command %s does not handle initialization error [%d] %s\n",
a0b824ac (Jakub Hrozek    2016-07-01 13:26:38 +0200 331)                       cmdline.command, tool_ctx->init_err,
a0b824ac (Jakub Hrozek    2016-07-01 13:26:38 +0200 332)                       sss_strerror(tool_ctx->init_err));
a0b824ac (Jakub Hrozek    2016-07-01 13:26:38 +0200 333)                 return tool_ctx->init_err;
a0b824ac (Jakub Hrozek    2016-07-01 13:26:38 +0200 334)             }
a0b824ac (Jakub Hrozek    2016-07-01 13:26:38 +0200 335)
cbee11e9 (Michal Židek    2016-10-12 13:09:37 +0200 336)             ret = tool_cmd_init(tool_ctx, &commands[i]);
cbee11e9 (Michal Židek    2016-10-12 13:09:37 +0200 337)             if (ret != EOK) {
cbee11e9 (Michal Židek    2016-10-12 13:09:37 +0200 338)                 DEBUG(SSSDBG_FATAL_FAILURE,
cbee11e9 (Michal Židek    2016-10-12 13:09:37 +0200 339)                       "Command initialization failed [%d] %s\n",
cbee11e9 (Michal Židek    2016-10-12 13:09:37 +0200 340)                       ret, sss_strerror(ret));
cbee11e9 (Michal Židek    2016-10-12 13:09:37 +0200 341)                 return ret;
cbee11e9 (Michal Židek    2016-10-12 13:09:37 +0200 342)             }
cbee11e9 (Michal Židek    2016-10-12 13:09:37 +0200 343)
284937e6 (Pavel Březina   2015-07-22 10:02:02 +0200 344)             return commands[i].fn(&cmdline, tool_ctx, pvt);

This rendered the original change a dead code, because sss_tool_init only returns ENOMEM or EOK.

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>

    
 1 @@ -346,7 +346,9 @@
 2   
 3               if (!tool_ctx->print_help) {
 4                   ret = tool_cmd_init(tool_ctx, &commands[i]);
 5 -                 if (ret != EOK) {
 6 +                 if (ret == ERR_SYSDB_VERSION_TOO_OLD) {
 7 +                     tool_ctx->init_err = ret;
 8 +                 } else if (ret != EOK) {
 9                       DEBUG(SSSDBG_FATAL_FAILURE,
10                             "Command initialization failed [%d] %s\n",
11                             ret, sss_strerror(ret));
12 @@ -516,9 +518,7 @@
13       }
14   
15       ret = sss_tool_init(NULL, &argc, argv, &tool_ctx);
16 -     if (ret == ERR_SYSDB_VERSION_TOO_OLD) {
17 -         tool_ctx->init_err = ret;
18 -     } else if (ret != EOK) {
19 +     if (ret != EOK) {
20           DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create tool context\n");
21           return EXIT_FAILURE;
22       }