[systemd-commits] 3 commits - man/systemctl.xml src/libsystemd src/login src/systemctl src/systemd
Lennart Poettering
lennart at kemper.freedesktop.org
Wed Jan 15 11:16:55 PST 2014
man/systemctl.xml | 13 ++++++
src/libsystemd/sd-event.c | 6 +-
src/login/logind-session.c | 92 ---------------------------------------------
src/systemctl/systemctl.c | 68 ++++++++++++++++++++++++++++++++-
src/systemd/sd-event.h | 4 -
5 files changed, 85 insertions(+), 98 deletions(-)
New commits:
commit 31927c16deb4b0fdc887220df54505fd6993822f
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 15 16:08:20 2014 +0800
event: extend priority raneg to 64bit
The kdbus prioq logic will use 64bit prios too, so let's keep this
similar in style. Using 64bit here has the advantage, that pointers and
pretty much anything else can be mapped naturally to priorities if so
desired.
diff --git a/src/libsystemd/sd-event.c b/src/libsystemd/sd-event.c
index 0b7b71d..f33a9ec 100644
--- a/src/libsystemd/sd-event.c
+++ b/src/libsystemd/sd-event.c
@@ -61,7 +61,7 @@ struct sd_event_source {
bool pending:1;
bool dispatching:1;
- int priority;
+ int64_t priority;
unsigned pending_index;
unsigned prepare_index;
unsigned pending_iteration;
@@ -1145,14 +1145,14 @@ _public_ int sd_event_source_get_signal(sd_event_source *s) {
return s->signal.sig;
}
-_public_ int sd_event_source_get_priority(sd_event_source *s, int *priority) {
+_public_ int sd_event_source_get_priority(sd_event_source *s, int64_t *priority) {
assert_return(s, -EINVAL);
assert_return(!event_pid_changed(s->event), -ECHILD);
return s->priority;
}
-_public_ int sd_event_source_set_priority(sd_event_source *s, int priority) {
+_public_ int sd_event_source_set_priority(sd_event_source *s, int64_t priority) {
assert_return(s, -EINVAL);
assert_return(s->event->state != SD_EVENT_FINISHED, -ESTALE);
assert_return(!event_pid_changed(s->event), -ECHILD);
diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h
index 4c1fbf2..b911485 100644
--- a/src/systemd/sd-event.h
+++ b/src/systemd/sd-event.h
@@ -101,8 +101,8 @@ sd_event_source* sd_event_source_unref(sd_event_source *s);
int sd_event_source_set_prepare(sd_event_source *s, sd_event_handler_t callback);
int sd_event_source_get_pending(sd_event_source *s);
-int sd_event_source_get_priority(sd_event_source *s, int *priority);
-int sd_event_source_set_priority(sd_event_source *s, int priority);
+int sd_event_source_get_priority(sd_event_source *s, int64_t *priority);
+int sd_event_source_set_priority(sd_event_source *s, int64_t priority);
int sd_event_source_get_enabled(sd_event_source *s, int *enabled);
int sd_event_source_set_enabled(sd_event_source *s, int enabled);
void* sd_event_source_get_userdata(sd_event_source *s);
commit ac3efa8ac62b60261d6c101bc98831316523b07a
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 15 15:21:29 2014 +0800
systemctl: introduce new "import-environment" command
This may be used in graphical session start-up scripts to upload
environment variables such as $DISPLAY into the systemd manager easily.
diff --git a/man/systemctl.xml b/man/systemctl.xml
index 13a4444..ed1bf48 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -1190,6 +1190,19 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
specified value.</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><command>import-environment <replaceable>VARIABLE</replaceable>...</command></term>
+
+ <listitem>
+ <para>Import all, one or more environment variables set on
+ the client into the systemd manager environment block. If
+ no arguments are passed the entire environment block is
+ imported. Otherwise a list of one or more environment
+ variable names should be passed, whose client side values
+ are then imported into the manager's environment
+ block.</para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsect2>
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index dd95df1..b9d9b3a 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -68,6 +68,7 @@
#include "logs-show.h"
#include "socket-util.h"
#include "fileio.h"
+#include "env-util.h"
#include "bus-util.h"
#include "bus-message.h"
#include "bus-error.h"
@@ -4467,6 +4468,69 @@ static int set_environment(sd_bus *bus, char **args) {
return 0;
}
+static int import_environment(sd_bus *bus, char **args) {
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
+ int r;
+
+ assert(bus);
+ assert(args);
+
+ r = sd_bus_message_new_method_call(
+ bus,
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager",
+ "SetEnvironment",
+ &m);
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ if (strv_isempty(args + 1))
+ r = sd_bus_message_append_strv(m, environ);
+ else {
+ char **a, **b;
+
+ r = sd_bus_message_open_container(m, 'a', "s");
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ STRV_FOREACH(a, args + 1) {
+
+ if (!env_name_is_valid(*a)) {
+ log_error("Not a valid environment variable name: %s", *a);
+ return -EINVAL;
+ }
+
+ STRV_FOREACH(b, environ) {
+ const char *eq;
+
+ eq = startswith(*b, *a);
+ if (eq && *eq == '=') {
+
+ r = sd_bus_message_append(m, "s", *b);
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ break;
+ }
+ }
+ }
+
+ r = sd_bus_message_close_container(m);
+ }
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ r = sd_bus_call(bus, m, 0, &error, NULL);
+ if (r < 0) {
+ log_error("Failed to import environment: %s", bus_error_message(&error, r));
+ return r;
+ }
+
+ return 0;
+}
+
static int enable_sysv_units(const char *verb, char **args) {
int r = 0;
@@ -4971,7 +5035,8 @@ static int systemctl_help(void) {
"Environment Commands:\n"
" show-environment Dump environment\n"
" set-environment NAME=VALUE... Set one or more environment variables\n"
- " unset-environment NAME... Unset one or more environment variables\n\n"
+ " unset-environment NAME... Unset one or more environment variables\n"
+ " import-environment NAME... Import all, one or more environment variables\n\n"
"Manager Lifecycle Commands:\n"
" daemon-reload Reload systemd manager configuration\n"
" daemon-reexec Reexecute systemd manager\n\n"
@@ -5937,6 +6002,7 @@ static int systemctl_main(sd_bus *bus, int argc, char *argv[], int bus_error) {
{ "show-environment", EQUAL, 1, show_environment },
{ "set-environment", MORE, 2, set_environment },
{ "unset-environment", MORE, 2, set_environment },
+ { "import-environment", MORE, 1, import_environment},
{ "halt", EQUAL, 1, start_special, FORCE },
{ "poweroff", EQUAL, 1, start_special, FORCE },
{ "reboot", EQUAL, 1, start_special, FORCE },
commit 6a38d04a036475bfc222f40961e2adcaa70a6174
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 15 15:19:17 2014 +0800
logind: get rid of X11 display socket symlink
X11 never made use of it anyway and it's probably better to just push
$DISPLAY into the systemd daemon from gnome-session (or equivalent
program) than to change libX11 to look for this socket. In particular
since we won't need this for Wayland anyway and we shouldn't add
infrastructure for stuff that's on its way out anyway.
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index dc4b3e1..4476f58 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -444,72 +444,6 @@ int session_activate(Session *s) {
return 0;
}
-static int session_link_x11_socket(Session *s) {
- _cleanup_free_ char *t = NULL, *f = NULL;
- char *c;
- size_t k;
-
- assert(s);
- assert(s->user);
- assert(s->user->runtime_path);
-
- if (s->user->display)
- return 0;
-
- if (!s->display || !display_is_local(s->display))
- return 0;
-
- k = strspn(s->display+1, "0123456789");
- f = new(char, sizeof("/tmp/.X11-unix/X") + k);
- if (!f)
- return log_oom();
-
- c = stpcpy(f, "/tmp/.X11-unix/X");
- memcpy(c, s->display+1, k);
- c[k] = 0;
-
- if (access(f, F_OK) < 0) {
- log_warning("Session %s has display %s with non-existing socket %s.", s->id, s->display, f);
- return -ENOENT;
- }
-
- /* Note that this cannot be in a subdir to avoid
- * vulnerabilities since we are privileged but the runtime
- * path is owned by the user */
-
- t = strappend(s->user->runtime_path, "/X11-display");
- if (!t)
- return log_oom();
-
- if (link(f, t) < 0) {
- if (errno == EEXIST) {
- unlink(t);
-
- if (link(f, t) >= 0)
- goto done;
- }
-
- if (symlink(f, t) < 0) {
-
- if (errno == EEXIST) {
- unlink(t);
-
- if (symlink(f, t) >= 0)
- goto done;
- }
-
- log_error("Failed to link %s to %s: %m", f, t);
- return -errno;
- }
- }
-
-done:
- log_info("Linked %s to %s.", f, t);
- s->user->display = s;
-
- return 0;
-}
-
static int session_start_scope(Session *s) {
int r;
@@ -581,9 +515,6 @@ int session_start(Session *s) {
"MESSAGE=New session %s of user %s.", s->id, s->user->name,
NULL);
- /* Create X11 symlink */
- session_link_x11_socket(s);
-
if (!dual_timestamp_is_set(&s->timestamp))
dual_timestamp_get(&s->timestamp);
@@ -634,26 +565,6 @@ static int session_stop_scope(Session *s) {
return 0;
}
-static int session_unlink_x11_socket(Session *s) {
- _cleanup_free_ char *t = NULL;
- int r;
-
- assert(s);
- assert(s->user);
-
- if (s->user->display != s)
- return 0;
-
- s->user->display = NULL;
-
- t = strappend(s->user->runtime_path, "/X11-display");
- if (!t)
- return log_oom();
-
- r = unlink(t);
- return r < 0 ? -errno : 0;
-}
-
int session_stop(Session *s) {
int r;
@@ -693,9 +604,6 @@ int session_finalize(Session *s) {
while ((sd = hashmap_first(s->devices)))
session_device_free(sd);
- /* Remove X11 symlink */
- session_unlink_x11_socket(s);
-
unlink(s->state_file);
session_add_to_gc_queue(s);
user_add_to_gc_queue(s->user);
More information about the systemd-commits
mailing list