]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
install: introduce a new unit file state "transient"
authorLennart Poettering <lennart@poettering.net>
Mon, 7 Mar 2016 18:07:30 +0000 (19:07 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Apr 2016 11:43:31 +0000 (13:43 +0200)
Now, that the search path logic knows the unit path for transient units we also
can introduce an explicit unit file state "transient" that clarifies to the
user what kind of unit file he is encountering.

man/systemctl.xml
src/core/dbus-manager.c
src/shared/install.c
src/shared/install.h
src/systemctl/systemctl.c

index 0febdfd4decd4d6e4819b89aca5546ff6b7ef6cc..064777810f7fb41bc53a1d390e7e99f4968f7c3d 100644 (file)
@@ -1186,6 +1186,11 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
                     <entry>The unit file was generated dynamically via a generator tool. See <citerefentry><refentrytitle>systemd.generator</refentrytitle><manvolnum>7</manvolnum></citerefentry>. Generated unit files may not be enabled, they are enabled implicitly by their generator.</entry>
                     <entry>0</entry>
                   </row>
+                  <row>
+                    <entry><literal>transient</literal></entry>
+                    <entry>The unit file has been created dynamically with the runtime API. Transient units may not be enabled.</entry>
+                    <entry>0</entry>
+                  </row>
                   <row>
                     <entry><literal>bad</literal></entry>
                     <entry>The unit file is invalid or another error occurred. Note that <command>is-enabled</command> will not actually return this state, but print an error message instead. However the unit file listing printed by <command>list-unit-files</command> might show it.</entry>
index 5fc3526751fd5de661709198ab9db277aeaf1861..f0ee2fcb36222879db1232ee4cbda9f509f7f820 100644 (file)
@@ -1641,7 +1641,7 @@ static int method_enable_unit_files_generic(
         if (r == -ESHUTDOWN)
                 return sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit file is masked.");
         if (r == -EADDRNOTAVAIL)
-                return sd_bus_error_setf(error, BUS_ERROR_UNIT_GENERATED, "Unit file is generated.");
+                return sd_bus_error_setf(error, BUS_ERROR_UNIT_GENERATED, "Unit file is transient or generated.");
         if (r < 0)
                 return r;
 
@@ -1866,7 +1866,7 @@ static int method_add_dependency_unit_files(sd_bus_message *message, void *userd
         if (r == -ESHUTDOWN)
                 return sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit file is masked.");
         if (r == -EADDRNOTAVAIL)
-                return sd_bus_error_setf(error, BUS_ERROR_UNIT_GENERATED, "Unit file is generated.");
+                return sd_bus_error_setf(error, BUS_ERROR_UNIT_GENERATED, "Unit file is transient or generated.");
         if (r < 0)
                 return r;
 
index 6c5d3ce7d162af381f45b3546fb3a9fa9f0d3c41..c19c85a3b5bb8c228767af9d47fad99e3f5255b6 100644 (file)
@@ -119,6 +119,19 @@ static int path_is_generator(const LookupPaths *p, const char *path) {
                 path_equal(p->generator_late, parent);
 }
 
+static int path_is_transient(const LookupPaths *p, const char *path) {
+        _cleanup_free_ char *parent = NULL;
+
+        assert(p);
+        assert(path);
+
+        parent = dirname_malloc(path);
+        if (!parent)
+                return -ENOMEM;
+
+        return path_equal(p->transient, parent);
+}
+
 static int path_is_config(const LookupPaths *p, const char *path) {
         _cleanup_free_ char *parent = NULL;
         const char *rpath;
@@ -1710,6 +1723,8 @@ int unit_file_add_dependency(
                 return -ESHUTDOWN;
         if (path_is_generator(&paths, target_info->path))
                 return -EADDRNOTAVAIL;
+        if (path_is_transient(&paths, target_info->path))
+                return -EADDRNOTAVAIL;
 
         assert(target_info->type == UNIT_FILE_TYPE_REGULAR);
 
@@ -1723,6 +1738,8 @@ int unit_file_add_dependency(
                         return -ESHUTDOWN;
                 if (path_is_generator(&paths, i->path))
                         return -EADDRNOTAVAIL;
+                if (path_is_transient(&paths, i->path))
+                        return -EADDRNOTAVAIL;
 
                 assert(i->type == UNIT_FILE_TYPE_REGULAR);
 
@@ -1777,6 +1794,8 @@ int unit_file_enable(
                         return -ESHUTDOWN;
                 if (path_is_generator(&paths, i->path))
                         return -EADDRNOTAVAIL;
+                if (path_is_transient(&paths, i->path))
+                        return -EADDRNOTAVAIL;
 
                 assert(i->type == UNIT_FILE_TYPE_REGULAR);
         }
@@ -1891,6 +1910,8 @@ int unit_file_set_default(
                 return -ESHUTDOWN;
         if (path_is_generator(&paths, i->path))
                 return -EADDRNOTAVAIL;
+        if (path_is_transient(&paths, i->path))
+                return -EADDRNOTAVAIL;
 
         old_path = skip_root(&paths, i->path);
         new_path = strjoina(paths.persistent_config, "/" SPECIAL_DEFAULT_TARGET);
@@ -1975,6 +1996,14 @@ int unit_file_lookup_state(
                         break;
                 }
 
+                r = path_is_transient(paths, i->path);
+                if (r < 0)
+                        return r;
+                if (r > 0) {
+                        state = UNIT_FILE_TRANSIENT;
+                        break;
+                }
+
                 r = find_symlinks_in_scope(scope, paths, i->name, &state);
                 if (r < 0)
                         return r;
@@ -2176,6 +2205,8 @@ static int preset_prepare_one(
                         return -ESHUTDOWN;
                 if (path_is_generator(paths, i->path))
                         return -EADDRNOTAVAIL;
+                if (path_is_transient(paths, i->path))
+                        return -EADDRNOTAVAIL;
         } else
                 r = install_info_discover(scope, minus, paths, name, SEARCH_FOLLOW_CONFIG_SYMLINKS, &i);
 
@@ -2372,6 +2403,7 @@ static const char* const unit_file_state_table[_UNIT_FILE_STATE_MAX] = {
         [UNIT_FILE_DISABLED] = "disabled",
         [UNIT_FILE_INDIRECT] = "indirect",
         [UNIT_FILE_GENERATED] = "generated",
+        [UNIT_FILE_TRANSIENT] = "transient",
         [UNIT_FILE_BAD] = "bad",
 };
 
index 9c33110e44d8d6deaa2846b0a09a5cfe9a487669..578664dd48860865f1b60e58cef3378663f28c9e 100644 (file)
@@ -55,6 +55,7 @@ enum UnitFileState {
         UNIT_FILE_DISABLED,
         UNIT_FILE_INDIRECT,
         UNIT_FILE_GENERATED,
+        UNIT_FILE_TRANSIENT,
         UNIT_FILE_BAD,
         _UNIT_FILE_STATE_MAX,
         _UNIT_FILE_STATE_INVALID = -1
index 3fd44a01d4a3c6c99b0f558fafd1b7d9b7e0c5c8..b64a97375e97dc9db97428efd1ebb26d6cbb270e 100644 (file)
@@ -5444,7 +5444,7 @@ static int enable_unit(int argc, char *argv[], void *userdata) {
                 if (r == -ESHUTDOWN)
                         return log_error_errno(r, "Unit file is masked.");
                 if (r == -EADDRNOTAVAIL)
-                        return log_error_errno(r, "Unit file is generated.");
+                        return log_error_errno(r, "Unit file is transient or generated.");
                 if (r < 0)
                         return log_error_errno(r, "Operation failed: %m");
 
@@ -5612,7 +5612,7 @@ static int add_dependency(int argc, char *argv[], void *userdata) {
                 if (r == -ESHUTDOWN)
                         return log_error_errno(r, "Unit file is masked.");
                 if (r == -EADDRNOTAVAIL)
-                        return log_error_errno(r, "Unit file is generated.");
+                        return log_error_errno(r, "Unit file is transient or generated.");
                 if (r < 0)
                         return log_error_errno(r, "Can't add dependency: %m");