From 1a7523a8c73ff91109c459da6f0af2fd3585e1e7 Mon Sep 17 00:00:00 2001 From: Sven Eden Date: Tue, 14 Aug 2018 18:39:33 +0200 Subject: [PATCH] Prep v239: Add missing updates that evaded migration. --- man/sd-bus.xml | 2 - man/sd_bus_creds_get_pid.xml | 2 - man/sd_bus_creds_new_from_pid.xml | 2 - man/sd_bus_default.xml | 2 - man/sd_bus_error.xml | 2 - man/sd_bus_message_append.xml | 2 - man/sd_bus_message_append_array.xml | 2 - man/sd_bus_message_append_basic.xml | 2 - man/sd_bus_message_append_string_memfd.xml | 2 - man/sd_bus_message_append_strv.xml | 2 - man/sd_bus_new.xml | 2 - man/sd_bus_path_encode.xml | 2 - man/sd_event_add_child.xml | 2 - man/sd_event_add_defer.xml | 2 - man/sd_event_add_inotify.xml | 10 +++++ man/sd_event_add_signal.xml | 2 - man/sd_event_get_fd.xml | 2 - man/sd_event_run.xml | 2 - man/sd_event_source_set_description.xml | 2 - man/sd_event_wait.xml | 2 - src/basic/cgroup-util.c | 2 +- src/basic/copy.c | 48 ++++++++++++++++------ src/basic/fileio.c | 22 ++++++---- src/basic/fs-util.c | 16 ++++++++ src/basic/fs-util.h | 1 + src/basic/log.h | 1 - src/basic/selinux-util.h | 2 +- src/basic/user-util.c | 2 + src/basic/user-util.h | 2 + src/libelogind/libelogind.pc.in | 4 +- src/login/logind-dbus.c | 6 +++ src/login/logind-gperf.gperf | 8 ++-- src/login/logind-user.c | 6 --- src/systemd/sd-event.h | 2 +- src/test/test-bus-util.c | 43 +++++++++++++++++++ src/test/test-fd-util.c | 4 ++ src/test/test-string-util.c | 4 -- tools/make-directive-index.py | 2 - tools/make-man-index.py | 2 - 39 files changed, 144 insertions(+), 81 deletions(-) diff --git a/man/sd-bus.xml b/man/sd-bus.xml index f7a959cb1..95e0e227b 100644 --- a/man/sd-bus.xml +++ b/man/sd-bus.xml @@ -4,8 +4,6 @@ diff --git a/man/sd_bus_creds_get_pid.xml b/man/sd_bus_creds_get_pid.xml index fd5fe1c54..d1bda1127 100644 --- a/man/sd_bus_creds_get_pid.xml +++ b/man/sd_bus_creds_get_pid.xml @@ -4,8 +4,6 @@ diff --git a/man/sd_bus_creds_new_from_pid.xml b/man/sd_bus_creds_new_from_pid.xml index ee3d4e171..dd9add13d 100644 --- a/man/sd_bus_creds_new_from_pid.xml +++ b/man/sd_bus_creds_new_from_pid.xml @@ -4,8 +4,6 @@ diff --git a/man/sd_bus_default.xml b/man/sd_bus_default.xml index c4e13a836..548e053b8 100644 --- a/man/sd_bus_default.xml +++ b/man/sd_bus_default.xml @@ -4,8 +4,6 @@ diff --git a/man/sd_bus_error.xml b/man/sd_bus_error.xml index 31be55fc9..070032bfe 100644 --- a/man/sd_bus_error.xml +++ b/man/sd_bus_error.xml @@ -4,8 +4,6 @@ diff --git a/man/sd_bus_message_append.xml b/man/sd_bus_message_append.xml index 9a040f991..ff3428a39 100644 --- a/man/sd_bus_message_append.xml +++ b/man/sd_bus_message_append.xml @@ -4,8 +4,6 @@ diff --git a/man/sd_bus_message_append_string_memfd.xml b/man/sd_bus_message_append_string_memfd.xml index 8b7e37194..f2de80abf 100644 --- a/man/sd_bus_message_append_string_memfd.xml +++ b/man/sd_bus_message_append_string_memfd.xml @@ -4,8 +4,6 @@ diff --git a/man/sd_bus_path_encode.xml b/man/sd_bus_path_encode.xml index 5464e96cd..d0a16ebfc 100644 --- a/man/sd_bus_path_encode.xml +++ b/man/sd_bus_path_encode.xml @@ -4,8 +4,6 @@ diff --git a/man/sd_event_add_child.xml b/man/sd_event_add_child.xml index ed461a1d9..6ec9a8f1d 100644 --- a/man/sd_event_add_child.xml +++ b/man/sd_event_add_child.xml @@ -4,8 +4,6 @@ diff --git a/man/sd_event_add_defer.xml b/man/sd_event_add_defer.xml index 76c7a74cb..a48793cf2 100644 --- a/man/sd_event_add_defer.xml +++ b/man/sd_event_add_defer.xml @@ -4,8 +4,6 @@ diff --git a/man/sd_event_add_inotify.xml b/man/sd_event_add_inotify.xml index ded7a53bf..79d866bf6 100644 --- a/man/sd_event_add_inotify.xml +++ b/man/sd_event_add_inotify.xml @@ -156,6 +156,16 @@ + + Examples + + + A simple program that uses inotify to monitor one or two directories + + + + + See Also diff --git a/man/sd_event_add_signal.xml b/man/sd_event_add_signal.xml index a82de268f..4c715dff7 100644 --- a/man/sd_event_add_signal.xml +++ b/man/sd_event_add_signal.xml @@ -4,8 +4,6 @@ diff --git a/man/sd_event_get_fd.xml b/man/sd_event_get_fd.xml index 8dcfde807..61fb83ce6 100644 --- a/man/sd_event_get_fd.xml +++ b/man/sd_event_get_fd.xml @@ -4,8 +4,6 @@ diff --git a/man/sd_event_run.xml b/man/sd_event_run.xml index 2b163e7ff..988eefa1b 100644 --- a/man/sd_event_run.xml +++ b/man/sd_event_run.xml @@ -4,8 +4,6 @@ diff --git a/man/sd_event_source_set_description.xml b/man/sd_event_source_set_description.xml index af9ca284b..c83396cca 100644 --- a/man/sd_event_source_set_description.xml +++ b/man/sd_event_source_set_description.xml @@ -4,8 +4,6 @@ diff --git a/man/sd_event_wait.xml b/man/sd_event_wait.xml index 9e2879fb7..6fb04661f 100644 --- a/man/sd_event_wait.xml +++ b/man/sd_event_wait.xml @@ -4,8 +4,6 @@ diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 1994104e6..dd2f3e866 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -1807,7 +1807,7 @@ int cg_path_get_owner_uid(const char *path, uid_t *uid) { #else p = strappend("/run/systemd/sessions/", slice); - r = parse_env_file(p, NEWLINE, "UID", &s, NULL); + r = parse_env_file(NULL, p, NEWLINE, "UID", &s, NULL); if (r == -ENOENT) return -ENXIO; if (r < 0) diff --git a/src/basic/copy.c b/src/basic/copy.c index 55b90bc47..1b1e512b8 100644 --- a/src/basic/copy.c +++ b/src/basic/copy.c @@ -716,31 +716,55 @@ int copy_file(const char *from, const char *to, int flags, mode_t mode, unsigned } int copy_file_atomic(const char *from, const char *to, mode_t mode, unsigned chattr_flags, CopyFlags copy_flags) { - _cleanup_free_ char *t = NULL; + _cleanup_(unlink_and_freep) char *t = NULL; + _cleanup_close_ int fdt = -1; int r; assert(from); assert(to); - r = tempfn_random(to, NULL, &t); - if (r < 0) - return r; + /* We try to use O_TMPFILE here to create the file if we can. Note that that only works if COPY_REPLACE is not + * set though as we need to use linkat() for linking the O_TMPFILE file into the file system but that system + * call can't replace existing files. Hence, if COPY_REPLACE is set we create a temporary name in the file + * system right-away and unconditionally which we then can renameat() to the right name after we completed + * writing it. */ + + if (copy_flags & COPY_REPLACE) { + r = tempfn_random(to, NULL, &t); + if (r < 0) + return r; + + fdt = open(t, O_CREAT|O_EXCL|O_NOFOLLOW|O_NOCTTY|O_WRONLY|O_CLOEXEC, 0600); + if (fdt < 0) { + t = mfree(t); + return -errno; + } + } else { + fdt = open_tmpfile_linkable(to, O_WRONLY|O_CLOEXEC, &t); + if (fdt < 0) + return fdt; + } - r = copy_file(from, t, O_NOFOLLOW|O_EXCL, mode, chattr_flags, copy_flags); + if (chattr_flags != 0) + (void) chattr_fd(fdt, chattr_flags, (unsigned) -1); + + r = copy_file_fd(from, fdt, copy_flags); if (r < 0) return r; + if (fchmod(fdt, mode) < 0) + return -errno; + if (copy_flags & COPY_REPLACE) { - r = renameat(AT_FDCWD, t, AT_FDCWD, to); + if (renameat(AT_FDCWD, t, AT_FDCWD, to) < 0) + return -errno; + } else { + r = link_tmpfile(fdt, t, to); if (r < 0) - r = -errno; - } else - r = rename_noreplace(AT_FDCWD, t, AT_FDCWD, to); - if (r < 0) { - (void) unlink(t); - return r; + return r; } + t = mfree(t); return 0; } diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 60573f2ef..1cee6d495 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -1566,21 +1566,29 @@ int read_nul_string(FILE *f, char **ret) { } int mkdtemp_malloc(const char *template, char **ret) { - char *p; + _cleanup_free_ char *p = NULL; + int r; - assert(template); assert(ret); - p = strdup(template); + if (template) + p = strdup(template); + else { + const char *tmp; + + r = tmp_dir(&tmp); + if (r < 0) + return r; + + p = strjoin(tmp, "/XXXXXX"); + } if (!p) return -ENOMEM; - if (!mkdtemp(p)) { - free(p); + if (!mkdtemp(p)) return -errno; - } - *ret = p; + *ret = TAKE_PTR(p); return 0; } #endif // 0 diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 942f43ae9..5a9b1c950 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -234,6 +234,22 @@ int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid) { return 0; } +int fchmod_and_chown(int fd, mode_t mode, uid_t uid, gid_t gid) { + /* Under the assumption that we are running privileged we + * first change the access mode and only then hand out + * ownership to avoid a window where access is too open. */ + + if (mode != MODE_INVALID) + if (fchmod(fd, mode) < 0) + return -errno; + + if (uid != UID_INVALID || gid != GID_INVALID) + if (fchown(fd, uid, gid) < 0) + return -errno; + + return 0; +} + int fchmod_umask(int fd, mode_t m) { mode_t u; int r; diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h index 6cb7345f5..e7ca03968 100644 --- a/src/basic/fs-util.h +++ b/src/basic/fs-util.h @@ -31,6 +31,7 @@ int readlink_and_make_absolute(const char *p, char **r); #endif // 0 int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid); +int fchmod_and_chown(int fd, mode_t mode, uid_t uid, gid_t gid); int fchmod_umask(int fd, mode_t mode); int fchmod_opath(int fd, mode_t m); diff --git a/src/basic/log.h b/src/basic/log.h index 5b5dfe8b5..e4caece30 100644 --- a/src/basic/log.h +++ b/src/basic/log.h @@ -246,7 +246,6 @@ int log_emergency_level(void); /* Structured logging */ #define log_struct_errno(level, error, ...) \ log_struct_internal(LOG_REALM_PLUS_LEVEL(LOG_REALM, level), \ - error, __FILE__, __LINE__, __func__, __VA_ARGS__) error, __FILE__, __LINE__, __func__, __VA_ARGS__, NULL) #define log_struct(level, ...) log_struct_errno(level, 0, __VA_ARGS__) diff --git a/src/basic/selinux-util.h b/src/basic/selinux-util.h index bba623e57..b2a0d6dd4 100644 --- a/src/basic/selinux-util.h +++ b/src/basic/selinux-util.h @@ -6,7 +6,7 @@ #include #include "macro.h" -//#include "label.h" +#include "label.h" bool mac_selinux_use(void); void mac_selinux_retest(void); diff --git a/src/basic/user-util.c b/src/basic/user-util.c index 6218c6fed..7bc5ba7e0 100644 --- a/src/basic/user-util.c +++ b/src/basic/user-util.c @@ -724,6 +724,7 @@ bool synthesize_nobody(void) { #endif } +#if 0 /// UNNEEDED by elogind int putpwent_sane(const struct passwd *pw, FILE *stream) { assert(pw); assert(stream); @@ -831,3 +832,4 @@ int fgetsgent_sane(FILE *stream, struct sgrp **sg) { return !!s; } #endif +#endif // 0 diff --git a/src/basic/user-util.h b/src/basic/user-util.h index bd6d8d3c4..14a4d180c 100644 --- a/src/basic/user-util.h +++ b/src/basic/user-util.h @@ -106,6 +106,7 @@ int maybe_setgroups(size_t size, const gid_t *list); bool synthesize_nobody(void); +#if 0 /// UNNEEDED by elogind int fgetpwent_sane(FILE *stream, struct passwd **pw); int fgetspent_sane(FILE *stream, struct spwd **sp); int fgetgrent_sane(FILE *stream, struct group **gr); @@ -116,3 +117,4 @@ int putgrent_sane(const struct group *gr, FILE *stream); int fgetsgent_sane(FILE *stream, struct sgrp **sg); int putsgent_sane(const struct sgrp *sg, FILE *stream); #endif +#endif // 0 diff --git a/src/libelogind/libelogind.pc.in b/src/libelogind/libelogind.pc.in index 64e34a3d1..2fd18b983 100644 --- a/src/libelogind/libelogind.pc.in +++ b/src/libelogind/libelogind.pc.in @@ -1,8 +1,8 @@ -# This file is part of elogind. # SPDX-License-Identifier: LGPL-2.1+ # -# elogind is free software; you can redistribute it and/or modify it +# This file is part of elogind. # +# elogind 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. diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 7706c408e..f9d0b1c9f 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -2367,6 +2367,7 @@ static int method_can_shutdown_or_sleep( const char *target; target = manager_target_for_action(handle); +#if 0 /// elogind does not support systemd units units. A valid handle is enough if (target) { _cleanup_free_ char *load_state = NULL; @@ -2375,9 +2376,14 @@ static int method_can_shutdown_or_sleep( return r; if (!streq(load_state, "loaded")) { +#else + if (NULL == target) { +#endif // 0 result = "no"; goto finish; +#if 0 /// one less with elogind... } +#endif // 0 } } diff --git a/src/login/logind-gperf.gperf b/src/login/logind-gperf.gperf index 90c346b92..80e9e8c20 100644 --- a/src/login/logind-gperf.gperf +++ b/src/login/logind-gperf.gperf @@ -17,8 +17,6 @@ struct ConfigPerfItem; %struct-type %includes %% -#if 0 /// UNNEEDED by elogind -#endif // 0 #if 1 /// Additions for elogind Sleep.SuspendMode, config_parse_strv, 0, offsetof(Manager, suspend_mode) Sleep.SuspendState, config_parse_strv, 0, offsetof(Manager, suspend_state) @@ -27,8 +25,10 @@ Sleep.HibernateState, config_parse_strv, 0, offsetof(Manag Sleep.HybridSleepMode, config_parse_strv, 0, offsetof(Manager, hybrid_sleep_mode) Sleep.HybridSleepState, config_parse_strv, 0, offsetof(Manager, hybrid_sleep_state) #endif // 1 -Login.NAutoVTs, config_parse_n_autovts, 0, offsetof(Manager, n_autovts) -Login.ReserveVT, config_parse_unsigned, 0, offsetof(Manager, reserve_vt) +#if 0 /// UNNEEDED by elogind +# Login.NAutoVTs, config_parse_n_autovts, 0, offsetof(Manager, n_autovts) +# Login.ReserveVT, config_parse_unsigned, 0, offsetof(Manager, reserve_vt) +#endif // 0 Login.KillUserProcesses, config_parse_bool, 0, offsetof(Manager, kill_user_processes) Login.KillOnlyUsers, config_parse_strv, 0, offsetof(Manager, kill_only_users) Login.KillExcludeUsers, config_parse_strv, 0, offsetof(Manager, kill_exclude_users) diff --git a/src/login/logind-user.c b/src/login/logind-user.c index c5a49e1b6..60e862e3b 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -317,12 +317,6 @@ int user_load(User *u) { } -#if 0 /// elogind can not ask systemd via dbus to start user services -#else - assert(u); - - hashmap_put(u->manager->user_units, u->slice, u); -#endif // 0 static int user_start_service(User *u) { #if 0 /// elogind can not ask systemd via dbus to start user services _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h index ea1f313b0..e6f2c50a8 100644 --- a/src/systemd/sd-event.h +++ b/src/systemd/sd-event.h @@ -21,7 +21,7 @@ #include #include #include -//#include +#include #include #include /*#include */ diff --git a/src/test/test-bus-util.c b/src/test/test-bus-util.c index 608052be1..a320a0d78 100644 --- a/src/test/test-bus-util.c +++ b/src/test/test-bus-util.c @@ -35,6 +35,48 @@ static void test_name_async(unsigned n_messages) { } } +static int callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { + return 1; +} + +static void destroy_callback(void *userdata) { + int *n_called = userdata; + + (*n_called) ++; +} + +static void test_destroy_callback(void) { + _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; + sd_bus_slot *slot = NULL; + sd_bus_destroy_t t; + + int r, n_called = 0; + + log_info("/* %s */", __func__); + + r = bus_open_system_watch_bind_with_description(&bus, "test-bus"); + if (r < 0) { + log_error_errno(r, "Failed to connect to bus: %m"); + return; + } + + r = sd_bus_request_name_async(bus, &slot, "org.freedesktop.elogind.test-bus-util", 0, callback, &n_called); + assert(r == 1); + + assert_se(sd_bus_slot_get_destroy_callback(slot, NULL) == 0); + assert_se(sd_bus_slot_get_destroy_callback(slot, &t) == 0); + + assert_se(sd_bus_slot_set_destroy_callback(slot, destroy_callback) == 0); + assert_se(sd_bus_slot_get_destroy_callback(slot, NULL) == 1); + assert_se(sd_bus_slot_get_destroy_callback(slot, &t) == 1); + assert_se(t == destroy_callback); + + /* Force cleanup so we can look at n_called */ + assert(n_called == 0); + sd_bus_slot_unref(slot); + assert(n_called == 1); +} + int main(int argc, char **argv) { log_set_max_level(LOG_DEBUG); log_parse_environment(); @@ -42,6 +84,7 @@ int main(int argc, char **argv) { test_name_async(0); test_name_async(20); + test_destroy_callback(); return 0; } diff --git a/src/test/test-fd-util.c b/src/test/test-fd-util.c index 2b6cd0511..4328442ad 100644 --- a/src/test/test-fd-util.c +++ b/src/test/test-fd-util.c @@ -246,6 +246,7 @@ static void assert_equal_fd(int fd1, int fd2) { } } +#if 0 /// UNNEEDED by elogind static void test_fd_duplicate_data_fd(void) { _cleanup_close_ int fd1 = -1, fd2 = -1; _cleanup_(close_pairp) int sfd[2] = { -1, -1 }; @@ -311,6 +312,7 @@ static void test_fd_duplicate_data_fd(void) { assert_se(read(fd2, &j, sizeof(j)) == 0); } +#endif // 0 static void test_read_nr_open(void) { log_info("nr-open: %i", read_nr_open()); @@ -329,7 +331,9 @@ int main(int argc, char *argv[]) { test_acquire_data_fd(); test_fd_move_above_stdio(); test_rearrange_stdio(); +#if 0 /// UNNEEDED by elogind test_fd_duplicate_data_fd(); +#endif // 0 test_read_nr_open(); return 0; diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index 7860499b7..47032729e 100644 --- a/src/test/test-string-util.c +++ b/src/test/test-string-util.c @@ -431,7 +431,6 @@ static void test_delete_trailing_slashes(void) { assert_se(streq(delete_trailing_chars(s4, "/"), "")); } -#if 0 /// UNNEEDED by elogind static void test_skip_leading_chars(void) { char input1[] = " \n \r k \n \r ", input2[] = "kkkkthiskkkiskkkaktestkkk", @@ -443,7 +442,6 @@ static void test_skip_leading_chars(void) { assert_se(streq(skip_leading_chars(input3, WHITESPACE), "abcdef")); assert_se(streq(skip_leading_chars(input3, "bcaef"), "def")); } -#endif // 0 static void test_in_charset(void) { assert_se(in_charset("dddaaabbbcccc", "abcd")); @@ -533,9 +531,7 @@ int main(int argc, char *argv[]) { #endif // 0 test_delete_trailing_chars(); test_delete_trailing_slashes(); -#if 0 /// UNNEEDED by elogind test_skip_leading_chars(); -#endif // 0 test_in_charset(); test_split_pair(); test_first_word(); diff --git a/tools/make-directive-index.py b/tools/make-directive-index.py index ef407324d..620a67e97 100755 --- a/tools/make-directive-index.py +++ b/tools/make-directive-index.py @@ -1,8 +1,6 @@ #!/usr/bin/env python3 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # SPDX-License-Identifier: LGPL-2.1+ -# -# Copyright © 2012-2013 Zbigniew Jędrzejewski-Szmek import sys import collections diff --git a/tools/make-man-index.py b/tools/make-man-index.py index 70c02a8d7..246ce5f8e 100755 --- a/tools/make-man-index.py +++ b/tools/make-man-index.py @@ -1,8 +1,6 @@ #!/usr/bin/env python3 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */ # SPDX-License-Identifier: LGPL-2.1+ -# -# Copyright © 2013 Zbigniew Jędrzejewski-Szmek import collections import sys -- 2.30.2