[systemd-commits] Makefile.am src/binfmt src/binfmt.c

Kay Sievers kay at kemper.freedesktop.org
Fri Dec 30 22:44:43 PST 2011


 Makefile.am         |   85 ++++++++++++--------------
 src/binfmt.c        |  164 ----------------------------------------------------
 src/binfmt/binfmt.c |  164 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 202 insertions(+), 211 deletions(-)

New commits:
commit 609518c1d2abb511bd1fce447a1aa369e92a0bdb
Author: Kay Sievers <kay.sievers at vrfy.org>
Date:   Sat Dec 31 07:40:31 2011 +0100

    binfmt: move sources to subdirectory

diff --git a/Makefile.am b/Makefile.am
index 299b9e5..5f7b505 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -197,11 +197,6 @@ rootlibexec_PROGRAMS = \
 	systemd-sysctl \
 	systemd-journald
 
-if ENABLE_BINFMT
-rootlibexec_PROGRAMS += \
-	systemd-binfmt
-endif
-
 systemgenerator_PROGRAMS = \
 	systemd-getty-generator
 
@@ -347,12 +342,6 @@ dist_systemunit_DATA += \
 	units/var-lock.mount
 endif
 
-if ENABLE_BINFMT
-dist_systemunit_DATA += \
-	units/proc-sys-fs-binfmt_misc.automount \
-	units/proc-sys-fs-binfmt_misc.mount
-endif
-
 nodist_systemunit_DATA = \
 	units/getty at .service \
 	units/serial-getty at .service \
@@ -388,11 +377,6 @@ nodist_systemunit_DATA = \
 	units/rescue.service \
 	units/user at .service
 
-if ENABLE_BINFMT
-nodist_systemunit_DATA += \
-	units/systemd-binfmt.service
-endif
-
 dist_userunit_DATA = \
 	units/user/default.target \
 	units/user/exit.target
@@ -447,11 +431,6 @@ EXTRA_DIST += \
 	src/99-systemd.rules.in \
 	man/custom-html.xsl
 
-if ENABLE_BINFMT
-EXTRA_DIST += \
-	units/systemd-binfmt.service.in
-endif
-
 if TARGET_FEDORA
 dist_systemunit_DATA += \
 	units/fedora/prefdm.service \
@@ -737,11 +716,6 @@ MANPAGES = \
 	man/sd_seat_get_active.3 \
 	man/sd_get_seats.3
 
-if ENABLE_BINFMT
-MANPAGES += \
-	man/binfmt.d.5
-endif
-
 MANPAGES_ALIAS = \
 	man/reboot.8 \
 	man/poweroff.8 \
@@ -1046,6 +1020,44 @@ dist_noinst_SCRIPT = \
 	src/generate-kbd-model-map
 
 # ------------------------------------------------------------------------------
+if ENABLE_BINFMT
+systemd_binfmt_SOURCES = \
+	src/binfmt/binfmt.c
+
+systemd_binfmt_LDADD = \
+	libsystemd-basic.la
+
+rootlibexec_PROGRAMS += \
+	systemd-binfmt
+
+dist_systemunit_DATA += \
+	units/proc-sys-fs-binfmt_misc.automount \
+	units/proc-sys-fs-binfmt_misc.mount
+
+nodist_systemunit_DATA += \
+	units/systemd-binfmt.service
+
+binfmt-install-data-hook:
+	$(MKDIR_P) -m 0755 \
+		$(DESTDIR)$(prefix)/lib/binfmt.d \
+		$(DESTDIR)$(sysconfdir)/binfmt.d
+	( cd $(DESTDIR)$(systemunitdir)/sysinit.target.wants && \
+		rm -f systemd-binfmt.service \
+			proc-sys-fs-binfmt_misc.automount && \
+		$(LN_S) ../systemd-binfmt.service systemd-binfmt.service && \
+		$(LN_S) ../proc-sys-fs-binfmt_misc.automount proc-sys-fs-binfmt_misc.automount )
+
+INSTALL_DATA_HOOKS += \
+	binfmt-install-data-hook
+
+MANPAGES += \
+	man/binfmt.d.5
+
+EXTRA_DIST += \
+	units/systemd-binfmt.service.in
+endif
+
+# ------------------------------------------------------------------------------
 if ENABLE_HOSTNAMED
 systemd_hostnamed_SOURCES = \
 	src/hostname/hostnamed.c \
@@ -1455,15 +1467,6 @@ systemd_sysctl_CFLAGS = \
 systemd_sysctl_LDADD = \
 	libsystemd-basic.la
 
