]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/volatile-util.c
fstab-generator: add support for volatile boots
[thirdparty/systemd.git] / src / shared / volatile-util.c
index 1329b51f4e44d4b5cbfa2bcdd487eded38e373d5..e7e9721411e70e86ea42556bbd5133c4f301096c 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include "alloc-util.h"
 #include "macro.h"
 #include "parse-util.h"
+#include "proc-cmdline.h"
 #include "string-util.h"
 #include "volatile-util.h"
 
@@ -39,3 +41,28 @@ VolatileMode volatile_mode_from_string(const char *s) {
 
         return _VOLATILE_MODE_INVALID;
 }
+
+int query_volatile_mode(VolatileMode *ret) {
+        _cleanup_free_ char *mode = NULL;
+        VolatileMode m = VOLATILE_NO;
+        int r;
+
+        r = proc_cmdline_get_key("systemd.volatile", PROC_CMDLINE_VALUE_OPTIONAL, &mode);
+        if (r < 0)
+                return r;
+        if (r == 0)
+                goto finish;
+
+        if (mode) {
+                m = volatile_mode_from_string(mode);
+                if (m < 0)
+                        return -EINVAL;
+        } else
+                m = VOLATILE_YES;
+
+        r = 1;
+
+finish:
+        *ret = m;
+        return r;
+}