chiark / gitweb /
install: make systemd-install useful for installation of template instances
authorLennart Poettering <lennart@poettering.net>
Fri, 18 Jun 2010 19:33:15 +0000 (21:33 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 18 Jun 2010 19:33:15 +0000 (21:33 +0200)
fixme
src/install.c
src/util.c
src/util.h

diff --git a/fixme b/fixme
index dfd496d..7a0b499 100644 (file)
--- a/fixme
+++ b/fixme
@@ -28,8 +28,6 @@
 
 * iCalendar semantics for the timer stuff (RFC2445)
 
-* provide sysv-like command line utilities
-
 * ability to kill services? i.e. in contrast to stopping them, go directly
   into killing mode?
 
 
 * systemd-sysvinit as package
 
-* install must understand templates
-
 * abstract namespace dbus socket
 
-* /sbin/shutdown argv[2..] message
-
 * discuss NOTIFY_SOCKET, make it configurable? security implications?
 
+* when reading pid for watching, verify we are parent
+
 Regularly:
 
 * look for close() vs. close_nointr() vs. close_nointr_nofail()
index 479a38c..e30f623 100644 (file)
@@ -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 */
 
-        if (strchr(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 (arg_action == ACTION_DISABLE)
+                        rmdir_parents(alias_path, config_path);
         }
 
         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 (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;
index 2363ea2..78d8d5d 100644 (file)
@@ -893,6 +893,53 @@ int mkdir_p(const char *path, mode_t mode) {
         return 0;
 }
 
+int rmdir_parents(const char *path, const char *stop) {
+        size_t l;
+        int r = 0;
+
+        assert(path);
+        assert(stop);
+
+        l = strlen(path);
+
+        /* Skip trailing slashes */
+        while (l > 0 && path[l-1] == '/')
+                l--;
+
+        while (l > 0) {
+                char *t;
+
+                /* Skip last component */
+                while (l > 0 && path[l-1] != '/')
+                        l--;
+
+                /* Skip trailing slashes */
+                while (l > 0 && path[l-1] == '/')
+                        l--;
+
+                if (l <= 0)
+                        break;
+
+                if (!(t = strndup(path, l)))
+                        return -ENOMEM;
+
+                if (path_startswith(stop, t)) {
+                        free(t);
+                        return 0;
+                }
+
+                r = rmdir(t);
+                free(t);
+
+                if (r < 0)
+                        if (errno != ENOENT)
+                                return -errno;
+        }
+
+        return 0;
+}
+
+
 char hexchar(int x) {
         static const char table[16] = "0123456789abcdef";
 
index 14c2859..9af2ca8 100644 (file)
@@ -163,6 +163,8 @@ char *file_in_same_dir(const char *path, const char *filename);
 int mkdir_parents(const char *path, mode_t mode);
 int mkdir_p(const char *path, mode_t mode);
 
+int rmdir_parents(const char *path, const char *stop);
+
 int get_process_name(pid_t pid, char **name);
 
 char hexchar(int x);