Commit c4c250e3 authored by Michael Biebl's avatar Michael Biebl
Browse files

Import patches

parent cdd39f04
From: Michael Biebl <biebl@debian.org>
Date: Thu, 18 Jul 2013 20:11:02 +0200
Subject: Add back support for Debian specific config files
For now fallback to read the locale settings from /etc/default/locale.
This reverts the Debian specific bits from
46a2911bf2780f616396df5671dd901cc7cb54fd
99f861310d3f05f4e86cb9582a94b891dbb3382b
---
src/core/locale-setup.c | 21 +++++++++++++++++++++
src/timedate/timedated.c | 18 ++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/src/core/locale-setup.c b/src/core/locale-setup.c
index d7113b9..ac922f1 100644
--- a/src/core/locale-setup.c
+++ b/src/core/locale-setup.c
@@ -117,6 +117,27 @@ int locale_setup(void) {
log_warning("Failed to read /etc/locale.conf: %s", strerror(-r));
}
+ if (r <= 0 &&
+ (r = parse_env_file("/etc/default/locale", NEWLINE,
+ "LANG", &variables[VARIABLE_LANG],
+ "LC_CTYPE", &variables[VARIABLE_LC_CTYPE],
+ "LC_NUMERIC", &variables[VARIABLE_LC_NUMERIC],
+ "LC_TIME", &variables[VARIABLE_LC_TIME],
+ "LC_COLLATE", &variables[VARIABLE_LC_COLLATE],
+ "LC_MONETARY", &variables[VARIABLE_LC_MONETARY],
+ "LC_MESSAGES", &variables[VARIABLE_LC_MESSAGES],
+ "LC_PAPER", &variables[VARIABLE_LC_PAPER],
+ "LC_NAME", &variables[VARIABLE_LC_NAME],
+ "LC_ADDRESS", &variables[VARIABLE_LC_ADDRESS],
+ "LC_TELEPHONE", &variables[VARIABLE_LC_TELEPHONE],
+ "LC_MEASUREMENT", &variables[VARIABLE_LC_MEASUREMENT],
+ "LC_IDENTIFICATION", &variables[VARIABLE_LC_IDENTIFICATION],
+ NULL)) < 0) {
+
+ if (r != -ENOENT)
+ log_warning("Failed to read /etc/default/locale: %s", strerror(-r));
+ }
+
if (!variables[VARIABLE_LANG]) {
variables[VARIABLE_LANG] = strdup("C");
if (!variables[VARIABLE_LANG]) {
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index cdb6e5b..c183438 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -183,6 +183,12 @@ static int read_data(void) {
}
}
+ r = read_one_line_file("/etc/timezone", &tz.zone);
+ if (r < 0) {
+ if (r != -ENOENT)
+ log_warning("Failed to read /etc/timezone: %s", strerror(-r));
+ }
+
have_timezone:
if (isempty(tz.zone)) {
free(tz.zone);
@@ -198,10 +204,15 @@ static int write_data_timezone(void) {
int r = 0;
_cleanup_free_ char *p = NULL;
+ struct stat st;
+
if (!tz.zone) {
if (unlink("/etc/localtime") < 0 && errno != ENOENT)
r = -errno;
+ if (unlink("/etc/timezone") < 0 && errno != ENOENT)
+ r = -errno;
+
return r;
}
@@ -213,6 +224,13 @@ static int write_data_timezone(void) {
if (r < 0)
return r;
+ if (stat("/etc/timezone", &st) == 0 && S_ISREG(st.st_mode)) {
+ r = write_string_file_atomic("/etc/timezone", tz.zone);
+ if (r < 0)
+ return r;
+ }
+
+
return 0;
}
From: Michael Stapelberg <michael@stapelberg.de>
Date: Mon, 29 Jul 2013 22:01:21 +0200
Subject: Make systemctl enable/disable call update-rc.d for sysv init scripts
(#709780)
---
src/systemctl/systemctl.c | 21 ++++++---------------
1 file changed, 6 insertions(+), 15 deletions(-)
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 3cca861..a008517 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4008,7 +4008,6 @@ static int set_environment(DBusConnection *bus, char **args) {
static int enable_sysv_units(char **args) {
int r = 0;
-#if defined(HAVE_SYSV_COMPAT) && defined(HAVE_CHKCONFIG)
const char *verb = args[0];
unsigned f = 1, t = 1;
LookupPaths paths = {};
@@ -4017,8 +4016,9 @@ static int enable_sysv_units(char **args) {
return 0;
if (!streq(verb, "enable") &&
- !streq(verb, "disable") &&
- !streq(verb, "is-enabled"))
+ !streq(verb, "disable"))
+ // update-rc.d currently does not provide is-enabled
+ //!streq(verb, "is-enabled"))
return 0;
/* Processes all SysV units, and reshuffles the array so that
@@ -4034,7 +4034,7 @@ static int enable_sysv_units(char **args) {
_cleanup_free_ char *p = NULL, *q = NULL;
bool found_native = false, found_sysv;
unsigned c = 1;
- const char *argv[6] = { "/sbin/chkconfig", NULL, NULL, NULL, NULL };
+ const char *argv[6] = { "/usr/sbin/update-rc.d", NULL, NULL, NULL, NULL };
char **k, *l;
int j;
pid_t pid;
@@ -4067,9 +4067,6 @@ static int enable_sysv_units(char **args) {
break;
}
- if (found_native)
- continue;
-
if (!isempty(arg_root))
asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name);
else
@@ -4088,15 +4085,10 @@ static int enable_sysv_units(char **args) {
/* Mark this entry, so that we don't try enabling it as native unit */
args[f] = (char*) "";
- log_info("%s is not a native service, redirecting to /sbin/chkconfig.", name);
-
- if (!isempty(arg_root))
- argv[c++] = q = strappend("--root=", arg_root);
+ log_info("%s is not a native service, redirecting to /usr/sbin/update-rc.d.", name);
argv[c++] = path_get_file_name(p);
- argv[c++] =
- streq(verb, "enable") ? "on" :
- streq(verb, "disable") ? "off" : "--level=5";
+ argv[c++] = streq(verb, "enable") ? "defaults" : "remove";
argv[c] = NULL;
l = strv_join((char**)argv, " ");
@@ -4162,7 +4154,6 @@ finish:
args[t] = NULL;
-#endif
return r;
}
From: Michael Stapelberg <michael@stapelberg.de>
Date: Thu, 8 Aug 2013 21:34:12 +0200
Subject: change the log_info() line in systemctl to reflect reality
---
src/systemctl/systemctl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index a008517..d70657c 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4085,7 +4085,7 @@ static int enable_sysv_units(char **args) {
/* Mark this entry, so that we don't try enabling it as native unit */
args[f] = (char*) "";
- log_info("%s is not a native service, redirecting to /usr/sbin/update-rc.d.", name);
+ log_info("Synchronizing state for %s with sysvinit using update-rc.d...", name);
argv[c++] = path_get_file_name(p);
argv[c++] = streq(verb, "enable") ? "defaults" : "remove";
From: Michael Stapelberg <michael@stapelberg.de>
Date: Fri, 9 Aug 2013 20:23:31 +0200
Subject: Also redirect to update-rc.d when not using .service
I.e. make systemctl enable rsyslog work (previously, only systemctl
enable rsyslog.service)
---
src/systemctl/systemctl.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index d70657c..aaad4fa 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4042,9 +4042,6 @@ static int enable_sysv_units(char **args) {
name = args[f];
- if (!endswith(name, ".service"))
- continue;
-
if (path_is_absolute(name))
continue;
@@ -4076,7 +4073,8 @@ static int enable_sysv_units(char **args) {
goto finish;
}
- p[strlen(p) - sizeof(".service") + 1] = 0;
+ if (endswith(name, ".service"))
+ p[strlen(p) - sizeof(".service") + 1] = 0;
found_sysv = access(p, F_OK) >= 0;
if (!found_sysv)
From: Michael Stapelberg <michael@stapelberg.de>
Date: Sat, 10 Aug 2013 11:06:06 +0200
Subject: =?utf-8?q?systemctl=3A_don=E2=80=99t_skip_native_units_when_enabl?=
=?utf-8?q?ing/disabling_sysv_units?=
---
src/systemctl/systemctl.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index aaad4fa..53d0612 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4080,8 +4080,10 @@ static int enable_sysv_units(char **args) {
if (!found_sysv)
continue;
- /* Mark this entry, so that we don't try enabling it as native unit */
- args[f] = (char*) "";
+ if (!found_native) {
+ /* Mark this entry, so that we don't try enabling it as native unit */
+ args[f] = (char*) "";
+ }
log_info("Synchronizing state for %s with sysvinit using update-rc.d...", name);
From: Michael Stapelberg <michael@stapelberg.de>
Date: Sat, 10 Aug 2013 11:12:52 +0200
Subject: systemctl: call update-rc.d enable|disable, not defaults|remove
---
src/systemctl/systemctl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 53d0612..ac0984d 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4088,7 +4088,7 @@ static int enable_sysv_units(char **args) {
log_info("Synchronizing state for %s with sysvinit using update-rc.d...", name);
argv[c++] = path_get_file_name(p);
- argv[c++] = streq(verb, "enable") ? "defaults" : "remove";
+ argv[c++] = verb;
argv[c] = NULL;
l = strv_join((char**)argv, " ");
From: Michael Stapelberg <stapelberg@debian.org>
Date: Sun, 27 Oct 2013 20:25:10 +0100
Subject: Run update-rc.d defaults before update-rc.d <enable|disable>
Closes: #722523
---
src/systemctl/systemctl.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index ac0984d..0c39c94 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4087,8 +4087,53 @@ static int enable_sysv_units(char **args) {
log_info("Synchronizing state for %s with sysvinit using update-rc.d...", name);
+ /* Run update-rc.d <file> defaults first to ensure the K- and
+ * S-symlinks are present. If they are missing, update-rc.d
+ * <enable|disable> will fail. See
+ * http://bugs.debian.org/722523 */
argv[c++] = path_get_file_name(p);
- argv[c++] = verb;
+ argv[c++] = "defaults";
+ argv[c] = NULL;
+
+ l = strv_join((char**)argv, " ");
+ if (!l) {
+ r = log_oom();
+ goto finish;
+ }
+
+ log_info("Executing %s", l);
+ free(l);
+
+ pid = fork();
+ if (pid < 0) {
+ log_error("Failed to fork: %m");
+ r = -errno;
+ goto finish;
+ } else if (pid == 0) {
+ /* Child */
+
+ execv(argv[0], (char**) argv);
+ _exit(EXIT_FAILURE);
+ }
+
+ j = wait_for_terminate(pid, &status);
+ if (j < 0) {
+ log_error("Failed to wait for child: %s", strerror(-r));
+ r = j;
+ goto finish;
+ }
+
+ if (status.si_code == CLD_EXITED) {
+ if (status.si_status != 0) {
+ r = -EINVAL;
+ goto finish;
+ }
+ } else {
+ r = -EPROTO;
+ goto finish;
+ }
+
+ argv[c-1] = verb;
argv[c] = NULL;
l = strv_join((char**)argv, " ");
From: =?utf-8?q?V=C3=A1clav_Pavl=C3=ADn?= <vpavlin@redhat.com>
Date: Fri, 17 May 2013 16:03:36 +0200
Subject: systemctl: mangle names when avoiding dbus
Unit names were mangled in function enable_unit only when dbus was
used. This patch adds mangling also when the dbus is not in use.
This makes it possible to say e.g.:
systemctl --root=/path enable cups
without spelling cups.service out in full.
---
src/systemctl/systemctl.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 0c39c94..81ac83e 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4253,24 +4253,28 @@ static int enable_unit(DBusConnection *bus, char **args) {
if (!args[1])
return 0;
+ r = mangle_names(args+1, &mangled_names);
+ if (r < 0)
+ goto finish;
+
if (!bus || avoid_bus()) {
if (streq(verb, "enable")) {
- r = unit_file_enable(arg_scope, arg_runtime, arg_root, args+1, arg_force, &changes, &n_changes);
+ r = unit_file_enable(arg_scope, arg_runtime, arg_root, mangled_names, arg_force, &changes, &n_changes);
carries_install_info = r;
} else if (streq(verb, "disable"))
- r = unit_file_disable(arg_scope, arg_runtime, arg_root, args+1, &changes, &n_changes);
+ r = unit_file_disable(arg_scope, arg_runtime, arg_root, mangled_names, &changes, &n_changes);
else if (streq(verb, "reenable")) {
- r = unit_file_reenable(arg_scope, arg_runtime, arg_root, args+1, arg_force, &changes, &n_changes);
+ r = unit_file_reenable(arg_scope, arg_runtime, arg_root, mangled_names, arg_force, &changes, &n_changes);
carries_install_info = r;
} else if (streq(verb, "link"))
- r = unit_file_link(arg_scope, arg_runtime, arg_root, args+1, arg_force, &changes, &n_changes);
+ r = unit_file_link(arg_scope, arg_runtime, arg_root, mangled_names, arg_force, &changes, &n_changes);
else if (streq(verb, "preset")) {
- r = unit_file_preset(arg_scope, arg_runtime, arg_root, args+1, arg_force, &changes, &n_changes);
+ r = unit_file_preset(arg_scope, arg_runtime, arg_root, mangled_names, arg_force, &changes, &n_changes);
carries_install_info = r;
} else if (streq(verb, "mask"))
- r = unit_file_mask(arg_scope, arg_runtime, arg_root, args+1, arg_force, &changes, &n_changes);
+ r = unit_file_mask(arg_scope, arg_runtime, arg_root, mangled_names, arg_force, &changes, &n_changes);
else if (streq(verb, "unmask"))
- r = unit_file_unmask(arg_scope, arg_runtime, arg_root, args+1, &changes, &n_changes);
+ r = unit_file_unmask(arg_scope, arg_runtime, arg_root, mangled_names, &changes, &n_changes);
else
assert_not_reached("Unknown verb");
@@ -4329,10 +4333,6 @@ static int enable_unit(DBusConnection *bus, char **args) {
dbus_message_iter_init_append(m, &iter);
- r = mangle_names(args+1, &mangled_names);
- if(r < 0)
- goto finish;
-
r = bus_append_strv_iter(&iter, mangled_names);
if (r < 0) {
log_error("Failed to append unit files.");
From: Michael Stapelberg <stapelberg@debian.org>
Date: Sun, 19 Jan 2014 18:40:56 +0100
Subject: =?utf-8?q?fix_systemctl_enable/disable/=E2=80=A6_error_message_?=
=?utf-8?q?=E2=80=9CFailed_to_issue_method_call=3A?=
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
No such file or directory”
The bug affected only non-native services, i.e. LSB SysV init scripts,
with isc-dhcp-server.service being an example for this commit message.
The bug was introduced with commit
fdcb1bce7b16f69c4d63451816e2c7f824d090b4. The issue is that
enable_unit() would not return even though the SysV init script was
disabled by enable_sysv_units(). enable_unit() then tried to
disable a native systemd unit called isc-dhcp-server.service, even
though there is no such native unit. This is what caused the “no such
file or directory” error message.
Closes: #734809
---
src/systemctl/systemctl.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 81ac83e..3147c4a 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4246,10 +4246,6 @@ static int enable_unit(DBusConnection *bus, char **args) {
dbus_error_init(&error);
- r = enable_sysv_units(args);
- if (r < 0)
- return r;
-
if (!args[1])
return 0;
@@ -4257,6 +4253,13 @@ static int enable_unit(DBusConnection *bus, char **args) {
if (r < 0)
goto finish;
+ r = enable_sysv_units(args);
+ if (r < 0)
+ return r;
+
+ if (!args[1])
+ return 0;
+
if (!bus || avoid_bus()) {
if (streq(verb, "enable")) {
r = unit_file_enable(arg_scope, arg_runtime, arg_root, mangled_names, arg_force, &changes, &n_changes);
From: Michael Stapelberg <stapelberg@debian.org>
Date: Sat, 21 Dec 2013 18:49:10 +0100
Subject: =?utf-8?q?don=E2=80=99t_try_to_start_autovt_units_when_not_runnin?=
=?utf-8?q?g_with_systemd_as_pid_1?=
Closes: #726466
---
src/login/logind.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/login/logind.c b/src/login/logind.c
index 5a39440..f415c6b 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -978,6 +978,11 @@ int manager_spawn_autovt(Manager *m, int vtnr) {
(unsigned) vtnr != m->reserve_vt)
return 0;
+ /* It only makes sense to send a StartUnit call to systemd if this
+ * machine is actually booted with systemd. */
+ if (!sd_booted())
+ return 0;
+
if ((unsigned) vtnr != m->reserve_vt) {
/* If this is the reserved TTY, we'll start the getty
* on it in any case, but otherwise only if it is not
From: Michael Stapelberg <stapelberg@debian.org>
Date: Wed, 27 Nov 2013 22:48:47 +0100
Subject: =?utf-8?q?timedated=3A_don=E2=80=99t_rely_on_/usr_being_mounted_i?=
=?utf-8?q?n_the_initrd?=
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
This reverts commit 92c4ef2d357baeef78b6f82f119b92f7ed12ac77
We don’t have /usr mounted in the initramfs yet in Debian, so let’s
support split usr by copying the file instead of symlinking if
necessary, for now.
Closes: #726256
---
src/timedate/timedated.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 89 insertions(+), 1 deletion(-)
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index c183438..467f567 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -153,6 +153,94 @@ static bool valid_timezone(const char *name) {
return true;
}
+static int symlink_or_copy(const char *from, const char *to) {
+ char *pf = NULL, *pt = NULL;
+ struct stat a, b;
+ int r;
+
+ assert(from);
+ assert(to);
+
+ if (path_get_parent(from, &pf) < 0 ||
+ path_get_parent(to, &pt) < 0) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ if (stat(pf, &a) < 0 ||
+ stat(pt, &b) < 0) {
+ r = -errno;
+ goto finish;
+ }
+
+ if (a.st_dev != b.st_dev) {
+ free(pf);
+ free(pt);
+
+ return copy_file(from, to);
+ }
+
+ if (symlink(from, to) < 0) {
+ r = -errno;
+ goto finish;
+ }
+
+ r = 0;
+
+finish:
+ free(pf);
+ free(pt);
+
+ return r;
+}
+
+static int symlink_or_copy_atomic(const char *from, const char *to) {
+ char *t, *x;
+ const char *fn;
+ size_t k;
+ unsigned long long ull;
+ unsigned i;
+ int r;
+
+ assert(from);
+ assert(to);
+
+ t = new(char, strlen(to) + 1 + 16 + 1);
+ if (!t)
+ return -ENOMEM;
+
+ fn = path_get_file_name(to);
+ k = fn-to;
+ memcpy(t, to, k);
+ t[k] = '.';
+ x = stpcpy(t+k+1, fn);
+
+ ull = random_ull();
+ for (i = 0; i < 16; i++) {
+ *(x++) = hexchar(ull & 0xF);
+ ull >>= 4;
+ }
+
+ *x = 0;
+
+ r = symlink_or_copy(from, t);