chiark / gitweb /
utils: show help blurb when run without any arguments
[elogind.git] / src / install.c
index 479a38c80a881d5fbe1cca91cffbcad70c07d6be..f56c0728b932e768357c7ce51ea859529f92ffe8 100644 (file)
@@ -59,13 +59,13 @@ Hashmap *will_install = NULL, *have_installed = NULL;
 
 static int help(void) {
 
 
 static int help(void) {
 
-        printf("%s [options]\n\n"
+        printf("%s [OPTIONS...] {COMMAND} ...\n\n"
                "Install init system units.\n\n"
                "  -h --help        Show this help\n"
                "     --force       Override existing links\n"
                "     --system      Install into system\n"
                "     --session     Install into session\n"
                "Install init system units.\n\n"
                "  -h --help        Show this help\n"
                "     --force       Override existing links\n"
                "     --system      Install into system\n"
                "     --session     Install into session\n"
-               "     --global      Install into all sessions\n"
+               "     --global      Install into all sessions\n\n"
                "Commands:\n"
                "  enable [NAME...]    Enable one or more units\n"
                "  disable [NAME...]   Disable one or more units\n"
                "Commands:\n"
                "  enable [NAME...]    Enable one or more units\n"
                "  disable [NAME...]   Disable one or more units\n"
@@ -132,7 +132,7 @@ static int parse_argv(int argc, char *argv[]) {
         }
 
         if (optind >= argc) {
         }
 
         if (optind >= argc) {
-                log_error("Missing verb.");
+                help();
                 return -EINVAL;
         }
 
                 return -EINVAL;
         }
 
@@ -143,7 +143,7 @@ static int parse_argv(int argc, char *argv[]) {
         else if (streq(argv[optind], "test"))
                 arg_action = ACTION_TEST;
         else {
         else if (streq(argv[optind], "test"))
                 arg_action = ACTION_TEST;
         else {
-                log_error("Unknown verb %s", argv[optind]);
+                log_error("Unknown verb %s.", argv[optind]);
                 return -EINVAL;
         }
 
                 return -EINVAL;
         }
 
@@ -181,9 +181,6 @@ static bool unit_name_valid(const char *name) {
         /* This is a minimal version of unit_name_valid() from
          * unit-name.c */
 
         /* This is a minimal version of unit_name_valid() from
          * unit-name.c */
 
-        if (strchr(name, '/'))
-                return false;
-
         if (!*name)
                 return false;
 
         if (!*name)
                 return false;
 
@@ -386,6 +383,9 @@ static int install_info_symlink_alias(InstallInfo *i, const char *config_path) {
 
                 if ((r = create_symlink(i->path, alias_path)) != 0)
                         goto finish;
 
                 if ((r = create_symlink(i->path, alias_path)) != 0)
                         goto finish;
+
+                if (arg_action == ACTION_DISABLE)
+                        rmdir_parents(alias_path, config_path);
         }
 
         r = 0;
         }
 
         r = 0;
@@ -422,15 +422,8 @@ static int install_info_symlink_wants(InstallInfo *i, const char *config_path) {
                 if ((r = create_symlink(i->path, alias_path)) != 0)
                         goto finish;
 
                 if ((r = create_symlink(i->path, alias_path)) != 0)
                         goto finish;
 
-                if (arg_action == ACTION_DISABLE) {
-                        char *t;
-
-                        /* Try to remove .wants dir if we don't need it anymore */
-                        if (asprintf(&t, "%s/%s.wants", config_path, *s) >= 0) {
-                                rmdir(t);
-                                free(t);
-                        }
-                }
+                if (arg_action == ACTION_DISABLE)
+                        rmdir_parents(alias_path, config_path);
         }
 
         r = 0;
         }
 
         r = 0;
@@ -542,7 +535,7 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
                 goto finish;
         }
 
-        if ((r = lookup_paths_init(&paths, arg_where == WHERE_SYSTEM ? MANAGER_INIT : MANAGER_SESSION)) < 0) {
+        if ((r = lookup_paths_init(&paths, arg_where == WHERE_SYSTEM ? MANAGER_SYSTEM : MANAGER_SESSION)) < 0) {
                 log_error("Failed to determine lookup paths: %s", strerror(-r));
                 goto finish;
         }
                 log_error("Failed to determine lookup paths: %s", strerror(-r));
                 goto finish;
         }