chiark / gitweb /
tree-wide: drop 'This file is part of systemd' blurb
[elogind.git] / src / basic / proc-cmdline.c
index d0146cae6053784bcb098a8a38cedfd9e9112ba0..31ffbc1ef9847efcefe006231b22e9925b56ee3e 100644 (file)
@@ -1,20 +1,6 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
-  This file is part of systemd.
-
   Copyright 2010 Lennart Poettering
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
 #include <stdbool.h>
@@ -110,6 +96,7 @@ static bool relaxed_equal_char(char a, char b) {
                 (a == '-' && b == '_');
 }
 
+#if 0 /// UNNEEDED by elogind
 char *proc_cmdline_key_startswith(const char *s, const char *prefix) {
 
         assert(s);
@@ -123,6 +110,7 @@ char *proc_cmdline_key_startswith(const char *s, const char *prefix) {
 
         return (char*) s;
 }
+#endif // 0
 
 bool proc_cmdline_key_streq(const char *x, const char *y) {
         assert(x);
@@ -137,6 +125,7 @@ bool proc_cmdline_key_streq(const char *x, const char *y) {
         return true;
 }
 
+#if 0 /// UNNEEDED by elogind
 int proc_cmdline_get_key(const char *key, unsigned flags, char **value) {
         _cleanup_free_ char *line = NULL, *ret = NULL;
         bool found = false;
@@ -148,13 +137,13 @@ int proc_cmdline_get_key(const char *key, unsigned flags, char **value) {
          * a) The "value" parameter is used. In this case a parameter beginning with the "key" string followed by "="
          *    is searched, and the value following this is returned in "value".
          *
-         * b) as above, but the PROC_CMDLINE_VALUE_OPTIONAL flag is set. In this case if the the key is found as a
+         * b) as above, but the PROC_CMDLINE_VALUE_OPTIONAL flag is set. In this case if the key is found as a
          *    separate word (i.e. not followed by "=" but instead by whitespace or the end of the command line), then
          *    this is also accepted, and "value" is returned as NULL.
          *
          * c) The "value" parameter is NULL. In this case a search for the exact "key" parameter is performed.
          *
-         * In all three cases, > 0 is returned if the key is found, 0 if not.*/
+         * In all three cases, > 0 is returned if the key is found, 0 if not. */
 
         if (isempty(key))
                 return -EINVAL;
@@ -203,10 +192,8 @@ int proc_cmdline_get_key(const char *key, unsigned flags, char **value) {
                 }
         }
 
-        if (value) {
-                *value = ret;
-                ret = NULL;
-        }
+        if (value)
+                *value = TAKE_PTR(ret);
 
         return found;
 }
@@ -236,7 +223,6 @@ int proc_cmdline_get_bool(const char *key, bool *ret) {
         return 1;
 }
 
-#if 0 /// UNNEEDED by elogind
 int shall_restore_state(void) {
         bool ret;
         int r;
@@ -271,17 +257,21 @@ static const char * const rlmap_initrd[] = {
 };
 
 const char* runlevel_to_target(const char *word) {
+        const char * const *rlmap_ptr;
         size_t i;
-        const char * const *rlmap_ptr = in_initrd() ? rlmap_initrd
-                                                    : rlmap;
 
         if (!word)
                 return NULL;
 
-        if (in_initrd() && (word = startswith(word, "rd.")) == NULL)
-                return NULL;
+        if (in_initrd()) {
+                word = startswith(word, "rd.");
+                if (!word)
+                        return NULL;
+        }
+
+        rlmap_ptr = in_initrd() ? rlmap_initrd : rlmap;
 
-        for (i = 0; rlmap_ptr[i] != NULL; i += 2)
+        for (i = 0; rlmap_ptr[i]; i += 2)
                 if (streq(word, rlmap_ptr[i]))
                         return rlmap_ptr[i+1];