units/session/default.target
sessionunit_DATA = \
- units/session/remote-fs.target
+ units/session/remote-fs.target \
+ units/session/exit.service
EXTRA_DIST = \
units/basic.target.m4 \
units/systemd-initctl.service.in \
units/systemd-logger.service.in \
units/syslog.target.in \
+ units/session/exit.service.in \
LICENSE \
README \
DISTRO_PORTING
$(SED) -e 's,@libexecdir\@,$(libexecdir),g' \
-e 's,@pkglibexecdir\@,$(pkglibexecdir),g' \
-e 's,@SPECIAL_SYSLOG_SERVICE\@,$(SPECIAL_SYSLOG_SERVICE),g' \
+ -e 's,@SPECIAL_DBUS_SERVICE\@,$(SPECIAL_DBUS_SERVICE),g' \
+ -e 's,@SYSTEMCTL\@,$(bindir)/systemctl,g' \
< $< > $@
units/%: units/%.in Makefile
units/multi-user.target \
units/remote-fs.target \
units/session/remote-fs.target \
+ units/session/exit.service \
man/systemd.special.7 \
man/systemd.special.html
* tcpwrap
-* introduce exit.target for session instances
-
Regularly:
* look for close() vs. close_nointr() vs. close_nointr_nofail()
<filename>default.target</filename>,
<filename>display-manager.service</filename>,
<filename>emergency.service</filename>,
+ <filename>exit.service</filename>,
<filename>graphical.target</filename>,
<filename>halt.target</filename>,
<filename>kbrequest.target</filename>,
<filename>shutdown.target</filename>,
<filename>sockets.target</filename>,
<filename>swap.target</filename>.</para>
+
+ <para>In addition the following special unit is
+ understood only when systemd runs as service instance:</para>
+
+ <variablelist>
+ <varlistentry>
+ <term><filename>exit.service</filename></term>
+ <listitem>
+ <para>A special service unit
+ for shutting down the
+ session.</para>
+
+ <para>Applications wanting to
+ terminate the session should
+ start this unit. If systemd
+ receives SIGTERM or SIGINT
+ when running as session daemon
+ it will start this
+ unit.</para>
+
+ <para>Normally, this pulls in
+ <filename>shutdown.target</filename>
+ which in turn should be
+ conflicted by all units that
+ want to be shut down on
+ session exit.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
</refsect1>
<refsect1>
return 0;
}
-static void manager_start_target(Manager *m, const char *name) {
+static int manager_start_target(Manager *m, const char *name) {
int r;
if ((r = manager_add_job_by_name(m, JOB_START, name, JOB_REPLACE, true, NULL)) < 0)
log_error("Failed to enqueue %s job: %s", name, strerror(-r));
+
+ return r;
}
static int manager_process_signal_fd(Manager *m) {
break;
case SIGTERM:
- if (m->running_as == MANAGER_INIT)
+ if (m->running_as == MANAGER_INIT) {
/* This is for compatibility with the
* original sysvinit */
m->exit_code = MANAGER_REEXECUTE;
- else
- m->exit_code = MANAGER_EXIT;
+ break;
+ }
- return 0;
+ /* Fall through */
case SIGINT:
if (m->running_as == MANAGER_INIT) {
break;
}
- m->exit_code = MANAGER_EXIT;
- return 0;
+ /* Run the exit target if there is one, if not, just exit. */
+ if (manager_start_target(m, SPECIAL_EXIT_SERVICE) < 0) {
+ m->exit_code = MANAGER_EXIT;
+ return 0;
+ }
+
+ break;
case SIGWINCH:
if (m->running_as == MANAGER_INIT)
#define SPECIAL_MAIL_TRANSFER_AGENT_TARGET "mail-transfer-agent.target" /* Debian's $mail-{transport|transfer-agent */
#define SPECIAL_BASIC_TARGET "basic.target"
#define SPECIAL_RESCUE_TARGET "rescue.target"
+#define SPECIAL_EXIT_SERVICE "exit.service"
#ifndef SPECIAL_DBUS_SERVICE
#define SPECIAL_DBUS_SERVICE "dbus.service"
--- /dev/null
+exit.service
--- /dev/null
+[Unit]
+Description=Exit
+Requires=shutdown.target
+After=shutdown.target
+
+[Service]
+Type=finish
+ExecStart=@SYSTEMCTL@ --session daemon-exit