diff options
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/cgroup-util.c | 14 | ||||
-rw-r--r-- | src/basic/def.h | 4 | ||||
-rw-r--r-- | src/basic/fileio.c | 66 | ||||
-rw-r--r-- | src/basic/fileio.h | 2 | ||||
-rw-r--r-- | src/basic/fs-util.c | 3 | ||||
-rw-r--r-- | src/basic/hashmap.c | 22 | ||||
-rw-r--r-- | src/basic/hashmap.h | 4 | ||||
-rw-r--r-- | src/basic/memfd-util.c | 2 | ||||
-rw-r--r-- | src/basic/meson.build | 3 | ||||
-rw-r--r-- | src/basic/missing.h | 22 | ||||
-rw-r--r-- | src/basic/path-util.h | 2 | ||||
-rw-r--r-- | src/basic/process-util.c | 14 | ||||
-rw-r--r-- | src/basic/random-util.c | 8 | ||||
-rw-r--r-- | src/basic/selinux-util.c | 34 | ||||
-rw-r--r-- | src/basic/set.c | 61 | ||||
-rw-r--r-- | src/basic/smack-util.c | 2 | ||||
-rw-r--r-- | src/basic/socket-util.c | 2 | ||||
-rw-r--r-- | src/basic/terminal-util.c | 4 | ||||
-rw-r--r-- | src/basic/time-util.c | 28 |
19 files changed, 194 insertions, 103 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 7d64c6a2b..630ae23a0 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -103,9 +103,12 @@ int cg_read_pid(FILE *f, pid_t *_pid) { return 1; } -int cg_read_event(const char *controller, const char *path, const char *event, - char **val) -{ +int cg_read_event( + const char *controller, + const char *path, + const char *event, + char **val) { + _cleanup_free_ char *events = NULL, *content = NULL; char *p, *line; int r; @@ -1034,7 +1037,7 @@ int cg_get_xattr(const char *controller, const char *path, const char *name, voi int cg_pid_get_path(const char *controller, pid_t pid, char **path) { _cleanup_fclose_ FILE *f = NULL; char line[LINE_MAX]; - const char *fs, *controller_str; + const char *fs, *controller_str = NULL; size_t cs = 0; int unified; @@ -2412,7 +2415,6 @@ int cg_mask_supported(CGroupMask *ret) { #if 0 /// UNNEEDED by elogind int cg_kernel_controllers(Set *controllers) { _cleanup_fclose_ FILE *f = NULL; - char buf[LINE_MAX]; int r; assert(controllers); @@ -2430,7 +2432,7 @@ int cg_kernel_controllers(Set *controllers) { } /* Ignore the header line */ - (void) fgets(buf, sizeof(buf), f); + (void) read_line(f, (size_t) -1, NULL); for (;;) { char *controller; diff --git a/src/basic/def.h b/src/basic/def.h index 1571f921b..377c0008c 100644 --- a/src/basic/def.h +++ b/src/basic/def.h @@ -55,7 +55,7 @@ #define SIGNALS_CRASH_HANDLER SIGSEGV,SIGILL,SIGFPE,SIGBUS,SIGQUIT,SIGABRT #define SIGNALS_IGNORE SIGPIPE -#ifdef HAVE_SPLIT_USR +#if HAVE_SPLIT_USR #define KBD_KEYMAP_DIRS \ "/usr/share/keymaps/\0" \ "/usr/share/kbd/keymaps/\0" \ @@ -80,7 +80,7 @@ #define NOTIFY_FD_MAX 768 #define NOTIFY_BUFFER_MAX PIPE_BUF -#ifdef HAVE_SPLIT_USR +#if HAVE_SPLIT_USR # define _CONF_PATHS_SPLIT_USR(n) "/lib/" n "\0" #else # define _CONF_PATHS_SPLIT_USR(n) diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 3990d4dce..46b8b4a69 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -53,13 +53,17 @@ #define READ_FULL_BYTES_MAX (4U*1024U*1024U) -int write_string_stream_ts(FILE *f, const char *line, bool enforce_newline, struct timespec *ts) { +int write_string_stream_ts( + FILE *f, + const char *line, + WriteStringFileFlags flags, + struct timespec *ts) { assert(f); assert(line); fputs(line, f); - if (enforce_newline && !endswith(line, "\n")) + if (!(flags & WRITE_STRING_FILE_AVOID_NEWLINE) && !endswith(line, "\n")) fputc('\n', f); if (ts) { @@ -69,10 +73,18 @@ int write_string_stream_ts(FILE *f, const char *line, bool enforce_newline, stru return -errno; } - return fflush_and_check(f); + if (flags & WRITE_STRING_FILE_SYNC) + return fflush_sync_and_check(f); + else + return fflush_and_check(f); } -static int write_string_file_atomic(const char *fn, const char *line, bool enforce_newline, bool do_fsync) { +static int write_string_file_atomic( + const char *fn, + const char *line, + WriteStringFileFlags flags, + struct timespec *ts) { + _cleanup_fclose_ FILE *f = NULL; _cleanup_free_ char *p = NULL; int r; @@ -86,22 +98,28 @@ static int write_string_file_atomic(const char *fn, const char *line, bool enfor (void) fchmod_umask(fileno(f), 0644); - r = write_string_stream(f, line, enforce_newline); - if (r >= 0 && do_fsync) - r = fflush_sync_and_check(f); + r = write_string_stream_ts(f, line, flags, ts); + if (r < 0) + goto fail; - if (r >= 0) { - if (rename(p, fn) < 0) - r = -errno; + if (rename(p, fn) < 0) { + r = -errno; + goto fail; } - if (r < 0) - (void) unlink(p); + return 0; +fail: + (void) unlink(p); return r; } -int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags flags, struct timespec *ts) { +int write_string_file_ts( + const char *fn, + const char *line, + WriteStringFileFlags flags, + struct timespec *ts) { + _cleanup_fclose_ FILE *f = NULL; int q, r; @@ -114,8 +132,7 @@ int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags if (flags & WRITE_STRING_FILE_ATOMIC) { assert(flags & WRITE_STRING_FILE_CREATE); - r = write_string_file_atomic(fn, line, !(flags & WRITE_STRING_FILE_AVOID_NEWLINE), - flags & WRITE_STRING_FILE_SYNC); + r = write_string_file_atomic(fn, line, flags, ts); if (r < 0) goto fail; @@ -148,16 +165,10 @@ int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags } } - r = write_string_stream_ts(f, line, !(flags & WRITE_STRING_FILE_AVOID_NEWLINE), ts); + r = write_string_stream_ts(f, line, flags, ts); if (r < 0) goto fail; - if (flags & WRITE_STRING_FILE_SYNC) { - r = fflush_sync_and_check(f); - if (r < 0) - return r; - } - return 0; fail: @@ -247,11 +258,11 @@ int read_full_stream(FILE *f, char **contents, size_t *size) { if (st.st_size > READ_FULL_BYTES_MAX) return -E2BIG; - /* Start with the right file size, but be prepared for - * files from /proc which generally report a file size - * of 0 */ + /* Start with the right file size, but be prepared for files from /proc which generally report a file + * size of 0. Note that we increase the size to read here by one, so that the first read attempt + * already makes us notice the EOF. */ if (st.st_size > 0) - n = st.st_size; + n = st.st_size + 1; } l = 0; @@ -264,12 +275,13 @@ int read_full_stream(FILE *f, char **contents, size_t *size) { return -ENOMEM; buf = t; + errno = 0; k = fread(buf + l, 1, n - l, f); if (k > 0) l += k; if (ferror(f)) - return -errno; + return errno > 0 ? -errno : -EIO; if (feof(f)) break; diff --git a/src/basic/fileio.h b/src/basic/fileio.h index 1160c5849..5b3d045e0 100644 --- a/src/basic/fileio.h +++ b/src/basic/fileio.h @@ -36,7 +36,7 @@ typedef enum { WRITE_STRING_FILE_SYNC = 1<<4, } WriteStringFileFlags; -int write_string_stream_ts(FILE *f, const char *line, bool enforce_newline, struct timespec *ts); +int write_string_stream_ts(FILE *f, const char *line, WriteStringFileFlags flags, struct timespec *ts); static inline int write_string_stream(FILE *f, const char *line, WriteStringFileFlags flags) { return write_string_stream_ts(f, line, flags, NULL); } diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 33467c379..9f18a42ff 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -46,6 +46,9 @@ #include "user-util.h" #include "util.h" +/// Additional includes needed by elogind +#include "process-util.h" + int unlink_noerrno(const char *path) { PROTECT_ERRNO; int r; diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index 51190b381..0a8f48d82 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -34,7 +34,7 @@ #include "strv.h" #include "util.h" -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP #include <pthread.h> #include "list.h" #endif @@ -142,7 +142,7 @@ typedef uint8_t dib_raw_t; #define DIB_FREE UINT_MAX -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP struct hashmap_debug_info { LIST_FIELDS(struct hashmap_debug_info, debug_list); unsigned max_entries; /* high watermark of n_entries */ @@ -499,7 +499,7 @@ static void base_remove_entry(HashmapBase *h, unsigned idx) { dibs = dib_raw_ptr(h); assert(dibs[idx] != DIB_RAW_FREE); -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP h->debug.rem_count++; h->debug.last_rem_idx = idx; #endif @@ -578,7 +578,7 @@ static unsigned hashmap_iterate_in_insertion_order(OrderedHashmap *h, Iterator * assert(e->p.b.key == i->next_key); } -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP i->prev_idx = idx; #endif @@ -635,7 +635,7 @@ static unsigned hashmap_iterate_in_internal_order(HashmapBase *h, Iterator *i) { } idx = i->idx; -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP i->prev_idx = idx; #endif @@ -658,7 +658,7 @@ static unsigned hashmap_iterate_entry(HashmapBase *h, Iterator *i) { return IDX_NIL; } -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP if (i->idx == IDX_FIRST) { i->put_count = h->debug.put_count; i->rem_count = h->debug.rem_count; @@ -750,7 +750,7 @@ static struct HashmapBase *hashmap_base_new(const struct hash_ops *hash_ops, enu shared_hash_key_initialized= true; } -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP h->debug.func = func; h->debug.file = file; h->debug.line = line; @@ -807,7 +807,7 @@ static void hashmap_free_no_clear(HashmapBase *h) { assert(!h->has_indirect); assert(!h->n_direct_entries); -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP assert_se(pthread_mutex_lock(&hashmap_debug_list_mutex) == 0); LIST_REMOVE(debug_list, hashmap_debug_list, &h->debug); assert_se(pthread_mutex_unlock(&hashmap_debug_list_mutex) == 0); @@ -919,7 +919,7 @@ static bool hashmap_put_robin_hood(HashmapBase *h, unsigned idx, dib_raw_t raw_dib, *dibs; unsigned dib, distance; -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP h->debug.put_count++; #endif @@ -1012,7 +1012,7 @@ static int hashmap_base_put_boldly(HashmapBase *h, unsigned idx, assert_se(hashmap_put_robin_hood(h, idx, swap) == false); n_entries_inc(h); -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP h->debug.max_entries = MAX(h->debug.max_entries, n_entries(h)); #endif @@ -1240,7 +1240,7 @@ int hashmap_replace(Hashmap *h, const void *key, void *value) { idx = bucket_scan(h, hash, key); if (idx != IDX_NIL) { e = plain_bucket_at(h, idx); -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP /* Although the key is equal, the key pointer may have changed, * and this would break our assumption for iterating. So count * this operation as incompatible with iteration. */ diff --git a/src/basic/hashmap.h b/src/basic/hashmap.h index 6d1ae48b2..c1089652d 100644 --- a/src/basic/hashmap.h +++ b/src/basic/hashmap.h @@ -58,7 +58,7 @@ typedef struct Set Set; /* Stores just keys */ typedef struct { unsigned idx; /* index of an entry to be iterated next */ const void *next_key; /* expected value of that entry's key pointer */ -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP unsigned put_count; /* hashmap's put_count recorded at start of iteration */ unsigned rem_count; /* hashmap's rem_count in previous iteration */ unsigned prev_idx; /* idx in previous iteration */ @@ -89,7 +89,7 @@ typedef struct { (Hashmap*)(h), \ (void)0) -#ifdef ENABLE_DEBUG_HASHMAP +#if ENABLE_DEBUG_HASHMAP # define HASHMAP_DEBUG_PARAMS , const char *func, const char *file, int line # define HASHMAP_DEBUG_SRC_ARGS , __func__, __FILE__, __LINE__ # define HASHMAP_DEBUG_PASS_ARGS , func, file, line diff --git a/src/basic/memfd-util.c b/src/basic/memfd-util.c index e857c040d..ad80d5662 100644 --- a/src/basic/memfd-util.c +++ b/src/basic/memfd-util.c @@ -21,7 +21,7 @@ #include <fcntl.h> #include <sys/stat.h> #include <unistd.h> -#ifdef HAVE_LINUX_MEMFD_H +#if HAVE_LINUX_MEMFD_H #include <linux/memfd.h> #endif #include <stdio.h> diff --git a/src/basic/meson.build b/src/basic/meson.build index 19e679fac..c1712f2db 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -295,6 +295,7 @@ basic_sources_plain = files(''' rm-rf.h selinux-util.c selinux-util.h + set.c set.h signal-util.c signal-util.h @@ -350,7 +351,7 @@ generate_gperfs = find_program('generate-gperfs.py') # output : 'af-list.txt', # command : [generate_af_list, cpp], # capture : true) -# +# # generate_arphrd_list = find_program('generate-arphrd-list.sh') # arphrd_list_txt = custom_target( # 'arphrd-list.txt', diff --git a/src/basic/missing.h b/src/basic/missing.h index f2f727822..7768b07e8 100644 --- a/src/basic/missing.h +++ b/src/basic/missing.h @@ -43,7 +43,7 @@ /// Additional includes needed by elogind #include "musl_missing.h" -#ifdef HAVE_AUDIT +#if HAVE_AUDIT #include <libaudit.h> #endif @@ -51,12 +51,12 @@ #include <asm/sgidefs.h> #endif -#ifdef HAVE_LINUX_BTRFS_H +#if HAVE_LINUX_BTRFS_H #include <linux/btrfs.h> #endif #if 0 /// UNNEEDED by elogind -#ifdef HAVE_LINUX_VM_SOCKETS_H +#if HAVE_LINUX_VM_SOCKETS_H #include <linux/vm_sockets.h> #else #define VMADDR_CID_ANY -1U @@ -210,7 +210,7 @@ struct sockaddr_vm { #endif #if 0 /// UNNEEDED by elogind (It can not support BTRFS at all) -#ifndef HAVE_LINUX_BTRFS_H +#if ! HAVE_LINUX_BTRFS_H struct btrfs_ioctl_vol_args { int64_t fd; char name[BTRFS_PATH_NAME_MAX + 1]; @@ -553,8 +553,8 @@ struct btrfs_ioctl_quota_ctl_args { #define MAX_HANDLE_SZ 128 #endif -#ifndef HAVE_SECURE_GETENV -# ifdef HAVE___SECURE_GETENV +#if ! HAVE_SECURE_GETENV +# if HAVE___SECURE_GETENV # define secure_getenv __secure_getenv # else # error "neither secure_getenv nor __secure_getenv are available" @@ -1117,7 +1117,7 @@ struct input_mask { #endif #endif // 0 -#ifndef HAVE_KEY_SERIAL_T +#if ! HAVE_KEY_SERIAL_T typedef int32_t key_serial_t; #endif @@ -1213,11 +1213,11 @@ typedef int32_t key_serial_t; #ifndef IF_OPER_UP #define IF_OPER_UP 6 -#ifndef HAVE_CHAR32_T +#if ! HAVE_CHAR32_T #define char32_t uint32_t #endif -#ifndef HAVE_CHAR16_T +#if ! HAVE_CHAR16_T #define char16_t uint16_t #endif @@ -1230,7 +1230,7 @@ typedef int32_t key_serial_t; #endif #if 0 /// UNNEEDED by elogind -#ifndef HAVE_STRUCT_ETHTOOL_LINK_SETTINGS +#if ! HAVE_STRUCT_ETHTOOL_LINK_SETTINGS #define ETHTOOL_GLINKSETTINGS 0x0000004c /* Get ethtool_link_settings */ #define ETHTOOL_SLINKSETTINGS 0x0000004d /* Set ethtool_link_settings */ @@ -1258,7 +1258,7 @@ struct ethtool_link_settings { #endif #endif // 0 -#ifndef HAVE_STRUCT_FIB_RULE_UID_RANGE +#if ! HAVE_STRUCT_FIB_RULE_UID_RANGE struct fib_rule_uid_range { __u32 start; diff --git a/src/basic/path-util.h b/src/basic/path-util.h index 0d162bac2..ed305e012 100644 --- a/src/basic/path-util.h +++ b/src/basic/path-util.h @@ -30,7 +30,7 @@ #define DEFAULT_PATH_NORMAL "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin" #define DEFAULT_PATH_SPLIT_USR DEFAULT_PATH_NORMAL ":/sbin:/bin" -#ifdef HAVE_SPLIT_USR +#if HAVE_SPLIT_USR # define DEFAULT_PATH DEFAULT_PATH_SPLIT_USR #else # define DEFAULT_PATH DEFAULT_PATH_NORMAL diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 62c7acfa2..708b45aa0 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -27,13 +27,14 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/mman.h> #include <sys/personality.h> #include <sys/prctl.h> #include <sys/types.h> #include <sys/wait.h> #include <syslog.h> #include <unistd.h> -#ifdef HAVE_VALGRIND_VALGRIND_H +#if HAVE_VALGRIND_VALGRIND_H #include <valgrind/valgrind.h> #endif @@ -48,6 +49,7 @@ #include "macro.h" #include "missing.h" #include "process-util.h" +//#include "raw-clone.h" #include "signal-util.h" //#include "stat-util.h" #include "string-table.h" @@ -478,7 +480,7 @@ static int get_process_id(pid_t pid, const char *field, uid_t *uid) { assert(field); assert(uid); - if (pid < 0) + if (!pid_is_valid(pid)) return -EINVAL; p = procfs_file_alloca(pid, "status"); @@ -793,7 +795,7 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value) { bool pid_is_unwaited(pid_t pid) { /* Checks whether a PID is still valid at all, including a zombie */ - if (pid < 0) + if (!pid_is_valid(pid)) return false; if (pid <= 1) /* If we or PID 1 would be dead and have been waited for, this code would not be running */ @@ -813,7 +815,7 @@ bool pid_is_alive(pid_t pid) { /* Checks whether a PID is still valid and not a zombie */ - if (pid < 0) + if (!pid_is_valid(pid)) return false; if (pid <= 1) /* If we or PID 1 would be a zombie, this code would not be running */ @@ -833,7 +835,7 @@ bool pid_is_alive(pid_t pid) { int pid_from_same_root_fs(pid_t pid) { const char *root; - if (pid < 0) + if (!pid_is_valid(pid)) return false; if (pid == 0 || pid == getpid_cached()) @@ -954,7 +956,7 @@ int opinionated_personality(unsigned long *ret) { } void valgrind_summary_hack(void) { -#ifdef HAVE_VALGRIND_VALGRIND_H +#if HAVE_VALGRIND_VALGRIND_H if (getpid_cached() == 1 && RUNNING_ON_VALGRIND) { pid_t pid; pid = raw_clone(SIGCHLD); diff --git a/src/basic/random-util.c b/src/basic/random-util.c index 42f484d68..146c8f55e 100644 --- a/src/basic/random-util.c +++ b/src/basic/random-util.c @@ -26,11 +26,11 @@ #include <linux/random.h> #include <stdint.h> -#ifdef HAVE_SYS_AUXV_H +#if HAVE_SYS_AUXV_H # include <sys/auxv.h> #endif -#ifdef USE_SYS_RANDOM_H +#if USE_SYS_RANDOM_H # include <sys/random.h> #else # include <linux/random.h> @@ -100,14 +100,14 @@ int acquire_random_bytes(void *p, size_t n, bool high_quality_required) { void initialize_srand(void) { static bool srand_called = false; unsigned x; -#ifdef HAVE_SYS_AUXV_H +#if HAVE_SYS_AUXV_H void *auxv; #endif if (srand_called) return; -#ifdef HAVE_SYS_AUXV_H +#if HAVE_SYS_AUXV_H /* The kernel provides us with 16 bytes of entropy in auxv, so let's * try to make use of that to seed the pseudo-random generator. It's * better than nothing... */ diff --git a/src/basic/selinux-util.c b/src/basic/selinux-util.c index c7a04ad76..51b807b85 100644 --- a/src/basic/selinux-util.c +++ b/src/basic/selinux-util.c @@ -26,7 +26,7 @@ #include <sys/un.h> #include <syslog.h> -#ifdef HAVE_SELINUX +#if HAVE_SELINUX #include <selinux/context.h> #include <selinux/label.h> #include <selinux/selinux.h> @@ -40,7 +40,7 @@ #include "time-util.h" #include "util.h" -#ifdef HAVE_SELINUX +#if HAVE_SELINUX DEFINE_TRIVIAL_CLEANUP_FUNC(char*, freecon); DEFINE_TRIVIAL_CLEANUP_FUNC(context_t, context_free); @@ -54,7 +54,7 @@ static struct selabel_handle *label_hnd = NULL; #endif bool mac_selinux_use(void) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX if (cached_use < 0) cached_use = is_selinux_enabled() > 0; @@ -65,7 +65,7 @@ bool mac_selinux_use(void) { } void mac_selinux_retest(void) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX cached_use = -1; #endif } @@ -73,7 +73,7 @@ void mac_selinux_retest(void) { int mac_selinux_init(void) { int r = 0; -#ifdef HAVE_SELINUX +#if HAVE_SELINUX usec_t before_timestamp, after_timestamp; struct mallinfo before_mallinfo, after_mallinfo; @@ -110,7 +110,7 @@ int mac_selinux_init(void) { void mac_selinux_finish(void) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX if (!label_hnd) return; @@ -121,7 +121,7 @@ void mac_selinux_finish(void) { int mac_selinux_fix(const char *path, bool ignore_enoent, bool ignore_erofs) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX struct stat st; int r; @@ -170,7 +170,7 @@ int mac_selinux_fix(const char *path, bool ignore_enoent, bool ignore_erofs) { #if 0 /// UNNEDED by elogind int mac_selinux_apply(const char *path, const char *label) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX if (!mac_selinux_use()) return 0; @@ -189,7 +189,7 @@ int mac_selinux_apply(const char *path, const char *label) { int mac_selinux_get_create_label_from_exe(const char *exe, char **label) { int r = -EOPNOTSUPP; -#ifdef HAVE_SELINUX +#if HAVE_SELINUX _cleanup_freecon_ char *mycon = NULL, *fcon = NULL; security_class_t sclass; @@ -221,7 +221,7 @@ int mac_selinux_get_our_label(char **label) { assert(label); -#ifdef HAVE_SELINUX +#if HAVE_SELINUX if (!mac_selinux_use()) return -EOPNOTSUPP; @@ -236,7 +236,7 @@ int mac_selinux_get_our_label(char **label) { int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *exec_label, char **label) { int r = -EOPNOTSUPP; -#ifdef HAVE_SELINUX +#if HAVE_SELINUX _cleanup_freecon_ char *mycon = NULL, *peercon = NULL, *fcon = NULL; _cleanup_context_free_ context_t pcon = NULL, bcon = NULL; security_class_t sclass; @@ -297,7 +297,7 @@ int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char * char* mac_selinux_free(char *label) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX if (!label) return NULL; @@ -314,7 +314,7 @@ char* mac_selinux_free(char *label) { int mac_selinux_create_file_prepare(const char *path, mode_t mode) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX _cleanup_freecon_ char *filecon = NULL; int r; @@ -357,7 +357,7 @@ int mac_selinux_create_file_prepare(const char *path, mode_t mode) { void mac_selinux_create_file_clear(void) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX PROTECT_ERRNO; if (!mac_selinux_use()) @@ -370,7 +370,7 @@ void mac_selinux_create_file_clear(void) { #if 0 /// UNNEEDED by elogind int mac_selinux_create_socket_prepare(const char *label) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX if (!mac_selinux_use()) return 0; @@ -389,7 +389,7 @@ int mac_selinux_create_socket_prepare(const char *label) { void mac_selinux_create_socket_clear(void) { -#ifdef HAVE_SELINUX +#if HAVE_SELINUX PROTECT_ERRNO; if (!mac_selinux_use()) @@ -403,7 +403,7 @@ int mac_selinux_bind(int fd, const struct sockaddr *addr, socklen_t addrlen) { /* Binds a socket and label its file system object according to the SELinux policy */ -#ifdef HAVE_SELINUX +#if HAVE_SELINUX _cleanup_freecon_ char *fcon = NULL; const struct sockaddr_un *un; bool context_changed = false; diff --git a/src/basic/set.c b/src/basic/set.c new file mode 100644 index 000000000..fd398b821 --- /dev/null +++ b/src/basic/set.c @@ -0,0 +1,61 @@ +/*** + This file is part of systemd. + + Copyright 2017 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 "set.h" + +int set_make(Set **ret, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS, void *add, ...) { + _cleanup_set_free_ Set *s = NULL; + int r; + + assert(ret); + + s = set_new(hash_ops HASHMAP_DEBUG_PASS_ARGS); + if (!s) + return -ENOMEM; + + if (add) { + va_list ap; + + r = set_put(s, add); + if (r < 0) + return r; + + va_start(ap, add); + + for(;;) { + void *arg = va_arg(ap, void*); + + if (!arg) + break; + + r = set_put(s, arg); + if (r < 0) { + va_end(ap); + return r; + } + } + + va_end(ap); + } + + *ret = s; + s = NULL; + + return 0; +} diff --git a/src/basic/smack-util.c b/src/basic/smack-util.c index 9bcc4a3a2..46ec68975 100644 --- a/src/basic/smack-util.c +++ b/src/basic/smack-util.c @@ -35,7 +35,7 @@ #include "string-table.h" #include "xattr-util.h" -#ifdef HAVE_SMACK +#if HAVE_SMACK bool mac_smack_use(void) { static int cached_use = -1; diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index fec5ee12e..3d622bb1c 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -48,7 +48,7 @@ #include "util.h" #if 0 /// UNNEEDED by elogind -#ifdef ENABLE_IDN +#if ENABLE_IDN # define IDN_FLAGS (NI_IDN|NI_IDN_USE_STD3_ASCII_RULES) #else # define IDN_FLAGS 0 diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index b83e778b2..d205870c2 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -47,7 +47,6 @@ #include "log.h" #include "macro.h" #include "parse-util.h" -#include "path-util.h" #include "process-util.h" #include "socket-util.h" #include "stat-util.h" @@ -57,6 +56,9 @@ #include "time-util.h" #include "util.h" +/// Additional includes needed by elogind +#include "path-util.h" + static volatile unsigned cached_columns = 0; static volatile unsigned cached_lines = 0; diff --git a/src/basic/time-util.c b/src/basic/time-util.c index f0b9cc183..fc94c945e 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -861,11 +861,11 @@ parse_usec: } from_tm: - x = mktime_or_timegm(&tm, utc); - if (x < 0) + if (weekday >= 0 && tm.tm_wday != weekday) return -EINVAL; - if (weekday >= 0 && tm.tm_wday != weekday) + x = mktime_or_timegm(&tm, utc); + if (x < 0) return -EINVAL; ret = (usec_t) x * USEC_PER_SEC + x_usec; @@ -895,20 +895,18 @@ typedef struct ParseTimestampResult { } ParseTimestampResult; int parse_timestamp(const char *t, usec_t *usec) { - char *last_space, *timezone = NULL; + char *last_space, *tz = NULL; ParseTimestampResult *shared, tmp; int r; pid_t pid; last_space = strrchr(t, ' '); if (last_space != NULL && timezone_is_valid(last_space + 1)) - timezone = last_space + 1; + tz = last_space + 1; - if (timezone == NULL || endswith_no_case(t, " UTC")) + if (tz == NULL || endswith_no_case(t, " UTC")) return parse_timestamp_impl(t, usec, false); - t = strndupa(t, last_space - t); - shared = mmap(NULL, sizeof *shared, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0); if (shared == MAP_FAILED) return negative_errno(); @@ -922,14 +920,24 @@ int parse_timestamp(const char *t, usec_t *usec) { } if (pid == 0) { - if (setenv("TZ", timezone, 1) != 0) { + bool with_tz = true; + + if (setenv("TZ", tz, 1) != 0) { shared->return_value = negative_errno(); _exit(EXIT_FAILURE); } tzset(); - shared->return_value = parse_timestamp_impl(t, &shared->usec, true); + /* If there is a timezone that matches the tzname fields, leave the parsing to the implementation. + * Otherwise just cut it off */ + with_tz = !STR_IN_SET(tz, tzname[0], tzname[1]); + + /*cut off the timezone if we dont need it*/ + if (with_tz) + t = strndupa(t, last_space - t); + + shared->return_value = parse_timestamp_impl(t, &shared->usec, with_tz); _exit(EXIT_SUCCESS); } |