diff options
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/cpu-set-util.c | 1 | ||||
-rw-r--r-- | src/basic/def.h | 21 | ||||
-rw-r--r-- | src/basic/escape.c | 1 | ||||
-rw-r--r-- | src/basic/extract-word.c | 3 | ||||
-rw-r--r-- | src/basic/glob-util.c | 1 | ||||
-rw-r--r-- | src/basic/glob-util.h | 2 | ||||
-rw-r--r-- | src/basic/macro.h | 15 | ||||
-rw-r--r-- | src/basic/replace-var.c | 4 | ||||
-rw-r--r-- | src/basic/string-util.c | 2 | ||||
-rw-r--r-- | src/basic/string-util.h | 12 | ||||
-rw-r--r-- | src/basic/terminal-util.c | 2 | ||||
-rw-r--r-- | src/basic/time-util.c | 14 | ||||
-rw-r--r-- | src/basic/time-util.h | 2 | ||||
-rw-r--r-- | src/basic/unit-name.c | 2 | ||||
-rw-r--r-- | src/basic/util.h | 7 | ||||
-rw-r--r-- | src/basic/virt.c | 26 | ||||
-rw-r--r-- | src/basic/virt.h | 1 |
17 files changed, 70 insertions, 46 deletions
diff --git a/src/basic/cpu-set-util.c b/src/basic/cpu-set-util.c index 4950c66767..e2ec4ca83f 100644 --- a/src/basic/cpu-set-util.c +++ b/src/basic/cpu-set-util.c @@ -24,6 +24,7 @@ #include "cpu-set-util.h" #include "extract-word.h" #include "parse-util.h" +#include "string-util.h" #include "util.h" cpu_set_t* cpu_set_malloc(unsigned *ncpus) { diff --git a/src/basic/def.h b/src/basic/def.h index cbef137410..950f693899 100644 --- a/src/basic/def.h +++ b/src/basic/def.h @@ -43,12 +43,6 @@ #define SIGNALS_CRASH_HANDLER SIGSEGV,SIGILL,SIGFPE,SIGBUS,SIGQUIT,SIGABRT #define SIGNALS_IGNORE SIGPIPE -#define DIGITS "0123456789" -#define LOWERCASE_LETTERS "abcdefghijklmnopqrstuvwxyz" -#define UPPERCASE_LETTERS "ABCDEFGHIJKLMNOPQRSTUVWXYZ" -#define LETTERS LOWERCASE_LETTERS UPPERCASE_LETTERS -#define ALPHANUMERICAL LETTERS DIGITS - #define REBOOT_PARAM_FILE "/run/systemd/reboot-param" #ifdef HAVE_SPLIT_USR @@ -81,3 +75,18 @@ #define NOTIFY_FD_MAX 768 #define NOTIFY_BUFFER_MAX PIPE_BUF + +/* Return a nulstr for a standard cascade of configuration directories, + * suitable to pass to conf_files_list_nulstr or config_parse_many. */ +#define CONF_DIRS_NULSTR(n) \ + "/etc/" n ".d\0" \ + "/run/" n ".d\0" \ + "/usr/local/lib/" n ".d\0" \ + "/usr/lib/" n ".d\0" \ + CONF_DIR_SPLIT_USR(n) + +#ifdef HAVE_SPLIT_USR +#define CONF_DIR_SPLIT_USR(n) "/lib/" n ".d\0" +#else +#define CONF_DIR_SPLIT_USR(n) +#endif diff --git a/src/basic/escape.c b/src/basic/escape.c index add0d7795b..4815161b09 100644 --- a/src/basic/escape.c +++ b/src/basic/escape.c @@ -22,6 +22,7 @@ #include "alloc-util.h" #include "escape.h" #include "hexdecoct.h" +#include "string-util.h" #include "utf8.h" #include "util.h" diff --git a/src/basic/extract-word.c b/src/basic/extract-word.c index c0f9394fad..6721b85c0a 100644 --- a/src/basic/extract-word.c +++ b/src/basic/extract-word.c @@ -21,9 +21,10 @@ #include "alloc-util.h" #include "escape.h" +#include "extract-word.h" +#include "string-util.h" #include "utf8.h" #include "util.h" -#include "extract-word.h" int extract_first_word(const char **p, char **ret, const char *separators, ExtractFlags flags) { _cleanup_free_ char *s = NULL; diff --git a/src/basic/glob-util.c b/src/basic/glob-util.c index 112c6392e5..0bfbcb1d37 100644 --- a/src/basic/glob-util.c +++ b/src/basic/glob-util.c @@ -22,6 +22,7 @@ #include <glob.h> #include "glob-util.h" +#include "string-util.h" #include "strv.h" #include "util.h" diff --git a/src/basic/glob-util.h b/src/basic/glob-util.h index 8817df14b4..793adf4a6c 100644 --- a/src/basic/glob-util.h +++ b/src/basic/glob-util.h @@ -24,7 +24,7 @@ #include <string.h> #include "macro.h" -#include "util.h" +#include "string-util.h" int glob_exists(const char *path); int glob_extend(char ***strv, const char *path); diff --git a/src/basic/macro.h b/src/basic/macro.h index daa7c416f7..5088e6720d 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -334,21 +334,6 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) { _found; \ }) -/* Return a nulstr for a standard cascade of configuration directories, - * suitable to pass to conf_files_list_nulstr or config_parse_many. */ -#define CONF_DIRS_NULSTR(n) \ - "/etc/" n ".d\0" \ - "/run/" n ".d\0" \ - "/usr/local/lib/" n ".d\0" \ - "/usr/lib/" n ".d\0" \ - CONF_DIR_SPLIT_USR(n) - -#ifdef HAVE_SPLIT_USR -#define CONF_DIR_SPLIT_USR(n) "/lib/" n ".d\0" -#else -#define CONF_DIR_SPLIT_USR(n) -#endif - /* Define C11 thread_local attribute even on older gcc compiler * version */ #ifndef thread_local diff --git a/src/basic/replace-var.c b/src/basic/replace-var.c index 18b49a9227..bf757cbc48 100644 --- a/src/basic/replace-var.c +++ b/src/basic/replace-var.c @@ -23,9 +23,9 @@ #include "alloc-util.h" #include "macro.h" -#include "util.h" #include "replace-var.h" -#include "def.h" +#include "string-util.h" +#include "util.h" /* * Generic infrastructure for replacing @FOO@ style variables in diff --git a/src/basic/string-util.c b/src/basic/string-util.c index c3be576816..6006767daa 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -21,9 +21,9 @@ #include "alloc-util.h" #include "gunicode.h" +#include "string-util.h" #include "utf8.h" #include "util.h" -#include "string-util.h" int strcmp_ptr(const char *a, const char *b) { diff --git a/src/basic/string-util.h b/src/basic/string-util.h index 15244b8184..54f9d3058c 100644 --- a/src/basic/string-util.h +++ b/src/basic/string-util.h @@ -26,6 +26,18 @@ #include "macro.h" +/* What is interpreted as whitespace? */ +#define WHITESPACE " \t\n\r" +#define NEWLINE "\n\r" +#define QUOTES "\"\'" +#define COMMENTS "#;" +#define GLOB_CHARS "*?[" +#define DIGITS "0123456789" +#define LOWERCASE_LETTERS "abcdefghijklmnopqrstuvwxyz" +#define UPPERCASE_LETTERS "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +#define LETTERS LOWERCASE_LETTERS UPPERCASE_LETTERS +#define ALPHANUMERICAL LETTERS DIGITS + #define streq(a,b) (strcmp((a),(b)) == 0) #define strneq(a, b, n) (strncmp((a), (b), (n)) == 0) #define strcaseeq(a,b) (strcasecmp((a),(b)) == 0) diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index b96bfcb8ef..3931b03bc2 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -420,7 +420,7 @@ int acquire_terminal( assert_se(sigaction(SIGHUP, &sa_old, NULL) == 0); - /* Sometimes it makes sense to ignore TIOCSCTTY + /* Sometimes, it makes sense to ignore TIOCSCTTY * returning EPERM, i.e. when very likely we already * are have this controlling terminal. */ if (r < 0 && r == -EPERM && ignore_tiocstty_eperm) diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 9dc280efc6..e629d91cb2 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -1122,3 +1122,17 @@ time_t mktime_or_timegm(struct tm *tm, bool utc) { struct tm *localtime_or_gmtime_r(const time_t *t, struct tm *tm, bool utc) { return utc ? gmtime_r(t, tm) : localtime_r(t, tm); } + +unsigned long usec_to_jiffies(usec_t u) { + static thread_local unsigned long hz = 0; + long r; + + if (hz == 0) { + r = sysconf(_SC_CLK_TCK); + + assert(r > 0); + hz = (unsigned long) r; + } + + return DIV_ROUND_UP(u , USEC_PER_SEC / hz); +} diff --git a/src/basic/time-util.h b/src/basic/time-util.h index 417376ea96..925bf18eb2 100644 --- a/src/basic/time-util.h +++ b/src/basic/time-util.h @@ -121,3 +121,5 @@ int get_timezone(char **timezone); time_t mktime_or_timegm(struct tm *tm, bool utc); struct tm *localtime_or_gmtime_r(const time_t *t, struct tm *tm, bool utc); + +unsigned long usec_to_jiffies(usec_t usec); diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c index 0775ae7c14..710421508c 100644 --- a/src/basic/unit-name.c +++ b/src/basic/unit-name.c @@ -655,7 +655,7 @@ static char *do_escape_mangle(const char *f, UnitNameMangle allow_globs, char *t * /blah/blah is converted to blah-blah.mount, anything else is left alone, * except that @suffix is appended if a valid unit suffix is not present. * - * If @allow_globs, globs characters are preserved. Otherwise they are escaped. + * If @allow_globs, globs characters are preserved. Otherwise, they are escaped. */ int unit_name_mangle_with_suffix(const char *name, UnitNameMangle allow_globs, const char *suffix, char **ret) { char *s, *t; diff --git a/src/basic/util.h b/src/basic/util.h index a8fba372d1..d9d2f72b75 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -44,13 +44,6 @@ #include "missing.h" #include "time-util.h" -/* What is interpreted as whitespace? */ -#define WHITESPACE " \t\n\r" -#define NEWLINE "\n\r" -#define QUOTES "\"\'" -#define COMMENTS "#;" -#define GLOB_CHARS "*?[" - size_t page_size(void) _pure_; #define PAGE_ALIGN(l) ALIGN_TO((l), page_size()) diff --git a/src/basic/virt.c b/src/basic/virt.c index fb181e5b55..ff006e96c6 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -34,7 +34,7 @@ static int detect_vm_cpuid(void) { - /* Both CPUID and DMI are x86 specific interfaces... */ + /* CPUID is an x86 specific interface. */ #if defined(__i386__) || defined(__x86_64__) static const struct { @@ -144,11 +144,10 @@ static int detect_vm_device_tree(void) { } static int detect_vm_dmi(void) { - - /* Both CPUID and DMI are x86 specific interfaces... */ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) static const char *const dmi_vendors[] = { + "/sys/class/dmi/id/product_name", /* Test this before sys_vendor to detect KVM over QEMU */ "/sys/class/dmi/id/sys_vendor", "/sys/class/dmi/id/board_vendor", "/sys/class/dmi/id/bios_vendor" @@ -158,6 +157,7 @@ static int detect_vm_dmi(void) { const char *vendor; int id; } dmi_vendor_table[] = { + { "KVM", VIRTUALIZATION_KVM }, { "QEMU", VIRTUALIZATION_QEMU }, /* http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1009458 */ { "VMware", VIRTUALIZATION_VMWARE }, @@ -267,12 +267,7 @@ int detect_vm(void) { if (cached_found >= 0) return cached_found; - /* Try xen capabilities file first, if not found try - * high-level hypervisor sysfs file: - * - * https://bugs.freedesktop.org/show_bug.cgi?id=77271 */ - - r = detect_vm_xen(); + r = detect_vm_cpuid(); if (r < 0) return r; if (r != VIRTUALIZATION_NONE) @@ -284,7 +279,14 @@ int detect_vm(void) { if (r != VIRTUALIZATION_NONE) goto finish; - r = detect_vm_cpuid(); + /* x86 xen will most likely be detected by cpuid. If not (most likely + * because we're not an x86 guest), then we should try the xen capabilities + * file next. If that's not found, then we check for the high-level + * hypervisor sysfs file: + * + * https://bugs.freedesktop.org/show_bug.cgi?id=77271 */ + + r = detect_vm_xen(); if (r < 0) return r; if (r != VIRTUALIZATION_NONE) @@ -327,6 +329,7 @@ int detect_container(void) { { "lxc-libvirt", VIRTUALIZATION_LXC_LIBVIRT }, { "systemd-nspawn", VIRTUALIZATION_SYSTEMD_NSPAWN }, { "docker", VIRTUALIZATION_DOCKER }, + { "rkt", VIRTUALIZATION_RKT }, }; static thread_local int cached_found = _VIRTUALIZATION_INVALID; @@ -443,6 +446,7 @@ static const char *const virtualization_table[_VIRTUALIZATION_MAX] = { [VIRTUALIZATION_LXC] = "lxc", [VIRTUALIZATION_OPENVZ] = "openvz", [VIRTUALIZATION_DOCKER] = "docker", + [VIRTUALIZATION_RKT] = "rkt", [VIRTUALIZATION_CONTAINER_OTHER] = "container-other", }; diff --git a/src/basic/virt.h b/src/basic/virt.h index ed83608019..aca961867c 100644 --- a/src/basic/virt.h +++ b/src/basic/virt.h @@ -48,6 +48,7 @@ enum { VIRTUALIZATION_LXC, VIRTUALIZATION_OPENVZ, VIRTUALIZATION_DOCKER, + VIRTUALIZATION_RKT, VIRTUALIZATION_CONTAINER_OTHER, VIRTUALIZATION_CONTAINER_LAST = VIRTUALIZATION_CONTAINER_OTHER, |