-systemd_binfmt_SOURCES = \
-	src/binfmt.c
-
-systemd_binfmt_CFLAGS = \
-	$(AM_CFLAGS)
-
-systemd_binfmt_LDADD = \
-	libsystemd-basic.la
-
 systemd_fsck_SOURCES = \
 	src/fsck.c \
 	src/dbus-common.c
@@ -2048,11 +2051,6 @@ systemd-install-data-hook:
 		$(DESTDIR)$(systemshutdowndir) \
 		$(DESTDIR)$(systemgeneratordir) \
 		$(DESTDIR)$(usergeneratordir)
-if ENABLE_BINFMT
-	$(MKDIR_P) -m 0755 \
-		$(DESTDIR)$(prefix)/lib/binfmt.d \
-		$(DESTDIR)$(sysconfdir)/binfmt.d
-endif
 	$(MKDIR_P) -m 0755 \
 		$(DESTDIR)$(systemunitdir) \
 		$(DESTDIR)$(userunitdir) \
@@ -2178,13 +2176,6 @@ endif
 		$(LN_S) ../systemd-ask-password-console.path systemd-ask-password-console.path && \
 		$(LN_S) ../systemd-kmsg-syslogd.service && \
 		$(LN_S) ../cryptsetup.target cryptsetup.target )
-if ENABLE_BINFMT
-	( cd $(DESTDIR)$(systemunitdir)/sysinit.target.wants && \
-		rm -f systemd-binfmt.service \
-			proc-sys-fs-binfmt_misc.automount && \
-		$(LN_S) ../systemd-binfmt.service systemd-binfmt.service && \
-		$(LN_S) ../proc-sys-fs-binfmt_misc.automount proc-sys-fs-binfmt_misc.automount )
-endif
 	( cd $(DESTDIR)$(systemunitdir)/basic.target.wants && \
 		rm -f systemd-tmpfiles-clean.timer && \
 		$(LN_S) ../systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.timer )
