[systemd-commits] 2 commits - CODING_STYLE Makefile.am src/core src/fsck src/import src/journal src/journal-remote src/libsystemd src/login src/machine src/network src/nspawn src/remount-fs src/resolve src/run src/shared src/systemctl src/test src/timesync src/tty-ask-password-agent src/udev

Lennart Poettering lennart at kemper.freedesktop.org
Fri May 29 11:14:56 PDT 2015


 CODING_STYLE                                        |   21 +
 Makefile.am                                         |    2 
 src/core/busname.c                                  |    5 
 src/core/dbus-kill.c                                |    4 
 src/core/execute.c                                  |    6 
 src/core/kill.c                                     |    4 
 src/core/load-fragment.c                            |    1 
 src/core/main.c                                     |    7 
 src/core/manager.c                                  |   13 -
 src/core/service.c                                  |    1 
 src/core/socket.c                                   |    3 
 src/fsck/fsck.c                                     |    1 
 src/import/export.c                                 |    1 
 src/import/import-common.c                          |    1 
 src/import/import.c                                 |    1 
 src/import/importd.c                                |    1 
 src/import/pull-common.c                            |    1 
 src/import/pull.c                                   |    1 
 src/journal-remote/journal-remote.c                 |    1 
 src/journal-remote/journal-upload.c                 |    3 
 src/journal/coredumpctl.c                           |    1 
 src/journal/journald-server.c                       |    9 
 src/libsystemd/sd-bus/bus-socket.c                  |    3 
 src/libsystemd/sd-bus/bus-util.c                    |    1 
 src/libsystemd/sd-event/sd-event.c                  |    1 
 src/libsystemd/sd-event/test-event.c                |    1 
 src/login/loginctl.c                                |    1 
 src/login/logind.c                                  |    3 
 src/machine/machinectl.c                            |    1 
 src/machine/machined.c                              |    3 
 src/network/networkd-wait-online.c                  |    5 
 src/network/networkd.c                              |    4 
 src/nspawn/nspawn.c                                 |    1 
 src/remount-fs/remount-fs.c                         |    1 
 src/resolve/resolved.c                              |    1 
 src/run/run.c                                       |    1 
 src/shared/ask-password-api.c                       |    2 
 src/shared/log.c                                    |    1 
 src/shared/machine-pool.c                           |    1 
 src/shared/process-util.c                           |    3 
 src/shared/pty.c                                    |    3 
 src/shared/signal-util.c                            |  228 ++++++++++++++++++++
 src/shared/signal-util.h                            |   41 +++
 src/shared/util.c                                   |  205 -----------------
 src/shared/util.h                                   |   16 -
 src/systemctl/systemctl.c                           |    1 
 src/test/test-pty.c                                 |    1 
 src/test/test-util.c                                |    1 
 src/timesync/timesyncd.c                            |    1 
 src/tty-ask-password-agent/tty-ask-password-agent.c |    1 
 src/udev/udev-event.c                               |    3 
 51 files changed, 369 insertions(+), 254 deletions(-)

New commits:
commit 24882e06c135584f16f31ba8a00fecde8b7f6fad
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri May 29 20:14:11 2015 +0200

    util: split out signal-util.[ch] from util.[ch]
    
    No functional changes.

diff --git a/Makefile.am b/Makefile.am
index c7da2f2..06512ae 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -785,6 +785,8 @@ libsystemd_shared_la_SOURCES = \
 	src/shared/time-util.h \
 	src/shared/locale-util.c \
 	src/shared/locale-util.h \
+	src/shared/signal-util.c \
+	src/shared/signal-util.h \
 	src/shared/mempool.c \
 	src/shared/mempool.h \
 	src/shared/hashmap.c \
diff --git a/src/core/busname.c b/src/core/busname.c
index 17b8513..11f3b98 100644
--- a/src/core/busname.c
+++ b/src/core/busname.c
@@ -22,15 +22,16 @@
 #include <sys/mman.h>
 
 #include "special.h"
+#include "formats-util.h"
+#include "signal-util.h"
 #include "bus-kernel.h"
 #include "bus-internal.h"
 #include "bus-util.h"
-#include "service.h"
 #include "kdbus.h"
 #include "bus-policy.h"
+#include "service.h"
 #include "dbus-busname.h"
 #include "busname.h"
-#include "formats-util.h"
 
 static const UnitActiveState state_translation_table[_BUSNAME_STATE_MAX] = {
         [BUSNAME_DEAD] = UNIT_INACTIVE,
diff --git a/src/core/dbus-kill.c b/src/core/dbus-kill.c
index fb29e14..3b81162 100644
--- a/src/core/dbus-kill.c
+++ b/src/core/dbus-kill.c
@@ -19,9 +19,11 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include "signal-util.h"
+#include "bus-util.h"
+
 #include "kill.h"
 #include "dbus-kill.h"
-#include "bus-util.h"
 
 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_kill_mode, kill_mode, KillMode);
 
diff --git a/src/core/execute.c b/src/core/execute.c
index e88a2dc..4120493 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -49,14 +49,13 @@
 #include <sys/apparmor.h>
 #endif
 
+#include "sd-messages.h"
 #include "rm-rf.h"
-#include "execute.h"
 #include "strv.h"
 #include "macro.h"
 #include "capability.h"
 #include "util.h"
 #include "log.h"
