]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: split out cpu set specific APIs into cpu-set-util.[ch]
authorLennart Poettering <lennart@poettering.net>
Wed, 30 Sep 2015 19:50:22 +0000 (21:50 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 30 Sep 2015 20:26:16 +0000 (22:26 +0200)
12 files changed:
Makefile.am
src/basic/cpu-set-util.c [new file with mode: 0644]
src/basic/cpu-set-util.h [new file with mode: 0644]
src/basic/util.c
src/basic/util.h
src/core/load-fragment.c
src/core/machine-id-setup.c
src/core/main.c
src/import/import-common.c
src/libsystemd-network/test-pppoe.c
src/test/test-util.c
src/udev/udevd.c

index 6ddc0b74f3d669f1a321a9504d73747afad575b9..4ea66cf8139b66e72b2838f127b510b5deee7cd7 100644 (file)
@@ -780,6 +780,8 @@ libbasic_la_SOURCES = \
        src/basic/refcnt.h \
        src/basic/util.c \
        src/basic/util.h \
+       src/basic/cpu-set-util.c \
+       src/basic/cpu-set-util.h \
        src/basic/lockfile-util.c \
        src/basic/lockfile-util.h \
        src/basic/path-util.c \
diff --git a/src/basic/cpu-set-util.c b/src/basic/cpu-set-util.c
new file mode 100644 (file)
index 0000000..519583c
--- /dev/null
@@ -0,0 +1,105 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010-2015 Lennart Poettering
+  Copyright 2015 Filipe Brandenburger
+
+  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 "cpu-set-util.h"
+
+cpu_set_t* cpu_set_malloc(unsigned *ncpus) {
+        cpu_set_t *c;
+        unsigned n = 1024;
+
+        /* Allocates the cpuset in the right size */
+
+        for (;;) {
+                c = CPU_ALLOC(n);
+                if (!c)
+                        return NULL;
+
+                if (sched_getaffinity(0, CPU_ALLOC_SIZE(n), c) >= 0) {
+                        CPU_ZERO_S(CPU_ALLOC_SIZE(n), c);
+
+                        if (ncpus)
+                                *ncpus = n;
+
+                        return c;
+                }
+
+                CPU_FREE(c);
+
+                if (errno != EINVAL)
+                        return NULL;
+
+                n *= 2;
+        }
+}
+
+int parse_cpu_set_and_warn(
+                const char *rvalue,
+                cpu_set_t **cpu_set,
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *lvalue) {
+
+        const char *whole_rvalue = rvalue;
+        _cleanup_cpu_free_ cpu_set_t *c = NULL;
+        unsigned ncpus = 0;
+
+        assert(lvalue);
+        assert(rvalue);
+
+        for (;;) {
+                _cleanup_free_ char *word = NULL;
+                unsigned cpu;
+                int r;
+
+                r = extract_first_word(&rvalue, &word, WHITESPACE, EXTRACT_QUOTES);
+                if (r < 0) {
+                        log_syntax(unit, LOG_ERR, filename, line, r, "Invalid value for %s: %s", lvalue, whole_rvalue);
+                        return r;
+                }
+                if (r == 0)
+                        break;
+
+                if (!c) {
+                        c = cpu_set_malloc(&ncpus);
+                        if (!c)
+                                return log_oom();
+                }
+
+                r = safe_atou(word, &cpu);
+                if (r < 0 || cpu >= ncpus) {
+                        log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse CPU affinity '%s'", rvalue);
+                        return -EINVAL;
+                }
+
+                CPU_SET_S(cpu, CPU_ALLOC_SIZE(ncpus), c);
+        }
+
+        /* On success, sets *cpu_set and returns ncpus for the system. */
+        if (c) {
+                *cpu_set = c;
+                c = NULL;
+        }
+
+        return (int) ncpus;
+}
diff --git a/src/basic/cpu-set-util.h b/src/basic/cpu-set-util.h
new file mode 100644 (file)
index 0000000..19b457a
--- /dev/null
@@ -0,0 +1,34 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010-2015 Lennart Poettering
+  Copyright 2015 Filipe Brandenburger
+
+  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 <sched.h>
+
+#include "macro.h"
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(cpu_set_t*, CPU_FREE);
+#define _cleanup_cpu_free_ _cleanup_(CPU_FREEp)
+
+cpu_set_t* cpu_set_malloc(unsigned *ncpus);
+
+int parse_cpu_set_and_warn(const char *rvalue, cpu_set_t **cpu_set, const char *unit, const char *filename, unsigned line, const char *lvalue);
index cc50c9aa7d4f0188fc068521132f4f50582ead34..33dc410c78286a621dc4f216a63e88332b223444 100644 (file)
@@ -2551,87 +2551,6 @@ int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid) {
         return 0;
 }
 
