Hi,

on openSUSE, we found the need to sometime force "--ignore-dependencies"
when systemctl is called (usually from other services / initscripts /
tools started by initscripts and which can cause deadlock).

To handle this in a transparent manner, I'd like to introduce
SYSTEMCTL_OPTIONS environment variable, which, if set, would cause
systemctl to append its contents as if it was specified on command line.


-- 
Frederic Crozat <fcro...@suse.com>
SUSE
>From aeaf77d093f03133a675fee709b6ac8666d472ae Mon Sep 17 00:00:00 2001
From: Frederic Crozat <fcro...@suse.com>
Date: Wed, 16 Jan 2013 17:21:13 +0100
Subject: [PATCH] systemctl: handle SYSTEMCTL_OPTIONS environment variable

SYSTEMCTL_OPTIONS environement variable allows to specify some options
for use by systemctl.
---
 man/systemctl.xml         |    7 +++++++
 src/systemctl/systemctl.c |   25 +++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/man/systemctl.xml b/man/systemctl.xml
index 2f33e0c..c623534 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -1293,7 +1293,14 @@
                                 <literal>cat</literal> is equivalent to passing
                                 <option>--no-pager</option>.</para></listitem>
                         </varlistentry>
+                        <varlistentry>
+                                <term><varname>$SYSTEMCTL_OPTIONS</varname></term>
+				<listitem><para>Options specified here will be used
+				by systemctl, as if they had been added on command line.</para></listitem>
+                        </varlistentry>
                 </variablelist>
+
+
         </refsect1>
 
         <refsect1>
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 7cf51dc..257fb39 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -43,6 +43,7 @@
 #include "log.h"
 #include "util.h"
 #include "macro.h"
+#include "missing.h"
 #include "set.h"
 #include "utmp-wtmp.h"
 #include "special.h"
@@ -5398,6 +5399,7 @@ static int runlevel_main(void) {
 
 int main(int argc, char*argv[]) {
         int r, retval = EXIT_FAILURE;
+        char **to_free = NULL;
         DBusConnection *bus = NULL;
         DBusError error;
 
@@ -5407,6 +5409,27 @@ int main(int argc, char*argv[]) {
         log_parse_environment();
         log_open();
 
+        if (secure_getenv("SYSTEMCTL_OPTIONS")) {
+                char **parsed_systemctl_options = strv_split_quoted(getenv("SYSTEMCTL_OPTIONS"));
+
+                if (*parsed_systemctl_options && **parsed_systemctl_options) {
+                        char **k,**a;
+                        char **new_argv = new(char*, strv_length(argv) + strv_length(parsed_systemctl_options) + 1);
+                        new_argv[0] = strdup(argv[0]);
+                        for (k = new_argv+1, a = parsed_systemctl_options; *a; k++, a++) {
+                                *k = strdup(*a);
+                        }
+                        for (a = argv+1; *a; k++, a++) {
+                                *k = strdup(*a);
+                        }
+                        *k = NULL;
+                        argv = new_argv;
+                        argc = strv_length(new_argv);
+                        strv_free (parsed_systemctl_options);
+                        to_free = new_argv;
+                }
+        }
+
         r = parse_argv(argc, argv);
         if (r < 0)
                 goto finish;
@@ -5508,6 +5531,8 @@ finish:
 
         strv_free(arg_property);
 
+        strv_free(to_free);
+
         pager_close();
         ask_password_agent_close();
         polkit_agent_close();
-- 
1.7.10.4

_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to