systemctl: clarify code - some actions never appear in arg_action (#6638)
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>
Thu, 31 Aug 2017 08:54:12 +0000 (09:54 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 31 Aug 2017 08:54:12 +0000 (10:54 +0200)
ACTION_EMERGENCY and ACTION_DEFAULT would be handled correctly by
start_with_fallback().  However there is no fallback available for
them, and they would never be set in `arg_action` in the first
place.  Remove the unused cases from the switch statement.

@poettering suggested this makes a good place to clarify the point,
explicitly listing all the `arg_action` values which would never be
set.

src/systemctl/systemctl.c

index 36675dc..d0c7ed7 100644 (file)
@@ -8562,6 +8562,10 @@ int main(int argc, char*argv[]) {
                 r = systemctl_main(argc, argv);
                 break;
 
+        /* Legacy command aliases set arg_action. They provide some fallbacks,
+         * e.g. to tell sysvinit to reboot after you have installed systemd
+         * binaries. */
+
         case ACTION_HALT:
         case ACTION_POWEROFF:
         case ACTION_REBOOT:
@@ -8574,8 +8578,6 @@ int main(int argc, char*argv[]) {
         case ACTION_RUNLEVEL4:
         case ACTION_RUNLEVEL5:
         case ACTION_RESCUE:
-        case ACTION_EMERGENCY:
-        case ACTION_DEFAULT:
                 r = start_with_fallback();
                 break;
 
@@ -8592,6 +8594,15 @@ int main(int argc, char*argv[]) {
                 r = runlevel_main();
                 break;
 
+        case ACTION_EXIT:
+        case ACTION_SUSPEND:
+        case ACTION_HIBERNATE:
+        case ACTION_HYBRID_SLEEP:
+        case ACTION_EMERGENCY:
+        case ACTION_DEFAULT:
+                /* systemctl verbs with no equivalent in the legacy commands.
+                 * These cannot appear in arg_action.  Fall through. */
+
         case _ACTION_INVALID:
         default:
                 assert_not_reached("Unknown action");