-cpu_set_t* cpu_set_malloc(unsigned *ncpus) {
-        cpu_set_t *c;
-        unsigned n = 1024;
-
-        /* Allocates the cpuset in the right size */
-
-        for (;;) {
-                c = CPU_ALLOC(n);
-                if (!c)
-                        return NULL;
-
-                if (sched_getaffinity(0, CPU_ALLOC_SIZE(n), c) >= 0) {
-                        CPU_ZERO_S(CPU_ALLOC_SIZE(n), c);
-
-                        if (ncpus)
-                                *ncpus = n;
-
-                        return c;
-                }
-
-                CPU_FREE(c);
-
-                if (errno != EINVAL)
-                        return NULL;
-
-                n *= 2;
-        }
-}
-
-int parse_cpu_set_and_warn(
-                const char *rvalue,
-                cpu_set_t **cpu_set,
-                const char *unit,
-                const char *filename,
-                unsigned line,
-                const char *lvalue) {
-
-        const char *whole_rvalue = rvalue;
-        _cleanup_cpu_free_ cpu_set_t *c = NULL;
-        unsigned ncpus = 0;
-
-        assert(lvalue);
-        assert(rvalue);
-
-        for (;;) {
-                _cleanup_free_ char *word = NULL;
-                unsigned cpu;
-                int r;
-
-                r = extract_first_word(&rvalue, &word, WHITESPACE, EXTRACT_QUOTES);
-                if (r < 0) {
-                        log_syntax(unit, LOG_ERR, filename, line, r, "Invalid value for %s: %s", lvalue, whole_rvalue);
-                        return r;
-                }
-                if (r == 0)
-                        break;
-
-                if (!c) {
-                        c = cpu_set_malloc(&ncpus);
-                        if (!c)
-                                return log_oom();
-                }
-
-                r = safe_atou(word, &cpu);
-                if (r < 0 || cpu >= ncpus) {
-                        log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse CPU affinity '%s'", rvalue);
-                        return -EINVAL;
-                }
-
-                CPU_SET_S(cpu, CPU_ALLOC_SIZE(ncpus), c);
-        }
-
-        /* On success, sets *cpu_set and returns ncpus for the system. */
-        if (c) {
-                *cpu_set = c;
-                c = NULL;
-        }
-
-        return (int) ncpus;
-}
-
 int files_same(const char *filea, const char *fileb) {
         struct stat a, b;
 
index ff6c39aaa3a52883ea9047e9c71aaf5ee40d7ddc..a4e367213088ad83892300589a7f89eb01ff2466 100644 (file)
@@ -28,7 +28,6 @@
 #include <limits.h>
 #include <locale.h>
 #include <mntent.h>
-#include <sched.h>
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stddef.h>
@@ -371,12 +370,6 @@ int fd_is_temporary_fs(int fd);
 
 int pipe_eof(int fd);
 
-DEFINE_TRIVIAL_CLEANUP_FUNC(cpu_set_t*, CPU_FREE);
-#define _cleanup_cpu_free_ _cleanup_(CPU_FREEp)
-
-cpu_set_t* cpu_set_malloc(unsigned *ncpus);
-int parse_cpu_set_and_warn(const char *rvalue, cpu_set_t **cpu_set, const char *unit, const char *filename, unsigned line, const char *lvalue);
-
 #define xsprintf(buf, fmt, ...) \
         assert_message_se((size_t) snprintf(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__) < ELEMENTSOF(buf), \
                           "xsprintf: " #buf "[] must be big enough")
index 2d73ef49c8ad41d77b08aa6a7a6420afca0c8756..fc2755cb92eec079cfe9eb95b0f0170112863d00 100644 (file)
 #include <fcntl.h>
 #include <linux/fs.h>
 #include <linux/oom.h>
+#ifdef HAVE_SECCOMP
+#include <seccomp.h>
+#endif
 #include <sched.h>
 #include <string.h>
 #include <sys/resource.h>
 #include <sys/stat.h>
-#ifdef HAVE_SECCOMP
-#include <seccomp.h>
-#endif
 
 #include "af-list.h"
 #include "bus-error.h"
@@ -39,6 +39,7 @@
 #include "cap-list.h"
 #include "cgroup.h"
 #include "conf-parser.h"
+#include "cpu-set-util.h"
 #include "env-util.h"
 #include "errno-list.h"
 #include "ioprio.h"
index 8f682c6d101fb7bb0ddb7ce86ac8ee296b1098d6..363ffaaf05af65f7b26df9dbaa4741537af9333e 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <unistd.h>
-#include <stdio.h>
 #include <errno.h>
-#include <string.h>
 #include <fcntl.h>
+#include <sched.h>
+#include <stdio.h>
+#include <string.h>
 #include <sys/mount.h>
+#include <unistd.h>
 
-#include "systemd/sd-id128.h"
+#include "sd-id128.h"
 
-#include "machine-id-setup.h"
+#include "fileio.h"
+#include "log.h"
 #include "macro.h"
-#include "util.h"
 #include "mkdir.h"
-#include "log.h"
-#include "virt.h"
-#include "fileio.h"
 #include "path-util.h"
 #include "process-util.h"
+#include "util.h"
+#include "virt.h"
+#include "machine-id-setup.h"
 
 static int shorten_uuid(char destination[34], const char source[36]) {
         unsigned i, j;
index ee6576fb35e3e07ea0aaf7f34cc1b1f675aec765..2406832694ff5593344dae91808a988a1dd438f6 100644 (file)
@@ -47,6 +47,7 @@
 #include "capability.h"
 #include "clock-util.h"
 #include "conf-parser.h"
+#include "cpu-set-util.h"
 #include "dbus-manager.h"
 #include "def.h"
 #include "env-util.h"
index d8a3bbc2498f96220358bbcb513e0ceee86ab018..9b86dbfa7986da7b9a709d308d14da7afd1ad71f 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <sched.h>
 #include <sys/prctl.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
-#include "util.h"
 #include "btrfs-util.h"
 #include "capability.h"
 #include "signal-util.h"
+#include "util.h"
 #include "import-common.h"
 
 int import_make_read_only_fd(int fd) {
index 6d71569a26595bdcc02dc9959b1304f962046a39..6ea460d9acae193690c01a454e7ae887f9606286 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <stdlib.h>
 #include <errno.h>
-#include <unistd.h>
-
 #include <linux/veth.h>
 #include <net/if.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sched.h>
 
-#include "util.h"
 #include "sd-event.h"
-#include "event-util.h"
 #include "sd-netlink.h"
 #include "sd-pppoe.h"
+
+#include "event-util.h"
 #include "process-util.h"
+#include "util.h"
 
 static void pppoe_handler(sd_pppoe *ppp, int event, void *userdata) {
         static int pppoe_state = -1;
index 70c125172942fddd831c31fcdfd9badaf492e2a7..7de1535fb6e8e165cb403a07f808fed7caf0288b 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <string.h>
-#include <unistd.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <locale.h>
-#include <errno.h>
-#include <signal.h>
 #include <math.h>
+#include <signal.h>
+#include <string.h>
 #include <sys/wait.h>
+#include <unistd.h>
 
-#include "util.h"
-#include "mkdir.h"
-#include "rm-rf.h"
-#include "strv.h"
+#include "conf-parser.h"
+#include "cpu-set-util.h"
 #include "def.h"
 #include "fileio.h"
-#include "conf-parser.h"
-#include "virt.h"
+#include "mkdir.h"
 #include "process-util.h"
+#include "rm-rf.h"
 #include "signal-util.h"
+#include "strv.h"
+#include "util.h"
+#include "virt.h"
 
 static void test_streq_ptr(void) {
         assert_se(streq_ptr(NULL, NULL));
index 20497ae8be6b88f72c39a5ad45ed8dcde65c5d0b..e4d2f477458d33ee0b2a05de35484a64bb1c68df 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <stddef.h>
-#include <signal.h>
-#include <unistd.h>
 #include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdbool.h>
 #include <string.h>
-#include <fcntl.h>
-#include <getopt.h>
+#include <sys/epoll.h>
 #include <sys/file.h>
-#include <sys/time.h>
+#include <sys/inotify.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
 #include <sys/prctl.h>
-#include <sys/socket.h>
 #include <sys/signalfd.h>
-#include <sys/epoll.h>
-#include <sys/mount.h>
-#include <sys/wait.h>
+#include <sys/socket.h>
 #include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/inotify.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <unistd.h>
 
 #include "sd-daemon.h"
 #include "sd-event.h"
 
-#include "terminal-util.h"
-#include "signal-util.h"
-#include "event-util.h"
-#include "netlink-util.h"
 #include "cgroup-util.h"
-#include "process-util.h"
+#include "cpu-set-util.h"
 #include "dev-setup.h"
+#include "event-util.h"
 #include "fileio.h"
-#include "selinux-util.h"
-#include "udev.h"
-#include "udev-util.h"
 #include "formats-util.h"
 #include "hashmap.h"
+#include "netlink-util.h"
+#include "process-util.h"
+#include "selinux-util.h"
+#include "signal-util.h"
+#include "terminal-util.h"
+#include "udev-util.h"
+#include "udev.h"
 
 static bool arg_debug = false;
 static int arg_daemonize = false;