[systemd-commits] 2 commits - Makefile.am man/systemd.exec.xml src/core
Zbigniew JÄdrzejewski-Szmek
zbyszek at kemper.freedesktop.org
Tue Sep 17 08:27:05 PDT 2013
Makefile.am | 4 -
man/systemd.exec.xml | 138 ++++++++++++++++++++++++++++++++++++++++++---------
src/core/async.c | 72 ++++++++++++++++++++++++++
src/core/async.h | 25 +++++++++
src/core/execute.c | 41 +++++++++------
src/core/job.c | 2
src/core/manager.c | 5 -
src/core/sync.c | 65 ------------------------
src/core/sync.h | 24 --------
9 files changed, 242 insertions(+), 134 deletions(-)
New commits:
commit f485606bf8957d2954cf6fa5b0aabd5c39db15c1
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Mon Sep 16 15:50:38 2013 -0500
Make tmpdir removal asynchronous
https://bugs.freedesktop.org/show_bug.cgi?id=68232
diff --git a/Makefile.am b/Makefile.am
index 4db064e..b69d66d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -967,8 +967,8 @@ libsystemd_core_la_SOURCES = \
src/core/syscall-list.h \
src/core/audit-fd.c \
src/core/audit-fd.h \
- src/core/sync.c \
- src/core/sync.h
+ src/core/async.c \
+ src/core/async.h
if HAVE_KMOD
libsystemd_core_la_SOURCES += \
diff --git a/src/core/async.c b/src/core/async.c
new file mode 100644
index 0000000..af527be
--- /dev/null
+++ b/src/core/async.c
@@ -0,0 +1,72 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2013 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 <pthread.h>
+#include <unistd.h>
+
+#include "async.h"
+#include "log.h"
+
+int asynchronous_job(void* (*func)(void *p), void *arg) {
+ pthread_attr_t a;
+ pthread_t t;
+ int r;
+
+ /* It kinda sucks that we have to resort to threads to
+ * implement an asynchronous sync(), but well, such is
+ * life.
+ *
+ * Note that issuing this command right before exiting a
+ * process will cause the process to wait for the sync() to
+ * complete. This function hence is nicely asynchronous really
+ * only in long running processes. */
+
+ r = pthread_attr_init(&a);
+ if (r != 0)
+ return -r;
+
+ r = pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
+ if (r != 0) {
+ r = -r;
+ goto finish;
+ }
+
+ r = pthread_create(&t, &a, func, arg);
+ if (r != 0) {
+ r = -r;
+ goto finish;
+ }
+
+finish:
+ pthread_attr_destroy(&a);
+ return r;
+}
+
+static void *sync_thread(void *p) {
+ sync();
+ return NULL;
+}
+
+int asynchronous_sync(void) {
+ log_debug("Spawning new thread for sync");
+
+ return asynchronous_job(sync_thread, NULL);
+}
diff --git a/src/core/async.h b/src/core/async.h
new file mode 100644
index 0000000..6601b4d
--- /dev/null
+++ b/src/core/async.h
@@ -0,0 +1,25 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+ This file is part of systemd.
+
+ Copyright 2013 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/>.
+***/
+
+int asynchronous_job(void* (*func)(void *p), void *arg);
+int asynchronous_sync(void);
diff --git a/src/core/execute.c b/src/core/execute.c
index 43b571e..f840642 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -67,6 +67,7 @@
#include "env-util.h"
#include "fileio.h"
#include "unit.h"
+#include "async.h"
#define IDLE_TIMEOUT_USEC (5*USEC_PER_SEC)
#define IDLE_TIMEOUT2_USEC (1*USEC_PER_SEC)
@@ -1581,6 +1582,28 @@ void exec_context_init(ExecContext *c) {
c->timer_slack_nsec = (nsec_t) -1;
}
+static void *remove_tmpdir_thread(void *p) {
+ int r;
+ _cleanup_free_ char *dirp = p;
+ char *dir;
+
+ assert(dirp);
+
+ r = rm_rf_dangerous(dirp, false, true, false);
+ dir = dirname(dirp);
+ if (r < 0)
+ log_warning("Failed to remove content of temporary directory %s: %s",
+ dir, strerror(-r));
+ else {
+ r = rmdir(dir);
+ if (r < 0)
+ log_warning("Failed to remove temporary directory %s: %s",
+ dir, strerror(-r));
+ }
+
+ return NULL;
+}
+
void exec_context_tmp_dirs_done(ExecContext *c) {
char* dirs[] = {c->tmp_dir ? c->tmp_dir : c->var_tmp_dir,
c->tmp_dir ? c->var_tmp_dir : NULL,
@@ -1588,22 +1611,8 @@ void exec_context_tmp_dirs_done(ExecContext *c) {
char **dirp;
for(dirp = dirs; *dirp; dirp++) {
- char *dir;
- int r;
-
- r = rm_rf_dangerous(*dirp, false, true, false);
- dir = dirname(*dirp);
- if (r < 0)
- log_warning("Failed to remove content of temporary directory %s: %s",
- dir, strerror(-r));
- else {
- r = rmdir(dir);
- if (r < 0)
- log_warning("Failed to remove temporary directory %s: %s",
- dir, strerror(-r));
- }
-
- free(*dirp);
+ log_debug("Spawning thread to nuke %s", *dirp);
+ asynchronous_job(remove_tmpdir_thread, *dirp);
}
c->tmp_dir = c->var_tmp_dir = NULL;
diff --git a/src/core/job.c b/src/core/job.c
index 85f77e8..bf1d956 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -35,7 +35,7 @@
#include "log.h"
#include "dbus-job.h"
#include "special.h"
-#include "sync.h"
+#include "async.h"
#include "virt.h"
JobBusClient* job_bus_client_new(DBusConnection *connection, const char *name) {
diff --git a/src/core/sync.c b/src/core/sync.c
deleted file mode 100644
index 7e74b63..0000000
--- a/src/core/sync.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 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 <pthread.h>
-#include <unistd.h>
-
-#include "sync.h"
-
-static void *sync_thread(void *p) {
- sync();
- return NULL;
-}
-
-int asynchronous_sync(void) {
- pthread_attr_t a;
- pthread_t t;
- int r;
-
- /* It kinda sucks that we have to resort to threads to
- * implement an asynchronous sync(), but well, such is
- * life.
- *
- * Note that issuing this command right before exiting a
- * process will cause the process to wait for the sync() to
- * complete. This function hence is nicely asynchronous really
- * only in long running processes. */
-
- r = pthread_attr_init(&a);
- if (r != 0)
- return -r;
-
- r = pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
- if (r != 0) {
- r = -r;
- goto finish;
- }
-
- r = pthread_create(&t, &a, sync_thread, NULL);
- if (r != 0) {
- r = -r;
- goto finish;
- }
-
-finish:
- pthread_attr_destroy(&a);
- return r;
-}
diff --git a/src/core/sync.h b/src/core/sync.h
deleted file mode 100644
index eb26c88..0000000
--- a/src/core/sync.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-#pragma once
-
-/***
- This file is part of systemd.
-
- Copyright 2013 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/>.
-***/
-
-int asynchronous_sync(void);
commit 43638332c4236ac2db44b0524ea5ade4f918e602
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Sun Sep 15 11:56:19 2013 -0400
man: add a list of environment variables
diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml
index 5721dc1..ba4e808 100644
--- a/man/systemd.exec.xml
+++ b/man/systemd.exec.xml
@@ -57,7 +57,7 @@
<title>Description</title>
<para>Unit configuration files for services, sockets,
- mount points and swap devices share a subset of
+ mount points, and swap devices share a subset of
configuration options which define the execution
environment of spawned processes.</para>
@@ -76,27 +76,6 @@
configuration options are configured in the [Service],
[Socket], [Mount], or [Swap] sections, depending on the unit
type.</para>
-
- <para>Processes started by the system systemd instance
- are executed in a clean environment in which only the
- <varname>$PATH</varname> and <varname>$LANG</varname>
- variables are set by default. In order to add
- additional variables, see the
- <varname>Environment=</varname> and
- <varname>EnvironmentFile=</varname> options below. To
- specify variables globally, see
- <varname>DefaultEnvironment=</varname> in
- <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
- or the kernel option
- <varname>systemd.setenv=</varname> in
- <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>. Processes
- started by the user systemd instances inherit all
- environment variables from the user systemd instance,
- and have <varname>$HOME</varname>,
- <varname>$USER</varname>,
- <varname>$XDG_RUNTIME_DIR</varname> defined, among
- others. In addition, <varname>$MANAGERPID</varname>
- contains the PID of the user systemd instance.</para>
</refsect1>
<refsect1>
@@ -1006,6 +985,118 @@
</refsect1>
<refsect1>
+ <title>Environment variables in spawned processes</title>
+
+ <para>Processes started by the system are executed in
+ a clean environment in which select variables
+ listed below are set. System processes started by systemd
+ do not inherit variables from PID 1, but processes
+ started by user systemd instances inherit all
+ environment variables from the user systemd instance.
+ </para>
+
+ <variablelist class='environment-variables'>
+ <varlistentry>
+ <term><varname>$PATH</varname></term>
+
+ <listitem><para>Colon-separated list
+ of directiories to use when launching
+ executables. Systemd uses a fixed
+ value of
+ <filename>/usr/local/sbin</filename>:<filename>/usr/local/bin</filename>:<filename>/usr/sbin</filename>:<filename>/usr/bin</filename>:<filename>/sbin</filename>:<filename>/bin</filename>.
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><varname>$LANG</varname></term>
+
+ <listitem><para>Locale. Can be set in
+ <citerefentry><refentrytitle>locale.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+ or on the kernel command line (see
+ <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+ and
+ <citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry>).
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><varname>$USER</varname></term>
+ <term><varname>$HOME</varname></term>
+
+ <listitem><para>User name and home
+ directory. Set for the units which
+ have <varname>User=</varname> set,
+ which includes user
+ <command>systemd</command> instances.
+ See
+ <citerefentry><refentrytitle>passwd</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><varname>$XDG_RUNTIME_DIR</varname></term>
+
+ <listitem><para>The directory for volatile
+ state. Set for the user <command>systemd</command>
+ instance, and also in user sessions.
+ See
+ <citerefentry><refentrytitle>pam_systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><varname>$XDG_SESSION_ID</varname></term>
+ <term><varname>$XDG_SEAT</varname></term>
+ <term><varname>$XDG_VTNR</varname></term>
+
+ <listitem><para>The identifier of the
+ session, and the seat name, and
+ virtual terminal of the session. Set
+ by
+ <citerefentry><refentrytitle>pam_systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>
+ for login sessions.
+ <varname>$XDG_SEAT</varname> and
+ <varname>$XDG_VTNR</varname> will be
+ only set when attached to a seat and a
+ tty.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><varname>$MANAGERPID</varname></term>
+
+ <listitem><para>The PID of the user
+ <command>systemd</command> instance,
+ set for processes spawned by it.
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><varname>$LISTEN_FDS</varname></term>
+ <term><varname>$LISTEN_PID</varname></term>
+
+ <listitem><para>Information about file
+ descriptors passed to a service for
+ socket activation. See
+ <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
+ </para></listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>Additional variables may be configured by the
+ following means: for processes spawned in specific
+ units, use the <varname>Environment=</varname> and
+ <varname>EnvironmentFile=</varname> options above; to
+ specify variables globally, use
+ <varname>DefaultEnvironment=</varname> (see
+ <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>)
+ or the kernel option
+ <varname>systemd.setenv=</varname> (see
+ <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>). Additional
+ variables may also be set through PAM,
+ c.f. <citerefentry><refentrytitle>pam_env</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
+ </refsect1>
+
+ <refsect1>
<title>See Also</title>
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
@@ -1018,7 +1109,8 @@
<citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>systemd.cgroup</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
- <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>
+ <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>exec</refentrytitle><manvolnum>3</manvolnum></citerefentry>
</para>
</refsect1>
diff --git a/src/core/manager.c b/src/core/manager.c
index 669af15..079db41 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -456,8 +456,6 @@ static int manager_setup_signals(Manager *m) {
}
static int manager_default_environment(Manager *m) {
- const char *path = "PATH=" DEFAULT_PATH;
-
assert(m);
if (m->running_as == SYSTEMD_SYSTEM) {
@@ -468,7 +466,8 @@ static int manager_default_environment(Manager *m) {
* The initial passed environ is untouched to keep
* /proc/self/environ valid; it is used for tagging
* the init process inside containers. */
- m->environment = strv_new(path, NULL);
+ m->environment = strv_new("PATH=" DEFAULT_PATH,
+ NULL);
/* Import locale variables LC_*= from configuration */
locale_setup(&m->environment);
More information about the systemd-commits
mailing list