chiark / gitweb /
Prep v228: Add remaining updates from upstream (3/3)
authorSven Eden <yamakuzure@gmx.net>
Thu, 6 Apr 2017 12:56:03 +0000 (14:56 +0200)
committerSven Eden <yamakuzure@gmx.net>
Wed, 26 Apr 2017 10:59:13 +0000 (12:59 +0200)
Apply remaining fixes and the performed move of utility functions
into their own foo-util.[hc] files on the rest of elogind.

60 files changed:
src/cgroups-agent/cgroups-agent.c
src/core/cgroup.c
src/core/cgroup.h
src/core/mount-setup.c
src/libelogind/sd-bus/bus-bloom.c
src/libelogind/sd-bus/bus-container.c
src/libelogind/sd-bus/bus-control.c
src/libelogind/sd-bus/bus-convenience.c
src/libelogind/sd-bus/bus-creds.c
src/libelogind/sd-bus/bus-error.c
src/libelogind/sd-bus/bus-internal.c
src/libelogind/sd-bus/bus-internal.h
src/libelogind/sd-bus/bus-introspect.c
src/libelogind/sd-bus/bus-kernel.c
src/libelogind/sd-bus/bus-match.c
src/libelogind/sd-bus/bus-match.h
src/libelogind/sd-bus/bus-message.c
src/libelogind/sd-bus/bus-message.h
src/libelogind/sd-bus/bus-objects.c
src/libelogind/sd-bus/bus-slot.c
src/libelogind/sd-bus/bus-socket.c
src/libelogind/sd-bus/bus-track.c
src/libelogind/sd-bus/sd-bus.c
src/libelogind/sd-daemon/sd-daemon.c
src/libelogind/sd-event/sd-event.c
src/libelogind/sd-id128/sd-id128.c
src/libelogind/sd-login/sd-login.c
src/libelogind/sd-login/test-login.c
src/login/inhibit.c
src/login/loginctl.c
src/login/logind-acl.c
src/login/logind-action.c
src/login/logind-action.h
src/login/logind-button.c
src/login/logind-core.c
src/login/logind-dbus.c
src/login/logind-device.c
src/login/logind-inhibit.c
src/login/logind-seat-dbus.c
src/login/logind-seat.c
src/login/logind-session-dbus.c
src/login/logind-session-device.c
src/login/logind-session.c
src/login/logind-user-dbus.c
src/login/logind-user.c
src/login/logind-user.h
src/login/logind-utmp.c
src/login/logind.c
src/login/logind.h
src/login/pam_elogind.c
src/login/sysfs-show.c
src/login/test-inhibit.c
src/shared/bus-util.c
src/shared/bus-util.h
src/shared/cgroup-show.c [new file with mode: 0644]
src/shared/clean-ipc.c
src/shared/conf-parser.c
src/shared/pager.c
src/shared/sleep-config.c
src/shared/spawn-polkit-agent.c

index 0e0ca77b3f4ae43bb788d9b4089b8161043380d0..f0371f23ee144953b44e347ab327b2fbf9709f56 100644 (file)
@@ -22,8 +22,9 @@
 #include <stdlib.h>
 
 #include "sd-bus.h"
 #include <stdlib.h>
 
 #include "sd-bus.h"
-#include "log.h"
 #include "bus-util.h"
 #include "bus-util.h"