diff --git a/src/binfmt.c b/src/binfmt.c
deleted file mode 100644
index e8d6524..0000000
--- a/src/binfmt.c
+++ /dev/null
@@ -1,164 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
-  This file is part of systemd.
-
-  Copyright 2010 Lennart Poettering
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 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
-  General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-#include <stdlib.h>
-#include <stdbool.h>
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <limits.h>
-#include <stdarg.h>
-
-#include "log.h"
-#include "hashmap.h"
-#include "strv.h"
-#include "util.h"
-
-static int delete_rule(const char *rule) {
-        char *x, *fn = NULL, *e;
-        int r;
-
-        assert(rule[0]);
-
-        if (!(x = strdup(rule)))
-                return -ENOMEM;
-
-        e = strchrnul(x+1, x[0]);
-        *e = 0;
-
-        asprintf(&fn, "/proc/sys/fs/binfmt_misc/%s", x+1);
-        free(x);
-
-        if (!fn)
-                return -ENOMEM;
-
-        r = write_one_line_file(fn, "-1");
-        free(fn);
-
-        return r;
-}
-
-static int apply_rule(const char *rule) {
-        int r;
-
-        delete_rule(rule);
-
-        if ((r = write_one_line_file("/proc/sys/fs/binfmt_misc/register", rule)) < 0) {
-                log_error("Failed to add binary format: %s", strerror(-r));
-                return r;
-        }
-
-        return 0;
-}
-
-static int apply_file(const char *path, bool ignore_enoent) {
-        FILE *f;
-        int r = 0;
-
-        assert(path);
-
-        if (!(f = fopen(path, "re"))) {
-                if (ignore_enoent && errno == ENOENT)
-                        return 0;
-
-                log_error("Failed to open file '%s', ignoring: %m", path);
-                return -errno;
-        }
-
-        log_debug("apply: %s\n", path);
-        while (!feof(f)) {
-                char l[LINE_MAX], *p;
-                int k;
-
-                if (!fgets(l, sizeof(l), f)) {
-                        if (feof(f))
-                                break;
-
-                        log_error("Failed to read file '%s', ignoring: %m", path);
-                        r = -errno;
-                        goto finish;
-                }
-
-                p = strstrip(l);
-
-                if (!*p)
-                        continue;
-
-                if (strchr(COMMENTS, *p))
-                        continue;
-
-                if ((k = apply_rule(p)) < 0 && r == 0)
-                        r = k;
-        }
-
-finish:
-        fclose(f);
-
-        return r;
-}
-
-int main(int argc, char *argv[]) {
-        int r = 0;
-
-        if (argc > 2) {
-                log_error("This program expects one or no arguments.");
-                return EXIT_FAILURE;
-        }
-
-        log_set_target(LOG_TARGET_AUTO);
-        log_parse_environment();
-        log_open();
-
-        umask(0022);
-
-        if (argc > 1) {
-                r = apply_file(argv[1], false);
-        } else {
-                char **files, **f;
-
-                /* Flush out all rules */
-                write_one_line_file("/proc/sys/fs/binfmt_misc/status", "-1");
-
-                r = conf_files_list(&files, ".conf",
-                                    "/run/binfmt.d",
-                                    "/etc/binfmt.d",
-                                    "/usr/local/lib/binfmt.d",
-                                    "/usr/lib/binfmt.d",
-                                    NULL);
-
-                if (r < 0) {
-                        log_error("Failed to enumerate binfmt.d files: %s", strerror(-r));
-                        goto finish;
-                }
-
-                STRV_FOREACH(f, files) {
-                        int k;
-
-                        k = apply_file(*f, true);
-                        if (k < 0 && r == 0)
-                                r = k;
-                }
-
-                strv_free(files);
-        }
-finish:
-        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
-}
diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c
new file mode 100644
index 0000000..e8d6524
--- /dev/null
+++ b/src/binfmt/binfmt.c
@@ -0,0 +1,164 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 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
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+#include <limits.h>
+#include <stdarg.h>
+
+#include "log.h"
+#include "hashmap.h"
+#include "strv.h"
+#include "util.h"
+
+static int delete_rule(const char *rule) {
+        char *x, *fn = NULL, *e;
+        int r;
+
+        assert(rule[0]);
+
+        if (!(x = strdup(rule)))
+                return -ENOMEM;
+
+        e = strchrnul(x+1, x[0]);
+        *e = 0;
+
+        asprintf(&fn, "/proc/sys/fs/binfmt_misc/%s", x+1);
+        free(x);
+
+        if (!fn)
+                return -ENOMEM;
+
+        r = write_one_line_file(fn, "-1");
+        free(fn);
+
+        return r;
+}
+
+static int apply_rule(const char *rule) {
+        int r;
+
+        delete_rule(rule);
+
+        if ((r = write_one_line_file("/proc/sys/fs/binfmt_misc/register", rule)) < 0) {
+                log_error("Failed to add binary format: %s", strerror(-r));
+                return r;
+        }
+
+        return 0;
+}
+
+static int apply_file(const char *path, bool ignore_enoent) {
+        FILE *f;
+        int r = 0;
+
+        assert(path);
+
+        if (!(f = fopen(path, "re"))) {
+                if (ignore_enoent && errno == ENOENT)
+                        return 0;
+
+                log_error("Failed to open file '%s', ignoring: %m", path);
+                return -errno;
+        }
+
+        log_debug("apply: %s\n", path);
+        while (!feof(f)) {
+                char l[LINE_MAX], *p;
+                int k;
+
+                if (!fgets(l, sizeof(l), f)) {
+                        if (feof(f))
+                                break;
+
+                        log_error("Failed to read file '%s', ignoring: %m", path);
+                        r = -errno;
+                        goto finish;
+                }
+
+                p = strstrip(l);
+
+                if (!*p)
+                        continue;
+
+                if (strchr(COMMENTS, *p))
+                        continue;
+
+                if ((k = apply_rule(p)) < 0 && r == 0)
+                        r = k;
+        }
+
+finish:
+        fclose(f);
+
+        return r;
+}
+
+int main(int argc, char *argv[]) {
+        int r = 0;
+
+        if (argc > 2) {
+                log_error("This program expects one or no arguments.");
+                return EXIT_FAILURE;
+        }
+
+        log_set_target(LOG_TARGET_AUTO);
+        log_parse_environment();
+        log_open();
+
+        umask(0022);
+
+        if (argc > 1) {
+                r = apply_file(argv[1], false);
+        } else {
+                char **files, **f;
+
+                /* Flush out all rules */
+                write_one_line_file("/proc/sys/fs/binfmt_misc/status", "-1");
+
+                r = conf_files_list(&files, ".conf",
+                                    "/run/binfmt.d",
+                                    "/etc/binfmt.d",
+                                    "/usr/local/lib/binfmt.d",
+                                    "/usr/lib/binfmt.d",
+                                    NULL);
+
+                if (r < 0) {
+                        log_error("Failed to enumerate binfmt.d files: %s", strerror(-r));
+                        goto finish;
+                }
+
+                STRV_FOREACH(f, files) {
+                        int k;
+
+                        k = apply_file(*f, true);
+                        if (k < 0 && r == 0)
+                                r = k;
+                }
+
+                strv_free(files);
+        }
+finish:
+        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+}



More information about the systemd-commits mailing list