-#include "sd-messages.h"
 #include "ioprio.h"
 #include "securebits.h"
 #include "namespace.h"
@@ -79,6 +78,7 @@
 #include "formats-util.h"
 #include "process-util.h"
 #include "terminal-util.h"
+#include "signal-util.h"
 
 #ifdef HAVE_APPARMOR
 #include "apparmor-util.h"
@@ -88,6 +88,8 @@
 #include "seccomp-util.h"
 #endif
 
+#include "execute.h"
+
 #define IDLE_TIMEOUT_USEC (5*USEC_PER_SEC)
 #define IDLE_TIMEOUT2_USEC (1*USEC_PER_SEC)
 
diff --git a/src/core/kill.c b/src/core/kill.c
index 60a510e..2de71c6 100644
--- a/src/core/kill.c
+++ b/src/core/kill.c
@@ -19,9 +19,9 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-
-#include "kill.h"
 #include "util.h"
+#include "signal-util.h"
+#include "kill.h"
 
 void kill_context_init(KillContext *c) {
         assert(c);
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 9415e92..c95c110 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -52,6 +52,7 @@
 #include "errno-list.h"
 #include "af-list.h"
 #include "cap-list.h"
+#include "signal-util.h"
 #include "bus-internal.h"
 
 #ifdef HAVE_SECCOMP
diff --git a/src/core/main.c b/src/core/main.c
index 212ab90..674e47e 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -60,6 +60,10 @@
 #include "bus-error.h"
 #include "bus-util.h"
 #include "selinux-util.h"
+#include "formats-util.h"
+#include "process-util.h"
+#include "terminal-util.h"
+#include "signal-util.h"
 #include "manager.h"
 #include "dbus-manager.h"
 #include "load-fragment.h"
@@ -72,9 +76,6 @@
 #include "ima-setup.h"
 #include "smack-setup.h"
 #include "kmod-setup.h"
-#include "formats-util.h"
-#include "process-util.h"
-#include "terminal-util.h"
 
 static enum {
         ACTION_RUN,
diff --git a/src/core/manager.c b/src/core/manager.c
index b931b0d..ae473d0 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -40,8 +40,6 @@
 #include "sd-daemon.h"
 #include "sd-messages.h"
 
-#include "manager.h"
-#include "transaction.h"
 #include "hashmap.h"
 #include "macro.h"
 #include "strv.h"
@@ -65,14 +63,17 @@
 #include "bus-common-errors.h"
 #include "bus-error.h"
 #include "bus-util.h"
-#include "dbus.h"
-#include "dbus-unit.h"
-#include "dbus-job.h"
-#include "dbus-manager.h"
 #include "bus-kernel.h"
 #include "time-util.h"
 #include "process-util.h"
 #include "terminal-util.h"
+#include "signal-util.h"
+#include "dbus.h"
+#include "dbus-unit.h"
+#include "dbus-job.h"
+#include "dbus-manager.h"
+#include "manager.h"
+#include "transaction.h"
 
 /* Initial delay and the interval for printing status messages about running jobs */
 #define JOBS_IN_PROGRESS_WAIT_USEC (5*USEC_PER_SEC)
diff --git a/src/core/service.c b/src/core/service.c
index 07347b9..c7e6577 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -47,6 +47,7 @@
 #include "bus-kernel.h"
 #include "formats-util.h"
 #include "process-util.h"
+#include "signal-util.h"
 
 static const UnitActiveState state_translation_table[_SERVICE_STATE_MAX] = {
         [SERVICE_DEAD] = UNIT_INACTIVE,
diff --git a/src/core/socket.c b/src/core/socket.c
index 17b8a50..fc5eb14 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -47,8 +47,9 @@
 #include "selinux-util.h"
 #include "dbus-socket.h"
 #include "unit.h"
-#include "socket.h"
 #include "formats-util.h"
+#include "signal-util.h"
+#include "socket.h"
 
 static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
         [SOCKET_DEAD] = UNIT_INACTIVE,
diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c
index 9bbe9ff..f0e5c5f 100644
--- a/src/fsck/fsck.c
+++ b/src/fsck/fsck.c
@@ -34,6 +34,7 @@
 
 #include "util.h"
 #include "process-util.h"
+#include "signal-util.h"
 #include "special.h"
 #include "bus-util.h"
 #include "bus-error.h"
diff --git a/src/import/export.c b/src/import/export.c
index 201c5ab..d4bc88e 100644
--- a/src/import/export.c
+++ b/src/import/export.c
@@ -23,6 +23,7 @@
 
 #include "sd-event.h"
 #include "event-util.h"
+#include "signal-util.h"
 #include "verbs.h"
 #include "build.h"
 #include "machine-image.h"
diff --git a/src/import/import-common.c b/src/import/import-common.c
index aede2f9..9711614 100644
--- a/src/import/import-common.c
+++ b/src/import/import-common.c
@@ -26,6 +26,7 @@
 #include "util.h"
 #include "btrfs-util.h"
 #include "capability.h"
+#include "signal-util.h"
 #include "import-common.h"
 
 int import_make_read_only_fd(int fd) {
diff --git a/src/import/import.c b/src/import/import.c
index f3072b3..fff5a10 100644
--- a/src/import/import.c
+++ b/src/import/import.c
@@ -25,6 +25,7 @@
 #include "event-util.h"
 #include "verbs.h"
 #include "build.h"
+#include "signal-util.h"
 #include "machine-image.h"
 #include "import-util.h"
 #include "import-tar.h"
diff --git a/src/import/importd.c b/src/import/importd.c
index 45d1d93..50566a6 100644
--- a/src/import/importd.c
+++ b/src/import/importd.c
@@ -34,6 +34,7 @@
 #include "path-util.h"
 #include "import-util.h"
 #include "process-util.h"
+#include "signal-util.h"
 
 typedef struct Transfer Transfer;
 typedef struct Manager Manager;
diff --git a/src/import/pull-common.c b/src/import/pull-common.c
index 59091ba..d2588d4 100644
--- a/src/import/pull-common.c
+++ b/src/import/pull-common.c
@@ -30,6 +30,7 @@
 #include "pull-job.h"
 #include "pull-common.h"
 #include "process-util.h"
+#include "signal-util.h"
 
 #define FILENAME_ESCAPE "/.#\"\'"
 
diff --git a/src/import/pull.c b/src/import/pull.c
index 0f2ad92..eec4583 100644
--- a/src/import/pull.c
+++ b/src/import/pull.c
@@ -25,6 +25,7 @@
 #include "event-util.h"
 #include "verbs.h"
 #include "build.h"
+#include "signal-util.h"
 #include "machine-image.h"
 #include "import-util.h"
 #include "pull-tar.h"
diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c
index f87a939..911e2a1 100644
--- a/src/journal-remote/journal-remote.c
+++ b/src/journal-remote/journal-remote.c
@@ -30,6 +30,7 @@
 #include <getopt.h>
 
 #include "sd-daemon.h"
+#include "signal-util.h"
 #include "journal-file.h"
 #include "journald-native.h"
 #include "socket-util.h"
diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c
index ddbb873..ddb1ef0 100644
--- a/src/journal-remote/journal-upload.c
+++ b/src/journal-remote/journal-upload.c
@@ -33,8 +33,9 @@
 #include "mkdir.h"
 #include "conf-parser.h"
 #include "sigbus.h"
-#include "journal-upload.h"
 #include "formats-util.h"
+#include "signal-util.h"
+#include "journal-upload.h"
 
 #define PRIV_KEY_FILE CERTIFICATE_ROOT "/private/journal-upload.pem"
 #define CERT_FILE     CERTIFICATE_ROOT "/certs/journal-upload.pem"
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index bcb0ff9..381bf72 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -39,6 +39,7 @@
 #include "sigbus.h"
 #include "process-util.h"
 #include "terminal-util.h"
+#include "signal-util.h"
 
 static enum {
         ACTION_NONE,
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index b3a4b53..3353024 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -25,6 +25,10 @@
 #include <sys/statvfs.h>
 #include <sys/mman.h>
 
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
 #include <libudev.h>
 
 #include "sd-journal.h"
@@ -43,6 +47,7 @@
 #include "formats-util.h"
 #include "process-util.h"
 #include "hostname-util.h"
+#include "signal-util.h"
 #include "journal-internal.h"
 #include "journal-vacuum.h"
 #include "journal-authenticate.h"
@@ -54,10 +59,6 @@
 #include "journald-audit.h"
 #include "journald-server.h"
 
-#ifdef HAVE_SELINUX
-#include <selinux/selinux.h>
-#endif
-
 #define USER_JOURNALS_MAX 1024
 
 #define DEFAULT_SYNC_INTERVAL_USEC (5*USEC_PER_MINUTE)
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
index 881efb1..4fffc65 100644
--- a/src/libsystemd/sd-bus/bus-socket.c
+++ b/src/libsystemd/sd-bus/bus-socket.c
@@ -24,12 +24,13 @@
 #include <unistd.h>
 #include <poll.h>
 
+#include "sd-daemon.h"
 #include "util.h"
 #include "macro.h"
 #include "missing.h"
 #include "utf8.h"
-#include "sd-daemon.h"
 #include "formats-util.h"
+#include "signal-util.h"
 
 #include "sd-bus.h"
 #include "bus-socket.h"
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c
index 5e375af..9993779 100644
--- a/src/libsystemd/sd-bus/bus-util.c
+++ b/src/libsystemd/sd-bus/bus-util.c
@@ -30,6 +30,7 @@
 #include "path-util.h"
 #include "missing.h"
 #include "set.h"
+#include "signal-util.h"
 #include "unit-name.h"
 
 #include "sd-bus.h"
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
index 0dc4680..cc8bc50 100644
--- a/src/libsystemd/sd-event/sd-event.c
+++ b/src/libsystemd/sd-event/sd-event.c
@@ -33,6 +33,7 @@
 #include "missing.h"
 #include "set.h"
 #include "list.h"
+#include "signal-util.h"
 
 #include "sd-event.h"
 
diff --git a/src/libsystemd/sd-event/test-event.c b/src/libsystemd/sd-event/test-event.c
index 721700b..94e98e0 100644
--- a/src/libsystemd/sd-event/test-event.c
+++ b/src/libsystemd/sd-event/test-event.c
@@ -23,6 +23,7 @@
 #include "log.h"
 #include "util.h"
 #include "macro.h"
+#include "signal-util.h"
 
 static int prepare_handler(sd_event_source *s, void *userdata) {
         log_info("preparing %c", PTR_TO_INT(userdata));
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 4a5a618..02d240c 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -43,6 +43,7 @@
 #include "verbs.h"
 #include "process-util.h"
 #include "terminal-util.h"
+#include "signal-util.h"
 
 static char **arg_property = NULL;
 static bool arg_all = false;
diff --git a/src/login/logind.c b/src/login/logind.c
index 5e66cb9..00f8dbd 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -30,9 +30,10 @@
 #include "conf-parser.h"
 #include "bus-util.h"
 #include "bus-error.h"
-#include "logind.h"
 #include "udev-util.h"
 #include "formats-util.h"
+#include "signal-util.h"
+#include "logind.h"
 
 static void manager_free(Manager *m);
 
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index b21a339..c86c36c 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -54,6 +54,7 @@
 #include "import-util.h"
 #include "process-util.h"
 #include "terminal-util.h"
+#include "signal-util.h"
 
 static char **arg_property = NULL;
 static bool arg_all = false;
diff --git a/src/machine/machined.c b/src/machine/machined.c
index 1e862ad..754c770 100644
--- a/src/machine/machined.c
+++ b/src/machine/machined.c
@@ -28,9 +28,10 @@
 #include "bus-util.h"
 #include "bus-error.h"
 #include "label.h"
+#include "formats-util.h"
+#include "signal-util.h"
 #include "machine-image.h"
 #include "machined.h"
-#include "formats-util.h"
 
 Manager *manager_new(void) {
         Manager *m;
diff --git a/src/network/networkd-wait-online.c b/src/network/networkd-wait-online.c
index f0ca6de..6a96f1d 100644
--- a/src/network/networkd-wait-online.c
+++ b/src/network/networkd-wait-online.c
@@ -21,11 +21,10 @@
 #include <getopt.h>
 
 #include "sd-daemon.h"
-
-#include "networkd-wait-online.h"
-
 #include "strv.h"
 #include "build.h"
+#include "signal-util.h"
+#include "networkd-wait-online.h"
 
 static bool arg_quiet = false;
 static usec_t arg_timeout = 120 * USEC_PER_SEC;
diff --git a/src/network/networkd.c b/src/network/networkd.c
index 543a4e4..41ec7cf 100644
--- a/src/network/networkd.c
+++ b/src/network/networkd.c
@@ -19,9 +19,9 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "capability.h"
 #include "sd-daemon.h"
-
+#include "capability.h"
+#include "signal-util.h"
 #include "networkd.h"
 
 int main(int argc, char *argv[]) {
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index de755ce..4211a3d 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -96,6 +96,7 @@
 #include "process-util.h"
 #include "terminal-util.h"
 #include "hostname-util.h"
+#include "signal-util.h"
 
 #ifdef HAVE_SECCOMP
 #include "seccomp-util.h"
diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c
index a09531b..e701fc9 100644
--- a/src/remount-fs/remount-fs.c
+++ b/src/remount-fs/remount-fs.c
@@ -29,6 +29,7 @@
 #include "log.h"
 #include "util.h"
 #include "path-util.h"
+#include "signal-util.h"
 #include "mount-setup.h"
 #include "exit-status.h"
 
diff --git a/src/resolve/resolved.c b/src/resolve/resolved.c
index 271247c..e283d8a 100644
--- a/src/resolve/resolved.c
+++ b/src/resolve/resolved.c
@@ -24,6 +24,7 @@
 #include "mkdir.h"
 #include "capability.h"
 #include "selinux-util.h"
+#include "signal-util.h"
 
 #include "resolved-manager.h"
 #include "resolved-conf.h"
diff --git a/src/run/run.c b/src/run/run.c
index fcd6b06..5b9f31c 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -35,6 +35,7 @@
 #include "calendarspec.h"
 #include "ptyfwd.h"
 #include "formats-util.h"
+#include "signal-util.h"
 
 static bool arg_scope = false;
 static bool arg_remain_after_exit = false;
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c
index a3a2e51..ef3788b 100644
--- a/src/shared/ask-password-api.c
+++ b/src/shared/ask-password-api.c
@@ -37,7 +37,7 @@
 #include "strv.h"
 #include "random-util.h"
 #include "terminal-util.h"
-
+#include "signal-util.h"
 #include "ask-password-api.h"
 
 static void backspace_chars(int ttyfd, size_t p) {
diff --git a/src/shared/log.c b/src/shared/log.c
index 6168a29..b96afc4 100644
--- a/src/shared/log.c
+++ b/src/shared/log.c
@@ -38,6 +38,7 @@
 #include "formats-util.h"
 #include "process-util.h"
 #include "terminal-util.h"
+#include "signal-util.h"
 
 #define SNDBUF_SIZE (8*1024*1024)
 
diff --git a/src/shared/machine-pool.c b/src/shared/machine-pool.c
index 447983f..d27931c 100644
--- a/src/shared/machine-pool.c
+++ b/src/shared/machine-pool.c
@@ -30,6 +30,7 @@
 #include "mkdir.h"
 #include "btrfs-util.h"
 #include "path-util.h"
+#include "signal-util.h"
 #include "machine-pool.h"
 
 #define VAR_LIB_MACHINES_SIZE_START (1024UL*1024UL*500UL)
diff --git a/src/shared/process-util.c b/src/shared/process-util.c
index 92a69f5..cfc8765 100644
--- a/src/shared/process-util.c
+++ b/src/shared/process-util.c
@@ -28,10 +28,11 @@
 #include <signal.h>
 #include <ctype.h>
 
-#include "process-util.h"
 #include "fileio.h"
 #include "util.h"
 #include "log.h"
+#include "signal-util.h"
+#include "process-util.h"
 
 int get_process_state(pid_t pid) {
         const char *p;
diff --git a/src/shared/pty.c b/src/shared/pty.c
index 0f80f48..119d66e 100644
--- a/src/shared/pty.c
+++ b/src/shared/pty.c
@@ -57,9 +57,10 @@
 
 #include "barrier.h"
 #include "macro.h"
-#include "pty.h"
 #include "ring.h"
 #include "util.h"
+#include "signal-util.h"
+#include "pty.h"
 
 #define PTY_BUFSIZE 4096
 
diff --git a/src/shared/signal-util.c b/src/shared/signal-util.c
new file mode 100644
index 0000000..9a2973b
--- /dev/null
+++ b/src/shared/signal-util.c
@@ -0,0 +1,228 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2015 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 "util.h"
+#include "signal-util.h"
+
+int reset_all_signal_handlers(void) {
+        int sig, r = 0;
+
+        for (sig = 1; sig < _NSIG; sig++) {
+                static const struct sigaction sa = {
+                        .sa_handler = SIG_DFL,
+                        .sa_flags = SA_RESTART,
+                };
+
+                /* These two cannot be caught... */
+                if (sig == SIGKILL || sig == SIGSTOP)
+                        continue;
+
+                /* On Linux the first two RT signals are reserved by
+                 * glibc, and sigaction() will return EINVAL for them. */
+                if ((sigaction(sig, &sa, NULL) < 0))
+                        if (errno != EINVAL && r == 0)
+                                r = -errno;
+        }
+
+        return r;
+}
+
+int reset_signal_mask(void) {
+        sigset_t ss;
+
+        if (sigemptyset(&ss) < 0)
+                return -errno;
+
+        if (sigprocmask(SIG_SETMASK, &ss, NULL) < 0)
+                return -errno;
+
+        return 0;
+}
+
+int sigaction_many(const struct sigaction *sa, ...) {
+        va_list ap;
+        int r = 0, sig;
+
+        va_start(ap, sa);
+        while ((sig = va_arg(ap, int)) > 0)
+                if (sigaction(sig, sa, NULL) < 0)
+                        r = -errno;
+        va_end(ap);
+
+        return r;
+}
+
+int ignore_signals(int sig, ...) {
+        static const struct sigaction sa = {
+                .sa_handler = SIG_IGN,
+                .sa_flags = SA_RESTART,
+        };
+        va_list ap;
+        int r = 0;
+
+        if (sigaction(sig, &sa, NULL) < 0)
+                r = -errno;
+
+        va_start(ap, sig);
+        while ((sig = va_arg(ap, int)) > 0)
+                if (sigaction(sig, &sa, NULL) < 0)
+                        r = -errno;
+        va_end(ap);
+
+        return r;
+}
+
+int default_signals(int sig, ...) {
+        static const struct sigaction sa = {
+                .sa_handler = SIG_DFL,
+                .sa_flags = SA_RESTART,
+        };
+        va_list ap;
+        int r = 0;
+
+        if (sigaction(sig, &sa, NULL) < 0)
+                r = -errno;
+
+        va_start(ap, sig);
+        while ((sig = va_arg(ap, int)) > 0)
+                if (sigaction(sig, &sa, NULL) < 0)
+                        r = -errno;
+        va_end(ap);
+
+        return r;
+}
+
+void sigset_add_many(sigset_t *ss, ...) {
+        va_list ap;
+        int sig;
+
+        assert(ss);
+
+        va_start(ap, ss);
+        while ((sig = va_arg(ap, int)) > 0)
+                assert_se(sigaddset(ss, sig) == 0);
+        va_end(ap);
+}
+
+int sigprocmask_many(int how, ...) {
+        va_list ap;
+        sigset_t ss;
+        int sig;
+
+        assert_se(sigemptyset(&ss) == 0);
+
+        va_start(ap, how);
+        while ((sig = va_arg(ap, int)) > 0)
+                assert_se(sigaddset(&ss, sig) == 0);
+        va_end(ap);
+
+        if (sigprocmask(how, &ss, NULL) < 0)
+                return -errno;
+
+        return 0;
+}
+
+static const char *const __signal_table[] = {
+        [SIGHUP] = "HUP",
+        [SIGINT] = "INT",
+        [SIGQUIT] = "QUIT",
+        [SIGILL] = "ILL",
+        [SIGTRAP] = "TRAP",
+        [SIGABRT] = "ABRT",
+        [SIGBUS] = "BUS",
+        [SIGFPE] = "FPE",
+        [SIGKILL] = "KILL",
+        [SIGUSR1] = "USR1",
+        [SIGSEGV] = "SEGV",
+        [SIGUSR2] = "USR2",
+        [SIGPIPE] = "PIPE",
+        [SIGALRM] = "ALRM",
+        [SIGTERM] = "TERM",
+#ifdef SIGSTKFLT
+        [SIGSTKFLT] = "STKFLT",  /* Linux on SPARC doesn't know SIGSTKFLT */
+#endif
+        [SIGCHLD] = "CHLD",
+        [SIGCONT] = "CONT",
+        [SIGSTOP] = "STOP",
+        [SIGTSTP] = "TSTP",
+        [SIGTTIN] = "TTIN",
+        [SIGTTOU] = "TTOU",
+        [SIGURG] = "URG",
+        [SIGXCPU] = "XCPU",
+        [SIGXFSZ] = "XFSZ",
+        [SIGVTALRM] = "VTALRM",
+        [SIGPROF] = "PROF",
+        [SIGWINCH] = "WINCH",
+        [SIGIO] = "IO",
+        [SIGPWR] = "PWR",
+        [SIGSYS] = "SYS"
+};
+
+DEFINE_PRIVATE_STRING_TABLE_LOOKUP(__signal, int);
+
+const char *signal_to_string(int signo) {
+        static thread_local char buf[sizeof("RTMIN+")-1 + DECIMAL_STR_MAX(int) + 1];
+        const char *name;
+
+        name = __signal_to_string(signo);
+        if (name)
+                return name;
+
+        if (signo >= SIGRTMIN && signo <= SIGRTMAX)
+                snprintf(buf, sizeof(buf), "RTMIN+%d", signo - SIGRTMIN);
+        else
+                snprintf(buf, sizeof(buf), "%d", signo);
+
+        return buf;
+}
+
+int signal_from_string(const char *s) {
+        int signo;
+        int offset = 0;
+        unsigned u;
+
+        signo = __signal_from_string(s);
+        if (signo > 0)
+                return signo;
+
+        if (startswith(s, "RTMIN+")) {
+                s += 6;
+                offset = SIGRTMIN;
+        }
+        if (safe_atou(s, &u) >= 0) {
+                signo = (int) u + offset;
+                if (signo > 0 && signo < _NSIG)
+                        return signo;
+        }
+        return -EINVAL;
+}
+
+int signal_from_string_try_harder(const char *s) {
+        int signo;
+        assert(s);
+
+        signo = signal_from_string(s);
+        if (signo <= 0)
+                if (startswith(s, "SIG"))
+                        return signal_from_string(s+3);
+
+        return signo;
+}
diff --git a/src/shared/signal-util.h b/src/shared/signal-util.h
new file mode 100644
index 0000000..ddf64cd
--- /dev/null
+++ b/src/shared/signal-util.h
@@ -0,0 +1,41 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010-2015 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 <signal.h>
+
+#include "macro.h"
+
+int reset_all_signal_handlers(void);
+int reset_signal_mask(void);
+
+int ignore_signals(int sig, ...);
+int default_signals(int sig, ...);
+int sigaction_many(const struct sigaction *sa, ...);
+
+void sigset_add_many(sigset_t *ss, ...);
+int sigprocmask_many(int how, ...);
+
+const char *signal_to_string(int i) _const_;
+int signal_from_string(const char *s) _pure_;
+
+int signal_from_string_try_harder(const char *s);
diff --git a/src/shared/util.c b/src/shared/util.c
index 74a2190..8a61079 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -93,6 +93,7 @@
 #include "random-util.h"
 #include "terminal-util.h"
 #include "hostname-util.h"
+#include "signal-util.h"
 
 /* Put this test here for a lack of better place */
 assert_cc(EAGAIN == EWOULDBLOCK);
@@ -771,41 +772,6 @@ int readlink_and_canonicalize(const char *p, char **r) {
         return 0;
 }
 
-int reset_all_signal_handlers(void) {
-        int sig, r = 0;
-
-        for (sig = 1; sig < _NSIG; sig++) {
-                struct sigaction sa = {
-                        .sa_handler = SIG_DFL,
-                        .sa_flags = SA_RESTART,
-                };
-
-                /* These two cannot be caught... */
-                if (sig == SIGKILL || sig == SIGSTOP)
-                        continue;
-
-                /* On Linux the first two RT signals are reserved by
-                 * glibc, and sigaction() will return EINVAL for them. */
-                if ((sigaction(sig, &sa, NULL) < 0))
-                        if (errno != EINVAL && r == 0)
-                                r = -errno;
-        }
-
-        return r;
-}
-
-int reset_signal_mask(void) {
-        sigset_t ss;
-
-        if (sigemptyset(&ss) < 0)
-                return -errno;
-
-        if (sigprocmask(SIG_SETMASK, &ss, NULL) < 0)
-                return -errno;
-
-        return 0;
-}
-
 char *strstrip(char *s) {
         char *e;
 
@@ -1561,59 +1527,6 @@ int flush_fd(int fd) {
         }
 }
 
-int sigaction_many(const struct sigaction *sa, ...) {
-        va_list ap;
-        int r = 0, sig;
-
-        va_start(ap, sa);
-        while ((sig = va_arg(ap, int)) > 0)
-                if (sigaction(sig, sa, NULL) < 0)
-                        r = -errno;
-        va_end(ap);
-
-        return r;
-}
-
-int ignore_signals(int sig, ...) {
-        struct sigaction sa = {
-                .sa_handler = SIG_IGN,
-                .sa_flags = SA_RESTART,
-        };
-        va_list ap;
-        int r = 0;
-
-        if (sigaction(sig, &sa, NULL) < 0)
-                r = -errno;
-
-        va_start(ap, sig);
-        while ((sig = va_arg(ap, int)) > 0)
-                if (sigaction(sig, &sa, NULL) < 0)
-                        r = -errno;
-        va_end(ap);
-
-        return r;
-}
-
-int default_signals(int sig, ...) {
-        struct sigaction sa = {
-                .sa_handler = SIG_DFL,
-                .sa_flags = SA_RESTART,
-        };
-        va_list ap;
-        int r = 0;
-
-        if (sigaction(sig, &sa, NULL) < 0)
-                r = -errno;
-
-        va_start(ap, sig);
-        while ((sig = va_arg(ap, int)) > 0)
-                if (sigaction(sig, &sa, NULL) < 0)
-                        r = -errno;
-        va_end(ap);
-
-        return r;
-}
-
 void safe_close_pair(int p[]) {
         assert(p);
 
@@ -1927,35 +1840,6 @@ void rename_process(const char name[8]) {
         }
 }
 
-void sigset_add_many(sigset_t *ss, ...) {
-        va_list ap;
-        int sig;
-
-        assert(ss);
-
-        va_start(ap, ss);
-        while ((sig = va_arg(ap, int)) > 0)
-                assert_se(sigaddset(ss, sig) == 0);
-        va_end(ap);
-}
-
-int sigprocmask_many(int how, ...) {
-        va_list ap;
-        sigset_t ss;
-        int sig;
-
-        assert_se(sigemptyset(&ss) == 0);
-
-        va_start(ap, how);
-        while ((sig = va_arg(ap, int)) > 0)
-                assert_se(sigaddset(&ss, sig) == 0);
-        va_end(ap);
-
-        if (sigprocmask(how, &ss, NULL) < 0)
-                return -errno;
-
-        return 0;
-}
 char *lookup_uid(uid_t uid) {
         long bufsize;
         char *name;
@@ -2344,18 +2228,6 @@ DIR *xopendirat(int fd, const char *name, int flags) {
         return d;
 }
 
-int signal_from_string_try_harder(const char *s) {
-        int signo;
-        assert(s);
-
-        signo = signal_from_string(s);
-        if (signo <= 0)
-                if (startswith(s, "SIG"))
-                        return signal_from_string(s+3);
-
-        return signo;
-}
-
 static char *tag_to_udev_node(const char *tagvalue, const char *by) {
         _cleanup_free_ char *t = NULL, *u = NULL;
         size_t enc_len;
@@ -3312,81 +3184,6 @@ static const char* const ip_tos_table[] = {
 
 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ip_tos, int, 0xff);
 
-static const char *const __signal_table[] = {
-        [SIGHUP] = "HUP",
-        [SIGINT] = "INT",
-        [SIGQUIT] = "QUIT",
-        [SIGILL] = "ILL",
-        [SIGTRAP] = "TRAP",
-        [SIGABRT] = "ABRT",
-        [SIGBUS] = "BUS",
-        [SIGFPE] = "FPE",
-        [SIGKILL] = "KILL",
-        [SIGUSR1] = "USR1",
-        [SIGSEGV] = "SEGV",
-        [SIGUSR2] = "USR2",
-        [SIGPIPE] = "PIPE",
-        [SIGALRM] = "ALRM",
-        [SIGTERM] = "TERM",
-#ifdef SIGSTKFLT
-        [SIGSTKFLT] = "STKFLT",  /* Linux on SPARC doesn't know SIGSTKFLT */
-#endif
-        [SIGCHLD] = "CHLD",
-        [SIGCONT] = "CONT",
-        [SIGSTOP] = "STOP",
-        [SIGTSTP] = "TSTP",
-        [SIGTTIN] = "TTIN",
-        [SIGTTOU] = "TTOU",
-        [SIGURG] = "URG",
-        [SIGXCPU] = "XCPU",
-        [SIGXFSZ] = "XFSZ",
-        [SIGVTALRM] = "VTALRM",
-        [SIGPROF] = "PROF",
-        [SIGWINCH] = "WINCH",
-        [SIGIO] = "IO",
-        [SIGPWR] = "PWR",
-        [SIGSYS] = "SYS"
-};
-
-DEFINE_PRIVATE_STRING_TABLE_LOOKUP(__signal, int);
-
-const char *signal_to_string(int signo) {
-        static thread_local char buf[sizeof("RTMIN+")-1 + DECIMAL_STR_MAX(int) + 1];
-        const char *name;
-
-        name = __signal_to_string(signo);
-        if (name)
-                return name;
-
-        if (signo >= SIGRTMIN && signo <= SIGRTMAX)
-                snprintf(buf, sizeof(buf), "RTMIN+%d", signo - SIGRTMIN);
-        else
-                snprintf(buf, sizeof(buf), "%d", signo);
-
-        return buf;
-}
-
-int signal_from_string(const char *s) {
-        int signo;
-        int offset = 0;
-        unsigned u;
-
-        signo = __signal_from_string(s);
-        if (signo > 0)
-                return signo;
-
-        if (startswith(s, "RTMIN+")) {
-                s += 6;
-                offset = SIGRTMIN;
-        }
-        if (safe_atou(s, &u) >= 0) {
-                signo = (int) u + offset;
-                if (signo > 0 && signo < _NSIG)
-                        return signo;
-        }
-        return -EINVAL;
-}
-
 bool kexec_loaded(void) {
        bool loaded = false;
        char *s;
diff --git a/src/shared/util.h b/src/shared/util.h
index eb35952..467ae23 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -29,7 +29,6 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <signal.h>
 #include <sched.h>
 #include <limits.h>
 #include <sys/types.h>
@@ -227,9 +226,6 @@ int readlink_value(const char *p, char **ret);
 int readlink_and_make_absolute(const char *p, char **r);
 int readlink_and_canonicalize(const char *p, char **r);
 
-int reset_all_signal_handlers(void);
-int reset_signal_mask(void);
-
 char *strstrip(char *s);
 char *delete_chars(char *s, const char *bad);
 char *truncate_nl(char *s);
@@ -334,10 +330,6 @@ bool fstype_is_network(const char *fstype);
 
 int flush_fd(int fd);
 
-int ignore_signals(int sig, ...);
-int default_signals(int sig, ...);
-int sigaction_many(const struct sigaction *sa, ...);
-
 int fopen_temporary(const char *path, FILE **_f, char **_temp_path);
 
 ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll);
@@ -349,9 +341,6 @@ bool is_device_path(const char *path);
 int dir_is_empty(const char *path);
 char* dirname_malloc(const char *path);
 
-void sigset_add_many(sigset_t *ss, ...);
-int sigprocmask_many(int how, ...);
-
 char* lookup_uid(uid_t uid);
 char* getlogname_malloc(void);
 char* getusername_malloc(void);
@@ -465,11 +454,6 @@ int rlimit_from_string(const char *s) _pure_;
 int ip_tos_to_string_alloc(int i, char **s);
 int ip_tos_from_string(const char *s);
 
-const char *signal_to_string(int i) _const_;
-int signal_from_string(const char *s) _pure_;
-
-int signal_from_string_try_harder(const char *s);
-
 extern int saved_argc;
 extern char **saved_argv;
 
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 897248a..a7b8e54 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -72,6 +72,7 @@
 #include "process-util.h"
 #include "terminal-util.h"
 #include "hostname-util.h"
+#include "signal-util.h"
 
 static char **arg_types = NULL;
 static char **arg_states = NULL;
diff --git a/src/test/test-pty.c b/src/test/test-pty.c
index b5f4d4f..f8807c9 100644
--- a/src/test/test-pty.c
+++ b/src/test/test-pty.c
@@ -27,6 +27,7 @@
 
 #include "pty.h"
 #include "util.h"
+#include "signal-util.h"
 
 static const char sndmsg[] = "message\n";
 static const char rcvmsg[] = "message\r\n";
diff --git a/src/test/test-util.c b/src/test/test-util.c
index 41cbe81..e026982 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -39,6 +39,7 @@
 #include "virt.h"
 #include "process-util.h"
 #include "hostname-util.h"
+#include "signal-util.h"
 
 static void test_streq_ptr(void) {
         assert_se(streq_ptr(NULL, NULL));
diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c
index 735668b..d69129e 100644
--- a/src/timesync/timesyncd.c
+++ b/src/timesync/timesyncd.c
@@ -24,6 +24,7 @@
 #include "capability.h"
 #include "clock-util.h"
 #include "network-util.h"
+#include "signal-util.h"
 
 #include "timesyncd-manager.h"
 #include "timesyncd-conf.h"
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c
index c440170..97251ef 100644
--- a/src/tty-ask-password-agent/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent/tty-ask-password-agent.c
@@ -44,6 +44,7 @@
 #include "def.h"
 #include "process-util.h"
 #include "terminal-util.h"
+#include "signal-util.h"
 
 static enum {
         ACTION_LIST,
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index 92dc44f..a5c3edb 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -30,11 +30,12 @@
 #include <sys/wait.h>
 #include <sys/signalfd.h>
 
-#include "udev.h"
 #include "rtnl-util.h"
 #include "event-util.h"
 #include "formats-util.h"
 #include "process-util.h"
+#include "signal-util.h"
+#include "udev.h"
 
 typedef struct Spawn {
         const char *cmd;

commit 1811232c4cc5d93cb02d93ed448a712e88e30868
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri May 29 20:12:17 2015 +0200

    CODING_STYLE: document order in which to #include headers

diff --git a/CODING_STYLE b/CODING_STYLE
index 91f09e8..bdec988 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -292,3 +292,24 @@
 
 - When returning a return code from main(), please preferably use
   EXIT_FAILURE and EXIT_SUCCESS as defined by libc.
+
+- The order in which header files are included doesn't matter too
+  much. However, please try to include the headers of external
+  libraries first (these are all headers enclosed in <>), followed by
+  the headers of our own public headers (these are all headers
+  starting with "sd-"), internal utility libraries from src/shared/,
+  followed by the headers of the specific component. Or in other
+  words:
+
+          #include <stdio.h>
+          #include "sd-daemon.h"
+          #include "util.h"
+          #include "frobnicator.h"
+
+  Where stdio.h is a public glibc API, sd-daemon.h is a public API of
+  our own, util.h is a utility library header from src/shared, and
+  frobnicator.h is an placeholder name for any systemd component. The
+  benefit of following this ordering is that more local definitions
+  are always defined after more global ones. Thus, our local
+  definitions will never "leak" into the global header files, possibly
+  altering their effect due to #ifdeffery.



More information about the systemd-commits mailing list