+#include "musl_missing.h"
+#include "log.h"
 
 int main(int argc, char *argv[]) {
         _cleanup_bus_flush_close_unref_ sd_bus *bus = NULL;
 
 int main(int argc, char *argv[]) {
         _cleanup_bus_flush_close_unref_ sd_bus *bus = NULL;
index 792f0d9119936402f2a178980c4504b84f5601e2..b18940f824e67a6fbf33fd465130dd03cc40a8a7 100644 (file)
 #include <fcntl.h>
 #include <fnmatch.h>
 
 #include <fcntl.h>
 #include <fnmatch.h>
 
+#include "alloc-util.h"
 #include "cgroup-util.h"
 #include "cgroup-util.h"
+#include "cgroup.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "fs-util.h"
+#include "parse-util.h"
 #include "path-util.h"
 #include "process-util.h"
 //#include "special.h"
 #include "path-util.h"
 #include "process-util.h"
 //#include "special.h"
-
-#include "cgroup.h"
+#include "string-table.h"
+#include "string-util.h"
 
 #define CGROUP_CPU_QUOTA_PERIOD_USEC ((usec_t) 100 * USEC_PER_MSEC)
 
 
 #define CGROUP_CPU_QUOTA_PERIOD_USEC ((usec_t) 100 * USEC_PER_MSEC)
 
@@ -1205,7 +1211,7 @@ int unit_search_main_pid(Unit *u, pid_t *ret) {
                         continue;
 
                 /* Ignore processes that aren't our kids */
                         continue;
 
                 /* Ignore processes that aren't our kids */
-                if (get_parent_of_pid(npid, &ppid) >= 0 && ppid != mypid)
+                if (get_process_ppid(npid, &ppid) >= 0 && ppid != mypid)
                         continue;
 
                 if (pid != 0)
                         continue;
 
                 if (pid != 0)
index 29782c58cc142bdf7831377d2f9540f3c401e734..6bef26c481ee04e6f4da50c7d6572ec6255acc6a 100644 (file)
@@ -96,6 +96,7 @@ struct CGroupContext {
         bool cpu_accounting;
         bool blockio_accounting;
         bool memory_accounting;
         bool cpu_accounting;
         bool blockio_accounting;
         bool memory_accounting;
+        bool tasks_accounting;
 
         uint64_t cpu_shares;
         uint64_t startup_cpu_shares;
 
         uint64_t cpu_shares;
         uint64_t startup_cpu_shares;
@@ -126,7 +127,7 @@ struct CGroupContext {
 // UNNNEEDE void cgroup_context_init(CGroupContext *c);
 // UNNEEDED void cgroup_context_done(CGroupContext *c);
 // UNNEEDED void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix);
 // UNNNEEDE void cgroup_context_init(CGroupContext *c);
 // UNNEEDED void cgroup_context_done(CGroupContext *c);
 // UNNEEDED void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix);
-// UNNEEDED void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, ManagerState state);
+// UNNEEDED void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, uint32_t netclass_id, ManagerState state);
 
 // UNNEEDED CGroupMask cgroup_context_get_mask(CGroupContext *c);
 
 
 // UNNEEDED CGroupMask cgroup_context_get_mask(CGroupContext *c);
 
index 9dfa77823d8efbccacc586cf67ff53cc5a5d37da..f30adabbf07137ddb49d4f1f4a1fa4b8e25fcd1e 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <sys/mount.h>
 #include <errno.h>
 #include <errno.h>
+#include <ftw.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <sys/mount.h>
 #include <unistd.h>
 #include <unistd.h>
-#include <ftw.h>
 
 
-#include "mount-setup.h"
-//#include "dev-setup.h"
+#include "alloc-util.h"
 //#include "bus-util.h"
 //#include "bus-util.h"
+#include "cgroup-util.h"
+//#include "dev-setup.h"
+//#include "efivars.h"
+#include "label.h"
 //#include "log.h"
 #include "macro.h"
 //#include "log.h"
 #include "macro.h"
-//#include "util.h"
-#include "label.h"
-//#include "set.h"
-//#include "strv.h"
+//#include "missing.h"
 #include "mkdir.h"
 #include "mkdir.h"
+#include "mount-setup.h"
+#include "mount-util.h"
 #include "path-util.h"
 #include "path-util.h"
-//#include "missing.h"
-#include "virt.h"
-//#include "efivars.h"
+//#include "set.h"
 //#include "smack-util.h"
 //#include "smack-util.h"
-#include "cgroup-util.h"
+//#include "strv.h"
+#include "string-util.h"
+#include "user-util.h"
+//#include "util.h"
+#include "virt.h"
 
 typedef enum MountMode {
         MNT_NONE  =        0,
 
 typedef enum MountMode {
         MNT_NONE  =        0,
index 91fab90cb0b8a2e4bda5432af88b6a1684aab32b..c0c5d445eb265566d869625d402ed78841390890 100644 (file)
@@ -19,9 +19,9 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "util.h"
-#include "siphash24.h"
 #include "bus-bloom.h"
 #include "bus-bloom.h"
+#include "siphash24.h"
+#include "util.h"
 
 static inline void set_bit(uint64_t filter[], unsigned long b) {
         filter[b >> 6] |= 1ULL << (b & 63);
 
 static inline void set_bit(uint64_t filter[], unsigned long b) {
         filter[b >> 6] |= 1ULL << (b & 63);
@@ -45,7 +45,7 @@ static void bloom_add_data(
                 const void *data,      /* Data to hash */
                 size_t n) {            /* Size of data to hash in bytes */
 
                 const void *data,      /* Data to hash */
                 size_t n) {            /* Size of data to hash in bytes */
 
-        uint8_t h[8];
+        uint64_t h;
         uint64_t m;
         unsigned w, i, c = 0;
         unsigned hash_index;
         uint64_t m;
         unsigned w, i, c = 0;
         unsigned hash_index;
@@ -72,11 +72,11 @@ static void bloom_add_data(
 
                 for (d = 0; d < w; d++) {
                         if (c <= 0) {
 
                 for (d = 0; d < w; d++) {
                         if (c <= 0) {
-                                siphash24(h, data, n, hash_keys[hash_index++].bytes);
+                                h = siphash24(data, n, hash_keys[hash_index++].bytes);
                                 c += 8;
                         }
 
                                 c += 8;
                         }
 
-                        p = (p << 8ULL) | (uint64_t) h[8 - c];
+                        p = (p << 8ULL) | (uint64_t) ((uint8_t *)&h)[8 - c];
                         c--;
                 }
 
                         c--;
                 }
 
index 435ec92d6fab3c7915fbc1eff63501bb5d899d4a..7da6ba990382f4da5e86a8545920d50f51a306ef 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <unistd.h>
 #include <fcntl.h>
 #include <fcntl.h>
+#include <unistd.h>
 
 
-#include "util.h"
-#include "process-util.h"
+#include "bus-container.h"
 #include "bus-internal.h"
 #include "bus-socket.h"
 #include "bus-internal.h"
 #include "bus-socket.h"
-#include "bus-container.h"
+#include "fd-util.h"
+#include "process-util.h"
+#include "util.h"
 
 int bus_container_connect_socket(sd_bus *b) {
         _cleanup_close_pair_ int pair[2] = { -1, -1 };
 
 int bus_container_connect_socket(sd_bus *b) {
         _cleanup_close_pair_ int pair[2] = { -1, -1 };
index 356772ca5f75506227b64a720376f05f95b3f99e..c29bf30e0b99dc1d082553a31eb5518093472787 100644 (file)
 #include <valgrind/memcheck.h>
 #endif
 
 #include <valgrind/memcheck.h>
 #endif
 
-#include <stddef.h>
 #include <errno.h>
 #include <errno.h>
+#include <stddef.h>
 
 
-#include "strv.h"
 #include "sd-bus.h"
 #include "sd-bus.h"
+
+#include "alloc-util.h"
+#include "bus-bloom.h"
+#include "bus-control.h"
 #include "bus-internal.h"
 #include "bus-message.h"
 #include "bus-internal.h"
 #include "bus-message.h"
-#include "bus-control.h"
-#include "bus-bloom.h"
 #include "bus-util.h"
 #include "bus-util.h"
-#include "capability.h"
+#include "capability-util.h"
+#include "stdio-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "user-util.h"
 
 _public_ int sd_bus_get_unique_name(sd_bus *bus, const char **unique) {
         int r;
 
 _public_ int sd_bus_get_unique_name(sd_bus *bus, const char **unique) {
         int r;
@@ -976,8 +981,12 @@ static int bus_get_owner_creds_kdbus(sd_bus *bus, uint64_t mask, sd_bus_creds **
 static int bus_get_owner_creds_dbus1(sd_bus *bus, uint64_t mask, sd_bus_creds **ret) {
         _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
         pid_t pid = 0;
 static int bus_get_owner_creds_dbus1(sd_bus *bus, uint64_t mask, sd_bus_creds **ret) {
         _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
         pid_t pid = 0;
+        bool do_label;
         int r;
         int r;
-        bool do_label = bus->label && (mask & SD_BUS_CREDS_SELINUX_CONTEXT);
+
+        assert(bus);
+
+        do_label = bus->label && (mask & SD_BUS_CREDS_SELINUX_CONTEXT);
 
         /* Avoid allocating anything if we have no chance of returning useful data */
         if (!bus->ucred_valid && !do_label)
 
         /* Avoid allocating anything if we have no chance of returning useful data */
         if (!bus->ucred_valid && !do_label)
index b72049ef074bfa0edced3fbe34c3db52eb2560e1..829e37e4a1ff8e02e18a0c8b433b80d16594387c 100644 (file)
@@ -22,8 +22,9 @@
 #include "bus-internal.h"
 #include "bus-message.h"
 #include "bus-signature.h"
 #include "bus-internal.h"
 #include "bus-message.h"
 #include "bus-signature.h"
-#include "bus-util.h"
 #include "bus-type.h"
 #include "bus-type.h"
+#include "bus-util.h"
+#include "string-util.h"
 
 _public_ int sd_bus_emit_signal(
                 sd_bus *bus,
 
 _public_ int sd_bus_emit_signal(
                 sd_bus *bus,
index ed82df2534ea0106d85b7de81bf2add624117a2c..90e37569886adb837a344c18973099931204845b 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <stdlib.h>
 #include <linux/capability.h>
 #include <linux/capability.h>
+#include <stdlib.h>
 
 
-#include "util.h"
-#include "formats-util.h"
-#include "process-util.h"
-#include "terminal-util.h"
-#include "capability.h"
-#include "cgroup-util.h"
-#include "fileio.h"
-#include "audit.h"
+#include "alloc-util.h"
+#include "audit-util.h"
+#include "bus-creds.h"
+#include "bus-label.h"
 #include "bus-message.h"
 #include "bus-util.h"
 #include "bus-message.h"
 #include "bus-util.h"
+#include "capability-util.h"
+#include "cgroup-util.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "formats-util.h"
+#include "hexdecoct.h"
+#include "parse-util.h"
+#include "process-util.h"
+#include "string-util.h"
 #include "strv.h"
 #include "strv.h"
-#include "bus-creds.h"
-#include "bus-label.h"
+#include "terminal-util.h"
+#include "user-util.h"
+#include "util.h"
 
 enum {
         CAP_OFFSET_INHERITABLE = 0,
 
 enum {
         CAP_OFFSET_INHERITABLE = 0,
index 64a5a972aef719637fdf9e527eb094ae3797bdea..404eaa3c895bbb65aa8d3071e3276b02219d0223 100644 (file)
 ***/
 
 #include <errno.h>
 ***/
 
 #include <errno.h>
-#include <stdlib.h>
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stdarg.h>
 #include <stdbool.h>
-#include <string.h>
 #include <stdio.h>
 #include <stdio.h>
-
-#include "util.h"
-#include "errno-list.h"
+#include <stdlib.h>
+#include <string.h>
 
 #include "sd-bus.h"
 
 #include "sd-bus.h"
+
+#include "alloc-util.h"
 #include "bus-error.h"
 #include "bus-error.h"
+#include "errno-list.h"
+#include "string-util.h"
+#include "util.h"
 
 BUS_ERROR_MAP_ELF_REGISTER const sd_bus_error_map bus_standard_errors[] = {
         SD_BUS_ERROR_MAP("org.freedesktop.DBus.Error.Failed",                           EACCES),
 
 BUS_ERROR_MAP_ELF_REGISTER const sd_bus_error_map bus_standard_errors[] = {
         SD_BUS_ERROR_MAP("org.freedesktop.DBus.Error.Failed",                           EACCES),
@@ -565,7 +567,7 @@ _public_ int sd_bus_error_set_errnof(sd_bus_error *e, int error, const char *for
 const char *bus_error_message(const sd_bus_error *e, int error) {
 
         if (e) {
 const char *bus_error_message(const sd_bus_error *e, int error) {
 
         if (e) {
-                /* Sometimes the D-Bus server is a little bit too verbose with
+                /* Sometimes, the D-Bus server is a little bit too verbose with
                  * its error messages, so let's override them here */
                 if (sd_bus_error_has_name(e, SD_BUS_ERROR_ACCESS_DENIED))
                         return "Access denied";
                  * its error messages, so let's override them here */
                 if (sd_bus_error_has_name(e, SD_BUS_ERROR_ACCESS_DENIED))
                         return "Access denied";
index 8bc2a14bf0f819e47d20ec9929f71237079bf840..40939f9f8d9cf3a8498639a3acb71098308ab9d9 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "bus-message.h"
+#include "alloc-util.h"
 #include "bus-internal.h"
 #include "bus-internal.h"
+#include "bus-message.h"
+#include "hexdecoct.h"
+#include "string-util.h"
 
 bool object_path_is_valid(const char *p) {
         const char *q;
 
 bool object_path_is_valid(const char *p) {
         const char *q;
index b4ec380cdc75a647db0f2e619692717288bf6dea..db344ac3727a3be346a626e154d886d3729aec8f 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <sys/socket.h>
 #include <pthread.h>
 #include <pthread.h>
-
-#include "hashmap.h"
-#include "prioq.h"
-#include "list.h"
-#include "util.h"
-#include "refcnt.h"
-#include "socket-util.h"
+#include <sys/socket.h>
 
 #include "sd-bus.h"
 
 #include "sd-bus.h"
+
 #include "bus-error.h"
 #include "bus-error.h"
-#include "bus-match.h"
 #include "bus-kernel.h"
 #include "bus-kernel.h"
+#include "bus-match.h"
+#include "hashmap.h"
 #include "kdbus.h"
 #include "kdbus.h"
+#include "list.h"
+#include "prioq.h"
+#include "refcnt.h"
+#include "socket-util.h"
+#include "util.h"
 
 struct reply_callback {
         sd_bus_message_handler_t callback;
 
 struct reply_callback {
         sd_bus_message_handler_t callback;
index c3aaa9b6d483b28b622fdb4bdad000ae68c6625c..a90536bac9d0086d01c8b640f03fc7bbb9bd0e0f 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "util.h"
-#include "bus-introspect.h"
-#include "bus-signature.h"
 #include "bus-internal.h"
 #include "bus-internal.h"
+#include "bus-introspect.h"
 #include "bus-protocol.h"
 #include "bus-protocol.h"
+#include "bus-signature.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "string-util.h"
+#include "util.h"
 
 int introspect_begin(struct introspect *i, bool trusted) {
         assert(i);
 
 int introspect_begin(struct introspect *i, bool trusted) {
         assert(i);
@@ -82,7 +85,7 @@ static void introspect_write_flags(struct introspect *i, int type, int flags) {
 
         if (type == _SD_BUS_VTABLE_PROPERTY || type == _SD_BUS_VTABLE_WRITABLE_PROPERTY) {
                 if (flags & SD_BUS_VTABLE_PROPERTY_EXPLICIT)
 
         if (type == _SD_BUS_VTABLE_PROPERTY || type == _SD_BUS_VTABLE_WRITABLE_PROPERTY) {
                 if (flags & SD_BUS_VTABLE_PROPERTY_EXPLICIT)
-                        fputs("   <annotation name=\"org.freedesktop.login1.Explicit\" value=\"true\"/>\n", i->f);
+                        fputs("   <annotation name=\"org.freedesktop.systemd1.Explicit\" value=\"true\"/>\n", i->f);
 
                 if (flags & SD_BUS_VTABLE_PROPERTY_CONST)
                         fputs("   <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"const\"/>\n", i->f);
 
                 if (flags & SD_BUS_VTABLE_PROPERTY_CONST)
                         fputs("   <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"const\"/>\n", i->f);
@@ -95,7 +98,7 @@ static void introspect_write_flags(struct introspect *i, int type, int flags) {
         if (!i->trusted &&
             (type == _SD_BUS_VTABLE_METHOD || type == _SD_BUS_VTABLE_WRITABLE_PROPERTY) &&
             !(flags & SD_BUS_VTABLE_UNPRIVILEGED))
         if (!i->trusted &&
             (type == _SD_BUS_VTABLE_METHOD || type == _SD_BUS_VTABLE_WRITABLE_PROPERTY) &&
             !(flags & SD_BUS_VTABLE_UNPRIVILEGED))
-                fputs("   <annotation name=\"org.freedesktop.login1.Privileged\" value=\"true\"/>\n", i->f);
+                fputs("   <annotation name=\"org.freedesktop.systemd1.Privileged\" value=\"true\"/>\n", i->f);
 }
 
 static int introspect_write_arguments(struct introspect *i, const char *signature, const char *direction) {
 }
 
 static int introspect_write_arguments(struct introspect *i, const char *signature, const char *direction) {
index 25fc4ba80e9e72b9854ff95a62545ff5d7cb0d63..ae53b7dec8cf3072c6267a3b9153f5a7e80fe426 100644 (file)
 #include <libgen.h>
 #undef basename
 
 #include <libgen.h>
 #undef basename
 
-#include "util.h"
-#include "strv.h"
-#include "memfd-util.h"
-#include "capability.h"
-#include "fileio.h"
-#include "formats-util.h"
-
+#include "alloc-util.h"
+#include "bus-bloom.h"
 #include "bus-internal.h"
 #include "bus-internal.h"
-#include "bus-message.h"
 #include "bus-kernel.h"
 #include "bus-kernel.h"
-#include "bus-bloom.h"
-#include "bus-util.h"
 #include "bus-label.h"
 #include "bus-label.h"
+#include "bus-message.h"
+#include "bus-util.h"
+#include "capability-util.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "formats-util.h"
+#include "memfd-util.h"
+#include "parse-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "user-util.h"
+#include "util.h"
 
 #define UNIQUE_NAME_MAX (3+DECIMAL_STR_MAX(uint64_t))
 
 
 #define UNIQUE_NAME_MAX (3+DECIMAL_STR_MAX(uint64_t))
 
@@ -1433,12 +1437,12 @@ int bus_kernel_pop_memfd(sd_bus *bus, void **address, size_t *mapped, size_t *al
         if (!bus || !bus->is_kernel)
                 return -EOPNOTSUPP;
 
         if (!bus || !bus->is_kernel)
                 return -EOPNOTSUPP;
 
-        assert_se(pthread_mutex_lock(&bus->memfd_cache_mutex) >= 0);
+        assert_se(pthread_mutex_lock(&bus->memfd_cache_mutex) == 0);
 
         if (bus->n_memfd_cache <= 0) {
                 int r;
 
 
         if (bus->n_memfd_cache <= 0) {
                 int r;
 
-                assert_se(pthread_mutex_unlock(&bus->memfd_cache_mutex) >= 0);
+                assert_se(pthread_mutex_unlock(&bus->memfd_cache_mutex) == 0);
 
                 r = memfd_new(bus->description);
                 if (r < 0)
 
                 r = memfd_new(bus->description);
                 if (r < 0)
@@ -1460,7 +1464,7 @@ int bus_kernel_pop_memfd(sd_bus *bus, void **address, size_t *mapped, size_t *al
         *allocated = c->allocated;
         fd = c->fd;
 
         *allocated = c->allocated;
         fd = c->fd;
 
-        assert_se(pthread_mutex_unlock(&bus->memfd_cache_mutex) >= 0);
+        assert_se(pthread_mutex_unlock(&bus->memfd_cache_mutex) == 0);
 
         return fd;
 }
 
         return fd;
 }
@@ -1484,10 +1488,10 @@ void bus_kernel_push_memfd(sd_bus *bus, int fd, void *address, size_t mapped, si
                 return;
         }
 
                 return;
         }
 
-        assert_se(pthread_mutex_lock(&bus->memfd_cache_mutex) >= 0);
+        assert_se(pthread_mutex_lock(&bus->memfd_cache_mutex) == 0);
 
         if (bus->n_memfd_cache >= ELEMENTSOF(bus->memfd_cache)) {
 
         if (bus->n_memfd_cache >= ELEMENTSOF(bus->memfd_cache)) {
-                assert_se(pthread_mutex_unlock(&bus->memfd_cache_mutex) >= 0);
+                assert_se(pthread_mutex_unlock(&bus->memfd_cache_mutex) == 0);
 
                 close_and_munmap(fd, address, mapped);
                 return;
 
                 close_and_munmap(fd, address, mapped);
                 return;
@@ -1507,7 +1511,7 @@ void bus_kernel_push_memfd(sd_bus *bus, int fd, void *address, size_t mapped, si
                 c->allocated = allocated;
         }
 
                 c->allocated = allocated;
         }
 
-        assert_se(pthread_mutex_unlock(&bus->memfd_cache_mutex) >= 0);
+        assert_se(pthread_mutex_unlock(&bus->memfd_cache_mutex) == 0);
 }
 
 void bus_kernel_flush_memfd(sd_bus *b) {
 }
 
 void bus_kernel_flush_memfd(sd_bus *b) {
index b1c00066098866e7ba956705bc35cf9ce018630a..de80c01b8099fc2b3dc0ade1733450b0a1f77278 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include "alloc-util.h"
 #include "bus-internal.h"
 #include "bus-internal.h"
-#include "bus-message.h"
 #include "bus-match.h"
 #include "bus-match.h"
+#include "bus-message.h"
 #include "bus-util.h"
 #include "bus-util.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "hexdecoct.h"
+#include "string-util.h"
 #include "strv.h"
 
 /* Example:
 #include "strv.h"
 
 /* Example:
index 8b72a4f7c1642820936064a8d99c26c88fa08527..c33f35dbc6c01b419e4ca39f2a079a93009ac226 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "hashmap.h"
-
 #include "sd-bus.h"
 
 #include "sd-bus.h"
 
+#include "hashmap.h"
+
 enum bus_match_node_type {
         BUS_MATCH_ROOT,
         BUS_MATCH_VALUE,
 enum bus_match_node_type {
         BUS_MATCH_ROOT,
         BUS_MATCH_VALUE,
index 7b121698998e6691dcb231093919f05e23a78e27..0575890e339e2f64f0eebcd11ee5a04898a71a28 100644 (file)
 #include <fcntl.h>
 #include <sys/mman.h>
 
 #include <fcntl.h>
 #include <sys/mman.h>
 
-#include "util.h"
-#include "utf8.h"
-#include "strv.h"
-#include "time-util.h"
-#include "memfd-util.h"
-
 #include "sd-bus.h"
 #include "sd-bus.h"
-#include "bus-message.h"
+
+#include "alloc-util.h"
+#include "bus-gvariant.h"
 #include "bus-internal.h"
 #include "bus-internal.h"
-#include "bus-type.h"
+#include "bus-message.h"
 #include "bus-signature.h"
 #include "bus-signature.h"
-#include "bus-gvariant.h"
+#include "bus-type.h"
 #include "bus-util.h"
 #include "bus-util.h"
+#include "fd-util.h"
+#include "io-util.h"
+#include "memfd-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "time-util.h"
+#include "utf8.h"
+#include "util.h"
 
 static int message_append_basic(sd_bus_message *m, char type, const void *p, const void **stored);
 
 
 static int message_append_basic(sd_bus_message *m, char type, const void *p, const void **stored);
 
index 9b004464116272029dec5da7de373447664b06ec..8aca18381b53b59472058dd907c7746d0fb8337a 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <stdbool.h>
 #include <byteswap.h>
 #include <byteswap.h>
+#include <stdbool.h>
 #include <sys/socket.h>
 
 #include <sys/socket.h>
 
-#include "macro.h"
 #include "sd-bus.h"
 #include "sd-bus.h"
-#include "time-util.h"
+
 #include "bus-creds.h"
 #include "bus-protocol.h"
 #include "bus-creds.h"
 #include "bus-protocol.h"
+#include "macro.h"
+#include "time-util.h"
 
 struct bus_container {
         char enclosing;
 
 struct bus_container {
         char enclosing;
index fdfd005a38ad3eea7b28cadb7c7c8dab8cecbc74..4b9c05d09ce15c9b53b57c7fb296274d0bb1efca 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "strv.h"
-#include "set.h"
+#include "alloc-util.h"
 #include "bus-internal.h"
 #include "bus-internal.h"
+#include "bus-introspect.h"
 #include "bus-message.h"
 #include "bus-message.h"
-#include "bus-type.h"
+#include "bus-objects.h"
 #include "bus-signature.h"
 #include "bus-signature.h"
-#include "bus-introspect.h"
-#include "bus-util.h"
 #include "bus-slot.h"
 #include "bus-slot.h"
-#include "bus-objects.h"
+#include "bus-type.h"
+#include "bus-util.h"
+#include "set.h"
+#include "string-util.h"
+#include "strv.h"
 
 static int node_vtable_get_userdata(
                 sd_bus *bus,
 
 static int node_vtable_get_userdata(
                 sd_bus *bus,
index 8626196062eecacaa7cad0a2f6967cb8b40aa140..6149a981d74d5bc46a35335285e5fe305fde333e 100644 (file)
 ***/
 
 #include "sd-bus.h"
 ***/
 
 #include "sd-bus.h"
+
+#include "alloc-util.h"
 #include "bus-control.h"
 #include "bus-objects.h"
 #include "bus-slot.h"
 #include "bus-control.h"
 #include "bus-objects.h"
 #include "bus-slot.h"
+#include "string-util.h"
 
 sd_bus_slot *bus_slot_allocate(
                 sd_bus *bus,
 
 sd_bus_slot *bus_slot_allocate(
                 sd_bus *bus,
index d0b1e3d7dc69873c8e6a727ae9198c903df0e7b1..067682e1c7a0b39af7ffec666161f8ef6738a081 100644 (file)
 ***/
 
 #include <endian.h>
 ***/
 
 #include <endian.h>
+#include <poll.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <poll.h>
 
 
+#include "sd-bus.h"
 #include "sd-daemon.h"
 #include "sd-daemon.h"
-#include "util.h"
-#include "macro.h"
-#include "missing.h"
-#include "utf8.h"
-#include "formats-util.h"
-#include "signal-util.h"
 
 
-#include "sd-bus.h"
-#include "bus-socket.h"
+#include "alloc-util.h"
 #include "bus-internal.h"
 #include "bus-message.h"
 #include "bus-internal.h"
 #include "bus-message.h"
+#include "bus-socket.h"
+#include "fd-util.h"
+#include "formats-util.h"
+#include "hexdecoct.h"
+#include "macro.h"
+#include "missing.h"
+#include "selinux-util.h"
+#include "signal-util.h"
+#include "stdio-util.h"
+#include "string-util.h"
+#include "user-util.h"
+#include "utf8.h"
+#include "util.h"
 
 #define SNDBUF_SIZE (8*1024*1024)
 
 
 #define SNDBUF_SIZE (8*1024*1024)
 
@@ -602,10 +609,12 @@ static void bus_get_peercred(sd_bus *b) {
         b->ucred_valid = getpeercred(b->input_fd, &b->ucred) >= 0;
 
         /* Get the SELinux context of the peer */
         b->ucred_valid = getpeercred(b->input_fd, &b->ucred) >= 0;
 
         /* Get the SELinux context of the peer */
+        if (mac_selinux_use()) {
         r = getpeersec(b->input_fd, &b->label);
         if (r < 0 && r != -EOPNOTSUPP)
                 log_debug_errno(r, "Failed to determine peer security context: %m");
 }
         r = getpeersec(b->input_fd, &b->label);
         if (r < 0 && r != -EOPNOTSUPP)
                 log_debug_errno(r, "Failed to determine peer security context: %m");
 }
+}
 
 static int bus_socket_start_auth_client(sd_bus *b) {
         size_t l;
 
 static int bus_socket_start_auth_client(sd_bus *b) {
         size_t l;
index 12ab53b7b71e24a00e94baa3e6ea3723dcaa51ed..f8b7cfada004fbc1b6ff5ee1e59fa03cf4a5f6a3 100644 (file)
 ***/
 
 #include "sd-bus.h"
 ***/
 
 #include "sd-bus.h"
-#include "bus-util.h"
+
+#include "alloc-util.h"
 #include "bus-internal.h"
 #include "bus-track.h"
 #include "bus-internal.h"
 #include "bus-track.h"
+#include "bus-util.h"
+
 
 struct sd_bus_track {
         unsigned n_ref;
 
 struct sd_bus_track {
         unsigned n_ref;
index 4340a219791d06375ad8e52fc28accf3794b4d81..7e733cdea0e04000924323a6d91a689d44f87232 100644 (file)
 ***/
 
 #include <endian.h>
 ***/
 
 #include <endian.h>
-#include <stdlib.h>
-#include <unistd.h>
 #include <netdb.h>
 #include <poll.h>
 #include <netdb.h>
 #include <poll.h>
-#include <sys/mman.h>
 #include <pthread.h>
 #include <pthread.h>
-
-#include "util.h"
-#include "macro.h"
-#include "strv.h"
-#include "missing.h"
-#include "def.h"
-#include "cgroup-util.h"
-#include "hostname-util.h"
-#include "bus-label.h"
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <unistd.h>
 
 #include "sd-bus.h"
 
 #include "sd-bus.h"
+
+#include "alloc-util.h"
+#include "bus-container.h"
+#include "bus-control.h"
 #include "bus-internal.h"
 #include "bus-internal.h"
-#include "bus-message.h"
-#include "bus-type.h"
-#include "bus-socket.h"
 #include "bus-kernel.h"
 #include "bus-kernel.h"
-#include "bus-control.h"
+#include "bus-label.h"
+#include "bus-message.h"
 #include "bus-objects.h"
 #include "bus-objects.h"
-#include "bus-util.h"
-#include "bus-container.h"
 #include "bus-protocol.h"
 #include "bus-protocol.h"
-#include "bus-track.h"
 #include "bus-slot.h"
 #include "bus-slot.h"
+#include "bus-socket.h"
+#include "bus-track.h"
+#include "bus-type.h"
+#include "bus-util.h"
+#include "cgroup-util.h"
+#include "def.h"
+#include "fd-util.h"
+#include "hexdecoct.h"
+#include "hostname-util.h"
+#include "macro.h"
+#include "missing.h"
+#include "parse-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "util.h"
 
 #define log_debug_bus_message(m)                                         \
         do {                                                             \
 
 #define log_debug_bus_message(m)                                         \
         do {                                                             \
index e47da68a66f3cd6a0bcd82998292e15a14b6b8f2..b5454f1ef557e58be010f11effccf9b1ece5cb0d 100644 (file)
@@ -21,7 +21,7 @@
 
 #include <errno.h>
 #include <limits.h>
 
 #include <errno.h>
 #include <limits.h>
-//#include <mqueue.h>
+#include <mqueue.h>
 #include <netinet/in.h>
 #include <stdarg.h>
 #include <stddef.h>
 #include <netinet/in.h>
 #include <stdarg.h>
 #include <stddef.h>
 #include <sys/un.h>
 #include <unistd.h>
 
 #include <sys/un.h>
 #include <unistd.h>
 
+#include "sd-daemon.h"
+
+#include "alloc-util.h"
+#include "fd-util.h"
+//#include "fs-util.h"
+#include "parse-util.h"
 #include "path-util.h"
 #include "socket-util.h"
 #include "path-util.h"
 #include "socket-util.h"
-//#include "strv.h"
+#include "strv.h"
 #include "util.h"
 
 #include "util.h"
 
-#include "sd-daemon.h"
+#define SNDBUF_SIZE (8*1024*1024)
 
 /// UNNEEDED by elogind
 #if 0
 
 /// UNNEEDED by elogind
 #if 0
@@ -452,6 +458,8 @@ _public_ int sd_pid_notify_with_fds(pid_t pid, int unset_environment, const char
                 goto finish;
         }
 
                 goto finish;
         }
 
+        fd_inc_sndbuf(fd, SNDBUF_SIZE);
+
         iovec.iov_len = strlen(state);
 
         strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path));
         iovec.iov_len = strlen(state);
 
         strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path));
index f6d0d1054030cb5486b86f9a179e981409068d23..d26efb8289fde67e2370a3f7a30c9cb40d144d51 100644 (file)
 #include <sys/timerfd.h>
 #include <sys/wait.h>
 
 #include <sys/timerfd.h>
 #include <sys/wait.h>
 
-#include "sd-id128.h"
 #include "sd-daemon.h"
 #include "sd-daemon.h"
-#include "macro.h"
-#include "prioq.h"
+#include "sd-event.h"
+#include "sd-id128.h"
+
+#include "alloc-util.h"
+#include "fd-util.h"
 #include "hashmap.h"
 #include "hashmap.h"
-#include "util.h"
-#include "time-util.h"
+#include "list.h"
+#include "macro.h"
 #include "missing.h"
 #include "missing.h"
+#include "prioq.h"
+#include "process-util.h"
 #include "set.h"
 #include "set.h"
-#include "list.h"
 #include "signal-util.h"
 #include "signal-util.h"
-
-#include "sd-event.h"
+#include "string-util.h"
+#include "time-util.h"
+#include "util.h"
 
 #define DEFAULT_ACCURACY_USEC (250 * USEC_PER_MSEC)
 
 
 #define DEFAULT_ACCURACY_USEC (250 * USEC_PER_MSEC)
 
@@ -808,7 +812,7 @@ static void source_disconnect(sd_event_source *s) {
                                 s->event->n_enabled_child_sources--;
                         }
 
                                 s->event->n_enabled_child_sources--;
                         }
 
-                        (void) hashmap_remove(s->event->child_sources, INT_TO_PTR(s->child.pid));
+                        (void) hashmap_remove(s->event->child_sources, PID_TO_PTR(s->child.pid));
                         event_gc_signal_data(s->event, &s->priority, SIGCHLD);
                 }
 
                         event_gc_signal_data(s->event, &s->priority, SIGCHLD);
                 }
 
@@ -1126,8 +1130,8 @@ _public_ int sd_event_add_signal(
                 callback = signal_exit_callback;
 
         r = pthread_sigmask(SIG_SETMASK, NULL, &ss);
                 callback = signal_exit_callback;
 
         r = pthread_sigmask(SIG_SETMASK, NULL, &ss);
-        if (r < 0)
-                return -errno;
+        if (r != 0)
+                return -r;
 
         if (!sigismember(&ss, sig))
                 return -EBUSY;
 
         if (!sigismember(&ss, sig))
                 return -EBUSY;
@@ -1190,7 +1194,7 @@ _public_ int sd_event_add_child(
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
-        if (hashmap_contains(e->child_sources, INT_TO_PTR(pid)))
+        if (hashmap_contains(e->child_sources, PID_TO_PTR(pid)))
                 return -EBUSY;
 
         s = source_new(e, !ret, SOURCE_CHILD);
                 return -EBUSY;
 
         s = source_new(e, !ret, SOURCE_CHILD);
@@ -1203,7 +1207,7 @@ _public_ int sd_event_add_child(
         s->userdata = userdata;
         s->enabled = SD_EVENT_ONESHOT;
 
         s->userdata = userdata;
         s->enabled = SD_EVENT_ONESHOT;
 
-        r = hashmap_put(e->child_sources, INT_TO_PTR(pid), s);
+        r = hashmap_put(e->child_sources, PID_TO_PTR(pid), s);
         if (r < 0) {
                 source_free(s);
                 return r;
         if (r < 0) {
                 source_free(s);
                 return r;
index eb539ad318fdee7c8fa37123d7809c91d62225b0..406a7f0a64683cb3503b0817567e15856e955a56 100644 (file)
 #include <fcntl.h>
 #include <unistd.h>
 
 #include <fcntl.h>
 #include <unistd.h>
 
-#include "util.h"
-#include "macro.h"
 #include "sd-id128.h"
 #include "sd-id128.h"
-#include "random-util.h"
+
+#include "fd-util.h"
+#include "hexdecoct.h"
+#include "io-util.h"
+#include "macro.h"
+ #include "random-util.h"
+#include "util.h"
 
 _public_ char *sd_id128_to_string(sd_id128_t id, char s[SD_ID128_STRING_MAX]) {
         unsigned n;
 
 _public_ char *sd_id128_to_string(sd_id128_t id, char s[SD_ID128_STRING_MAX]) {
         unsigned n;
index 6c81c18d4c27bc4ac79604404a1063ee09c9fc05..671700b5e8e051843b5c6cc48762ca6c0dd76d2a 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <unistd.h>
-#include <string.h>
 #include <errno.h>
 #include <errno.h>
-#include <sys/inotify.h>
 #include <poll.h>
 #include <poll.h>
+#include <string.h>
+#include <sys/inotify.h>
+#include <unistd.h>
 
 
-#include "util.h"
+#include "sd-login.h"
+
+#include "alloc-util.h"
 #include "cgroup-util.h"
 #include "cgroup-util.h"
-#include "macro.h"
-#include "strv.h"
+#include "dirent-util.h"
+#include "escape.h"
+#include "fd-util.h"
 #include "fileio.h"
 #include "fileio.h"
-#include "login-util.h"
 #include "formats-util.h"
 #include "formats-util.h"
+#include "fs-util.h"
 #include "hostname-util.h"
 #include "hostname-util.h"
-#include "sd-login.h"
+#include "io-util.h"
+#include "login-util.h"
+#include "macro.h"
+#include "parse-util.h"
+#include "path-util.h"
+#include "socket-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "user-util.h"
+#include "util.h"
 
 /* Error codes:
  *
 
 /* Error codes:
  *
@@ -985,9 +997,7 @@ _public_ int sd_machine_get_ifindices(const char *machine, int **ifindices) {
 
                 *(char*) (mempcpy(buf, word, l)) = 0;
 
 
                 *(char*) (mempcpy(buf, word, l)) = 0;
 
-                if (safe_atoi(buf, &ifi) < 0)
-                        continue;
-                if (ifi <= 0)
+                if (parse_ifindex(buf, &ifi) < 0)
                         continue;
 
                 if (!GREEDY_REALLOC(ni, allocated, nr+1)) {
                         continue;
 
                 if (!GREEDY_REALLOC(ni, allocated, nr+1)) {
index b60ad0c38603faf0ec12a59979ed46b332f8aa5d..a1b95963c625bebeec6f75afbf81b976bbf7ec8c 100644 (file)
 #include <poll.h>
 #include <string.h>
 
 #include <poll.h>
 #include <string.h>
 
-#include "systemd/sd-login.h"
+#include "sd-login.h"
 
 
-#include "util.h"
-#include "strv.h"
+#include "alloc-util.h"
+#include "fd-util.h"
 #include "formats-util.h"
 #include "formats-util.h"
+#include "musl_missing.h"
+#include "string-util.h"
+#include "strv.h"
+#include "util.h"
 
 static void test_login(void) {
         _cleanup_close_pair_ int pair[2] = { -1, -1 };
 
 static void test_login(void) {
         _cleanup_close_pair_ int pair[2] = { -1, -1 };
index bfee1ca063ed3ace2186cb1a840a9fbb49cac8e2..a8328592fcfd83c4911d0eacca906dfce9533c3d 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <fcntl.h>
 #include <getopt.h>
 #include <getopt.h>
-#include <stdlib.h>
 #include <stdio.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <unistd.h>
-#include <fcntl.h>
 
 #include "sd-bus.h"
 
 #include "sd-bus.h"
-#include "bus-util.h"
+
+#include "alloc-util.h"
 #include "bus-error.h"
 #include "bus-error.h"
-#include "util.h"
-#include "build.h"
-#include "strv.h"
+#include "bus-util.h"
+#include "fd-util.h"
 #include "formats-util.h"
 #include "process-util.h"
 #include "signal-util.h"
 #include "formats-util.h"
 #include "process-util.h"
 #include "signal-util.h"
+#include "strv.h"
+#include "user-util.h"
+#include "util.h"
+
+/// Additional includes needed by elogind
+#include "musl_missing.h"
 
 static const char* arg_what = "idle:sleep:shutdown";
 static const char* arg_who = NULL;
 
 static const char* arg_what = "idle:sleep:shutdown";
 static const char* arg_who = NULL;
index ce0adc45c047913ac754de6344d68f305dc0727d..fec9fe58b047f5567d04ad66f8f46283da135b8b 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <unistd.h>
 #include <errno.h>
 #include <errno.h>
-#include <string.h>
 #include <getopt.h>
 #include <locale.h>
 #include <getopt.h>
 #include <locale.h>
+#include <string.h>
+#include <unistd.h>
 
 #include "sd-bus.h"
 
 #include "sd-bus.h"
-#include "sd-login.h"
-#include "bus-util.h"
+
+#include "alloc-util.h"
 #include "bus-error.h"
 #include "bus-error.h"
+#include "bus-util.h"
+//#include "cgroup-show.h"
+#include "cgroup-util.h"
 #include "log.h"
 #include "log.h"
-#include "util.h"
+//#include "logs-show.h"
 #include "macro.h"
 #include "pager.h"
 #include "macro.h"
 #include "pager.h"
-#include "build.h"
+#include "parse-util.h"
+#include "process-util.h"
+#include "signal-util.h"
+#include "spawn-polkit-agent.h"
 #include "strv.h"
 #include "strv.h"
-#include "unit-name.h"
 #include "sysfs-show.h"
 #include "sysfs-show.h"
-//#include "logs-show.h"
-//#include "cgroup-show.h"
-#include "cgroup-util.h"
-#include "spawn-polkit-agent.h"
-#include "verbs.h"
-#include "process-util.h"
 #include "terminal-util.h"
 #include "terminal-util.h"
-#include "signal-util.h"
+#include "unit-name.h"
+#include "user-util.h"
+#include "util.h"
+#include "verbs.h"
+
+/// Additional includes for elogind
 #include "logind-action.h"
 #include "logind-action.h"
+#include "musl_missing.h"
+#include "sd-login.h"
+#include "virt.h"
 
 static char **arg_property = NULL;
 static bool arg_all = false;
 
 static char **arg_property = NULL;
 static bool arg_all = false;
@@ -1694,7 +1701,7 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 0);
         assert(argv);
 
         assert(argc >= 0);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "hp:als:H:M:ci", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "hp:als:H:M:n:o:ci", options, NULL)) >= 0)
 
                 switch (c) {
 
 
                 switch (c) {
 
index 466225d69c7e84ee2a10300cabaef99f2b04dffe..d0dd569a03cf96490a8639f968b983d2cb923f65 100644 (file)
 #include <errno.h>
 #include <string.h>
 
 #include <errno.h>
 #include <string.h>
 
-#include "util.h"
-#include "formats-util.h"
 #include "acl-util.h"
 #include "acl-util.h"
-#include "set.h"
+#include "alloc-util.h"
+#include "dirent-util.h"
+#include "escape.h"
+#include "fd-util.h"
+#include "formats-util.h"
 #include "logind-acl.h"
 #include "logind-acl.h"
+#include "set.h"
+#include "string-util.h"
 #include "udev-util.h"
 #include "udev-util.h"
+#include "util.h"
 
 static int flush_acl(acl_t acl) {
         acl_entry_t i;
 
 static int flush_acl(acl_t acl) {
         acl_entry_t i;
index 9b2ec6e24258652fee94f4732886ba743e01b19f..474b69628e991013c2761f1e4954ddd939691edc 100644 (file)
 
 #include <unistd.h>
 
 
 #include <unistd.h>
 
-#include "sd-messages.h"
-#include "util.h"
-#include "strv.h"
-#include "fileio.h"
-#include "conf-parser.h"
-// #include "special.h"
-#include "sleep-config.h"
+#include "alloc-util.h"
 #include "bus-error.h"
 #include "bus-util.h"
 #include "bus-error.h"
 #include "bus-util.h"
+#include "conf-parser.h"
+#include "formats-util.h"
 #include "logind-action.h"
 #include "logind-action.h"
-// #include "formats-util.h"
 #include "process-util.h"
 #include "process-util.h"
+#include "sleep-config.h"
+//#include "special.h"
+#include "string-table.h"
 #include "terminal-util.h"
 #include "terminal-util.h"
+#include "user-util.h"
+
+// Additional includes needed by elogind
+#include "fd-util.h"
+#include "fileio.h"
+#include "sd-messages.h"
+#include "strv.h"
+
 
 int manager_handle_action(
                 Manager *m,
 
 int manager_handle_action(
                 Manager *m,
index 6b63b92d3c5e2c62432b8d938c4709f9ce62f8ee..2fcad0397d6ca8a81c264f501041ebb167a1e8e7 100644 (file)
@@ -22,7 +22,7 @@
 ***/
 
 typedef enum HandleAction {
 ***/
 
 typedef enum HandleAction {
-        HANDLE_IGNORE = 0,
+        HANDLE_IGNORE,
         HANDLE_POWEROFF,
         HANDLE_REBOOT,
         HANDLE_HALT,
         HANDLE_POWEROFF,
         HANDLE_REBOOT,
         HANDLE_HALT,
@@ -36,6 +36,7 @@ typedef enum HandleAction {
 } HandleAction;
 
 #include "logind.h"
 } HandleAction;
 
 #include "logind.h"
+#include "logind-inhibit.h"
 
 int manager_handle_action(
                 Manager *m,
 
 int manager_handle_action(
                 Manager *m,
index f40e35a8cbbf60ffec2eb369fd7f3b24ddca6e7b..b08b69dbfc39c0350b4db9e3a94eb0c05ed18ded 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <string.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <string.h>
 #include <sys/ioctl.h>
 #include <unistd.h>
 #include <linux/input.h>
 
 #include "sd-messages.h"
 #include <sys/ioctl.h>
 #include <unistd.h>
 #include <linux/input.h>
 
 #include "sd-messages.h"
-#include "util.h"
+
+#include "alloc-util.h"
+#include "fd-util.h"
 #include "logind-button.h"
 #include "logind-button.h"
+#include "string-util.h"
+#include "util.h"
 
 Button* button_new(Manager *m, const char *name) {
         Button *b;
 
 Button* button_new(Manager *m, const char *name) {
         Button *b;
index fe97c1de0e01e1f3db09b1ca998893dfcbee9b62..4ab66cd9bf0c3199791983fdfa01d6991cbe0fe9 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <sys/types.h>
-#include <sys/ioctl.h>
 #include <fcntl.h>
 #include <pwd.h>
 #include <fcntl.h>
 #include <pwd.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
 #include <linux/vt.h>
 
 #include <linux/vt.h>
 
-#include "strv.h"
-#include "cgroup-util.h"
-#include "bus-util.h"
+#include "alloc-util.h"
 #include "bus-error.h"
 #include "bus-error.h"
-#include "udev-util.h"
+#include "bus-util.h"
+#include "cgroup-util.h"
+#include "fd-util.h"
 #include "logind.h"
 #include "logind.h"
+#include "strv.h"
 #include "terminal-util.h"
 #include "terminal-util.h"
+#include "udev-util.h"
+#include "user-util.h"
 
 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device) {
         Device *d;
 
 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device) {
         Device *d;
@@ -95,15 +98,16 @@ int manager_add_session(Manager *m, const char *id, Session **_session) {
 
 int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **_user) {
         User *u;
 
 int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **_user) {
         User *u;
+        int r;
 
         assert(m);
         assert(name);
 
         u = hashmap_get(m->users, UID_TO_PTR(uid));
         if (!u) {
 
         assert(m);
         assert(name);
 
         u = hashmap_get(m->users, UID_TO_PTR(uid));
         if (!u) {
-                u = user_new(m, uid, gid, name);
-                if (!u)
-                        return -ENOMEM;
+                r = user_new(&u, m, uid, gid, name);
+                if (r < 0)
+                        return r;
         }
 
         if (_user)
         }
 
         if (_user)
index d88636f7471a4b1afa2da1162f3a574d5222fddb..0c25d1f6f13dc70286cfb76c438eb13a55d2c271 100644 (file)
 ***/
 
 #include <errno.h>
 ***/
 
 #include <errno.h>
+#include <pwd.h>
 #include <string.h>
 #include <unistd.h>
 #include <string.h>
 #include <unistd.h>
-#include <pwd.h>
 
 #include "sd-messages.h"
 
 #include "sd-messages.h"
-#include "strv.h"
-#include "mkdir.h"
-#include "path-util.h"
-// #include "special.h"
-#include "sleep-config.h"
-#include "fileio-label.h"
-#include "unit-name.h"
-#include "audit.h"
-#include "bus-util.h"
-#include "bus-error.h"
+
+#include "alloc-util.h"
+#include "audit-util.h"
 #include "bus-common-errors.h"
 #include "bus-common-errors.h"
-#include "udev-util.h"
-#include "selinux-util.h"
+#include "bus-error.h"
+#include "bus-util.h"
+#include "dirent-util.h"
 #include "efivars.h"
 #include "efivars.h"
-#include "logind.h"
+#include "escape.h"
+#include "fd-util.h"
+#include "fileio-label.h"
 #include "formats-util.h"
 #include "formats-util.h"
+#include "fs-util.h"
+#include "logind.h"
+#include "mkdir.h"
+#include "path-util.h"
 #include "process-util.h"
 #include "process-util.h"
+#include "selinux-util.h"
+#include "sleep-config.h"
+//#include "special.h"
+#include "strv.h"
 #include "terminal-util.h"
 #include "terminal-util.h"
+#include "udev-util.h"
+#include "unit-name.h"
+#include "user-util.h"
 #include "utmp-wtmp.h"
 
 int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret) {
 #include "utmp-wtmp.h"
 
 int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret) {
@@ -301,8 +308,10 @@ static int method_get_session_by_pid(sd_bus_message *message, void *userdata, sd
         r = sd_bus_message_read(message, "u", &pid);
         if (r < 0)
                 return r;
         r = sd_bus_message_read(message, "u", &pid);
         if (r < 0)
                 return r;
+        if (pid < 0)
+                return -EINVAL;
 
 
-        if (pid <= 0) {
+        if (pid == 0) {
                 r = manager_get_session_from_creds(m, message, NULL, error, &session);
                 if (r < 0)
                         return r;
                 r = manager_get_session_from_creds(m, message, NULL, error, &session);
                 if (r < 0)
                         return r;
@@ -362,8 +371,10 @@ static int method_get_user_by_pid(sd_bus_message *message, void *userdata, sd_bu
         r = sd_bus_message_read(message, "u", &pid);
         if (r < 0)
                 return r;
         r = sd_bus_message_read(message, "u", &pid);
         if (r < 0)
                 return r;
+        if (pid < 0)
+                return -EINVAL;
 
 
-        if (pid <= 0) {
+        if (pid == 0) {
                 r = manager_get_user_from_creds(m, message, UID_INVALID, error, &user);
                 if (r < 0)
                         return r;
                 r = manager_get_user_from_creds(m, message, UID_INVALID, error, &user);
                 if (r < 0)
                         return r;
@@ -566,12 +577,14 @@ static int method_list_inhibitors(sd_bus_message *message, void *userdata, sd_bu
 
 static int method_create_session(sd_bus_message *message, void *userdata, sd_bus_error *error) {
         const char *service, *type, *class, *cseat, *tty, *display, *remote_user, *remote_host, *desktop;
 
 static int method_create_session(sd_bus_message *message, void *userdata, sd_bus_error *error) {
         const char *service, *type, *class, *cseat, *tty, *display, *remote_user, *remote_host, *desktop;
-        uint32_t uid, leader, audit_id = 0;
+        uint32_t audit_id = 0;
         _cleanup_free_ char *id = NULL;
         Session *session = NULL;
         Manager *m = userdata;
         User *user = NULL;
         Seat *seat = NULL;
         _cleanup_free_ char *id = NULL;
         Session *session = NULL;
         Manager *m = userdata;
         User *user = NULL;
         Seat *seat = NULL;
+        pid_t leader;
+        uid_t uid;
         int remote;
         uint32_t vtnr = 0;
         SessionType t;
         int remote;
         uint32_t vtnr = 0;
         SessionType t;
@@ -581,11 +594,16 @@ static int method_create_session(sd_bus_message *message, void *userdata, sd_bus
         assert(message);
         assert(m);
 
         assert(message);
         assert(m);
 
+        assert_cc(sizeof(pid_t) == sizeof(uint32_t));
+        assert_cc(sizeof(uid_t) == sizeof(uint32_t));
+
         r = sd_bus_message_read(message, "uusssssussbss", &uid, &leader, &service, &type, &class, &desktop, &cseat, &vtnr, &tty, &display, &remote, &remote_user, &remote_host);
         if (r < 0)
                 return r;
 
         r = sd_bus_message_read(message, "uusssssussbss", &uid, &leader, &service, &type, &class, &desktop, &cseat, &vtnr, &tty, &display, &remote, &remote_user, &remote_host);
         if (r < 0)
                 return r;
 
-        if (leader == 1)
+        if (!uid_is_valid(uid))
+                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UID");
+        if (leader < 0 || leader == 1)
                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid leader PID");
 
         if (isempty(type))
                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid leader PID");
 
         if (isempty(type))
@@ -677,7 +695,7 @@ static int method_create_session(sd_bus_message *message, void *userdata, sd_bus
                         c = SESSION_USER;
         }
 
                         c = SESSION_USER;
         }
 
-        if (leader <= 0) {
+        if (leader == 0) {
                 _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
 
                 r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
                 _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
 
                 r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
@@ -1092,7 +1110,9 @@ static int method_set_user_linger(sd_bus_message *message, void *userdata, sd_bu
                 r = sd_bus_creds_get_owner_uid(creds, &uid);
                 if (r < 0)
                         return r;
                 r = sd_bus_creds_get_owner_uid(creds, &uid);
                 if (r < 0)
                         return r;
-        }
+
+        } else if (!uid_is_valid(uid))
+                return -EINVAL;
 
         errno = 0;
         pw = getpwuid(uid);
 
         errno = 0;
         pw = getpwuid(uid);
@@ -1347,39 +1367,70 @@ static int have_multiple_sessions(
 static int bus_manager_log_shutdown(
                 Manager *m,
                 InhibitWhat w,
 static int bus_manager_log_shutdown(
                 Manager *m,
                 InhibitWhat w,
-                HandleAction action) {
+/// elogind does not support systemd units
+#if 0
+                const char *unit_name) {
 
         const char *p, *q;
 
         assert(m);
 
         const char *p, *q;
 
         assert(m);
+        assert(unit_name);
 
         if (w != INHIBIT_SHUTDOWN)
                 return 0;
 
 
         if (w != INHIBIT_SHUTDOWN)
                 return 0;
 
-        switch (action) {
-        case HANDLE_POWEROFF:
-                p = "MESSAGE=System is powering down.";
+        if (streq(unit_name, SPECIAL_POWEROFF_TARGET)) {
+                p = "MESSAGE=System is powering down";
                 q = "SHUTDOWN=power-off";
                 q = "SHUTDOWN=power-off";
-                break;
-        case HANDLE_HALT:
-                p = "MESSAGE=System is halting.";
+        } else if (streq(unit_name, SPECIAL_HALT_TARGET)) {
+                p = "MESSAGE=System is halting";
                 q = "SHUTDOWN=halt";
                 q = "SHUTDOWN=halt";
-                break;
-        case HANDLE_REBOOT:
-                p = "MESSAGE=System is rebooting.";
+        } else if (streq(unit_name, SPECIAL_REBOOT_TARGET)) {
+                p = "MESSAGE=System is rebooting";
                 q = "SHUTDOWN=reboot";
                 q = "SHUTDOWN=reboot";
-                break;
-        case HANDLE_KEXEC:
-                p = "MESSAGE=System is rebooting with kexec.";
+        } else if (streq(unit_name, SPECIAL_KEXEC_TARGET)) {
+                p = "MESSAGE=System is rebooting with kexec";
                 q = "SHUTDOWN=kexec";
                 q = "SHUTDOWN=kexec";
-                break;
-        default:
-                p = "MESSAGE=System is shutting down.";
+        } else {
+                p = "MESSAGE=System is shutting down";
                 q = NULL;
         }
                 q = NULL;
         }
-
-        if (!isempty(m->wall_message))
-                p = strjoina(p, " (", m->wall_message, ")");
+#else
+                 HandleAction action) {
+
+         const char *p, *q;
+
+         assert(m);
+
+         if (w != INHIBIT_SHUTDOWN)
+                 return 0;
+
+         switch (action) {
+         case HANDLE_POWEROFF:
+                 p = "MESSAGE=System is powering down.";
+                 q = "SHUTDOWN=power-off";
+                 break;
+         case HANDLE_HALT:
+                 p = "MESSAGE=System is halting.";
+                 q = "SHUTDOWN=halt";
+                 break;
+         case HANDLE_REBOOT:
+                 p = "MESSAGE=System is rebooting.";
+                 q = "SHUTDOWN=reboot";
+                 break;
+         case HANDLE_KEXEC:
+                 p = "MESSAGE=System is rebooting with kexec.";
+                 q = "SHUTDOWN=kexec";
+                 break;
+         default:
+                 p = "MESSAGE=System is shutting down.";
+                 q = NULL;
+         }
+#endif // 0
+        if (isempty(m->wall_message))
+                p = strjoina(p, ".");
+        else
+                p = strjoina(p, " (", m->wall_message, ").");
 
         return log_struct(LOG_NOTICE,
                           LOG_MESSAGE_ID(SD_MESSAGE_SHUTDOWN),
 
         return log_struct(LOG_NOTICE,
                           LOG_MESSAGE_ID(SD_MESSAGE_SHUTDOWN),
@@ -1433,26 +1484,18 @@ int manager_set_lid_switch_ignore(Manager *m, usec_t until) {
         return r;
 }
 
         return r;
 }
 
-static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) {
-
-        static const char * const signal_name[_INHIBIT_WHAT_MAX] = {
-                [INHIBIT_SHUTDOWN] = "PrepareForShutdown",
-                [INHIBIT_SLEEP] = "PrepareForSleep"
-        };
-
-        int active = _active;
-
-        assert(m);
-        assert(w >= 0);
-        assert(w < _INHIBIT_WHAT_MAX);
-        assert(signal_name[w]);
+static void reset_scheduled_shutdown(Manager *m) {
+        m->scheduled_shutdown_timeout_source = sd_event_source_unref(m->scheduled_shutdown_timeout_source);
+        m->wall_message_timeout_source = sd_event_source_unref(m->wall_message_timeout_source);
+        m->nologin_timeout_source = sd_event_source_unref(m->nologin_timeout_source);
+        m->scheduled_shutdown_type = mfree(m->scheduled_shutdown_type);
+        m->scheduled_shutdown_timeout = 0;
+        m->shutdown_dry_run = false;
 
 
-        return sd_bus_emit_signal(m->bus,
-                                  "/org/freedesktop/login1",
-                                  "org.freedesktop.login1.Manager",
-                                  signal_name[w],
-                                  "b",
-                                  active);
+        if (m->unlink_nologin) {
+                (void) unlink("/run/nologin");
+                m->unlink_nologin = false;
+        }
 }
 
 static int execute_shutdown_or_sleep(
 }
 
 static int execute_shutdown_or_sleep(
@@ -1464,8 +1507,8 @@ static int execute_shutdown_or_sleep(
 /// elogind does not need these, we do it ourselves
 #if 0
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
 /// elogind does not need these, we do it ourselves
 #if 0
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+        char *c = NULL;
         const char *p;
         const char *p;
-        char *c;
 #endif // 0
         int r;
 
 #endif // 0
         int r;
 
@@ -1477,6 +1520,10 @@ static int execute_shutdown_or_sleep(
 
 /// elogind does it directly without depending on systemd running the system
 #if 0
 
 /// elogind does it directly without depending on systemd running the system
 #if 0
+        if (m->shutdown_dry_run) {
+                log_info("Running in dry run, suppressing action.");
+                reset_scheduled_shutdown(m);
+        } else {
         r = sd_bus_call_method(
                         m->bus,
                         "org.freedesktop.systemd1",
         r = sd_bus_call_method(
                         m->bus,
                         "org.freedesktop.systemd1",
@@ -1501,6 +1548,7 @@ static int execute_shutdown_or_sleep(
         c = strdup(p);
         if (!c)
                 return -ENOMEM;
         c = strdup(p);
         if (!c)
                 return -ENOMEM;
+        }
 
         m->action_unit = unit_name;
         free(m->action_job);
 
         m->action_unit = unit_name;
         free(m->action_job);
@@ -1508,12 +1556,6 @@ static int execute_shutdown_or_sleep(
         m->action_what = w;
 #endif // 0
 
         m->action_what = w;
 #endif // 0
 
-        if (w == INHIBIT_SLEEP)
-                /* And we're back. */
-                send_prepare_for(m, w, false);
-
-        m->action_what = 0;
-
         /* Make sure the lid switch is ignored for a while */
         manager_set_lid_switch_ignore(m, now(CLOCK_MONOTONIC) + m->holdoff_timeout_usec);
 
         /* Make sure the lid switch is ignored for a while */
         manager_set_lid_switch_ignore(m, now(CLOCK_MONOTONIC) + m->holdoff_timeout_usec);
 
@@ -1608,6 +1650,28 @@ static int delay_shutdown_or_sleep(
         return 0;
 }
 
         return 0;
 }
 
+static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) {
+
+        static const char * const signal_name[_INHIBIT_WHAT_MAX] = {
+                [INHIBIT_SHUTDOWN] = "PrepareForShutdown",
+                [INHIBIT_SLEEP] = "PrepareForSleep"
+        };
+
+        int active = _active;
+
+        assert(m);
+        assert(w >= 0);
+        assert(w < _INHIBIT_WHAT_MAX);
+        assert(signal_name[w]);
+
+        return sd_bus_emit_signal(m->bus,
+                                  "/org/freedesktop/login1",
+                                  "org.freedesktop.login1.Manager",
+                                  signal_name[w],
+                                  "b",
+                                  active);
+}
+
 int bus_manager_shutdown_or_sleep_now_or_later(
                 Manager *m,
                 HandleAction action,
 int bus_manager_shutdown_or_sleep_now_or_later(
                 Manager *m,
                 HandleAction action,
@@ -1911,6 +1975,11 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
+        if (startswith(type, "dry-")) {
+                type += 4;
+                m->shutdown_dry_run = true;
+        }
+
         if (streq(type, "reboot")) {
                 action = "org.freedesktop.login1.reboot";
                 action_multiple_sessions = "org.freedesktop.login1.reboot-multiple-sessions";
         if (streq(type, "reboot")) {
                 action = "org.freedesktop.login1.reboot";
                 action_multiple_sessions = "org.freedesktop.login1.reboot-multiple-sessions";
@@ -2005,17 +2074,7 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd
         assert(message);
 
         cancelled = m->scheduled_shutdown_type != NULL;
         assert(message);
 
         cancelled = m->scheduled_shutdown_type != NULL;
-
-        m->scheduled_shutdown_timeout_source = sd_event_source_unref(m->scheduled_shutdown_timeout_source);
-        m->wall_message_timeout_source = sd_event_source_unref(m->wall_message_timeout_source);
-        m->nologin_timeout_source = sd_event_source_unref(m->nologin_timeout_source);
-        m->scheduled_shutdown_type = mfree(m->scheduled_shutdown_type);
-        m->scheduled_shutdown_timeout = 0;
-
-        if (m->unlink_nologin) {
-                (void) unlink("/run/nologin");
-                m->unlink_nologin = false;
-        }
+        reset_scheduled_shutdown(m);
 
         if (cancelled) {
                 _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
 
         if (cancelled) {
                 _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
@@ -2030,7 +2089,7 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd
                 }
 
                 utmp_wall("The system shutdown has been cancelled",
                 }
 
                 utmp_wall("The system shutdown has been cancelled",
-                          lookup_uid(uid), tty, logind_wall_tty_filter, m);
+                          uid_to_name(uid), tty, logind_wall_tty_filter, m);
         }
 
         return sd_bus_reply_method_return(message, "b", cancelled);
         }
 
         return sd_bus_reply_method_return(message, "b", cancelled);
@@ -2743,13 +2802,101 @@ int manager_send_changed(Manager *manager, const char *property, ...) {
 
 /// UNNEEDED by elogind
 #if 0
 
 /// UNNEEDED by elogind
 #if 0
+int manager_start_slice(
+                Manager *manager,
+                const char *slice,
+                const char *description,
+                const char *after,
+                const char *after2,
+                uint64_t tasks_max,
+                sd_bus_error *error,
+                char **job) {
+
+        _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
+        int r;
+
+        assert(manager);
+        assert(slice);
+
+        r = sd_bus_message_new_method_call(
+                        manager->bus,
+                        &m,
+                        "org.freedesktop.systemd1",
+                        "/org/freedesktop/systemd1",
+                        "org.freedesktop.systemd1.Manager",
+                        "StartTransientUnit");
+        if (r < 0)
+                return r;
+
+        r = sd_bus_message_append(m, "ss", strempty(slice), "fail");
+        if (r < 0)
+                return r;
+
+        r = sd_bus_message_open_container(m, 'a', "(sv)");
+        if (r < 0)
+                return r;
+
+        if (!isempty(description)) {
+                r = sd_bus_message_append(m, "(sv)", "Description", "s", description);
+                if (r < 0)
+                        return r;
+        }
+
+        if (!isempty(after)) {
+                r = sd_bus_message_append(m, "(sv)", "After", "as", 1, after);
+                if (r < 0)
+                        return r;
+        }
+
+        if (!isempty(after2)) {
+                r = sd_bus_message_append(m, "(sv)", "After", "as", 1, after2);
+                if (r < 0)
+                        return r;
+        }
+
+        r = sd_bus_message_append(m, "(sv)", "TasksMax", "t", tasks_max);
+        if (r < 0)
+                return r;
+
+        r = sd_bus_message_close_container(m);
+        if (r < 0)
+                return r;
+
+        r = sd_bus_message_append(m, "a(sa(sv))", 0);
+        if (r < 0)
+                return r;
+
+        r = sd_bus_call(manager->bus, m, 0, error, &reply);
+        if (r < 0)
+                return r;
+
+        if (job) {
+                const char *j;
+                char *copy;
+
+                r = sd_bus_message_read(reply, "o", &j);
+                if (r < 0)
+                        return r;
+
+                copy = strdup(j);
+                if (!copy)
+                        return -ENOMEM;
+
+                *job = copy;
+        }
+
+        return 1;
+}
+
 int manager_start_scope(
                 Manager *manager,
                 const char *scope,
                 pid_t pid,
                 const char *slice,
                 const char *description,
 int manager_start_scope(
                 Manager *manager,
                 const char *scope,
                 pid_t pid,
                 const char *slice,
                 const char *description,
-                const char *after, const char *after2,
+                const char *after,
+                const char *after2,
+                uint64_t tasks_max,
                 sd_bus_error *error,
                 char **job) {
 
                 sd_bus_error *error,
                 char **job) {
 
@@ -2817,6 +2964,10 @@ int manager_start_scope(
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
+        r = sd_bus_message_append(m, "(sv)", "TasksMax", "t", tasks_max);
+        if (r < 0)
+                return r;
+
         r = sd_bus_message_close_container(m);
         if (r < 0)
                 return r;
         r = sd_bus_message_close_container(m);
         if (r < 0)
                 return r;
index ee4c45fb8dd9125d76d0bc0d366981a67c31f5c4..ffb9162e56c435f7a7add489d410b9e96c94a555 100644 (file)
@@ -21,8 +21,9 @@
 
 #include <string.h>
 
 
 #include <string.h>
 
-#include "util.h"
+#include "alloc-util.h"
 #include "logind-device.h"
 #include "logind-device.h"
+#include "util.h"
 
 Device* device_new(Manager *m, const char *sysfs, bool master) {
         Device *d;
 
 Device* device_new(Manager *m, const char *sysfs, bool master) {
         Device *d;
index 0c9c1e5e9795065e1ce4bd552cae76e281579b91..33fbdde557c92ae5d4f6a10b0eae0846c7454c3b 100644 (file)
 #include <string.h>
 #include <unistd.h>
 
 #include <string.h>
 #include <unistd.h>
 
-#include "util.h"
-#include "mkdir.h"
-#include "logind-inhibit.h"
+#include "alloc-util.h"
+#include "escape.h"
+#include "fd-util.h"
 #include "fileio.h"
 #include "formats-util.h"
 #include "fileio.h"
 #include "formats-util.h"
+#include "logind-inhibit.h"
+#include "mkdir.h"
+#include "parse-util.h"
+#include "string-table.h"
+#include "string-util.h"
+#include "user-util.h"
+#include "util.h"
 
 Inhibitor* inhibitor_new(Manager *m, const char* id) {
         Inhibitor *i;
 
 Inhibitor* inhibitor_new(Manager *m, const char* id) {
         Inhibitor *i;
index 346e1d2cece27f970ee2d537c13a106a66a7f6b1..43b578f364d447b11ecf0a445fa9ac3bb7091e12 100644 (file)
 #include <errno.h>
 #include <string.h>
 
 #include <errno.h>
 #include <string.h>
 
-#include "util.h"
-#include "bus-util.h"
-#include "strv.h"
+#include "alloc-util.h"
 #include "bus-common-errors.h"
 #include "bus-label.h"
 #include "bus-common-errors.h"
 #include "bus-label.h"
-#include "logind.h"
+#include "bus-util.h"
 #include "logind-seat.h"
 #include "logind-seat.h"
+#include "logind.h"
+#include "strv.h"
+#include "user-util.h"
+#include "util.h"
 
 static int property_get_active_session(
                 sd_bus *bus,
 
 static int property_get_active_session(
                 sd_bus *bus,
index 1be8713754c3fec5503c8c8e06a6b8a9273fc3c4..6838d36997ec97cfeba41986e36ec6856ada77df 100644 (file)
 ***/
 
 #include <errno.h>
 ***/
 
 #include <errno.h>
-#include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
 #include <fcntl.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "sd-messages.h"
 
 #include "sd-messages.h"
-#include "logind-seat.h"
+
+#include "alloc-util.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "formats-util.h"
 #include "logind-acl.h"
 #include "logind-acl.h"
-#include "util.h"
+#include "logind-seat.h"
 #include "mkdir.h"
 #include "mkdir.h"
-#include "formats-util.h"
+#include "parse-util.h"
+#include "string-util.h"
 #include "terminal-util.h"
 #include "terminal-util.h"
+#include "util.h"
 
 Seat *seat_new(Manager *m, const char *id) {
         Seat *s;
 
 Seat *seat_new(Manager *m, const char *id) {
         Seat *s;
index 5d3fec41146157dd5c5bb2fc9232bb2ef2c8cd57..0be2f8abef94791facedd88ef1654c82e57a6321 100644 (file)
 #include <errno.h>
 #include <string.h>
 
 #include <errno.h>
 #include <string.h>
 
-#include "util.h"
-#include "strv.h"
-#include "bus-util.h"
+#include "alloc-util.h"
 #include "bus-common-errors.h"
 #include "bus-label.h"
 #include "bus-common-errors.h"
 #include "bus-label.h"
-
-#include "logind.h"
-#include "logind-session.h"
+#include "bus-util.h"
+#include "fd-util.h"
 #include "logind-session-device.h"
 #include "logind-session-device.h"
+#include "logind-session.h"
+#include "logind.h"
+#include "strv.h"
+#include "util.h"
 
 static int property_get_user(
                 sd_bus *bus,
 
 static int property_get_user(
                 sd_bus *bus,
index 656f268dba4eae34440005ec6a870359e7fb2608..9bf3ca0995530eca91c25aedcf911416f31fe8a1 100644 (file)
 ***/
 
 #include <fcntl.h>
 ***/
 
 #include <fcntl.h>
-#include <libudev.h>
 #include <linux/input.h>
 #include <string.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
 
 #include <linux/input.h>
 #include <string.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
 
-#include "util.h"
-#include "missing.h"
+#include "libudev.h"
+
+#include "alloc-util.h"
 #include "bus-util.h"
 #include "bus-util.h"
+#include "fd-util.h"
 #include "logind-session-device.h"
 #include "logind-session-device.h"
+#include "missing.h"
+#include "util.h"
 
 enum SessionDeviceNotifications {
         SESSION_DEVICE_RESUME,
 
 enum SessionDeviceNotifications {
         SESSION_DEVICE_RESUME,
index 9b6f46b6faebd120ea6dd0615831133727da8fcb..c53e9f9a5059c44caea2e8a79d89bd4db0ce9edd 100644 (file)
 
 #include <errno.h>
 #include <fcntl.h>
 
 #include <errno.h>
 #include <fcntl.h>
-#include <linux/vt.h>
 #include <linux/kd.h>
 #include <linux/kd.h>
+#include <linux/vt.h>
 #include <signal.h>
 #include <string.h>
 #include <sys/ioctl.h>
 #include <unistd.h>
 
 #include "sd-messages.h"
 #include <signal.h>
 #include <string.h>
 #include <sys/ioctl.h>
 #include <unistd.h>
 
 #include "sd-messages.h"
-#include "util.h"
-#include "mkdir.h"
-#include "path-util.h"
-#include "fileio.h"
-#include "audit.h"
-#include "bus-util.h"
+
+#include "alloc-util.h"
+#include "audit-util.h"
 #include "bus-error.h"
 #include "bus-error.h"
-#include "logind-session.h"
+#include "bus-util.h"
+#include "escape.h"
+#include "fd-util.h"
+#include "fileio.h"
 #include "formats-util.h"
 #include "formats-util.h"
+#include "io-util.h"
+#include "logind-session.h"
+#include "mkdir.h"
+#include "parse-util.h"
+#include "path-util.h"
+#include "string-table.h"
 #include "terminal-util.h"
 #include "terminal-util.h"
+#include "user-util.h"
+#include "util.h"
 
 // #define RELEASE_USEC (20*USEC_PER_SEC)
 
 
 // #define RELEASE_USEC (20*USEC_PER_SEC)
 
@@ -511,28 +519,35 @@ int session_activate(Session *s) {
 /// UNNEEDED by elogind
 #if 0
 static int session_start_scope(Session *s) {
 /// UNNEEDED by elogind
 #if 0
 static int session_start_scope(Session *s) {
-        int r = 0;
+        int r;
 
         assert(s);
         assert(s->user);
 
         if (!s->scope) {
                 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
 
         assert(s);
         assert(s->user);
 
         if (!s->scope) {
                 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
-                _cleanup_free_ char *description = NULL;
-                char *scope = NULL; //, *job = NULL;
-
-                description = strjoin("Session ", s->id, " of user ", s->user->name, NULL);
-                if (!description)
-                        return log_oom();
+                char *scope, *job = NULL;
+                const char *description;
 
                 scope = strjoin("session-", s->id, ".scope", NULL);
                 if (!scope)
                         return log_oom();
 
 
                 scope = strjoin("session-", s->id, ".scope", NULL);
                 if (!scope)
                         return log_oom();
 
-                r = manager_start_scope(s->manager, scope, s->leader, s->user->slice, description, "systemd-logind.service", "systemd-user-sessions.service", &error, &job);
+                description = strjoina("Session ", s->id, " of user ", s->user->name, NULL);
+
+                r = manager_start_scope(
+                                s->manager,
+                                scope,
+                                s->leader,
+                                s->user->slice,
+                                description,
+                                "systemd-logind.service",
+                                "systemd-user-sessions.service",
+                                (uint64_t) -1, /* disable TasksMax= for the scope, rely on the slice setting for it */
+                                &error,
+                                &job);
                 if (r < 0) {
                 if (r < 0) {
-                        log_error("Failed to start session scope %s: %s %s",
-                                  scope, bus_error_message(&error, r), error.name);
+                        log_error_errno(r, "Failed to start session scope %s: %s", scope, bus_error_message(&error, r));
                         free(scope);
                         return r;
                 } else {
                         free(scope);
                         return r;
                 } else {
@@ -544,7 +559,7 @@ static int session_start_scope(Session *s) {
         }
 
         if (s->scope)
         }
 
         if (s->scope)
-                hashmap_put(s->manager->session_units, s->scope, s);
+                (void) hashmap_put(s->manager->session_units, s->scope, s);
 
         return 0;
 }
 
         return 0;
 }
@@ -1091,7 +1106,7 @@ static int session_open_vt(Session *s) {
         sprintf(path, "/dev/tty%u", s->vtnr);
         s->vtfd = open_terminal(path, O_RDWR | O_CLOEXEC | O_NONBLOCK | O_NOCTTY);
         if (s->vtfd < 0)
         sprintf(path, "/dev/tty%u", s->vtnr);
         s->vtfd = open_terminal(path, O_RDWR | O_CLOEXEC | O_NONBLOCK | O_NOCTTY);
         if (s->vtfd < 0)
-                return log_error_errno(errno, "cannot open VT %s of session %s: %m", path, s->id);
+                return log_error_errno(s->vtfd, "cannot open VT %s of session %s: %m", path, s->id);
 
         return s->vtfd;
 }
 
         return s->vtfd;
 }
index 20ea2fbdc415882b28461ab7a70db53378b25921..df901f6558101111fb8ed65c02cee4242160f5a1 100644 (file)
 #include <errno.h>
 #include <string.h>
 
 #include <errno.h>
 #include <string.h>
 
-#include "strv.h"
+#include "alloc-util.h"
 #include "bus-util.h"
 #include "bus-util.h"
-#include "logind.h"
-#include "logind-user.h"
 #include "formats-util.h"
 #include "formats-util.h"
+#include "logind-user.h"
+#include "logind.h"
+#include "strv.h"
+#include "user-util.h"
 
 static int property_get_display(
                 sd_bus *bus,
 
 static int property_get_display(
                 sd_bus *bus,
index 27f73700008ccbc8f6fc3fdd4fca56cdb8a1739a..ecc61080a322a6f321f723e6a222113d5bf6f0e1 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <sys/mount.h>
+#include <errno.h>
 #include <string.h>
 #include <string.h>
+#include <sys/mount.h>
 #include <unistd.h>
 #include <unistd.h>
-#include <errno.h>
 
 
-#include "util.h"
-#include "mkdir.h"
-#include "rm-rf.h"
-#include "hashmap.h"
-#include "fileio.h"
-#include "path-util.h"
-// #include "special.h"
-#include "unit-name.h"
-#include "bus-util.h"
+#include "alloc-util.h"
+#include "bus-common-errors.h"
 #include "bus-error.h"
 #include "bus-error.h"
-#include "conf-parser.h"
+#include "bus-util.h"
 #include "clean-ipc.h"
 #include "clean-ipc.h"
-#include "smack-util.h"
+#include "conf-parser.h"
+#include "escape.h"
+#include "fd-util.h"
+#include "fileio.h"
 #include "formats-util.h"
 #include "formats-util.h"
+#include "fs-util.h"
+#include "hashmap.h"
 #include "label.h"
 #include "logind-user.h"
 #include "label.h"
 #include "logind-user.h"
+#include "mkdir.h"
+#include "mount-util.h"
+#include "parse-util.h"
+#include "path-util.h"
+#include "rm-rf.h"
+#include "smack-util.h"
+//#include "special.h"
+#include "stdio-util.h"
+#include "string-table.h"
+#include "unit-name.h"
+#include "user-util.h"
+#include "util.h"
 
 
-User* user_new(Manager *m, uid_t uid, gid_t gid, const char *name) {
-        User *u;
+int user_new(User **out, Manager *m, uid_t uid, gid_t gid, const char *name) {
+        _cleanup_(user_freep) User *u = NULL;
+        char lu[DECIMAL_STR_MAX(uid_t) + 1];
+        int r;
 
 
+        assert(out);
         assert(m);
         assert(name);
 
         u = new0(User, 1);
         if (!u)
         assert(m);
         assert(name);
 
         u = new0(User, 1);
         if (!u)
-                return NULL;
+                return -ENOMEM;
+
+        u->manager = m;
+        u->uid = uid;
+        u->gid = gid;
+        xsprintf(lu, UID_FMT, uid);
 
         u->name = strdup(name);
         if (!u->name)
 
         u->name = strdup(name);
         if (!u->name)
-                goto fail;
+                return -ENOMEM;
 
         if (asprintf(&u->state_file, "/run/systemd/users/"UID_FMT, uid) < 0)
 
         if (asprintf(&u->state_file, "/run/systemd/users/"UID_FMT, uid) < 0)
-                goto fail;
+                return -ENOMEM;
 
 
-        if (hashmap_put(m->users, UID_TO_PTR(uid), u) < 0)
-                goto fail;
+        if (asprintf(&u->runtime_path, "/run/user/"UID_FMT, uid) < 0)
+                return -ENOMEM;
 
 
-        u->manager = m;
-        u->uid = uid;
-        u->gid = gid;
+        r = slice_build_subslice("user.slice", lu, &u->slice);
+        if (r < 0)
+                return r;
 
 
-        return u;
+        r = unit_name_build("user", lu, ".service", &u->service);
+        if (r < 0)
+                return r;
 
 
-fail:
-        free(u->state_file);
-        free(u->name);
-        free(u);
+        r = hashmap_put(m->users, UID_TO_PTR(uid), u);
+        if (r < 0)
+                return r;
+
+        r = hashmap_put(m->user_units, u->slice, u);
+        if (r < 0)
+                return r;
+
+        r = hashmap_put(m->user_units, u->service, u);
+        if (r < 0)
+                return r;
 
 
-        return NULL;
+        *out = u;
+        u = NULL;
+        return 0;
 }
 
 }
 
-void user_free(User *u) {
-        assert(u);
+User *user_free(User *u) {
+        if (!u)
+                return NULL;
 
         if (u->in_gc_queue)
                 LIST_REMOVE(gc_queue, u->manager->user_gc_queue, u);
 
         if (u->in_gc_queue)
                 LIST_REMOVE(gc_queue, u->manager->user_gc_queue, u);
@@ -84,29 +114,26 @@ void user_free(User *u) {
         while (u->sessions)
                 session_free(u->sessions);
 
         while (u->sessions)
                 session_free(u->sessions);
 
-        if (u->slice) {
-                hashmap_remove(u->manager->user_units, u->slice);
-                free(u->slice);
-        }
+        if (u->service)
+                hashmap_remove_value(u->manager->user_units, u->service, u);
 
 
-        if (u->service) {
-                hashmap_remove(u->manager->user_units, u->service);
-                free(u->service);
-        }
+        if (u->slice)
+                hashmap_remove_value(u->manager->user_units, u->slice, u);
+
+        hashmap_remove_value(u->manager->users, UID_TO_PTR(u->uid), u);
 
 
-/// elogind does not support slice and service jobs
+/// elogind neither supports slice nor service jobs.
 #if 0
 #if 0
-        free(u->slice_job);
-        free(u->service_job);
+        u->slice_job = mfree(u->slice_job);
+        u->service_job = mfree(u->service_job);
 #endif // 0
 #endif // 0
+        u->service = mfree(u->service);
+        u->slice = mfree(u->slice);
+        u->runtime_path = mfree(u->runtime_path);
+        u->state_file = mfree(u->state_file);
+        u->name = mfree(u->name);
 
 
-        free(u->runtime_path);
-
-        hashmap_remove(u->manager->users, UID_TO_PTR(u->uid));
-
-        free(u->name);
-        free(u->state_file);
-        free(u);
+        return mfree(u);
 }
 
 static int user_save_internal(User *u) {
 }
 
 static int user_save_internal(User *u) {
@@ -134,21 +161,15 @@ static int user_save_internal(User *u) {
                 u->name,
                 user_state_to_string(user_get_state(u)));
 
                 u->name,
                 user_state_to_string(user_get_state(u)));
 
+        /* LEGACY: no-one reads RUNTIME= anymore, drop it at some point */
         if (u->runtime_path)
                 fprintf(f, "RUNTIME=%s\n", u->runtime_path);
 
         if (u->runtime_path)
                 fprintf(f, "RUNTIME=%s\n", u->runtime_path);
 
-        if (u->service)
-                fprintf(f, "SERVICE=%s\n", u->service);
-/// elogind does not support service jobs
+/// elogind neither supports service nor slice jobs
 #if 0
         if (u->service_job)
                 fprintf(f, "SERVICE_JOB=%s\n", u->service_job);
 #if 0
         if (u->service_job)
                 fprintf(f, "SERVICE_JOB=%s\n", u->service_job);
-#endif // 0
 
 
-        if (u->slice)
-                fprintf(f, "SLICE=%s\n", u->slice);
-/// elogind does not support slice jobs
-#if 0
         if (u->slice_job)
                 fprintf(f, "SLICE_JOB=%s\n", u->slice_job);
 #endif // 0
         if (u->slice_job)
                 fprintf(f, "SLICE_JOB=%s\n", u->slice_job);
 #endif // 0
@@ -287,15 +308,9 @@ int user_load(User *u) {
         assert(u);
 
         r = parse_env_file(u->state_file, NEWLINE,
         assert(u);
 
         r = parse_env_file(u->state_file, NEWLINE,
-                           "RUNTIME",     &u->runtime_path,
-                           "SERVICE",     &u->service,
-/// elogind does not support service jobs
+/// elogind neither supports service nor slice jobs
 #if 0
                            "SERVICE_JOB", &u->service_job,
 #if 0
                            "SERVICE_JOB", &u->service_job,
-#endif // 0
-                           "SLICE",       &u->slice,
-/// elogind does not support slice jobs
-#if 0
                            "SLICE_JOB",   &u->slice_job,
 #endif // 0
                            "DISPLAY",     &display,
                            "SLICE_JOB",   &u->slice_job,
 #endif // 0
                            "DISPLAY",     &display,
@@ -332,7 +347,6 @@ int user_load(User *u) {
 }
 
 static int user_mkdir_runtime_path(User *u) {
 }
 
 static int user_mkdir_runtime_path(User *u) {
-        char *p;
         int r;
 
         assert(u);
         int r;
 
         assert(u);
@@ -341,16 +355,10 @@ static int user_mkdir_runtime_path(User *u) {
         if (r < 0)
                 return log_error_errno(r, "Failed to create /run/user: %m");
 
         if (r < 0)
                 return log_error_errno(r, "Failed to create /run/user: %m");
 
-        if (!u->runtime_path) {
-                if (asprintf(&p, "/run/user/" UID_FMT, u->uid) < 0)
-                        return log_oom();
-        } else
-                p = u->runtime_path;
-
-        if (path_is_mount_point(p, 0) <= 0) {
+        if (path_is_mount_point(u->runtime_path, 0) <= 0) {
                 _cleanup_free_ char *t = NULL;
 
                 _cleanup_free_ char *t = NULL;
 
-                (void) mkdir_label(p, 0700);
+                (void) mkdir_label(u->runtime_path, 0700);
 
                 if (mac_smack_use())
                         r = asprintf(&t, "mode=0700,smackfsroot=*,uid=" UID_FMT ",gid=" GID_FMT ",size=%zu", u->uid, u->gid, u->manager->runtime_dir_size);
 
                 if (mac_smack_use())
                         r = asprintf(&t, "mode=0700,smackfsroot=*,uid=" UID_FMT ",gid=" GID_FMT ",size=%zu", u->uid, u->gid, u->manager->runtime_dir_size);
@@ -361,10 +369,10 @@ static int user_mkdir_runtime_path(User *u) {
                         goto fail;
                 }
 
                         goto fail;
                 }
 
-                r = mount("tmpfs", p, "tmpfs", MS_NODEV|MS_NOSUID, t);
+                r = mount("tmpfs", u->runtime_path, "tmpfs", MS_NODEV|MS_NOSUID, t);
                 if (r < 0) {
                         if (errno != EPERM) {
                 if (r < 0) {
                         if (errno != EPERM) {
-                                r = log_error_errno(errno, "Failed to mount per-user tmpfs directory %s: %m", p);
+                                r = log_error_errno(errno, "Failed to mount per-user tmpfs directory %s: %m", u->runtime_path);
                                 goto fail;
                         }
 
                                 goto fail;
                         }
 
@@ -372,106 +380,91 @@ static int user_mkdir_runtime_path(User *u) {
                          * CAP_SYS_ADMIN-less container? In this case,
                          * just use a normal directory. */
 
                          * CAP_SYS_ADMIN-less container? In this case,
                          * just use a normal directory. */
 
-                        r = chmod_and_chown(p, 0700, u->uid, u->gid);
+                        r = chmod_and_chown(u->runtime_path, 0700, u->uid, u->gid);
                         if (r < 0) {
                                 log_error_errno(r, "Failed to change runtime directory ownership and mode: %m");
                                 goto fail;
                         }
                 }
 
                         if (r < 0) {
                                 log_error_errno(r, "Failed to change runtime directory ownership and mode: %m");
                                 goto fail;
                         }
                 }
 
-                r = label_fix(p, false, false);
+                r = label_fix(u->runtime_path, false, false);
                 if (r < 0)
                 if (r < 0)
-                        log_warning_errno(r, "Failed to fix label of '%s', ignoring: %m", p);
+                        log_warning_errno(r, "Failed to fix label of '%s', ignoring: %m", u->runtime_path);
         }
 
         }
 
-        u->runtime_path = p;
         return 0;
 
 fail:
         return 0;
 
 fail:
-        if (p) {
                 /* Try to clean up, but ignore errors */
                 /* Try to clean up, but ignore errors */
-                (void) rmdir(p);
-                free(p);
-        }
-
-        u->runtime_path = NULL;
+        (void) rmdir(u->runtime_path);
         return r;
 }
 
 static int user_start_slice(User *u) {
         return r;
 }
 
 static int user_start_slice(User *u) {
-        // char *job;
+/// elogind can not ask systemd via dbus to start user services
+#if 0
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+        const char *description;
+        char *job;
         int r;
 
         assert(u);
 
         int r;
 
         assert(u);
 
-        if (!u->slice) {
-                _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
-                char lu[DECIMAL_STR_MAX(uid_t) + 1], *slice;
-                sprintf(lu, UID_FMT, u->uid);
-
-                r = slice_build_subslice("user.slice", lu, &slice);
-                if (r < 0)
-                        return r;
-
-/// elogind : Do not try to use dbus to ask systemd
-#if 0
-                r = manager_start_unit(u->manager, slice, &error, &job);
+        u->slice_job = mfree(u->slice_job);
+        description = strjoina("User Slice of ", u->name);
+
+        r = manager_start_slice(
+                        u->manager,
+                        u->slice,
+                        description,
+                        "systemd-logind.service",
+                        "systemd-user-sessions.service",
+                        u->manager->user_tasks_max,
+                        &error,
+                        &job);
                 if (r < 0) {
                 if (r < 0) {
-                        log_error("Failed to start user slice: %s", bus_error_message(&error, r));
-                        free(slice);
+                /* we don't fail due to this, let's try to continue */
+                if (!sd_bus_error_has_name(&error, BUS_ERROR_UNIT_EXISTS))
+                        log_error_errno(r, "Failed to start user slice %s, ignoring: %s (%s)", u->slice, bus_error_message(&error, r), error.name);
                 } else {
                 } else {
-#endif // 0
-                        u->slice = slice;
-
-/// elogind does not support slice jobs
-#if 0
-                        free(u->slice_job);
                         u->slice_job = job;
                 }
                         u->slice_job = job;
                 }
-#endif // 0
-        }
+#else
+        assert(u);
 
 
-        if (u->slice)
-                hashmap_put(u->manager->user_units, u->slice, u);
+        hashmap_put(u->manager->user_units, u->slice, u);
+#endif // 0
 
         return 0;
 }
 
 static int user_start_service(User *u) {
 
         return 0;
 }
 
 static int user_start_service(User *u) {
+/// elogind can not ask systemd via dbus to start user services
+#if 0
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
-        // char *job;
+        char *job;
         int r;
 
         assert(u);
 
         int r;
 
         assert(u);
 
-        if (!u->service) {
-                char lu[DECIMAL_STR_MAX(uid_t) + 1], *service;
-                sprintf(lu, UID_FMT, u->uid);
-
-                r = unit_name_build("user", lu, ".service", &service);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to build service name: %m");
+        u->service_job = mfree(u->service_job);
 
 
-/// elogind : Do not try to use dbus to ask systemd
-#if 0
-                r = manager_start_unit(u->manager, service, &error, &job);
-#endif // 0
+        r = manager_start_unit(
+                        u->manager,
+                        u->service,
+                        &error,
+                        &job);
                 if (r < 0) {
                 if (r < 0) {
-                        log_error("Failed to start user service: %s", bus_error_message(&error, r));
-                        free(service);
+                /* we don't fail due to this, let's try to continue */
+                log_error_errno(r, "Failed to start user service, ignoring: %s", bus_error_message(&error, r));
                 } else {
                 } else {
-                        u->service = service;
-
-/// elogind does not support service jobs
-#if 0
-                        free(u->service_job);
                         u->service_job = job;
                         u->service_job = job;
-#endif // 0
-                }
         }
         }
+#else
+        assert(u);
 
 
-        if (u->service)
-                hashmap_put(u->manager->user_units, u->service, u);
+        hashmap_put(u->manager->user_units, u->service, u);
+#endif // 0
 
         return 0;
 }
 
         return 0;
 }
@@ -541,14 +534,11 @@ int user_start(User *u) {
 #if 0
 static int user_stop_slice(User *u) {
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
 #if 0
 static int user_stop_slice(User *u) {
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
-        // char *job;
-        int r = 0;
+        char *job;
+        int r;
 
         assert(u);
 
 
         assert(u);
 
-        if (!u->slice)
-                return 0;
-
         r = manager_stop_unit(u->manager, u->slice, &error, &job);
         if (r < 0) {
                 log_error("Failed to stop user slice: %s", bus_error_message(&error, r));
         r = manager_stop_unit(u->manager, u->slice, &error, &job);
         if (r < 0) {
                 log_error("Failed to stop user slice: %s", bus_error_message(&error, r));
@@ -563,14 +553,11 @@ static int user_stop_slice(User *u) {
 
 static int user_stop_service(User *u) {
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
 
 static int user_stop_service(User *u) {
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
-        // char *job;
-        int r = 0;
+        char *job;
+        int r;
 
         assert(u);
 
 
         assert(u);
 
-        if (!u->service)
-                return 0;
-
         r = manager_stop_unit(u->manager, u->service, &error, &job);
         if (r < 0) {
                 log_error("Failed to stop user service: %s", bus_error_message(&error, r));
         r = manager_stop_unit(u->manager, u->service, &error, &job);
         if (r < 0) {
                 log_error("Failed to stop user service: %s", bus_error_message(&error, r));
@@ -589,9 +576,6 @@ static int user_remove_runtime_path(User *u) {
 
         assert(u);
 
 
         assert(u);
 
-        if (!u->runtime_path)
-                return 0;
-
         r = rm_rf(u->runtime_path, 0);
         if (r < 0)
                 log_error_errno(r, "Failed to remove runtime directory %s: %m", u->runtime_path);
         r = rm_rf(u->runtime_path, 0);
         if (r < 0)
                 log_error_errno(r, "Failed to remove runtime directory %s: %m", u->runtime_path);
@@ -607,8 +591,6 @@ static int user_remove_runtime_path(User *u) {
         if (r < 0)
                 log_error_errno(r, "Failed to remove runtime directory %s: %m", u->runtime_path);
 
         if (r < 0)
                 log_error_errno(r, "Failed to remove runtime directory %s: %m", u->runtime_path);
 
-        u->runtime_path = mfree(u->runtime_path);
-
         return r;
 }
 
         return r;
 }
 
@@ -748,7 +730,7 @@ bool user_check_gc(User *u, bool drop_not_started) {
         if (user_check_linger_file(u) > 0)
                 return true;
 
         if (user_check_linger_file(u) > 0)
                 return true;
 
-/// elogind does not support systemd services and slices
+/// elogind neither supports service nor slice jobs
 #if 0
         if (u->slice_job && manager_job_is_active(u->manager, u->slice_job))
                 return true;
 #if 0
         if (u->slice_job && manager_job_is_active(u->manager, u->slice_job))
                 return true;
@@ -778,7 +760,7 @@ UserState user_get_state(User *u) {
         if (u->stopping)
                 return USER_CLOSING;
 
         if (u->stopping)
                 return USER_CLOSING;
 
-/// elogind does not support slice and service jobs
+/// elogind neither supports service nor slice jobs.
 #if 0
         if (!u->started || u->slice_job || u->service_job)
 #else
 #if 0
         if (!u->started || u->slice_job || u->service_job)
 #else
@@ -813,9 +795,6 @@ int user_kill(User *u, int signo) {
 #if 0
         assert(u);
 
 #if 0
         assert(u);
 
-        if (!u->slice)
-                return -ESRCH;
-
         return manager_kill_unit(u->manager, u->slice, KILL_ALL, signo, NULL);
 #else
         Session *s;
         return manager_kill_unit(u->manager, u->slice, KILL_ALL, signo, NULL);
 #else
         Session *s;
index b30e7d60c23bf6600816237a59e2a313e2f47cac..a59b11b2a3f1f02df468159dc357dda5b933ff1d 100644 (file)
@@ -39,19 +39,17 @@ typedef enum UserState {
 
 struct User {
         Manager *manager;
 
 struct User {
         Manager *manager;
-
         uid_t uid;
         gid_t gid;
         char *name;
         uid_t uid;
         gid_t gid;
         char *name;
-
         char *state_file;
         char *runtime_path;
 
         /* These are always NULL, and here just for logind-user-dbus.c
            to easily provide a NULL value for the user's service and
            slice properties. */
         char *state_file;
         char *runtime_path;
 
         /* These are always NULL, and here just for logind-user-dbus.c
            to easily provide a NULL value for the user's service and
            slice properties. */
-        char *service;
         char *slice;
         char *slice;
+        char *service;
 
 /// UNNEEDED (and unsupported) by elogind
 #if 0
 
 /// UNNEEDED (and unsupported) by elogind
 #if 0
@@ -71,8 +69,11 @@ struct User {
         LIST_FIELDS(User, gc_queue);
 };
 
         LIST_FIELDS(User, gc_queue);
 };
 
-User* user_new(Manager *m, uid_t uid, gid_t gid, const char *name);
-void user_free(User *u);
+int user_new(User **out, Manager *m, uid_t uid, gid_t gid, const char *name);
+User *user_free(User *u);
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(User *, user_free);
+
 bool user_check_gc(User *u, bool drop_not_started);
 void user_add_to_gc_queue(User *u);
 int user_start(User *u);
 bool user_check_gc(User *u, bool drop_not_started);
 void user_add_to_gc_queue(User *u);
 int user_start(User *u);
index faa4fc73394848d2dc59e522590f5b6fb7530cd6..8c2bfb07a19cbfa7405b5b8744310f2a2af4006a 100644 (file)
 ***/
 
 #include <errno.h>
 ***/
 
 #include <errno.h>
+#include <pwd.h>
 #include <string.h>
 #include <unistd.h>
 #include <string.h>
 #include <unistd.h>
-#include <pwd.h>
 
 #include "sd-messages.h"
 
 #include "sd-messages.h"
-#include "strv.h"
-// #include "special.h"
-#include "unit-name.h"
-#include "audit.h"
-#include "bus-util.h"
-#include "bus-error.h"
+
+#include "alloc-util.h"
+#include "audit-util.h"
 #include "bus-common-errors.h"
 #include "bus-common-errors.h"
-#include "logind.h"
+#include "bus-error.h"
+#include "bus-util.h"
 #include "formats-util.h"
 #include "formats-util.h"
+#include "logind.h"
+//#include "special.h"
+#include "strv.h"
+#include "unit-name.h"
+#include "user-util.h"
 #include "utmp-wtmp.h"
 
 _const_ static usec_t when_wall(usec_t n, usec_t elapse) {
 #include "utmp-wtmp.h"
 
 _const_ static usec_t when_wall(usec_t n, usec_t elapse) {
@@ -94,7 +97,7 @@ static int warn_wall(Manager *m, usec_t n) {
                 return 0;
         }
 
                 return 0;
         }
 
-        utmp_wall(l, lookup_uid(m->scheduled_shutdown_uid),
+        utmp_wall(l, uid_to_name(m->scheduled_shutdown_uid),
                   m->scheduled_shutdown_tty, logind_wall_tty_filter, m);
 
         return 1;
                   m->scheduled_shutdown_tty, logind_wall_tty_filter, m);
 
         return 1;
index 2e4342b0aedf4af9792bae02018107ac46fca38e..8693627f241b556679a4bc85e54c6a96535f0b60 100644 (file)
 ***/
 
 #include <errno.h>
 ***/
 
 #include <errno.h>
-#include <libudev.h>
 #include <fcntl.h>
 #include <string.h>
 #include <unistd.h>
 
 #include <fcntl.h>
 #include <string.h>
 #include <unistd.h>
 
+#include "libudev.h"
 #include "sd-daemon.h"
 #include "sd-daemon.h"
-#include "strv.h"
-#include "conf-parser.h"
-#include "bus-util.h"
+
+#include "alloc-util.h"
 #include "bus-error.h"
 #include "bus-error.h"
-#include "udev-util.h"
+#include "bus-util.h"
+#include "conf-parser.h"
+#include "def.h"
+#include "dirent-util.h"
+#include "fd-util.h"
 #include "formats-util.h"
 #include "formats-util.h"
+#include "logind.h"
 #include "signal-util.h"
 #include "signal-util.h"
+#include "strv.h"
+#include "udev-util.h"
+
+/// additional includes elogind needs
+#include "cgroup.h"       // From src/core/
 #include "label.h"
 #include "label.h"
-#include "logind.h"
-#include "cgroup.h"
-#include "mount-setup.h"
-#include "virt.h"
+#include "mount-setup.h"  // From src/core
+#include "musl_missing.h"
 
 static void manager_free(Manager *m);
 
 
 static void manager_free(Manager *m);
 
@@ -75,6 +82,7 @@ static Manager *manager_new(void) {
         m->idle_action_not_before_usec = now(CLOCK_MONOTONIC);
 
         m->runtime_dir_size = PAGE_ALIGN((size_t) (physical_memory() / 10)); /* 10% */
         m->idle_action_not_before_usec = now(CLOCK_MONOTONIC);
 
         m->runtime_dir_size = PAGE_ALIGN((size_t) (physical_memory() / 10)); /* 10% */
+        m->user_tasks_max = UINT64_C(4096);
 
         m->devices = hashmap_new(&string_hash_ops);
         m->seats = hashmap_new(&string_hash_ops);
 
         m->devices = hashmap_new(&string_hash_ops);
         m->seats = hashmap_new(&string_hash_ops);
@@ -215,12 +223,6 @@ static void manager_free(Manager *m) {
         safe_close(m->reserve_vt_fd);
 #endif // 0
 
         safe_close(m->reserve_vt_fd);
 #endif // 0
 
-        /* Avoid the creation of new processes forked by the
-         * kernel; at this point, we will not listen to the
-         * signals anyway */
-        if (detect_container() <= 0)
-                (void) cg_uninstall_release_agent(SYSTEMD_CGROUP_CONTROLLER);
-
         manager_shutdown_cgroup(m, true);
 
         strv_free(m->kill_only_users);
         manager_shutdown_cgroup(m, true);
 
         strv_free(m->kill_only_users);
@@ -352,8 +354,7 @@ static int manager_enumerate_seats(Manager *m) {
                 if (errno == ENOENT)
                         return 0;
 
                 if (errno == ENOENT)
                         return 0;
 
-                log_error_errno(errno, "Failed to open /run/systemd/seats: %m");
-                return -errno;
+                return log_error_errno(errno, "Failed to open /run/systemd/seats: %m");
         }
 
         FOREACH_DIRENT(de, d, return -errno) {
         }
 
         FOREACH_DIRENT(de, d, return -errno) {
@@ -389,8 +390,7 @@ static int manager_enumerate_linger_users(Manager *m) {
                 if (errno == ENOENT)
                         return 0;
 
                 if (errno == ENOENT)
                         return 0;
 
-                log_error_errno(errno, "Failed to open /var/lib/systemd/linger/: %m");
-                return -errno;
+                return log_error_errno(errno, "Failed to open /var/lib/systemd/linger/: %m");
         }
 
         FOREACH_DIRENT(de, d, return -errno) {
         }
 
         FOREACH_DIRENT(de, d, return -errno) {
@@ -425,8 +425,7 @@ static int manager_enumerate_users(Manager *m) {
                 if (errno == ENOENT)
                         return 0;
 
                 if (errno == ENOENT)
                         return 0;
 
-                log_error_errno(errno, "Failed to open /run/systemd/users: %m");
-                return -errno;
+                return log_error_errno(errno, "Failed to open /run/systemd/users: %m");
         }
 
         FOREACH_DIRENT(de, d, return -errno) {
         }
 
         FOREACH_DIRENT(de, d, return -errno) {
@@ -466,8 +465,7 @@ static int manager_enumerate_sessions(Manager *m) {
                 if (errno == ENOENT)
                         return 0;
 
                 if (errno == ENOENT)
                         return 0;
 
-                log_error_errno(errno, "Failed to open /run/systemd/sessions: %m");
-                return -errno;
+                return log_error_errno(errno, "Failed to open /run/systemd/sessions: %m");
         }
 
         FOREACH_DIRENT(de, d, return -errno) {
         }
 
         FOREACH_DIRENT(de, d, return -errno) {
@@ -513,8 +511,7 @@ static int manager_enumerate_inhibitors(Manager *m) {
                 if (errno == ENOENT)
                         return 0;
 
                 if (errno == ENOENT)
                         return 0;
 
-                log_error_errno(errno, "Failed to open /run/systemd/inhibit: %m");
-                return -errno;
+                return log_error_errno(errno, "Failed to open /run/systemd/inhibit: %m");
         }
 
         FOREACH_DIRENT(de, d, return -errno) {
         }
 
         FOREACH_DIRENT(de, d, return -errno) {
@@ -729,7 +726,7 @@ static int manager_connect_bus(Manager *m) {
                              "path='/org/freedesktop/systemd1'",
                              match_job_removed, m);
         if (r < 0)
                              "path='/org/freedesktop/systemd1'",
                              match_job_removed, m);
         if (r < 0)
-                log_warning_errno(r, "Failed to add match for JobRemoved: %m");
+                return log_error_errno(r, "Failed to add match for JobRemoved: %m");
 
         r = sd_bus_add_match(m->bus,
                              NULL,
 
         r = sd_bus_add_match(m->bus,
                              NULL,
@@ -740,7 +737,7 @@ static int manager_connect_bus(Manager *m) {
                              "path='/org/freedesktop/systemd1'",
                              match_unit_removed, m);
         if (r < 0)
                              "path='/org/freedesktop/systemd1'",
                              match_unit_removed, m);
         if (r < 0)
-                log_warning_errno(r, "Failed to add match for UnitRemoved: %m");
+                return log_error_errno(r, "Failed to add match for UnitRemoved: %m");
 
         r = sd_bus_add_match(m->bus,
                              NULL,
 
         r = sd_bus_add_match(m->bus,
                              NULL,
@@ -750,7 +747,7 @@ static int manager_connect_bus(Manager *m) {
                              "member='PropertiesChanged'",
                              match_properties_changed, m);
         if (r < 0)
                              "member='PropertiesChanged'",
                              match_properties_changed, m);
         if (r < 0)
-                log_warning_errno(r, "Failed to add match for PropertiesChanged: %m");
+                return log_error_errno(r, "Failed to add match for PropertiesChanged: %m");
 
         r = sd_bus_add_match(m->bus,
                              NULL,
 
         r = sd_bus_add_match(m->bus,
                              NULL,
@@ -761,7 +758,7 @@ static int manager_connect_bus(Manager *m) {
                              "path='/org/freedesktop/systemd1'",
                              match_reloading, m);
         if (r < 0)
                              "path='/org/freedesktop/systemd1'",
                              match_reloading, m);
         if (r < 0)
-                log_warning_errno(r, "Failed to add match for Reloading: %m");
+                return log_error_errno(r, "Failed to add match for Reloading: %m");
 
         r = sd_bus_call_method(
                         m->bus,
 
         r = sd_bus_call_method(
                         m->bus,
@@ -771,8 +768,10 @@ static int manager_connect_bus(Manager *m) {
                         "Subscribe",
                         &error,
                         NULL, NULL);
                         "Subscribe",
                         &error,
                         NULL, NULL);
-        if (r < 0)
-                log_notice("Failed to enable subscription: %s", bus_error_message(&error, r));
+        if (r < 0) {
+                log_error("Failed to enable subscription: %s", bus_error_message(&error, r));
+                return r;
+        }
 #endif // 0
 
         r = sd_bus_request_name(m->bus, "org.freedesktop.login1", 0);
 #endif // 0
 
         r = sd_bus_request_name(m->bus, "org.freedesktop.login1", 0);
@@ -847,8 +846,7 @@ static int manager_connect_console(Manager *m) {
                 if (errno == ENOENT)
                         return 0;
 
                 if (errno == ENOENT)
                         return 0;
 
-                log_error_errno(errno, "Failed to open /sys/class/tty/tty0/active: %m");
-                return -errno;
+                return log_error_errno(errno, "Failed to open /sys/class/tty/tty0/active: %m");
         }
 
         r = sd_event_add_io(m->event, &m->console_active_event_source, m->console_active_fd, 0, manager_dispatch_console, m);
         }
 
         r = sd_event_add_io(m->event, &m->console_active_event_source, m->console_active_fd, 0, manager_dispatch_console, m);
@@ -1210,20 +1208,22 @@ static int manager_run(Manager *m) {
 }
 
 static int manager_parse_config_file(Manager *m) {
 }
 
 static int manager_parse_config_file(Manager *m) {
-        const char *unit = NULL, *logind_conf, *sections;
-        FILE *file = NULL;
-        bool relaxed = false, allow_include = false, warn = true;
+/// elogind parses its own config file
+#if 0
 
         assert(m);
 
 
         assert(m);
 
-/// elogind parses its own config file
-#if 0
-        return config_parse_many("/etc/systemd/logind.conf",
-                                 CONF_DIRS_NULSTR("systemd/logind.conf"),
+        return config_parse_many(PKGSYSCONFDIR "/logind.conf",
+                                 CONF_PATHS_NULSTR("systemd/logind.conf.d"),
                                  "Login\0",
                                  config_item_perf_lookup, logind_gperf_lookup,
                                  false, m);
                                  "Login\0",
                                  config_item_perf_lookup, logind_gperf_lookup,
                                  false, m);
-#endif // 0
+#else
+        const char *unit = NULL, *logind_conf, *sections;
+        FILE *file = NULL;
+        bool relaxed = false, allow_include = false, warn = true;
+
+        assert(m);
 
         logind_conf = getenv("ELOGIND_CONF_FILE");
         if (!logind_conf)
 
         logind_conf = getenv("ELOGIND_CONF_FILE");
         if (!logind_conf)
@@ -1233,6 +1233,7 @@ static int manager_parse_config_file(Manager *m) {
         return config_parse(unit, logind_conf, file, sections,
                             config_item_perf_lookup, logind_gperf_lookup,
                             relaxed, allow_include, warn, m);
         return config_parse(unit, logind_conf, file, sections,
                             config_item_perf_lookup, logind_gperf_lookup,
                             relaxed, allow_include, warn, m);
+#endif // 0
 }
 
 int main(int argc, char *argv[]) {
 }
 
 int main(int argc, char *argv[]) {
@@ -1262,6 +1263,12 @@ int main(int argc, char *argv[]) {
          * existence of /run/systemd/seats/ to determine whether
          * logind is available, so please always make sure this check
          * stays in. */
          * existence of /run/systemd/seats/ to determine whether
          * logind is available, so please always make sure this check
          * stays in. */
+/// elogind can not rely on systemd to help, so we need a bit more effort than this
+#if 0
+        mkdir_label("/run/systemd/seats", 0755);
+        mkdir_label("/run/systemd/users", 0755);
+        mkdir_label("/run/systemd/sessions", 0755);
+#else
         r = mkdir_label("/run/systemd", 0755);
         if ( (r < 0) && (-EEXIST != r) )
                 return log_error_errno(r, "Failed to create /run/systemd : %m");
         r = mkdir_label("/run/systemd", 0755);
         if ( (r < 0) && (-EEXIST != r) )
                 return log_error_errno(r, "Failed to create /run/systemd : %m");
@@ -1277,6 +1284,7 @@ int main(int argc, char *argv[]) {
         r = mkdir_label("/run/systemd/machines", 0755);
         if ( r < 0 && (-EEXIST != r) )
                 return log_error_errno(r, "Failed to create /run/systemd/machines : %m");
         r = mkdir_label("/run/systemd/machines", 0755);
         if ( r < 0 && (-EEXIST != r) )
                 return log_error_errno(r, "Failed to create /run/systemd/machines : %m");
+#endif // 0
 
         m = manager_new();
         if (!m) {
 
         m = manager_new();
         if (!m) {
@@ -1292,7 +1300,7 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
                 goto finish;
         }
 
-        log_debug("logind running as pid "PID_FMT, getpid());
+        log_debug("elogind running as pid "PID_FMT, getpid());
 
         sd_notify(false,
                   "READY=1\n"
 
         sd_notify(false,
                   "READY=1\n"
@@ -1300,7 +1308,7 @@ int main(int argc, char *argv[]) {
 
         r = manager_run(m);
 
 
         r = manager_run(m);
 
-        log_debug("logind stopped as pid "PID_FMT, getpid());
+        log_debug("elogind stopped as pid "PID_FMT, getpid());
 
 finish:
         sd_notify(false,
 
 finish:
         sd_notify(false,
index 4783ea3b2106dc1d77222eca1f47638b07dc1a2d..b57e8d0a2ebe439dece54cd129008ea92b4e4632 100644 (file)
 ***/
 
 #include <stdbool.h>
 ***/
 
 #include <stdbool.h>
-#include <libudev.h>
 
 
-#include "config.h"
-#include "sd-event.h"
+#include "libudev.h"
 #include "sd-bus.h"
 #include "sd-bus.h"
+#include "sd-event.h"
+
 #include "cgroup-util.h"
 #include "cgroup-util.h"
-#include "path-lookup.h"
-#include "list.h"
 #include "hashmap.h"
 #include "hashmap.h"
+#include "list.h"
+#include "path-lookup.h"
 #include "set.h"
 
 typedef struct Manager Manager;
 
 #include "set.h"
 
 typedef struct Manager Manager;
 
+#include "logind-action.h"
+#include "logind-button.h"
 #include "logind-device.h"
 #include "logind-inhibit.h"
 #include "logind-device.h"
 #include "logind-inhibit.h"
-#include "logind-button.h"
-#include "logind-action.h"
 
 struct Manager {
         sd_event *event;
 
 struct Manager {
         sd_event *event;
@@ -134,6 +134,8 @@ struct Manager {
         unsigned enable_wall_messages;
         sd_event_source *wall_message_timeout_source;
 
         unsigned enable_wall_messages;
         sd_event_source *wall_message_timeout_source;
 
+        bool shutdown_dry_run;
+
         sd_event_source *idle_action_event_source;
         usec_t idle_action_usec;
         usec_t idle_action_not_before_usec;
         sd_event_source *idle_action_event_source;
         usec_t idle_action_usec;
         usec_t idle_action_not_before_usec;
@@ -162,6 +164,7 @@ struct Manager {
         sd_event_source *lid_switch_ignore_event_source;
 
         size_t runtime_dir_size;
         sd_event_source *lid_switch_ignore_event_source;
 
         size_t runtime_dir_size;
+        uint64_t user_tasks_max;
 };
 
 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device);
 };
 
 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device);
@@ -204,7 +207,7 @@ int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, HandleAction action,
 
 int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_;
 
 
 int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_;
 
-// UNNEEDED int manager_start_scope(Manager *manager, const char *scope, pid_t pid, const char *slice, const char *description, const char *after, const char *after2, sd_bus_error *error, char **job);
+// UNNEEDED int manager_start_slice(Manager *manager, const char *slice, const char *description, const char *after, const char *after2, uint64_t tasks_max, sd_bus_error *error, char **job);// UNNEEDED int manager_start_scope(Manager *manager, const char *scope, pid_t pid, const char *slice, const char *description, const char *after, const char *after2, sd_bus_error *error, char **job);
 // UNNEEDED int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
 // UNNEEDED int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
 // UNNEEDED int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error);
 // UNNEEDED int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
 // UNNEEDED int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
 // UNNEEDED int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error);
index f66f1ce8428bfcfc6ee135dd940e330e4cd62ae1..50c4483ed5cc1fe31571964fca8ad6e3ba483d98 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <endian.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <sys/file.h>
 #include <pwd.h>
 #include <pwd.h>
-#include <endian.h>
-
-#include <security/pam_modules.h>
 #include <security/_pam_macros.h>
 #include <security/_pam_macros.h>
-#include <security/pam_modutil.h>
 #include <security/pam_ext.h>
 #include <security/pam_misc.h>
 #include <security/pam_ext.h>
 #include <security/pam_misc.h>
+#include <security/pam_modules.h>
+#include <security/pam_modutil.h>
+#include <sys/file.h>
 
 
+#include "alloc-util.h"
+#include "audit-util.h"
 #include "bus-common-errors.h"
 #include "bus-common-errors.h"
-#include "util.h"
-#include "audit.h"
-#include "macro.h"
-#include "strv.h"
+#include "bus-error.h"
 #include "bus-util.h"
 #include "def.h"
 #include "bus-util.h"
 #include "def.h"
-#include "socket-util.h"
+#include "fd-util.h"
 #include "fileio.h"
 #include "fileio.h"
-#include "bus-error.h"
 #include "formats-util.h"
 #include "formats-util.h"
-#include "terminal-util.h"
 #include "hostname-util.h"
 #include "hostname-util.h"
+#include "login-util.h"
+#include "macro.h"
+#include "parse-util.h"
+#include "socket-util.h"
+#include "strv.h"
+#include "terminal-util.h"
+#include "util.h"
 
 static int parse_argv(
                 pam_handle_t *handle,
 
 static int parse_argv(
                 pam_handle_t *handle,
@@ -264,18 +267,11 @@ _public_ PAM_EXTERN int pam_sm_open_session(
 
         pam_get_item(handle, PAM_SERVICE, (const void**) &service);
         if (streq_ptr(service, "systemd-user")) {
 
         pam_get_item(handle, PAM_SERVICE, (const void**) &service);
         if (streq_ptr(service, "systemd-user")) {
-                _cleanup_free_ char *p = NULL, *rt = NULL;
+                _cleanup_free_ char *rt = NULL;
 
 
-                if (asprintf(&p, "/run/systemd/users/"UID_FMT, pw->pw_uid) < 0)
+                if (asprintf(&rt, "/run/user/"UID_FMT, pw->pw_uid) < 0)
                         return PAM_BUF_ERR;
 
                         return PAM_BUF_ERR;
 
-                r = parse_env_file(p, NEWLINE,
-                                   "RUNTIME", &rt,
-                                   NULL);
-                if (r < 0 && r != -ENOENT)
-                        return PAM_SESSION_ERR;
-
-                if (rt)  {
                         r = pam_misc_setenv(handle, "XDG_RUNTIME_DIR", rt, 0);
                         if (r != PAM_SUCCESS) {
                                 pam_syslog(handle, LOG_ERR, "Failed to set runtime dir.");
                         r = pam_misc_setenv(handle, "XDG_RUNTIME_DIR", rt, 0);
                         if (r != PAM_SUCCESS) {
                                 pam_syslog(handle, LOG_ERR, "Failed to set runtime dir.");
@@ -285,7 +281,6 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                         r = export_legacy_dbus_address(handle, pw->pw_uid, rt);
                         if (r != PAM_SUCCESS)
                                 return r;
                         r = export_legacy_dbus_address(handle, pw->pw_uid, rt);
                         if (r != PAM_SUCCESS)
                                 return r;
-                }
 
                 return PAM_SUCCESS;
         }
 
                 return PAM_SUCCESS;
         }
@@ -498,7 +493,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                         return PAM_SESSION_ERR;
                 }
 
                         return PAM_SESSION_ERR;
                 }
 
-                r = pam_set_data(handle, "systemd.session-fd", INT_TO_PTR(session_fd+1), NULL);
+                r = pam_set_data(handle, "systemd.session-fd", FD_TO_PTR(session_fd), NULL);
                 if (r != PAM_SUCCESS) {
                         pam_syslog(handle, LOG_ERR, "Failed to install session fd.");
                         safe_close(session_fd);
                 if (r != PAM_SUCCESS) {
                         pam_syslog(handle, LOG_ERR, "Failed to install session fd.");
                         safe_close(session_fd);
index f38f06baf9dec578b42dbd298f52e7dd91c23f0d..e9ca4bb03d0d15cdb0c02a14eeeffedd6d1087af 100644 (file)
 
 #include <errno.h>
 #include <string.h>
 
 #include <errno.h>
 #include <string.h>
-#include <libudev.h>
 
 
-#include "util.h"
-#include "sysfs-show.h"
+#include "libudev.h"
+
+#include "alloc-util.h"
+#include "locale-util.h"
 #include "path-util.h"
 #include "path-util.h"
-#include "udev-util.h"
+#include "string-util.h"
+#include "sysfs-show.h"
 #include "terminal-util.h"
 #include "terminal-util.h"
+#include "udev-util.h"
+#include "util.h"
 
 static int show_sysfs_one(
                 struct udev *udev,
 
 static int show_sysfs_one(
                 struct udev *udev,
index 03516de916b02bd57afc9673bef0d7e463aa9bdc..d0727ff7c7e760b98eb381b947f30989c203f34f 100644 (file)
 
 #include <unistd.h>
 
 
 #include <unistd.h>
 
-#include "macro.h"
-#include "util.h"
 #include "sd-bus.h"
 #include "sd-bus.h"
+
 #include "bus-util.h"
 #include "bus-util.h"
+#include "fd-util.h"
+#include "macro.h"
+#include "util.h"
 
 static int inhibit(sd_bus *bus, const char *what) {
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
 
 static int inhibit(sd_bus *bus, const char *what) {
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
index cd05a82d345cc5be54b63fa976484bdf0e2b075d..c7e51a11b2ae5b3ddea0f71fb8ff337f4b687916 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-// #include <sys/socket.h>
+#include <sys/socket.h>
 
 
-// #include "sd-daemon.h"
-// #include "sd-event.h"
-// #include "util.h"
-#include "strv.h"
-// #include "macro.h"
-// #include "def.h"
-// #include "path-util.h"
-// #include "missing.h"
-// #include "set.h"
-// #include "signal-util.h"
-#include "unit-name.h"
+#include "sd-bus.h"
+#include "sd-daemon.h"
+#include "sd-event.h"
 
 
-// #include "sd-bus.h"
-// #include "bus-error.h"
-// #include "bus-label.h"
+#include "alloc-util.h"
+#include "bus-error.h"
+#include "bus-internal.h"
+#include "bus-label.h"
 #include "bus-message.h"
 #include "bus-util.h"
 #include "bus-message.h"
 #include "bus-util.h"
-#include "bus-internal.h"
+#include "cgroup-util.h"
+#include "def.h"
+//#include "env-util.h"
+#include "escape.h"
+#include "fd-util.h"
+#include "macro.h"
+#include "missing.h"
+#include "parse-util.h"
+#include "path-util.h"
+#include "proc-cmdline.h"
+#include "process-util.h"
+//#include "rlimit-util.h"
+#include "set.h"
+#include "signal-util.h"
+#include "stdio-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "syslog-util.h"
+#include "unit-name.h"
+#include "user-util.h"
+#include "utf8.h"
+#include "util.h"
 
 /// UNNEEDED by elogind
 #if 0
 
 /// UNNEEDED by elogind
 #if 0
@@ -1431,6 +1445,17 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
                         return bus_log_create_error(r);
 
                 return 0;
                         return bus_log_create_error(r);
 
                 return 0;
+        } else if (streq(field, "EnvironmentFile")) {
+                r = sd_bus_message_append_basic(m, SD_BUS_TYPE_STRING, "EnvironmentFiles");
+                if (r < 0)
+                        return r;
+
+                r = sd_bus_message_append(m, "v", "a(sb)", 1,
+                                          eq[0] == '-' ? eq + 1 : eq,
+                                          eq[0] == '-');
+                if (r < 0)
+                        return r;
+                return 0;
         }
 
         r = sd_bus_message_append_basic(m, SD_BUS_TYPE_STRING, field);
         }
 
         r = sd_bus_message_append_basic(m, SD_BUS_TYPE_STRING, field);
@@ -1441,7 +1466,8 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
                        "CPUAccounting", "MemoryAccounting", "BlockIOAccounting", "TasksAccounting",
                        "SendSIGHUP", "SendSIGKILL", "WakeSystem", "DefaultDependencies",
                        "IgnoreSIGPIPE", "TTYVHangup", "TTYReset", "RemainAfterExit",
                        "CPUAccounting", "MemoryAccounting", "BlockIOAccounting", "TasksAccounting",
                        "SendSIGHUP", "SendSIGKILL", "WakeSystem", "DefaultDependencies",
                        "IgnoreSIGPIPE", "TTYVHangup", "TTYReset", "RemainAfterExit",
-                       "PrivateTmp", "PrivateDevices", "PrivateNetwork", "NoNewPrivileges")) {
+                       "PrivateTmp", "PrivateDevices", "PrivateNetwork", "NoNewPrivileges",
+                       "SyslogLevelPrefix", "Delegate")) {
 
                 r = parse_boolean(eq);
                 if (r < 0) {
 
                 r = parse_boolean(eq);
                 if (r < 0) {
@@ -1508,10 +1534,33 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
                               "UtmpIdentifier", "UtmpMode", "PAMName", "TTYPath",
                               "StandardInput", "StandardOutput", "StandardError",
                               "Description", "Slice", "Type", "WorkingDirectory",
                               "UtmpIdentifier", "UtmpMode", "PAMName", "TTYPath",
                               "StandardInput", "StandardOutput", "StandardError",
                               "Description", "Slice", "Type", "WorkingDirectory",
-                              "RootDirectory"))
+                              "RootDirectory", "SyslogIdentifier", "ProtectSystem",
+                              "ProtectHome"))
                 r = sd_bus_message_append(m, "v", "s", eq);
 
                 r = sd_bus_message_append(m, "v", "s", eq);
 
-        else if (streq(field, "DeviceAllow")) {
+        else if (streq(field, "SyslogLevel")) {
+                int level;
+
+                level = log_level_from_string(eq);
+                if (level < 0) {
+                        log_error("Failed to parse %s value %s.", field, eq);
+                        return -EINVAL;
+                }
+
+                r = sd_bus_message_append(m, "v", "i", level);
+
+        } else if (streq(field, "SyslogFacility")) {
+                int facility;
+
+                facility = log_facility_unshifted_from_string(eq);
+                if (facility < 0) {
+                        log_error("Failed to parse %s value %s.", field, eq);
+                        return -EINVAL;
+                }
+
+                r = sd_bus_message_append(m, "v", "i", facility);
+
+        } else if (streq(field, "DeviceAllow")) {
 
                 if (isempty(eq))
                         r = sd_bus_message_append(m, "v", "a(ss)", 0);
 
                 if (isempty(eq))
                         r = sd_bus_message_append(m, "v", "a(ss)", 0);
@@ -1622,9 +1671,52 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
 
                 r = sd_bus_message_append(m, "v", "i", i);
 
 
                 r = sd_bus_message_append(m, "v", "i", i);
 
-        } else if (streq(field, "Environment")) {
+        } else if (STR_IN_SET(field, "Environment", "PassEnvironment")) {
+                const char *p;
 
 
-                r = sd_bus_message_append(m, "v", "as", 1, eq);
+                r = sd_bus_message_open_container(m, 'v', "as");
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                r = sd_bus_message_open_container(m, 'a', "s");
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                p = eq;
+
+                for (;;) {
+                        _cleanup_free_ char *word = NULL;
+
+                        r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_CUNESCAPE);
+                        if (r < 0) {
+                                log_error("Failed to parse Environment value %s", eq);
+                                return -EINVAL;
+                        }
+                        if (r == 0)
+                                break;
+
+                        if (streq(field, "Environment")) {
+                                if (!env_assignment_is_valid(word)) {
+                                        log_error("Invalid environment assignment: %s", word);
+                                        return -EINVAL;
+                                }
+                        } else {  /* PassEnvironment */
+                                if (!env_name_is_valid(word)) {
+                                        log_error("Invalid environment variable name: %s", word);
+                                        return -EINVAL;
+                                }
+                        }
+
+                        r = sd_bus_message_append_basic(m, 's', word);
+                        if (r < 0)
+                                return bus_log_create_error(r);
+                }
+
+                r = sd_bus_message_close_container(m);
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                r = sd_bus_message_close_container(m);
 
         } else if (streq(field, "KillSignal")) {
                 int sig;
 
         } else if (streq(field, "KillSignal")) {
                 int sig;
@@ -1647,6 +1739,113 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
                 }
 
                 r = sd_bus_message_append(m, "v", "t", u);
                 }
 
                 r = sd_bus_message_append(m, "v", "t", u);
+        } else if (streq(field, "TimerSlackNSec")) {
+                nsec_t n;
+
+                r = parse_nsec(eq, &n);
+                if (r < 0) {
+                        log_error("Failed to parse %s value %s", field, eq);
+                        return -EINVAL;
+                }
+
+                r = sd_bus_message_append(m, "v", "t", n);
+        } else if (streq(field, "OOMScoreAdjust")) {
+                int oa;
+
+                r = safe_atoi(eq, &oa);
+                if (r < 0) {
+                        log_error("Failed to parse %s value %s", field, eq);
+                        return -EINVAL;
+                }
+
+                if (!oom_score_adjust_is_valid(oa)) {
+                        log_error("OOM score adjust value out of range");
+                        return -EINVAL;
+                }
+
+                r = sd_bus_message_append(m, "v", "i", oa);
+        } else if (STR_IN_SET(field, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories")) {
+                const char *p;
+
+                r = sd_bus_message_open_container(m, 'v', "as");
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                r = sd_bus_message_open_container(m, 'a', "s");
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                p = eq;
+
+                for (;;) {
+                        _cleanup_free_ char *word = NULL;
+                        int offset;
+
+                        r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES);
+                        if (r < 0) {
+                                log_error("Failed to parse %s value %s", field, eq);
+                                return -EINVAL;
+                        }
+                        if (r == 0)
+                                break;
+
+                        if (!utf8_is_valid(word)) {
+                                log_error("Failed to parse %s value %s", field, eq);
+                                return -EINVAL;
+                        }
+
+                        offset = word[0] == '-';
+                        if (!path_is_absolute(word + offset)) {
+                                log_error("Failed to parse %s value %s", field, eq);
+                                return -EINVAL;
+                        }
+
+                        path_kill_slashes(word + offset);
+
+                        r = sd_bus_message_append_basic(m, 's', word);
+                        if (r < 0)
+                                return bus_log_create_error(r);
+                }
+
+                r = sd_bus_message_close_container(m);
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                r = sd_bus_message_close_container(m);
+
+        } else if (streq(field, "RuntimeDirectory")) {
+                const char *p;
+
+                r = sd_bus_message_open_container(m, 'v', "as");
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                r = sd_bus_message_open_container(m, 'a', "s");
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                p = eq;
+
+                for (;;) {
+                        _cleanup_free_ char *word = NULL;
+
+                        r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES);
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to parse %s value %s", field, eq);
+
+                        if (r == 0)
+                                break;
+
+                        r = sd_bus_message_append_basic(m, 's', word);
+                        if (r < 0)
+                                return bus_log_create_error(r);
+                }
+
+                r = sd_bus_message_close_container(m);
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                r = sd_bus_message_close_container(m);
 
         } else {
                 log_error("Unknown assignment %s.", assignment);
 
         } else {
                 log_error("Unknown assignment %s.", assignment);
@@ -2156,3 +2355,45 @@ bool is_kdbus_available(void) {
 
         return ioctl(fd, KDBUS_CMD_BUS_MAKE, &cmd) >= 0;
 }
 
         return ioctl(fd, KDBUS_CMD_BUS_MAKE, &cmd) >= 0;
 }
+
+/// UNNEEDED by elogind
+#if 0
+int bus_property_get_rlimit(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
+
+        struct rlimit *rl;
+        uint64_t u;
+        rlim_t x;
+
+        assert(bus);
+        assert(reply);
+        assert(userdata);
+
+        rl = *(struct rlimit**) userdata;
+        if (rl)
+                x = rl->rlim_max;
+        else {
+                struct rlimit buf = {};
+                int z;
+
+                z = rlimit_from_string(strstr(property, "Limit"));
+                assert(z >= 0);
+
+                getrlimit(z, &buf);
+                x = buf.rlim_max;
+        }
+
+        /* rlim_t might have different sizes, let's map
+         * RLIMIT_INFINITY to (uint64_t) -1, so that it is the same on
+         * all archs */
+        u = x == RLIM_INFINITY ? (uint64_t) -1 : (uint64_t) x;
+
+        return sd_bus_message_append(reply, "t", u);
+}
+#endif // 0
index db735d9c975cef0bdb11a7221b573d71552b3a0d..cb15a3b56592c3a710bc591015c599c23fac91fe 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <sys/types.h>
-#include <inttypes.h>
-#include <stdbool.h>
-
-// #include "sd-event.h"
 #include "sd-bus.h"
 #include "sd-bus.h"
+#include "sd-event.h"
+
 #include "hashmap.h"
 #include "hashmap.h"
-// #include "install.h"
-// #include "time-util.h"
+//#include "install.h"
+#include "string-util.h"
+#include "time-util.h"
 
 typedef enum BusTransport {
         BUS_TRANSPORT_LOCAL,
 
 typedef enum BusTransport {
         BUS_TRANSPORT_LOCAL,
@@ -207,3 +205,5 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_track*, sd_bus_track_unref);
 
 bool is_kdbus_wanted(void);
 bool is_kdbus_available(void);
 
 bool is_kdbus_wanted(void);
 bool is_kdbus_available(void);
+
+// UNNEEDED int bus_property_get_rlimit(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
new file mode 100644 (file)
index 0000000..4239907
--- /dev/null
@@ -0,0 +1,281 @@
+/*-*- 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 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 <dirent.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "alloc-util.h"
+#include "cgroup-show.h"
+#include "cgroup-util.h"
+#include "fd-util.h"
+#include "formats-util.h"
+#include "locale-util.h"
+#include "macro.h"
+#include "path-util.h"
+#include "process-util.h"
+#include "string-util.h"
+#include "terminal-util.h"
+#include "util.h"
+
+static int compare(const void *a, const void *b) {
+        const pid_t *p = a, *q = b;
+
+        if (*p < *q)
+                return -1;
+        if (*p > *q)
+                return 1;
+        return 0;
+}
+
+static void show_pid_array(pid_t pids[], unsigned n_pids, const char *prefix, unsigned n_columns, bool extra, bool more, bool kernel_threads, OutputFlags flags) {
+        unsigned i, j, pid_width;
+
+        if (n_pids == 0)
+                return;
+
+        qsort(pids, n_pids, sizeof(pid_t), compare);
+
+        /* Filter duplicates */
+        for (j = 0, i = 1; i < n_pids; i++) {
+                if (pids[i] == pids[j])
+                        continue;
+                pids[++j] = pids[i];
+        }
+        n_pids = j + 1;
+        pid_width = DECIMAL_STR_WIDTH(pids[j]);
+
+        if (flags & OUTPUT_FULL_WIDTH)
+                n_columns = 0;
+        else {
+                if (n_columns > pid_width+2)
+                        n_columns -= pid_width+2;
+                else
+                        n_columns = 20;
+        }
+        for (i = 0; i < n_pids; i++) {
+                _cleanup_free_ char *t = NULL;
+
+                get_process_cmdline(pids[i], n_columns, true, &t);
+
+                if (extra)
+                        printf("%s%s ", prefix, draw_special_char(DRAW_TRIANGULAR_BULLET));
+                else
+                        printf("%s%s", prefix, draw_special_char(((more || i < n_pids-1) ? DRAW_TREE_BRANCH : DRAW_TREE_RIGHT)));
+
+                printf("%*"PID_PRI" %s\n", pid_width, pids[i], strna(t));
+        }
+}
+
+
+static int show_cgroup_one_by_path(const char *path, const char *prefix, unsigned n_columns, bool more, bool kernel_threads, OutputFlags flags) {
+        char *fn;
+        _cleanup_fclose_ FILE *f = NULL;
+        size_t n = 0, n_allocated = 0;
+        _cleanup_free_ pid_t *pids = NULL;
+        _cleanup_free_ char *p = NULL;
+        pid_t pid;
+        int r;
+
+        r = cg_mangle_path(path, &p);
+        if (r < 0)
+                return r;
+
+        fn = strjoina(p, "/cgroup.procs");
+        f = fopen(fn, "re");
+        if (!f)
+                return -errno;
+
+        while ((r = cg_read_pid(f, &pid)) > 0) {
+
+                if (!kernel_threads && is_kernel_thread(pid) > 0)
+                        continue;
+
+                if (!GREEDY_REALLOC(pids, n_allocated, n + 1))
+                        return -ENOMEM;
+
+                assert(n < n_allocated);
+                pids[n++] = pid;
+        }
+
+        if (r < 0)
+                return r;
+
+        show_pid_array(pids, n, prefix, n_columns, false, more, kernel_threads, flags);
+
+        return 0;
+}
+
+int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns, bool kernel_threads, OutputFlags flags) {
+        _cleanup_free_ char *fn = NULL, *p1 = NULL, *last = NULL, *p2 = NULL;
+        _cleanup_closedir_ DIR *d = NULL;
+        char *gn = NULL;
+        bool shown_pids = false;
+        int r;
+
+        assert(path);
+
+        if (n_columns <= 0)
+                n_columns = columns();
+
+        if (!prefix)
+                prefix = "";
+
+        r = cg_mangle_path(path, &fn);
+        if (r < 0)
+                return r;
+
+        d = opendir(fn);
+        if (!d)
+                return -errno;
+
+        while ((r = cg_read_subgroup(d, &gn)) > 0) {
+                _cleanup_free_ char *k = NULL;
+
+                k = strjoin(fn, "/", gn, NULL);
+                free(gn);
+                if (!k)
+                        return -ENOMEM;
+
+                if (!(flags & OUTPUT_SHOW_ALL) && cg_is_empty_recursive(NULL, k) > 0)
+                        continue;
+
+                if (!shown_pids) {
+                        show_cgroup_one_by_path(path, prefix, n_columns, true, kernel_threads, flags);
+                        shown_pids = true;
+                }
+
+                if (last) {
+                        printf("%s%s%s\n", prefix, draw_special_char(DRAW_TREE_BRANCH), cg_unescape(basename(last)));
+
+                        if (!p1) {
+                                p1 = strappend(prefix, draw_special_char(DRAW_TREE_VERTICAL));
+                                if (!p1)
+                                        return -ENOMEM;
+                        }
+
+                        show_cgroup_by_path(last, p1, n_columns-2, kernel_threads, flags);
+                        free(last);
+                }
+
+                last = k;
+                k = NULL;
+        }
+
+        if (r < 0)
+                return r;
+
+        if (!shown_pids)
+                show_cgroup_one_by_path(path, prefix, n_columns, !!last, kernel_threads, flags);
+
+        if (last) {
+                printf("%s%s%s\n", prefix, draw_special_char(DRAW_TREE_RIGHT), cg_unescape(basename(last)));
+
+                if (!p2) {
+                        p2 = strappend(prefix, "  ");
+                        if (!p2)
+                                return -ENOMEM;
+                }
+
+                show_cgroup_by_path(last, p2, n_columns-2, kernel_threads, flags);
+        }
+
+        return 0;
+}
+
+int show_cgroup(const char *controller, const char *path, const char *prefix, unsigned n_columns, bool kernel_threads, OutputFlags flags) {
+        _cleanup_free_ char *p = NULL;
+        int r;
+
+        assert(path);
+
+        r = cg_get_path(controller, path, NULL, &p);
+        if (r < 0)
+                return r;
+
+        return show_cgroup_by_path(p, prefix, n_columns, kernel_threads, flags);
+}
+
+static int show_extra_pids(const char *controller, const char *path, const char *prefix, unsigned n_columns, const pid_t pids[], unsigned n_pids, OutputFlags flags) {
+        _cleanup_free_ pid_t *copy = NULL;
+        unsigned i, j;
+        int r;
+
+        assert(path);
+
+        if (n_pids <= 0)
+                return 0;
+
+        if (n_columns <= 0)
+                n_columns = columns();
+
+        prefix = strempty(prefix);
+
+        copy = new(pid_t, n_pids);
+        if (!copy)
+                return -ENOMEM;
+
+        for (i = 0, j = 0; i < n_pids; i++) {
+                _cleanup_free_ char *k = NULL;
+
+                r = cg_pid_get_path(controller, pids[i], &k);
+                if (r < 0)
+                        return r;
+
+                if (path_startswith(k, path))
+                        continue;
+
+                copy[j++] = pids[i];
+        }
+
+        show_pid_array(copy, j, prefix, n_columns, true, false, false, flags);
+
+        return 0;
+}
+
+int show_cgroup_and_extra(const char *controller, const char *path, const char *prefix, unsigned n_columns, bool kernel_threads, const pid_t extra_pids[], unsigned n_extra_pids, OutputFlags flags) {
+        int r;
+
+        assert(path);
+
+        r = show_cgroup(controller, path, prefix, n_columns, kernel_threads, flags);
+        if (r < 0)
+                return r;
+
+        return show_extra_pids(controller, path, prefix, n_columns, extra_pids, n_extra_pids, flags);
+}
+
+/// UNNEEDED by elogind
+#if 0
+int show_cgroup_and_extra_by_spec(const char *spec, const char *prefix, unsigned n_columns, bool kernel_threads, const pid_t extra_pids[], unsigned n_extra_pids, OutputFlags flags) {
+        _cleanup_free_ char *controller = NULL, *path = NULL;
+        int r;
+
+        assert(spec);
+
+        r = cg_split_spec(spec, &controller, &path);
+        if (r < 0)
+                return r;
+
+        return show_cgroup_and_extra(controller, path, prefix, n_columns, kernel_threads, extra_pids, n_extra_pids, flags);
+}
+#endif // 0
index 85d35a567be74ae3431d789837bfcdcc9d009671..d2e0240a800a1cbea965064da08a553596aa4ab8 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <dirent.h>
+#include <fcntl.h>
+#include <mqueue.h>
 #include <sys/ipc.h>
 #include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/sem.h>
 #include <sys/msg.h>
 #include <sys/msg.h>
+#include <sys/sem.h>
+#include <sys/shm.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
-#include <fcntl.h>
-#include <dirent.h>
-//#include <mqueue.h>
 
 
-#include "util.h"
+#include "clean-ipc.h"
+#include "dirent-util.h"
+#include "fd-util.h"
+#include "fileio.h"
 #include "formats-util.h"
 #include "formats-util.h"
+#include "string-util.h"
 #include "strv.h"
 #include "strv.h"
-#include "clean-ipc.h"
+#include "util.h"
 
 static int clean_sysvipc_shm(uid_t delete_uid) {
         _cleanup_fclose_ FILE *f = NULL;
 
 static int clean_sysvipc_shm(uid_t delete_uid) {
         _cleanup_fclose_ FILE *f = NULL;
@@ -44,8 +48,7 @@ static int clean_sysvipc_shm(uid_t delete_uid) {
                 if (errno == ENOENT)
                         return 0;
 
                 if (errno == ENOENT)
                         return 0;
 
-                log_warning_errno(errno, "Failed to open /proc/sysvipc/shm: %m");
-                return -errno;
+                return log_warning_errno(errno, "Failed to open /proc/sysvipc/shm: %m");
         }
 
         FOREACH_LINE(line, f, goto fail) {
         }
 
         FOREACH_LINE(line, f, goto fail) {
@@ -87,8 +90,7 @@ static int clean_sysvipc_shm(uid_t delete_uid) {
         return ret;
 
 fail:
         return ret;
 
 fail:
-        log_warning_errno(errno, "Failed to read /proc/sysvipc/shm: %m");
-        return -errno;
+        return log_warning_errno(errno, "Failed to read /proc/sysvipc/shm: %m");
 }
 
 static int clean_sysvipc_sem(uid_t delete_uid) {
 }
 
 static int clean_sysvipc_sem(uid_t delete_uid) {
@@ -102,8 +104,7 @@ static int clean_sysvipc_sem(uid_t delete_uid) {
                 if (errno == ENOENT)
                         return 0;
 
                 if (errno == ENOENT)
                         return 0;
 
-                log_warning_errno(errno, "Failed to open /proc/sysvipc/sem: %m");
-                return -errno;
+                return log_warning_errno(errno, "Failed to open /proc/sysvipc/sem: %m");
         }
 
         FOREACH_LINE(line, f, goto fail) {
         }
 
         FOREACH_LINE(line, f, goto fail) {
@@ -140,8 +141,7 @@ static int clean_sysvipc_sem(uid_t delete_uid) {
         return ret;
 
 fail:
         return ret;
 
 fail:
-        log_warning_errno(errno, "Failed to read /proc/sysvipc/sem: %m");
-        return -errno;
+        return log_warning_errno(errno, "Failed to read /proc/sysvipc/sem: %m");
 }
 
 static int clean_sysvipc_msg(uid_t delete_uid) {
 }
 
 static int clean_sysvipc_msg(uid_t delete_uid) {
@@ -155,8 +155,7 @@ static int clean_sysvipc_msg(uid_t delete_uid) {
                 if (errno == ENOENT)
                         return 0;
 
                 if (errno == ENOENT)
                         return 0;
 
-                log_warning_errno(errno, "Failed to open /proc/sysvipc/msg: %m");
-                return -errno;
+                return log_warning_errno(errno, "Failed to open /proc/sysvipc/msg: %m");
         }
 
         FOREACH_LINE(line, f, goto fail) {
         }
 
         FOREACH_LINE(line, f, goto fail) {
@@ -194,8 +193,7 @@ static int clean_sysvipc_msg(uid_t delete_uid) {
         return ret;
 
 fail:
         return ret;
 
 fail:
-        log_warning_errno(errno, "Failed to read /proc/sysvipc/msg: %m");
-        return -errno;
+        return log_warning_errno(errno, "Failed to read /proc/sysvipc/msg: %m");
 }
 
 static int clean_posix_shm_internal(DIR *dir, uid_t uid) {
 }
 
 static int clean_posix_shm_internal(DIR *dir, uid_t uid) {
@@ -273,8 +271,7 @@ static int clean_posix_shm(uid_t uid) {
                 if (errno == ENOENT)
                         return 0;
 
                 if (errno == ENOENT)
                         return 0;
 
-                log_warning_errno(errno, "Failed to open /dev/shm: %m");
-                return -errno;
+                return log_warning_errno(errno, "Failed to open /dev/shm: %m");
         }
 
         return clean_posix_shm_internal(dir, uid);
         }
 
         return clean_posix_shm_internal(dir, uid);
@@ -292,8 +289,7 @@ static int clean_posix_mq(uid_t uid) {
                 if (errno == ENOENT)
                         return 0;
 
                 if (errno == ENOENT)
                         return 0;
 
-                log_warning_errno(errno, "Failed to open /dev/mqueue: %m");
-                return -errno;
+                return log_warning_errno(errno, "Failed to open /dev/mqueue: %m");
         }
 
         FOREACH_DIRENT(de, dir, goto fail) {
         }
 
         FOREACH_DIRENT(de, dir, goto fail) {
@@ -332,8 +328,7 @@ static int clean_posix_mq(uid_t uid) {
         return ret;
 
 fail:
         return ret;
 
 fail:
-        log_warning_errno(errno, "Failed to read /dev/mqueue: %m");
-        return -errno;
+        return log_warning_errno(errno, "Failed to read /dev/mqueue: %m");
 }
 #endif // 0
 
 }
 #endif // 0
 
index 57b153a568c1f33ff1fa8aed82d20bb8e31acaad..579cf843b4925e8b6757316d4ccbdb224bf292cd 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <string.h>
-#include <stdio.h>
 #include <errno.h>
 #include <errno.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "sd-messages.h"
 
 #include "sd-messages.h"
+
+#include "alloc-util.h"
 #include "conf-files.h"
 #include "conf-files.h"
-#include "util.h"
-#include "macro.h"
-#include "strv.h"
+#include "conf-parser.h"
+#include "fd-util.h"
+#include "fs-util.h"
 #include "log.h"
 #include "log.h"
-#include "utf8.h"
+#include "macro.h"
+#include "parse-util.h"
 #include "path-util.h"
 #include "path-util.h"
+#include "process-util.h"
 #include "signal-util.h"
 #include "signal-util.h"
-#include "conf-parser.h"
+#include "string-util.h"
+#include "strv.h"
+#include "syslog-util.h"
+#include "utf8.h"
+#include "util.h"
 
 int config_item_table_lookup(
                 const void *table,
 
 int config_item_table_lookup(
                 const void *table,
index 789d20003b2d8aeca1ca532593a21cd089afe5c5..de30de9e75e255a63d5779df7190731e57288991 100644 (file)
 
 #include <fcntl.h>
 #include <stdlib.h>
 
 #include <fcntl.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
 #include <sys/prctl.h>
 #include <string.h>
 #include <sys/prctl.h>
+#include <unistd.h>
 
 
+#include "copy.h"
+#include "fd-util.h"
+#include "locale-util.h"
+#include "macro.h"
 #include "pager.h"
 #include "pager.h"
-#include "util.h"
 #include "process-util.h"
 #include "process-util.h"
-#include "macro.h"
-#include "terminal-util.h"
 #include "signal-util.h"
 #include "signal-util.h"
-#include "copy.h"
+#include "string-util.h"
+#include "terminal-util.h"
+#include "util.h"
 
 static pid_t pager_pid = 0;
 
 
 static pid_t pager_pid = 0;
 
index 3dedbd1f6269db89a72569a466b9ce7a4296300d..39b836d0535403c0c598ee8998dd6ecf5627d1c5 100644 (file)
 
 #include <stdio.h>
 
 
 #include <stdio.h>
 
+#include "alloc-util.h"
 #include "conf-parser.h"
 #include "conf-parser.h"
-#include "sleep-config.h"
+#include "def.h"
+#include "fd-util.h"
 #include "fileio.h"
 #include "log.h"
 #include "fileio.h"
 #include "log.h"
+#include "parse-util.h"
+#include "sleep-config.h"
+#include "string-util.h"
 #include "strv.h"
 #include "util.h"
 
 #include "strv.h"
 #include "util.h"
 
@@ -49,7 +54,7 @@ int parse_sleep_config(const char *verb, char ***_modes, char ***_states) {
         };
 
         config_parse_many(PKGSYSCONFDIR "/sleep.conf",
         };
 
         config_parse_many(PKGSYSCONFDIR "/sleep.conf",
-                          CONF_DIRS_NULSTR("systemd/sleep.conf"),
+                          CONF_PATHS_NULSTR("systemd/sleep.conf.d"),
                           "Sleep\0", config_item_table_lookup, items,
                           false, NULL);
 
                           "Sleep\0", config_item_table_lookup, items,
                           false, NULL);
 
index 4db249e1cac8fd298fe072c15116d2925581f061..8ea6cb830bfc7ea9c1b8849a37749b57179cbf1c 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
 #include <errno.h>
 #include <poll.h>
 #include <errno.h>
 #include <poll.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
 
 
+#include "fd-util.h"
+#include "io-util.h"
 #include "log.h"
 #include "log.h"
-#include "util.h"
 #include "process-util.h"
 #include "spawn-polkit-agent.h"
 #include "process-util.h"
 #include "spawn-polkit-agent.h"
+#include "stdio-util.h"
+#include "util.h"
 
 #ifdef ENABLE_POLKIT
 static pid_t agent_pid = 0;
 
 #ifdef ENABLE_POLKIT
 static pid_t agent_pid = 0;
@@ -76,8 +79,9 @@ void polkit_agent_close(void) {
                 return;
 
         /* Inform agent that we are done */
                 return;
 
         /* Inform agent that we are done */
-        kill(agent_pid, SIGTERM);
-        kill(agent_pid, SIGCONT);
+        (void) kill(agent_pid, SIGTERM);
+        (void) kill(agent_pid, SIGCONT);
+
         (void) wait_for_terminate(agent_pid, NULL);
         agent_pid = 0;
 }
         (void) wait_for_terminate(agent_pid, NULL);
         agent_pid = 0;
 }