From 931d4e4b3ff83b89d85c443d35674021c1888ba7 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Fri, 3 Feb 2012 09:32:33 -0800 Subject: [PATCH] cnf: Default to exit code 127 for command not found The only way success should be returned is if there was no input or if the command was installed and run successfully. All other exit paths should return the shell's command not found code of 127. --- contrib/command-not-found/pk-command-not-found.c | 23 +++++---------------- 1 files changed, 6 insertions(+), 17 deletions(-) diff --git a/contrib/command-not-found/pk-command-not-found.c b/contrib/command-not-found/pk-command-not-found.c index 502cbd8..ff5c64c 100644 --- a/contrib/command-not-found/pk-command-not-found.c +++ b/contrib/command-not-found/pk-command-not-found.c @@ -679,7 +679,7 @@ main (int argc, char *argv[]) gchar *text; const gchar *possible; gchar **parts; - guint retval = EXIT_SUCCESS; + guint retval = EXIT_COMMAND_NOT_FOUND; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); @@ -696,8 +696,10 @@ main (int argc, char *argv[]) pk_debug_add_log_domain (G_LOG_DOMAIN); /* no input */ - if (argv[1] == NULL) + if (argv[1] == NULL) { + retval = EXIT_SUCCESS; goto out; + } /* do stuff on ctrl-c */ signal (SIGINT, pk_cnf_sigint_handler); @@ -714,10 +716,8 @@ main (int argc, char *argv[]) /* get length */ len = strlen (argv[1]); - if (len < 1) { - retval = EXIT_COMMAND_NOT_FOUND; + if (len < 1) goto out; - } /* TRANSLATORS: the prefix of all the output telling the user * why it's not executing. NOTE: this is lowercase to mimic @@ -726,10 +726,8 @@ main (int argc, char *argv[]) /* user is not allowing CNF to do anything useful */ if (!config->software_source_search && - !config->similar_name_search) { - retval = EXIT_COMMAND_NOT_FOUND; + !config->similar_name_search) goto out; - } /* generate swizzles */ if (config->similar_name_search) @@ -741,7 +739,6 @@ main (int argc, char *argv[]) if (config->single_match == PK_CNF_POLICY_WARN) { /* TRANSLATORS: tell the user what we think the command is */ g_printerr ("%s '%s'\n", _("Similar command is:"), possible); - retval = EXIT_COMMAND_NOT_FOUND; goto out; } @@ -758,8 +755,6 @@ main (int argc, char *argv[]) ret = pk_console_get_prompt (text, TRUE); if (ret) retval = pk_cnf_spawn_command (possible, &argv[2]); - else - retval = EXIT_COMMAND_NOT_FOUND; g_free (text); } goto out; @@ -816,8 +811,6 @@ main (int argc, char *argv[]) ret = pk_cnf_install_package_id (package_ids[0]); if (ret) retval = pk_cnf_spawn_command (argv[1], &argv[2]); - else - retval = EXIT_COMMAND_NOT_FOUND; } g_print ("\n"); goto out; @@ -828,8 +821,6 @@ main (int argc, char *argv[]) ret = pk_cnf_install_package_id (package_ids[0]); if (ret) retval = pk_cnf_spawn_command (argv[1], &argv[2]); - else - retval = EXIT_COMMAND_NOT_FOUND; } g_strfreev (parts); goto out; @@ -861,8 +852,6 @@ main (int argc, char *argv[]) ret = pk_cnf_install_package_id (package_ids[i]); if (ret) retval = pk_cnf_spawn_command (argv[1], &argv[2]); - else - retval = EXIT_COMMAND_NOT_FOUND; } goto out; } -- 1.7.7.6