summaryrefslogtreecommitdiff
path: root/src/libelogind
diff options
context:
space:
mode:
authorSven Eden <yamakuzure@gmx.net>2016-12-16 12:09:41 +0100
committerSven Eden <yamakuzure@gmx.net>2017-03-14 10:18:01 +0100
commit1cfc78c91965df340cdde100ad6cb3ed50b28927 (patch)
treeadc3d49b97131cd3e70edff05b14e9b67926e404 /src/libelogind
parent86e97d599f8b1ca379dce64fadac9b8f6b002ac5 (diff)
Prep v221: Update and clean up build system to sync with upstream
This commit replays the moving around of source files that have been done between systemd-219 and systemd-221. Further the Makefile.am is synchronized with the upstream version and then "re-cleaned". A lot of functions, that are not used anywhere in elogind have been coated into #if 0/#endif directives to further shorten the list of dependencies. All unneeded files have been removed.
Diffstat (limited to 'src/libelogind')
-rw-r--r--src/libelogind/sd-bus/bus-container.c245
-rw-r--r--src/libelogind/sd-bus/bus-control.c3
-rw-r--r--src/libelogind/sd-bus/bus-convenience.c12
-rw-r--r--src/libelogind/sd-bus/bus-creds.c27
-rw-r--r--src/libelogind/sd-bus/bus-internal.c29
-rw-r--r--src/libelogind/sd-bus/bus-internal.h6
-rw-r--r--src/libelogind/sd-bus/bus-match.c3
-rw-r--r--src/libelogind/sd-bus/bus-match.h2
-rw-r--r--src/libelogind/sd-bus/bus-message.c39
-rw-r--r--src/libelogind/sd-bus/bus-message.h4
-rw-r--r--src/libelogind/sd-bus/bus-objects.c6
-rw-r--r--src/libelogind/sd-bus/bus-slot.c3
-rw-r--r--src/libelogind/sd-bus/bus-track.c3
-rw-r--r--src/libelogind/sd-bus/bus-type.c3
-rw-r--r--src/libelogind/sd-bus/bus-type.h2
-rw-r--r--src/libelogind/sd-bus/bus-util.c2078
-rw-r--r--src/libelogind/sd-bus/bus-util.h203
-rw-r--r--src/libelogind/sd-bus/sd-bus.c37
-rw-r--r--src/libelogind/sd-daemon/sd-daemon.c31
-rw-r--r--src/libelogind/sd-device/device-internal.h126
-rw-r--r--src/libelogind/sd-device/device-private.c1117
-rw-r--r--src/libelogind/sd-device/device-private.h64
-rw-r--r--src/libelogind/sd-device/device-util.h60
-rw-r--r--src/libelogind/sd-event/sd-event.c36
-rw-r--r--src/libelogind/sd-hwdb/hwdb-internal.h70
-rw-r--r--src/libelogind/sd-hwdb/sd-hwdb.c470
l---------src/libelogind/sd-netlink/Makefile (renamed from src/libelogind/sd-hwdb/Makefile)0
-rw-r--r--src/libelogind/sd-netlink/netlink-types.h (renamed from src/libelogind/sd-rtnl/rtnl-types.h)63
-rw-r--r--src/libelogind/sd-network/network-util.c37
-rw-r--r--src/libelogind/sd-network/network-util.h29
-rw-r--r--src/libelogind/sd-network/sd-network.c422
l---------src/libelogind/sd-resolve/Makefile1
l---------src/libelogind/sd-rtnl/Makefile1
-rw-r--r--src/libelogind/sd-rtnl/local-addresses.h37
-rw-r--r--src/libelogind/sd-rtnl/rtnl-internal.h135
-rw-r--r--src/libelogind/sd-rtnl/rtnl-types.c561
-rw-r--r--src/libelogind/sd-rtnl/rtnl-util.h47
l---------src/libelogind/sd-utf8/Makefile1
-rw-r--r--src/libelogind/sd-utf8/sd-utf8.c36
39 files changed, 258 insertions, 5791 deletions
diff --git a/src/libelogind/sd-bus/bus-container.c b/src/libelogind/sd-bus/bus-container.c
deleted file mode 100644
index fa7a20744..000000000
--- a/src/libelogind/sd-bus/bus-container.c
+++ /dev/null
@@ -1,245 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 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 <unistd.h>
-#include <fcntl.h>
-
-#include "util.h"
-#include "process-util.h"
-#include "bus-internal.h"
-#include "bus-socket.h"
-#include "bus-container.h"
-
-int bus_container_connect_socket(sd_bus *b) {
- _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, rootfd = -1;
- pid_t child;
- siginfo_t si;
- int r;
-
- assert(b);
- assert(b->input_fd < 0);
- assert(b->output_fd < 0);
- assert(b->nspid > 0 || b->machine);
-
- if (b->nspid <= 0) {
- r = container_get_leader(b->machine, &b->nspid);
- if (r < 0)
- return r;
- }
-
- r = namespace_open(b->nspid, &pidnsfd, &mntnsfd, NULL, &rootfd);
- if (r < 0)
- return r;
-
- b->input_fd = socket(b->sockaddr.sa.sa_family, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
- if (b->input_fd < 0)
- return -errno;
-
- b->output_fd = b->input_fd;
-
- bus_socket_setup(b);
-
- child = fork();
- if (child < 0)
- return -errno;
-
- if (child == 0) {
- pid_t grandchild;
-
- r = namespace_enter(pidnsfd, mntnsfd, -1, rootfd);
- if (r < 0)
- _exit(255);
-
- /* We just changed PID namespace, however it will only
- * take effect on the children we now fork. Hence,
- * let's fork another time, and connect from this
- * grandchild, so that SO_PEERCRED of our connection
- * comes from a process from within the container, and
- * not outside of it */
-
- grandchild = fork();
- if (grandchild < 0)
- _exit(255);
-
- if (grandchild == 0) {
-
- r = connect(b->input_fd, &b->sockaddr.sa, b->sockaddr_size);
- if (r < 0) {
- if (errno == EINPROGRESS)
- _exit(1);
-
- _exit(255);
- }
-
- _exit(EXIT_SUCCESS);
- }
-
- r = wait_for_terminate(grandchild, &si);
- if (r < 0)
- _exit(255);
-
- if (si.si_code != CLD_EXITED)
- _exit(255);
-
- _exit(si.si_status);
- }
-
- r = wait_for_terminate(child, &si);
- if (r < 0)
- return r;
-
- if (si.si_code != CLD_EXITED)
- return -EIO;
-
- if (si.si_status == 1)
- return 1;
-
- if (si.si_status != EXIT_SUCCESS)
- return -EIO;
-
- return bus_socket_start_auth(b);
-}
-
-int bus_container_connect_kernel(sd_bus *b) {
- _cleanup_close_pair_ int pair[2] = { -1, -1 };
- _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, rootfd = -1;
- union {
- struct cmsghdr cmsghdr;
- uint8_t buf[CMSG_SPACE(sizeof(int))];
- } control = {};
- struct msghdr mh = {
- .msg_control = &control,
- .msg_controllen = sizeof(control),
- };
- struct cmsghdr *cmsg;
- pid_t child;
- siginfo_t si;
- int r;
- _cleanup_close_ int fd = -1;
-
- assert(b);
- assert(b->input_fd < 0);
- assert(b->output_fd < 0);
- assert(b->nspid > 0 || b->machine);
-
- if (b->nspid <= 0) {
- r = container_get_leader(b->machine, &b->nspid);
- if (r < 0)
- return r;
- }
-
- r = namespace_open(b->nspid, &pidnsfd, &mntnsfd, NULL, &rootfd);
- if (r < 0)
- return r;
-
- if (socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) < 0)
- return -errno;
-
- child = fork();
- if (child < 0)
- return -errno;
-
- if (child == 0) {
- pid_t grandchild;
-
- pair[0] = safe_close(pair[0]);
-
- r = namespace_enter(pidnsfd, mntnsfd, -1, rootfd);
- if (r < 0)
- _exit(EXIT_FAILURE);
-
- /* We just changed PID namespace, however it will only
- * take effect on the children we now fork. Hence,
- * let's fork another time, and connect from this
- * grandchild, so that kdbus only sees the credentials
- * of this process which comes from within the
- * container, and not outside of it */
-
- grandchild = fork();
- if (grandchild < 0)
- _exit(EXIT_FAILURE);
-
- if (grandchild == 0) {
-
- fd = open(b->kernel, O_RDWR|O_NOCTTY|O_CLOEXEC);
- if (fd < 0)
- _exit(EXIT_FAILURE);
-
- cmsg = CMSG_FIRSTHDR(&mh);
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = SCM_RIGHTS;
- cmsg->cmsg_len = CMSG_LEN(sizeof(int));
- memcpy(CMSG_DATA(cmsg), &fd, sizeof(int));
-
- mh.msg_controllen = cmsg->cmsg_len;
-
- if (sendmsg(pair[1], &mh, MSG_NOSIGNAL) < 0)
- _exit(EXIT_FAILURE);
-
- _exit(EXIT_SUCCESS);
- }
-
- r = wait_for_terminate(grandchild, &si);
- if (r < 0)
- _exit(EXIT_FAILURE);
-
- if (si.si_code != CLD_EXITED)
- _exit(EXIT_FAILURE);
-
- _exit(si.si_status);
- }
-
- pair[1] = safe_close(pair[1]);
-
- r = wait_for_terminate(child, &si);
- if (r < 0)
- return r;
-
- if (si.si_code != CLD_EXITED)
- return -EIO;
-
- if (si.si_status != EXIT_SUCCESS)
- return -EIO;
-
- if (recvmsg(pair[0], &mh, MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) < 0)
- return -errno;
-
- CMSG_FOREACH(cmsg, &mh)
- if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
- int *fds;
- unsigned n_fds;
-
- fds = (int*) CMSG_DATA(cmsg);
- n_fds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int);
-
- if (n_fds != 1) {
- close_many(fds, n_fds);
- return -EIO;
- }
-
- fd = fds[0];
- }
-
- b->input_fd = b->output_fd = fd;
- fd = -1;
-
- return bus_kernel_take_fd(b);
-}
diff --git a/src/libelogind/sd-bus/bus-control.c b/src/libelogind/sd-bus/bus-control.c
index 4c45a58e8..3cdce6600 100644
--- a/src/libelogind/sd-bus/bus-control.c
+++ b/src/libelogind/sd-bus/bus-control.c
@@ -1526,6 +1526,8 @@ int bus_remove_match_internal(
return bus_remove_match_internal_dbus1(bus, match);
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_get_name_machine_id(sd_bus *bus, const char *name, sd_id128_t *machine) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL, *m = NULL;
const char *mid;
@@ -1570,3 +1572,4 @@ _public_ int sd_bus_get_name_machine_id(sd_bus *bus, const char *name, sd_id128_
return sd_id128_from_string(mid, machine);
}
+#endif // 0
diff --git a/src/libelogind/sd-bus/bus-convenience.c b/src/libelogind/sd-bus/bus-convenience.c
index dfd82e746..59c7c86ae 100644
--- a/src/libelogind/sd-bus/bus-convenience.c
+++ b/src/libelogind/sd-bus/bus-convenience.c
@@ -58,6 +58,8 @@ _public_ int sd_bus_emit_signal(
return sd_bus_send(bus, m, NULL);
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_call_method_async(
sd_bus *bus,
sd_bus_slot **slot,
@@ -94,6 +96,7 @@ _public_ int sd_bus_call_method_async(
return sd_bus_call_async(bus, slot, m, callback, userdata, 0);
}
+#endif // 0
_public_ int sd_bus_call_method(
sd_bus *bus,
@@ -249,6 +252,8 @@ _public_ int sd_bus_reply_method_errno(
return sd_bus_reply_method_error(call, &berror);
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_reply_method_errnof(
sd_bus_message *call,
int error,
@@ -276,6 +281,7 @@ _public_ int sd_bus_reply_method_errnof(
return sd_bus_reply_method_error(call, &berror);
}
+#endif // 0
_public_ int sd_bus_get_property(
sd_bus *bus,
@@ -314,6 +320,8 @@ _public_ int sd_bus_get_property(
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_get_property_trivial(
sd_bus *bus,
const char *destination,
@@ -350,6 +358,7 @@ _public_ int sd_bus_get_property_trivial(
return 0;
}
+#endif // 0
_public_ int sd_bus_get_property_string(
sd_bus *bus,
@@ -394,6 +403,8 @@ _public_ int sd_bus_get_property_string(
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_get_property_strv(
sd_bus *bus,
const char *destination,
@@ -476,6 +487,7 @@ _public_ int sd_bus_set_property(
return sd_bus_call(bus, m, 0, error, NULL);
}
+#endif // 0
_public_ int sd_bus_query_sender_creds(sd_bus_message *call, uint64_t mask, sd_bus_creds **creds) {
sd_bus_creds *c;
diff --git a/src/libelogind/sd-bus/bus-creds.c b/src/libelogind/sd-bus/bus-creds.c
index 1c365b7fc..40ed95dbe 100644
--- a/src/libelogind/sd-bus/bus-creds.c
+++ b/src/libelogind/sd-bus/bus-creds.c
@@ -128,11 +128,14 @@ _public_ sd_bus_creds *sd_bus_creds_unref(sd_bus_creds *c) {
return NULL;
}
+/// UNNEEDED by elogind
+#if 0
_public_ uint64_t sd_bus_creds_get_mask(const sd_bus_creds *c) {
assert_return(c, 0);
return c->mask;
}
+#endif // 0
_public_ uint64_t sd_bus_creds_get_augmented_mask(const sd_bus_creds *c) {
assert_return(c, 0);
@@ -152,6 +155,8 @@ sd_bus_creds* bus_creds_new(void) {
return c;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_creds_new_from_pid(sd_bus_creds **ret, pid_t pid, uint64_t mask) {
sd_bus_creds *c;
int r;
@@ -183,6 +188,7 @@ _public_ int sd_bus_creds_new_from_pid(sd_bus_creds **ret, pid_t pid, uint64_t m
*ret = c;
return 0;
}
+#endif // 0
_public_ int sd_bus_creds_get_uid(sd_bus_creds *c, uid_t *uid) {
assert_return(c, -EINVAL);
@@ -206,6 +212,8 @@ _public_ int sd_bus_creds_get_euid(sd_bus_creds *c, uid_t *euid) {
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_creds_get_suid(sd_bus_creds *c, uid_t *suid) {
assert_return(c, -EINVAL);
assert_return(suid, -EINVAL);
@@ -239,6 +247,7 @@ _public_ int sd_bus_creds_get_gid(sd_bus_creds *c, gid_t *gid) {
*gid = c->gid;
return 0;
}
+#endif // 0
_public_ int sd_bus_creds_get_egid(sd_bus_creds *c, gid_t *egid) {
assert_return(c, -EINVAL);
@@ -251,6 +260,8 @@ _public_ int sd_bus_creds_get_egid(sd_bus_creds *c, gid_t *egid) {
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_creds_get_sgid(sd_bus_creds *c, gid_t *sgid) {
assert_return(c, -EINVAL);
assert_return(sgid, -EINVAL);
@@ -283,6 +294,7 @@ _public_ int sd_bus_creds_get_supplementary_gids(sd_bus_creds *c, const gid_t **
*gids = c->supplementary_gids;
return (int) c->n_supplementary_gids;
}
+#endif // 0
_public_ int sd_bus_creds_get_pid(sd_bus_creds *c, pid_t *pid) {
assert_return(c, -EINVAL);
@@ -296,6 +308,8 @@ _public_ int sd_bus_creds_get_pid(sd_bus_creds *c, pid_t *pid) {
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_creds_get_ppid(sd_bus_creds *c, pid_t *ppid) {
assert_return(c, -EINVAL);
assert_return(ppid, -EINVAL);
@@ -312,6 +326,7 @@ _public_ int sd_bus_creds_get_ppid(sd_bus_creds *c, pid_t *ppid) {
*ppid = c->ppid;
return 0;
}
+#endif // 0
_public_ int sd_bus_creds_get_tid(sd_bus_creds *c, pid_t *tid) {
assert_return(c, -EINVAL);
@@ -336,6 +351,8 @@ _public_ int sd_bus_creds_get_selinux_context(sd_bus_creds *c, const char **ret)
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_creds_get_comm(sd_bus_creds *c, const char **ret) {
assert_return(c, -EINVAL);
assert_return(ret, -EINVAL);
@@ -493,6 +510,7 @@ _public_ int sd_bus_creds_get_user_slice(sd_bus_creds *c, const char **ret) {
*ret = c->user_slice;
return 0;
}
+#endif // 0
_public_ int sd_bus_creds_get_session(sd_bus_creds *c, const char **ret) {
int r;
@@ -559,6 +577,8 @@ _public_ int sd_bus_creds_get_cmdline(sd_bus_creds *c, char ***cmdline) {
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_creds_get_audit_session_id(sd_bus_creds *c, uint32_t *sessionid) {
assert_return(c, -EINVAL);
assert_return(sessionid, -EINVAL);
@@ -572,6 +592,7 @@ _public_ int sd_bus_creds_get_audit_session_id(sd_bus_creds *c, uint32_t *sessio
*sessionid = c->audit_session_id;
return 0;
}
+#endif // 0
_public_ int sd_bus_creds_get_audit_login_uid(sd_bus_creds *c, uid_t *uid) {
assert_return(c, -EINVAL);
@@ -601,6 +622,8 @@ _public_ int sd_bus_creds_get_tty(sd_bus_creds *c, const char **ret) {
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_creds_get_unique_name(sd_bus_creds *c, const char **unique_name) {
assert_return(c, -EINVAL);
assert_return(unique_name, -EINVAL);
@@ -663,6 +686,7 @@ _public_ int sd_bus_creds_get_description(sd_bus_creds *c, const char **ret) {
*ret = c->unescaped_description;
return 0;
}
+#endif // 0
static int has_cap(sd_bus_creds *c, unsigned offset, int capability) {
size_t sz;
@@ -689,6 +713,8 @@ _public_ int sd_bus_creds_has_effective_cap(sd_bus_creds *c, int capability) {
return has_cap(c, CAP_OFFSET_EFFECTIVE, capability);
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_creds_has_permitted_cap(sd_bus_creds *c, int capability) {
assert_return(c, -EINVAL);
assert_return(capability >= 0, -EINVAL);
@@ -718,6 +744,7 @@ _public_ int sd_bus_creds_has_bounding_cap(sd_bus_creds *c, int capability) {
return has_cap(c, CAP_OFFSET_BOUNDING, capability);
}
+#endif // 0
static int parse_caps(sd_bus_creds *c, unsigned offset, const char *p) {
size_t sz, max;
diff --git a/src/libelogind/sd-bus/bus-internal.c b/src/libelogind/sd-bus/bus-internal.c
index 37793e48e..8bc2a14bf 100644
--- a/src/libelogind/sd-bus/bus-internal.c
+++ b/src/libelogind/sd-bus/bus-internal.c
@@ -19,6 +19,7 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "bus-message.h"
#include "bus-internal.h"
bool object_path_is_valid(const char *p) {
@@ -166,6 +167,8 @@ bool service_name_is_valid(const char *p) {
return true;
}
+/// UNNEEDED by elogind
+#if 0
char* service_name_startswith(const char *a, const char *b) {
const char *p;
@@ -185,6 +188,7 @@ char* service_name_startswith(const char *a, const char *b) {
return NULL;
}
+#endif // 0
bool member_name_is_valid(const char *p) {
const char *q;
@@ -345,3 +349,28 @@ char *bus_address_escape(const char *v) {
*b = 0;
return r;
}
+
+int bus_maybe_reply_error(sd_bus_message *m, int r, sd_bus_error *error) {
+ assert(m);
+
+ if (r < 0) {
+ if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL)
+ sd_bus_reply_method_errno(m, r, error);
+
+ } else if (sd_bus_error_is_set(error)) {
+ if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL)
+ sd_bus_reply_method_error(m, error);
+ } else
+ return r;
+
+ log_debug("Failed to process message [type=%s sender=%s path=%s interface=%s member=%s signature=%s]: %s",
+ bus_message_type_to_string(m->header->type),
+ strna(m->sender),
+ strna(m->path),
+ strna(m->interface),
+ strna(m->member),
+ strna(m->root_container.signature),
+ bus_error_message(error, r));
+
+ return 1;
+}
diff --git a/src/libelogind/sd-bus/bus-internal.h b/src/libelogind/sd-bus/bus-internal.h
index a8e1eb1f3..05dae42b2 100644
--- a/src/libelogind/sd-bus/bus-internal.h
+++ b/src/libelogind/sd-bus/bus-internal.h
@@ -344,7 +344,7 @@ struct sd_bus {
bool interface_name_is_valid(const char *p) _pure_;
bool service_name_is_valid(const char *p) _pure_;
-char* service_name_startswith(const char *a, const char *b);
+// UNNEEDED char* service_name_startswith(const char *a, const char *b);
bool member_name_is_valid(const char *p) _pure_;
bool object_path_is_valid(const char *p) _pure_;
char *object_path_startswith(const char *a, const char *b) _pure_;
@@ -388,6 +388,8 @@ int bus_set_address_user(sd_bus *bus);
int bus_set_address_system_remote(sd_bus *b, const char *host);
int bus_set_address_system_machine(sd_bus *b, const char *machine);
-int bus_remove_match_by_string(sd_bus *bus, const char *match, sd_bus_message_handler_t callback, void *userdata);
+// UNNEEDED int bus_remove_match_by_string(sd_bus *bus, const char *match, sd_bus_message_handler_t callback, void *userdata);
int bus_get_root_path(sd_bus *bus);
+
+int bus_maybe_reply_error(sd_bus_message *m, int r, sd_bus_error *error);
diff --git a/src/libelogind/sd-bus/bus-match.c b/src/libelogind/sd-bus/bus-match.c
index 132b37526..53c231331 100644
--- a/src/libelogind/sd-bus/bus-match.c
+++ b/src/libelogind/sd-bus/bus-match.c
@@ -909,6 +909,8 @@ fail:
return r;
}
+/// UNNEEDED by elogind
+#if 0
char *bus_match_to_string(struct bus_match_component *components, unsigned n_components) {
_cleanup_free_ FILE *f = NULL;
char *buffer = NULL;
@@ -948,6 +950,7 @@ char *bus_match_to_string(struct bus_match_component *components, unsigned n_com
return buffer;
}
+#endif // 0
int bus_match_add(
struct bus_match_node *root,
diff --git a/src/libelogind/sd-bus/bus-match.h b/src/libelogind/sd-bus/bus-match.h
index 56516be9f..cefb87e08 100644
--- a/src/libelogind/sd-bus/bus-match.h
+++ b/src/libelogind/sd-bus/bus-match.h
@@ -95,6 +95,6 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n
int bus_match_parse(const char *match, struct bus_match_component **_components, unsigned *_n_components);
void bus_match_parse_free(struct bus_match_component *components, unsigned n_components);
-char *bus_match_to_string(struct bus_match_component *components, unsigned n_components);
+// UNNEEDED char *bus_match_to_string(struct bus_match_component *components, unsigned n_components);
enum bus_match_scope bus_match_get_scope(const struct bus_match_component *components, unsigned n_components);
diff --git a/src/libelogind/sd-bus/bus-message.c b/src/libelogind/sd-bus/bus-message.c
index 006e4a2b5..b7948a6ca 100644
--- a/src/libelogind/sd-bus/bus-message.c
+++ b/src/libelogind/sd-bus/bus-message.c
@@ -832,6 +832,8 @@ _public_ int sd_bus_message_new_method_errno(
return sd_bus_message_new_method_error(call, m, &berror);
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_message_new_method_errnof(
sd_bus_message *call,
sd_bus_message **m,
@@ -848,6 +850,7 @@ _public_ int sd_bus_message_new_method_errnof(
return sd_bus_message_new_method_error(call, m, &berror);
}
+#endif // 0
void bus_message_set_sender_local(sd_bus *bus, sd_bus_message *m) {
assert(bus);
@@ -943,6 +946,8 @@ _public_ sd_bus_message* sd_bus_message_unref(sd_bus_message *m) {
return NULL;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_message_get_type(sd_bus_message *m, uint8_t *type) {
assert_return(m, -EINVAL);
assert_return(type, -EINVAL);
@@ -988,6 +993,7 @@ _public_ int sd_bus_message_get_auto_start(sd_bus_message *m) {
return !(m->header->flags & BUS_MESSAGE_NO_AUTO_START);
}
+#endif // 0
_public_ int sd_bus_message_get_allow_interactive_authorization(sd_bus_message *m) {
assert_return(m, -EINVAL);
@@ -1033,6 +1039,8 @@ _public_ const sd_bus_error *sd_bus_message_get_error(sd_bus_message *m) {
return &m->error;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_message_get_monotonic_usec(sd_bus_message *m, uint64_t *usec) {
assert_return(m, -EINVAL);
assert_return(usec, -EINVAL);
@@ -1065,6 +1073,7 @@ _public_ int sd_bus_message_get_seqnum(sd_bus_message *m, uint64_t *seqnum) {
*seqnum = m->seqnum;
return 0;
}
+#endif // 0
_public_ sd_bus_creds *sd_bus_message_get_creds(sd_bus_message *m) {
assert_return(m, NULL);
@@ -1075,6 +1084,8 @@ _public_ sd_bus_creds *sd_bus_message_get_creds(sd_bus_message *m) {
return &m->creds;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_message_is_signal(
sd_bus_message *m,
const char *interface,
@@ -1093,6 +1104,7 @@ _public_ int sd_bus_message_is_signal(
return 1;
}
+#endif // 0
_public_ int sd_bus_message_is_method_call(
sd_bus_message *m,
@@ -1125,6 +1137,8 @@ _public_ int sd_bus_message_is_method_error(sd_bus_message *m, const char *name)
return 1;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_message_set_expect_reply(sd_bus_message *m, int b) {
assert_return(m, -EINVAL);
assert_return(!m->sealed, -EPERM);
@@ -1137,6 +1151,7 @@ _public_ int sd_bus_message_set_expect_reply(sd_bus_message *m, int b) {
return 0;
}
+#endif // 0
_public_ int sd_bus_message_set_auto_start(sd_bus_message *m, int b) {
assert_return(m, -EINVAL);
@@ -1150,6 +1165,8 @@ _public_ int sd_bus_message_set_auto_start(sd_bus_message *m, int b) {
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_message_set_allow_interactive_authorization(sd_bus_message *m, int b) {
assert_return(m, -EINVAL);
assert_return(!m->sealed, -EPERM);
@@ -1161,6 +1178,7 @@ _public_ int sd_bus_message_set_allow_interactive_authorization(sd_bus_message *
return 0;
}
+#endif // 0
static struct bus_container *message_get_container(sd_bus_message *m) {
assert(m);
@@ -1712,6 +1730,8 @@ _public_ int sd_bus_message_append_string_space(
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_message_append_string_iovec(
sd_bus_message *m,
const struct iovec *iov,
@@ -1745,6 +1765,7 @@ _public_ int sd_bus_message_append_string_iovec(
return 0;
}
+#endif // 0
static int bus_message_open_array(
sd_bus_message *m,
@@ -2636,6 +2657,8 @@ _public_ int sd_bus_message_append_array(
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_message_append_array_iovec(
sd_bus_message *m,
char type,
@@ -2846,6 +2869,7 @@ _public_ int sd_bus_message_append_string_memfd(
return 0;
}
+#endif // 0
_public_ int sd_bus_message_append_strv(sd_bus_message *m, char **l) {
char **i;
@@ -3146,6 +3170,8 @@ static bool message_end_of_array(sd_bus_message *m, size_t index) {
}
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_message_at_end(sd_bus_message *m, int complete) {
assert_return(m, -EINVAL);
assert_return(m->sealed, -EPERM);
@@ -3161,6 +3187,7 @@ _public_ int sd_bus_message_at_end(sd_bus_message *m, int complete) {
return false;
}
+#endif // 0
static struct bus_body_part* find_part(sd_bus_message *m, size_t index, size_t sz, void **p) {
struct bus_body_part *part;
@@ -5544,6 +5571,8 @@ _public_ int sd_bus_message_set_destination(sd_bus_message *m, const char *desti
return message_append_field_string(m, BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, destination, &m->destination);
}
+/// UNNEEDED by elogind
+#if 0
int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz) {
size_t total;
void *p, *e;
@@ -5571,6 +5600,7 @@ int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz) {
return 0;
}
+#endif // 0
int bus_message_read_strv_extend(sd_bus_message *m, char ***l) {
const char *s;
@@ -5687,6 +5717,8 @@ _public_ const char* sd_bus_message_get_signature(sd_bus_message *m, int complet
return strempty(c->signature);
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_message_is_empty(sd_bus_message *m) {
assert_return(m, -EINVAL);
@@ -5698,6 +5730,7 @@ _public_ int sd_bus_message_has_signature(sd_bus_message *m, const char *signatu
return streq(strempty(m->root_container.signature), strempty(signature));
}
+#endif // 0
_public_ int sd_bus_message_copy(sd_bus_message *m, sd_bus_message *source, int all) {
bool done_something = false;
@@ -5778,6 +5811,8 @@ _public_ int sd_bus_message_copy(sd_bus_message *m, sd_bus_message *source, int
return done_something;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_message_verify_type(sd_bus_message *m, char type, const char *contents) {
const char *c;
char t;
@@ -5802,6 +5837,7 @@ _public_ int sd_bus_message_verify_type(sd_bus_message *m, char type, const char
return 1;
}
+#endif // 0
_public_ sd_bus *sd_bus_message_get_bus(sd_bus_message *m) {
assert_return(m, NULL);
@@ -5894,6 +5930,8 @@ int bus_message_remarshal(sd_bus *bus, sd_bus_message **m) {
return 0;
}
+/// UNNEEDED by elogind
+#if 0
int bus_message_append_sender(sd_bus_message *m, const char *sender) {
assert(m);
assert(sender);
@@ -5919,3 +5957,4 @@ _public_ int sd_bus_message_set_priority(sd_bus_message *m, int64_t priority) {
m->priority = priority;
return 0;
}
+#endif // 0
diff --git a/src/libelogind/sd-bus/bus-message.h b/src/libelogind/sd-bus/bus-message.h
index 088d5b110..2f338ff6f 100644
--- a/src/libelogind/sd-bus/bus-message.h
+++ b/src/libelogind/sd-bus/bus-message.h
@@ -193,7 +193,7 @@ static inline bool BUS_MESSAGE_IS_GVARIANT(sd_bus_message *m) {
}
int bus_message_seal(sd_bus_message *m, uint64_t serial, usec_t timeout);
-int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz);
+// UNNEEDED int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz);
int bus_message_read_strv_extend(sd_bus_message *m, char ***l);
int bus_message_from_header(
@@ -238,7 +238,7 @@ int bus_message_new_synthetic_error(sd_bus *bus, uint64_t serial, const sd_bus_e
int bus_message_remarshal(sd_bus *bus, sd_bus_message **m);
-int bus_message_append_sender(sd_bus_message *m, const char *sender);
+// UNNEEDED int bus_message_append_sender(sd_bus_message *m, const char *sender);
void bus_message_set_sender_driver(sd_bus *bus, sd_bus_message *m);
void bus_message_set_sender_local(sd_bus *bus, sd_bus_message *m);
diff --git a/src/libelogind/sd-bus/bus-objects.c b/src/libelogind/sd-bus/bus-objects.c
index c25293e5e..a3d9e552d 100644
--- a/src/libelogind/sd-bus/bus-objects.c
+++ b/src/libelogind/sd-bus/bus-objects.c
@@ -2366,6 +2366,8 @@ _public_ int sd_bus_emit_object_added(sd_bus *bus, const char *path) {
return sd_bus_send(bus, m, NULL);
}
+/// UNNEEDED by elogind
+#if 0
static int object_removed_append_all_prefix(
sd_bus *bus,
sd_bus_message *m,
@@ -2535,6 +2537,7 @@ _public_ int sd_bus_emit_object_removed(sd_bus *bus, const char *path) {
return sd_bus_send(bus, m, NULL);
}
+#endif // 0
static int interfaces_added_append_one_prefix(
sd_bus *bus,
@@ -2773,6 +2776,8 @@ _public_ int sd_bus_emit_interfaces_removed(sd_bus *bus, const char *path, const
return sd_bus_emit_interfaces_removed_strv(bus, path, interfaces);
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_add_object_manager(sd_bus *bus, sd_bus_slot **slot, const char *path) {
sd_bus_slot *s;
struct node *n;
@@ -2807,3 +2812,4 @@ fail:
return r;
}
+#endif // 0
diff --git a/src/libelogind/sd-bus/bus-slot.c b/src/libelogind/sd-bus/bus-slot.c
index b149ea16d..862619606 100644
--- a/src/libelogind/sd-bus/bus-slot.c
+++ b/src/libelogind/sd-bus/bus-slot.c
@@ -214,6 +214,8 @@ _public_ sd_bus_slot* sd_bus_slot_unref(sd_bus_slot *slot) {
return NULL;
}
+/// UNNEEDED by elogind
+#if 0
_public_ sd_bus* sd_bus_slot_get_bus(sd_bus_slot *slot) {
assert_return(slot, NULL);
@@ -281,3 +283,4 @@ _public_ int sd_bus_slot_get_description(sd_bus_slot *slot, const char **descrip
*description = slot->description;
return 0;
}
+#endif // 0
diff --git a/src/libelogind/sd-bus/bus-track.c b/src/libelogind/sd-bus/bus-track.c
index e43891be2..12ab53b7b 100644
--- a/src/libelogind/sd-bus/bus-track.c
+++ b/src/libelogind/sd-bus/bus-track.c
@@ -317,6 +317,8 @@ void bus_track_dispatch(sd_bus_track *track) {
sd_bus_track_unref(track);
}
+/// UNNEEDED by elogind
+#if 0
_public_ void *sd_bus_track_get_userdata(sd_bus_track *track) {
assert_return(track, NULL);
@@ -333,3 +335,4 @@ _public_ void *sd_bus_track_set_userdata(sd_bus_track *track, void *userdata) {
return ret;
}
+#endif // 0
diff --git a/src/libelogind/sd-bus/bus-type.c b/src/libelogind/sd-bus/bus-type.c
index 6bc7b880a..afdf234ef 100644
--- a/src/libelogind/sd-bus/bus-type.c
+++ b/src/libelogind/sd-bus/bus-type.c
@@ -45,6 +45,8 @@ bool bus_type_is_valid(char c) {
return !!memchr(valid, c, sizeof(valid));
}
+/// UNNEEDED by elogind
+#if 0
bool bus_type_is_valid_in_signature(char c) {
static const char valid[] = {
SD_BUS_TYPE_BYTE,
@@ -70,6 +72,7 @@ bool bus_type_is_valid_in_signature(char c) {
return !!memchr(valid, c, sizeof(valid));
}
+#endif // 0
bool bus_type_is_basic(char c) {
static const char valid[] = {
diff --git a/src/libelogind/sd-bus/bus-type.h b/src/libelogind/sd-bus/bus-type.h
index 581574ab7..9a2a4f809 100644
--- a/src/libelogind/sd-bus/bus-type.h
+++ b/src/libelogind/sd-bus/bus-type.h
@@ -27,7 +27,7 @@
#include "sd-bus.h"
bool bus_type_is_valid(char c) _const_;
-bool bus_type_is_valid_in_signature(char c) _const_;
+// UNNEEDED bool bus_type_is_valid_in_signature(char c) _const_;
bool bus_type_is_basic(char c) _const_;
/* "trivial" is systemd's term for what the D-Bus Specification calls
* a "fixed type": that is, a basic type of fixed length */
diff --git a/src/libelogind/sd-bus/bus-util.c b/src/libelogind/sd-bus/bus-util.c
deleted file mode 100644
index 2e4cd572f..000000000
--- a/src/libelogind/sd-bus/bus-util.c
+++ /dev/null
@@ -1,2078 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 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 <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 "bus-error.h"
-#include "bus-label.h"
-#include "bus-message.h"
-#include "bus-util.h"
-#include "bus-internal.h"
-
-static int name_owner_change_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
- sd_event *e = userdata;
-
- assert(m);
- assert(e);
-
- sd_bus_close(sd_bus_message_get_bus(m));
- sd_event_exit(e, 0);
-
- return 1;
-}
-
-int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name) {
- _cleanup_free_ char *match = NULL;
- const char *unique;
- int r;
-
- assert(e);
- assert(bus);
- assert(name);
-
- /* We unregister the name here and then wait for the
- * NameOwnerChanged signal for this event to arrive before we
- * quit. We do this in order to make sure that any queued
- * requests are still processed before we really exit. */
-
- r = sd_bus_get_unique_name(bus, &unique);
- if (r < 0)
- return r;
-
- r = asprintf(&match,
- "sender='org.freedesktop.DBus',"
- "type='signal',"
- "interface='org.freedesktop.DBus',"
- "member='NameOwnerChanged',"
- "path='/org/freedesktop/DBus',"
- "arg0='%s',"
- "arg1='%s',"
- "arg2=''", name, unique);
- if (r < 0)
- return -ENOMEM;
-
- r = sd_bus_add_match(bus, NULL, match, name_owner_change_callback, e);
- if (r < 0)
- return r;
-
- r = sd_bus_release_name(bus, name);
- if (r < 0)
- return r;
-
- return 0;
-}
-
-int bus_event_loop_with_idle(
- sd_event *e,
- sd_bus *bus,
- const char *name,
- usec_t timeout,
- check_idle_t check_idle,
- void *userdata) {
- bool exiting = false;
- int r, code;
-
- assert(e);
- assert(bus);
- assert(name);
-
- for (;;) {
- bool idle;
-
- r = sd_event_get_state(e);
- if (r < 0)
- return r;
- if (r == SD_EVENT_FINISHED)
- break;
-
- if (check_idle)
- idle = check_idle(userdata);
- else
- idle = true;
-
- r = sd_event_run(e, exiting || !idle ? (uint64_t) -1 : timeout);
- if (r < 0)
- return r;
-
- if (r == 0 && !exiting && idle) {
-
- r = sd_bus_try_close(bus);
- if (r == -EBUSY)
- continue;
-
- /* Fallback for dbus1 connections: we
- * unregister the name and wait for the
- * response to come through for it */
- if (r == -EOPNOTSUPP) {
-
- /* Inform the service manager that we
- * are going down, so that it will
- * queue all further start requests,
- * instead of assuming we are already
- * running. */
- sd_notify(false, "STOPPING=1");
-
- r = bus_async_unregister_and_exit(e, bus, name);
- if (r < 0)
- return r;
-
- exiting = true;
- continue;
- }
-
- if (r < 0)
- return r;
-
- sd_event_exit(e, 0);
- break;
- }
- }
-
- r = sd_event_get_exit_code(e, &code);
- if (r < 0)
- return r;
-
- return code;
-}
-
-int bus_name_has_owner(sd_bus *c, const char *name, sd_bus_error *error) {
- _cleanup_bus_message_unref_ sd_bus_message *rep = NULL;
- int r, has_owner = 0;
-
- assert(c);
- assert(name);
-
- r = sd_bus_call_method(c,
- "org.freedesktop.DBus",
- "/org/freedesktop/dbus",
- "org.freedesktop.DBus",
- "NameHasOwner",
- error,
- &rep,
- "s",
- name);
- if (r < 0)
- return r;
-
- r = sd_bus_message_read_basic(rep, 'b', &has_owner);
- if (r < 0)
- return sd_bus_error_set_errno(error, r);
-
- return has_owner;
-}
-
-static int check_good_user(sd_bus_message *m, uid_t good_user) {
- _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
- uid_t sender_uid;
- int r;
-
- assert(m);
-
- if (good_user == UID_INVALID)
- return 0;
-
- r = sd_bus_query_sender_creds(m, SD_BUS_CREDS_EUID, &creds);
- if (r < 0)
- return r;
-
- /* Don't trust augmented credentials for authorization */
- assert_return((sd_bus_creds_get_augmented_mask(creds) & SD_BUS_CREDS_EUID) == 0, -EPERM);
-
- r = sd_bus_creds_get_euid(creds, &sender_uid);
- if (r < 0)
- return r;
-
- return sender_uid == good_user;
-}
-
-int bus_test_polkit(
- sd_bus_message *call,
- int capability,
- const char *action,
- uid_t good_user,
- bool *_challenge,
- sd_bus_error *e) {
-
- int r;
-
- assert(call);
- assert(action);
-
- /* Tests non-interactively! */
-
- r = check_good_user(call, good_user);
- if (r != 0)
- return r;
-
- r = sd_bus_query_sender_privilege(call, capability);
- if (r < 0)
- return r;
- else if (r > 0)
- return 1;
-#ifdef ENABLE_POLKIT
- else {
- _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
- int authorized = false, challenge = false;
- const char *sender;
-
- sender = sd_bus_message_get_sender(call);
- if (!sender)
- return -EBADMSG;
-
- r = sd_bus_call_method(
- call->bus,
- "org.freedesktop.PolicyKit1",
- "/org/freedesktop/PolicyKit1/Authority",
- "org.freedesktop.PolicyKit1.Authority",
- "CheckAuthorization",
- e,
- &reply,
- "(sa{sv})sa{ss}us",
- "system-bus-name", 1, "name", "s", sender,
- action,
- 0,
- 0,
- "");
-
- if (r < 0) {
- /* Treat no PK available as access denied */
- if (sd_bus_error_has_name(e, SD_BUS_ERROR_SERVICE_UNKNOWN)) {
- sd_bus_error_free(e);
- return -EACCES;
- }
-
- return r;
- }
-
- r = sd_bus_message_enter_container(reply, 'r', "bba{ss}");
- if (r < 0)
- return r;
-
- r = sd_bus_message_read(reply, "bb", &authorized, &challenge);
- if (r < 0)
- return r;
-
- if (authorized)
- return 1;
-
- if (_challenge) {
- *_challenge = challenge;
- return 0;
- }
- }
-#endif
-
- return -EACCES;
-}
-
-#ifdef ENABLE_POLKIT
-
-typedef struct AsyncPolkitQuery {
- sd_bus_message *request, *reply;
- sd_bus_message_handler_t callback;
- void *userdata;
- sd_bus_slot *slot;
- Hashmap *registry;
-} AsyncPolkitQuery;
-
-static void async_polkit_query_free(AsyncPolkitQuery *q) {
-
- if (!q)
- return;
-
- sd_bus_slot_unref(q->slot);
-
- if (q->registry && q->request)
- hashmap_remove(q->registry, q->request);
-
- sd_bus_message_unref(q->request);
- sd_bus_message_unref(q->reply);
-
- free(q);
-}
-
-static int async_polkit_callback(sd_bus_message *reply, void *userdata, sd_bus_error *error) {
- _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
- AsyncPolkitQuery *q = userdata;
- int r;
-
- assert(reply);
- assert(q);
-
- q->slot = sd_bus_slot_unref(q->slot);
- q->reply = sd_bus_message_ref(reply);
-
- r = sd_bus_message_rewind(q->request, true);
- if (r < 0) {
- r = sd_bus_reply_method_errno(q->request, r, NULL);
- goto finish;
- }
-
- r = q->callback(q->request, q->userdata, &error_buffer);
- r = bus_maybe_reply_error(q->request, r, &error_buffer);
-
-finish:
- async_polkit_query_free(q);
-
- return r;
-}
-
-#endif
-
-int bus_verify_polkit_async(
- sd_bus_message *call,
- int capability,
- const char *action,
- bool interactive,
- uid_t good_user,
- Hashmap **registry,
- sd_bus_error *error) {
-
-#ifdef ENABLE_POLKIT
- _cleanup_bus_message_unref_ sd_bus_message *pk = NULL;
- AsyncPolkitQuery *q;
- const char *sender;
- sd_bus_message_handler_t callback;
- void *userdata;
- int c;
-#endif
- int r;
-
- assert(call);
- assert(action);
- assert(registry);
-
- r = check_good_user(call, good_user);
- if (r != 0)
- return r;
-
-#ifdef ENABLE_POLKIT
- q = hashmap_get(*registry, call);
- if (q) {
- int authorized, challenge;
-
- /* This is the second invocation of this function, and
- * there's already a response from polkit, let's
- * process it */
- assert(q->reply);
-
- if (sd_bus_message_is_method_error(q->reply, NULL)) {
- const sd_bus_error *e;
-
- /* Copy error from polkit reply */
- e = sd_bus_message_get_error(q->reply);
- sd_bus_error_copy(error, e);
-
- /* Treat no PK available as access denied */
- if (sd_bus_error_has_name(e, SD_BUS_ERROR_SERVICE_UNKNOWN))
- return -EACCES;
-
- return -sd_bus_error_get_errno(e);
- }
-
- r = sd_bus_message_enter_container(q->reply, 'r', "bba{ss}");
- if (r >= 0)
- r = sd_bus_message_read(q->reply, "bb", &authorized, &challenge);
-
- if (r < 0)
- return r;
-
- if (authorized)
- return 1;
-
- if (challenge)
- return sd_bus_error_set(error, SD_BUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED, "Interactive authentication required.");
-
- return -EACCES;
- }
-#endif
-
- r = sd_bus_query_sender_privilege(call, capability);
- if (r < 0)
- return r;
- else if (r > 0)
- return 1;
-
-#ifdef ENABLE_POLKIT
- if (sd_bus_get_current_message(call->bus) != call)
- return -EINVAL;
-
- callback = sd_bus_get_current_handler(call->bus);
- if (!callback)
- return -EINVAL;
-
- userdata = sd_bus_get_current_userdata(call->bus);
-
- sender = sd_bus_message_get_sender(call);
- if (!sender)
- return -EBADMSG;
-
- c = sd_bus_message_get_allow_interactive_authorization(call);
- if (c < 0)
- return c;
- if (c > 0)
- interactive = true;
-
- r = hashmap_ensure_allocated(registry, NULL);
- if (r < 0)
- return r;
-
- r = sd_bus_message_new_method_call(
- call->bus,
- &pk,
- "org.freedesktop.PolicyKit1",
- "/org/freedesktop/PolicyKit1/Authority",
- "org.freedesktop.PolicyKit1.Authority",
- "CheckAuthorization");
- if (r < 0)
- return r;
-
- r = sd_bus_message_append(
- pk,
- "(sa{sv})sa{ss}us",
- "system-bus-name", 1, "name", "s", sender,
- action,
- 0,
- !!interactive,
- NULL);
- if (r < 0)
- return r;
-
- q = new0(AsyncPolkitQuery, 1);
- if (!q)
- return -ENOMEM;
-
- q->request = sd_bus_message_ref(call);
- q->callback = callback;
- q->userdata = userdata;
-
- r = hashmap_put(*registry, call, q);
- if (r < 0) {
- async_polkit_query_free(q);
- return r;
- }
-
- q->registry = *registry;
-
- r = sd_bus_call_async(call->bus, &q->slot, pk, async_polkit_callback, q, 0);
- if (r < 0) {
- async_polkit_query_free(q);
- return r;
- }
-
- return 0;
-#endif
-
- return -EACCES;
-}
-
-void bus_verify_polkit_async_registry_free(Hashmap *registry) {
-#ifdef ENABLE_POLKIT
- AsyncPolkitQuery *q;
-
- while ((q = hashmap_steal_first(registry)))
- async_polkit_query_free(q);
-
- hashmap_free(registry);
-#endif
-}
-
-int bus_check_peercred(sd_bus *c) {
- struct ucred ucred;
- socklen_t l;
- int fd;
-
- assert(c);
-
- fd = sd_bus_get_fd(c);
- if (fd < 0)
- return fd;
-
- l = sizeof(struct ucred);
- if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &l) < 0)
- return -errno;
-
- if (l != sizeof(struct ucred))
- return -E2BIG;
-
- if (ucred.uid != 0 && ucred.uid != geteuid())
- return -EPERM;
-
- return 1;
-}
-
-int bus_open_system_systemd(sd_bus **_bus) {
- _cleanup_bus_unref_ sd_bus *bus = NULL;
- int r;
-
- assert(_bus);
-
- if (geteuid() != 0)
- return sd_bus_open_system(_bus);
-
- /* If we are root and kdbus is not available, then let's talk
- * directly to the system instance, instead of going via the
- * bus */
-
- r = sd_bus_new(&bus);
- if (r < 0)
- return r;
-
- r = sd_bus_set_address(bus, KERNEL_SYSTEM_BUS_ADDRESS);
- if (r < 0)
- return r;
-
- bus->bus_client = true;
-
- r = sd_bus_start(bus);
- if (r >= 0) {
- *_bus = bus;
- bus = NULL;
- return 0;
- }
-
- bus = sd_bus_unref(bus);
-
- r = sd_bus_new(&bus);
- if (r < 0)
- return r;
-
- r = sd_bus_set_address(bus, "unix:path=/run/systemd/private");
- if (r < 0)
- return r;
-
- r = sd_bus_start(bus);
- if (r < 0)
- return sd_bus_open_system(_bus);
-
- r = bus_check_peercred(bus);
- if (r < 0)
- return r;
-
- *_bus = bus;
- bus = NULL;
-
- return 0;
-}
-
-int bus_open_user_systemd(sd_bus **_bus) {
- _cleanup_bus_unref_ sd_bus *bus = NULL;
- _cleanup_free_ char *ee = NULL;
- const char *e;
- int r;
-
- /* Try via kdbus first, and then directly */
-
- assert(_bus);
-
- r = sd_bus_new(&bus);
- if (r < 0)
- return r;
-
- if (asprintf(&bus->address, KERNEL_USER_BUS_ADDRESS_FMT, getuid()) < 0)
- return -ENOMEM;
-
- bus->bus_client = true;
-
- r = sd_bus_start(bus);
- if (r >= 0) {
- *_bus = bus;
- bus = NULL;
- return 0;
- }
-
- bus = sd_bus_unref(bus);
-
- e = secure_getenv("XDG_RUNTIME_DIR");
- if (!e)
- return sd_bus_open_user(_bus);
-
- ee = bus_address_escape(e);
- if (!ee)
- return -ENOMEM;
-
- r = sd_bus_new(&bus);
- if (r < 0)
- return r;
-
- bus->address = strjoin("unix:path=", ee, "/systemd/private", NULL);
- if (!bus->address)
- return -ENOMEM;
-
- r = sd_bus_start(bus);
- if (r < 0)
- return sd_bus_open_user(_bus);
-
- r = bus_check_peercred(bus);
- if (r < 0)
- return r;
-
- *_bus = bus;
- bus = NULL;
-
- return 0;
-}
-
-int bus_print_property(const char *name, sd_bus_message *property, bool all) {
- char type;
- const char *contents;
- int r;
-
- assert(name);
- assert(property);
-
- r = sd_bus_message_peek_type(property, &type, &contents);
- if (r < 0)
- return r;
-
- switch (type) {
-
- case SD_BUS_TYPE_STRING: {
- const char *s;
-
- r = sd_bus_message_read_basic(property, type, &s);
- if (r < 0)
- return r;
-
- if (all || !isempty(s)) {
- _cleanup_free_ char *escaped = NULL;
-
- escaped = xescape(s, "\n");
- if (!escaped)
- return -ENOMEM;
-
- printf("%s=%s\n", name, escaped);
- }
-
- return 1;
- }
-
- case SD_BUS_TYPE_BOOLEAN: {
- int b;
-
- r = sd_bus_message_read_basic(property, type, &b);
- if (r < 0)
- return r;
-
- printf("%s=%s\n", name, yes_no(b));
-
- return 1;
- }
-
- case SD_BUS_TYPE_UINT64: {
- uint64_t u;
-
- r = sd_bus_message_read_basic(property, type, &u);
- if (r < 0)
- return r;
-
- /* Yes, heuristics! But we can change this check
- * should it turn out to not be sufficient */
-
- if (endswith(name, "Timestamp")) {
- char timestamp[FORMAT_TIMESTAMP_MAX], *t;
-
- t = format_timestamp(timestamp, sizeof(timestamp), u);
- if (t || all)
- printf("%s=%s\n", name, strempty(t));
-
- } else if (strstr(name, "USec")) {
- char timespan[FORMAT_TIMESPAN_MAX];
-
- printf("%s=%s\n", name, format_timespan(timespan, sizeof(timespan), u, 0));
- } else
- printf("%s=%llu\n", name, (unsigned long long) u);
-
- return 1;
- }
-
- case SD_BUS_TYPE_INT64: {
- int64_t i;
-
- r = sd_bus_message_read_basic(property, type, &i);
- if (r < 0)
- return r;
-
- printf("%s=%lld\n", name, (long long) i);
-
- return 1;
- }
-
- case SD_BUS_TYPE_UINT32: {
- uint32_t u;
-
- r = sd_bus_message_read_basic(property, type, &u);
- if (r < 0)
- return r;
-
- if (strstr(name, "UMask") || strstr(name, "Mode"))
- printf("%s=%04o\n", name, u);
- else
- printf("%s=%u\n", name, (unsigned) u);
-
- return 1;
- }
-
- case SD_BUS_TYPE_INT32: {
- int32_t i;
-
- r = sd_bus_message_read_basic(property, type, &i);
- if (r < 0)
- return r;
-
- printf("%s=%i\n", name, (int) i);
- return 1;
- }
-
- case SD_BUS_TYPE_DOUBLE: {
- double d;
-
- r = sd_bus_message_read_basic(property, type, &d);
- if (r < 0)
- return r;
-
- printf("%s=%g\n", name, d);
- return 1;
- }
-
- case SD_BUS_TYPE_ARRAY:
- if (streq(contents, "s")) {
- bool first = true;
- const char *str;
-
- r = sd_bus_message_enter_container(property, SD_BUS_TYPE_ARRAY, contents);
- if (r < 0)
- return r;
-
- while((r = sd_bus_message_read_basic(property, SD_BUS_TYPE_STRING, &str)) > 0) {
- _cleanup_free_ char *escaped = NULL;
-
- if (first)
- printf("%s=", name);
-
- escaped = xescape(str, "\n ");
- if (!escaped)
- return -ENOMEM;
-
- printf("%s%s", first ? "" : " ", escaped);
-
- first = false;
- }
- if (r < 0)
- return r;
-
- if (first && all)
- printf("%s=", name);
- if (!first || all)
- puts("");
-
- r = sd_bus_message_exit_container(property);
- if (r < 0)
- return r;
-
- return 1;
-
- } else if (streq(contents, "y")) {
- const uint8_t *u;
- size_t n;
-
- r = sd_bus_message_read_array(property, SD_BUS_TYPE_BYTE, (const void**) &u, &n);
- if (r < 0)
- return r;
-
- if (all || n > 0) {
- unsigned int i;
-
- printf("%s=", name);
-
- for (i = 0; i < n; i++)
- printf("%02x", u[i]);
-
- puts("");
- }
-
- return 1;
-
- } else if (streq(contents, "u")) {
- uint32_t *u;
- size_t n;
-
- r = sd_bus_message_read_array(property, SD_BUS_TYPE_UINT32, (const void**) &u, &n);
- if (r < 0)
- return r;
-
- if (all || n > 0) {
- unsigned int i;
-
- printf("%s=", name);
-
- for (i = 0; i < n; i++)
- printf("%08x", u[i]);
-
- puts("");
- }
-
- return 1;
- }
-
- break;
- }
-
- return 0;
-}
-
-int bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, char **filter, bool all) {
- _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
- int r;
-
- assert(bus);
- assert(path);
-
- r = sd_bus_call_method(bus,
- dest,
- path,
- "org.freedesktop.DBus.Properties",
- "GetAll",
- &error,
- &reply,
- "s", "");
- if (r < 0)
- return r;
-
- r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "{sv}");
- if (r < 0)
- return r;
-
- while ((r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_DICT_ENTRY, "sv")) > 0) {
- const char *name;
- const char *contents;
-
- r = sd_bus_message_read_basic(reply, SD_BUS_TYPE_STRING, &name);
- if (r < 0)
- return r;
-
- if (!filter || strv_find(filter, name)) {
- r = sd_bus_message_peek_type(reply, NULL, &contents);
- if (r < 0)
- return r;
-
- r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_VARIANT, contents);
- if (r < 0)
- return r;
-
- r = bus_print_property(name, reply, all);
- if (r < 0)
- return r;
- if (r == 0) {
- if (all)
- printf("%s=[unprintable]\n", name);
- /* skip what we didn't read */
- r = sd_bus_message_skip(reply, contents);
- if (r < 0)
- return r;
- }
-
- r = sd_bus_message_exit_container(reply);
- if (r < 0)
- return r;
- } else {
- r = sd_bus_message_skip(reply, "v");
- if (r < 0)
- return r;
- }
-
- r = sd_bus_message_exit_container(reply);
- if (r < 0)
- return r;
- }
- if (r < 0)
- return r;
-
- r = sd_bus_message_exit_container(reply);
- if (r < 0)
- return r;
-
- return 0;
-}
-
-int bus_map_id128(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
- sd_id128_t *p = userdata;
- const void *v;
- size_t n;
- int r;
-
- r = sd_bus_message_read_array(m, SD_BUS_TYPE_BYTE, &v, &n);
- if (r < 0)
- return r;
-
- if (n == 0)
- *p = SD_ID128_NULL;
- else if (n == 16)
- memcpy((*p).bytes, v, n);
- else
- return -EINVAL;
-
- return 0;
-}
-
-static int map_basic(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
- char type;
- int r;
-
- r = sd_bus_message_peek_type(m, &type, NULL);
- if (r < 0)
- return r;
-
- switch (type) {
- case SD_BUS_TYPE_STRING: {
- const char *s;
- char **p = userdata;
-
- r = sd_bus_message_read_basic(m, type, &s);
- if (r < 0)
- break;
-
- if (isempty(s))
- break;
-
- r = free_and_strdup(p, s);
- break;
- }
-
- case SD_BUS_TYPE_ARRAY: {
- _cleanup_strv_free_ char **l = NULL;
- char ***p = userdata;
-
- r = bus_message_read_strv_extend(m, &l);
- if (r < 0)
- break;
-
- strv_free(*p);
- *p = l;
- l = NULL;
-
- break;
- }
-
- case SD_BUS_TYPE_BOOLEAN: {
- unsigned b;
- bool *p = userdata;
-
- r = sd_bus_message_read_basic(m, type, &b);
- if (r < 0)
- break;
-
- *p = b;
-
- break;
- }
-
- case SD_BUS_TYPE_UINT32: {
- uint64_t u;
- uint32_t *p = userdata;
-
- r = sd_bus_message_read_basic(m, type, &u);
- if (r < 0)
- break;
-
- *p = u;
-
- break;
- }
-
- case SD_BUS_TYPE_UINT64: {
- uint64_t t;
- uint64_t *p = userdata;
-
- r = sd_bus_message_read_basic(m, type, &t);
- if (r < 0)
- break;
-
- *p = t;
-
- break;
- }
-
- default:
- break;
- }
-
- return r;
-}
-
-int bus_message_map_all_properties(
- sd_bus_message *m,
- const struct bus_properties_map *map,
- void *userdata) {
-
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
- int r;
-
- assert(m);
- assert(map);
-
- r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}");
- if (r < 0)
- return r;
-
- while ((r = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "sv")) > 0) {
- const struct bus_properties_map *prop;
- const char *member;
- const char *contents;
- void *v;
- unsigned i;
-
- r = sd_bus_message_read_basic(m, SD_BUS_TYPE_STRING, &member);
- if (r < 0)
- return r;
-
- for (i = 0, prop = NULL; map[i].member; i++)
- if (streq(map[i].member, member)) {
- prop = &map[i];
- break;
- }
-
- if (prop) {
- r = sd_bus_message_peek_type(m, NULL, &contents);
- if (r < 0)
- return r;
-
- r = sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, contents);
- if (r < 0)
- return r;
-
- v = (uint8_t *)userdata + prop->offset;
- if (map[i].set)
- r = prop->set(sd_bus_message_get_bus(m), member, m, &error, v);
- else
- r = map_basic(sd_bus_message_get_bus(m), member, m, &error, v);
- if (r < 0)
- return r;
-
- r = sd_bus_message_exit_container(m);
- if (r < 0)
- return r;
- } else {
- r = sd_bus_message_skip(m, "v");
- if (r < 0)
- return r;
- }
-
- r = sd_bus_message_exit_container(m);
- if (r < 0)
- return r;
- }
- if (r < 0)
- return r;
-
- return sd_bus_message_exit_container(m);
-}
-
-int bus_message_map_properties_changed(
- sd_bus_message *m,
- const struct bus_properties_map *map,
- void *userdata) {
-
- const char *member;
- int r, invalidated, i;
-
- assert(m);
- assert(map);
-
- r = bus_message_map_all_properties(m, map, userdata);
- if (r < 0)
- return r;
-
- r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "s");
- if (r < 0)
- return r;
-
- invalidated = 0;
- while ((r = sd_bus_message_read_basic(m, SD_BUS_TYPE_STRING, &member)) > 0)
- for (i = 0; map[i].member; i++)
- if (streq(map[i].member, member)) {
- ++invalidated;
- break;
- }
- if (r < 0)
- return r;
-
- r = sd_bus_message_exit_container(m);
- if (r < 0)
- return r;
-
- return invalidated;
-}
-
-int bus_map_all_properties(
- sd_bus *bus,
- const char *destination,
- const char *path,
- const struct bus_properties_map *map,
- void *userdata) {
-
- _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
- int r;
-
- assert(bus);
- assert(destination);
- assert(path);
- assert(map);
-
- r = sd_bus_call_method(
- bus,
- destination,
- path,
- "org.freedesktop.DBus.Properties",
- "GetAll",
- &error,
- &m,
- "s", "");
- if (r < 0)
- return r;
-
- return bus_message_map_all_properties(m, map, userdata);
-}
-
-int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus) {
- int r;
-
- assert(transport >= 0);
- assert(transport < _BUS_TRANSPORT_MAX);
- assert(bus);
-
- assert_return((transport == BUS_TRANSPORT_LOCAL) == !host, -EINVAL);
- assert_return(transport == BUS_TRANSPORT_LOCAL || !user, -EOPNOTSUPP);
-
- switch (transport) {
-
- case BUS_TRANSPORT_LOCAL:
- if (user)
- r = sd_bus_default_user(bus);
- else
- r = sd_bus_default_system(bus);
-
- break;
-
- case BUS_TRANSPORT_REMOTE:
- r = sd_bus_open_system_remote(bus, host);
- break;
-
- case BUS_TRANSPORT_MACHINE:
- r = sd_bus_open_system_machine(bus, host);
- break;
-
- default:
- assert_not_reached("Hmm, unknown transport type.");
- }
-
- return r;
-}
-
-int bus_open_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus) {
- int r;
-
- assert(transport >= 0);
- assert(transport < _BUS_TRANSPORT_MAX);
- assert(bus);
-
- assert_return((transport == BUS_TRANSPORT_LOCAL) == !host, -EINVAL);
- assert_return(transport == BUS_TRANSPORT_LOCAL || !user, -EOPNOTSUPP);
-
- switch (transport) {
-
- case BUS_TRANSPORT_LOCAL:
- if (user)
- r = bus_open_user_systemd(bus);
- else
- r = bus_open_system_systemd(bus);
-
- break;
-
- case BUS_TRANSPORT_REMOTE:
- r = sd_bus_open_system_remote(bus, host);
- break;
-
- case BUS_TRANSPORT_MACHINE:
- r = sd_bus_open_system_machine(bus, host);
- break;
-
- default:
- assert_not_reached("Hmm, unknown transport type.");
- }
-
- return r;
-}
-
-int bus_property_get_bool(
- sd_bus *bus,
- const char *path,
- const char *interface,
- const char *property,
- sd_bus_message *reply,
- void *userdata,
- sd_bus_error *error) {
-
- int b = *(bool*) userdata;
-
- return sd_bus_message_append_basic(reply, 'b', &b);
-}
-
-#if __SIZEOF_SIZE_T__ != 8
-int bus_property_get_size(
- sd_bus *bus,
- const char *path,
- const char *interface,
- const char *property,
- sd_bus_message *reply,
- void *userdata,
- sd_bus_error *error) {
-
- uint64_t sz = *(size_t*) userdata;
-
- return sd_bus_message_append_basic(reply, 't', &sz);
-}
-#endif
-
-#if __SIZEOF_LONG__ != 8
-int bus_property_get_long(
- sd_bus *bus,
- const char *path,
- const char *interface,
- const char *property,
- sd_bus_message *reply,
- void *userdata,
- sd_bus_error *error) {
-
- int64_t l = *(long*) userdata;
-
- return sd_bus_message_append_basic(reply, 'x', &l);
-}
-
-int bus_property_get_ulong(
- sd_bus *bus,
- const char *path,
- const char *interface,
- const char *property,
- sd_bus_message *reply,
- void *userdata,
- sd_bus_error *error) {
-
- uint64_t ul = *(unsigned long*) userdata;
-
- return sd_bus_message_append_basic(reply, 't', &ul);
-}
-#endif
-
-int bus_log_parse_error(int r) {
- return log_error_errno(r, "Failed to parse bus message: %m");
-}
-
-int bus_log_create_error(int r) {
- return log_error_errno(r, "Failed to create bus message: %m");
-}
-
-int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u) {
- assert(message);
- assert(u);
-
- u->machine = NULL;
-
- return sd_bus_message_read(
- message,
- "(ssssssouso)",
- &u->id,
- &u->description,
- &u->load_state,
- &u->active_state,
- &u->sub_state,
- &u->following,
- &u->unit_path,
- &u->job_id,
- &u->job_type,
- &u->job_path);
-}
-
-int bus_maybe_reply_error(sd_bus_message *m, int r, sd_bus_error *error) {
- assert(m);
-
- if (r < 0) {
- if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL)
- sd_bus_reply_method_errno(m, r, error);
-
- } else if (sd_bus_error_is_set(error)) {
- if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL)
- sd_bus_reply_method_error(m, error);
- } else
- return r;
-
- log_debug("Failed to process message [type=%s sender=%s path=%s interface=%s member=%s signature=%s]: %s",
- bus_message_type_to_string(m->header->type),
- strna(m->sender),
- strna(m->path),
- strna(m->interface),
- strna(m->member),
- strna(m->root_container.signature),
- bus_error_message(error, r));
-
- return 1;
-}
-
-int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignment) {
- const char *eq, *field;
- int r;
-
- assert(m);
- assert(assignment);
-
- eq = strchr(assignment, '=');
- if (!eq) {
- log_error("Not an assignment: %s", assignment);
- return -EINVAL;
- }
-
- field = strndupa(assignment, eq - assignment);
- eq ++;
-
- if (streq(field, "CPUQuota")) {
-
- if (isempty(eq)) {
-
- r = sd_bus_message_append_basic(m, SD_BUS_TYPE_STRING, "CPUQuotaPerSecUSec");
- if (r < 0)
- return bus_log_create_error(r);
-
- r = sd_bus_message_append(m, "v", "t", USEC_INFINITY);
-
- } else if (endswith(eq, "%")) {
- double percent;
-
- if (sscanf(eq, "%lf%%", &percent) != 1 || percent <= 0) {
- log_error("CPU quota '%s' invalid.", eq);
- return -EINVAL;
- }
-
- r = sd_bus_message_append_basic(m, SD_BUS_TYPE_STRING, "CPUQuotaPerSecUSec");
- if (r < 0)
- return bus_log_create_error(r);
-
- r = sd_bus_message_append(m, "v", "t", (usec_t) percent * USEC_PER_SEC / 100);
- } else {
- log_error("CPU quota needs to be in percent.");
- return -EINVAL;
- }
-
- if (r < 0)
- return bus_log_create_error(r);
-
- return 0;
- }
-
- r = sd_bus_message_append_basic(m, SD_BUS_TYPE_STRING, field);
- if (r < 0)
- return bus_log_create_error(r);
-
- if (STR_IN_SET(field,
- "CPUAccounting", "MemoryAccounting", "BlockIOAccounting",
- "SendSIGHUP", "SendSIGKILL", "WakeSystem", "DefaultDependencies")) {
-
- r = parse_boolean(eq);
- if (r < 0) {
- log_error("Failed to parse boolean assignment %s.", assignment);
- return -EINVAL;
- }
-
- r = sd_bus_message_append(m, "v", "b", r);
-
- } else if (streq(field, "MemoryLimit")) {
- off_t bytes;
-
- r = parse_size(eq, 1024, &bytes);
- if (r < 0) {
- log_error("Failed to parse bytes specification %s", assignment);
- return -EINVAL;
- }
-
- r = sd_bus_message_append(m, "v", "t", (uint64_t) bytes);
-
- } else if (STR_IN_SET(field, "CPUShares", "BlockIOWeight")) {
- uint64_t u;
-
- r = safe_atou64(eq, &u);
- if (r < 0) {
- log_error("Failed to parse %s value %s.", field, eq);
- return -EINVAL;
- }
-
- r = sd_bus_message_append(m, "v", "t", u);
-
- } else if (STR_IN_SET(field, "User", "Group", "DevicePolicy", "KillMode"))
- r = sd_bus_message_append(m, "v", "s", eq);
-
- else if (streq(field, "DeviceAllow")) {
-
- if (isempty(eq))
- r = sd_bus_message_append(m, "v", "a(ss)", 0);
- else {
- const char *path, *rwm, *e;
-
- e = strchr(eq, ' ');
- if (e) {
- path = strndupa(eq, e - eq);
- rwm = e+1;
- } else {
- path = eq;
- rwm = "";
- }
-
- if (!path_startswith(path, "/dev")) {
- log_error("%s is not a device file in /dev.", path);
- return -EINVAL;
- }
-
- r = sd_bus_message_append(m, "v", "a(ss)", 1, path, rwm);
- }
-
- } else if (STR_IN_SET(field, "BlockIOReadBandwidth", "BlockIOWriteBandwidth")) {
-
- if (isempty(eq))
- r = sd_bus_message_append(m, "v", "a(st)", 0);
- else {
- const char *path, *bandwidth, *e;
- off_t bytes;
-
- e = strchr(eq, ' ');
- if (e) {
- path = strndupa(eq, e - eq);
- bandwidth = e+1;
- } else {
- log_error("Failed to parse %s value %s.", field, eq);
- return -EINVAL;
- }
-
- if (!path_startswith(path, "/dev")) {
- log_error("%s is not a device file in /dev.", path);
- return -EINVAL;
- }
-
- r = parse_size(bandwidth, 1000, &bytes);
- if (r < 0) {
- log_error("Failed to parse byte value %s.", bandwidth);
- return -EINVAL;
- }
-
- r = sd_bus_message_append(m, "v", "a(st)", 1, path, (uint64_t) bytes);
- }
-
- } else if (streq(field, "BlockIODeviceWeight")) {
-
- if (isempty(eq))
- r = sd_bus_message_append(m, "v", "a(st)", 0);
- else {
- const char *path, *weight, *e;
- uint64_t u;
-
- e = strchr(eq, ' ');
- if (e) {
- path = strndupa(eq, e - eq);
- weight = e+1;
- } else {
- log_error("Failed to parse %s value %s.", field, eq);
- return -EINVAL;
- }
-
- if (!path_startswith(path, "/dev")) {
- log_error("%s is not a device file in /dev.", path);
- return -EINVAL;
- }
-
- r = safe_atou64(weight, &u);
- if (r < 0) {
- log_error("Failed to parse %s value %s.", field, weight);
- return -EINVAL;
- }
- r = sd_bus_message_append(m, "v", "a(st)", path, u);
- }
-
- } else if (rlimit_from_string(field) >= 0) {
- uint64_t rl;
-
- if (streq(eq, "infinity"))
- rl = (uint64_t) -1;
- else {
- r = safe_atou64(eq, &rl);
- if (r < 0) {
- log_error("Invalid resource limit: %s", eq);
- return -EINVAL;
- }
- }
-
- r = sd_bus_message_append(m, "v", "t", rl);
-
- } else if (streq(field, "Nice")) {
- int32_t i;
-
- r = safe_atoi32(eq, &i);
- if (r < 0) {
- log_error("Failed to parse %s value %s.", field, eq);
- return -EINVAL;
- }
-
- r = sd_bus_message_append(m, "v", "i", i);
-
- } else if (streq(field, "Environment")) {
-
- r = sd_bus_message_append(m, "v", "as", 1, eq);
-
- } else if (streq(field, "KillSignal")) {
- int sig;
-
- sig = signal_from_string_try_harder(eq);
- if (sig < 0) {
- log_error("Failed to parse %s value %s.", field, eq);
- return -EINVAL;
- }
-
- r = sd_bus_message_append(m, "v", "i", sig);
-
- } else if (streq(field, "AccuracySec")) {
- usec_t u;
-
- r = parse_sec(eq, &u);
- if (r < 0) {
- log_error("Failed to parse %s value %s", field, eq);
- return -EINVAL;
- }
-
- r = sd_bus_message_append(m, "v", "t", u);
-
- } else {
- log_error("Unknown assignment %s.", assignment);
- return -EINVAL;
- }
-
- if (r < 0)
- return bus_log_create_error(r);
-
- return 0;
-}
-
-typedef struct BusWaitForJobs {
- sd_bus *bus;
- Set *jobs;
-
- char *name;
- char *result;
-
- sd_bus_slot *slot_job_removed;
- sd_bus_slot *slot_disconnected;
-} BusWaitForJobs;
-
-static int match_disconnected(sd_bus_message *m, void *userdata, sd_bus_error *error) {
- assert(m);
-
- log_error("Warning! D-Bus connection terminated.");
- sd_bus_close(sd_bus_message_get_bus(m));
-
- return 0;
-}
-
-static int match_job_removed(sd_bus_message *m, void *userdata, sd_bus_error *error) {
- const char *path, *unit, *result;
- BusWaitForJobs *d = userdata;
- uint32_t id;
- char *found;
- int r;
-
- assert(m);
- assert(d);
-
- r = sd_bus_message_read(m, "uoss", &id, &path, &unit, &result);
- if (r < 0) {
- bus_log_parse_error(r);
- return 0;
- }
-
- found = set_remove(d->jobs, (char*) path);
- if (!found)
- return 0;
-
- free(found);
-
- if (!isempty(result))
- d->result = strdup(result);
-
- if (!isempty(unit))
- d->name = strdup(unit);
-
- return 0;
-}
-
-void bus_wait_for_jobs_free(BusWaitForJobs *d) {
- if (!d)
- return;
-
- set_free_free(d->jobs);
-
- sd_bus_slot_unref(d->slot_disconnected);
- sd_bus_slot_unref(d->slot_job_removed);
-
- sd_bus_unref(d->bus);
-
- free(d->name);
- free(d->result);
-
- free(d);
-}
-
-int bus_wait_for_jobs_new(sd_bus *bus, BusWaitForJobs **ret) {
- _cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *d = NULL;
- int r;
-
- assert(bus);
- assert(ret);
-
- d = new0(BusWaitForJobs, 1);
- if (!d)
- return -ENOMEM;
-
- d->bus = sd_bus_ref(bus);
-
- /* When we are a bus client we match by sender. Direct
- * connections OTOH have no initialized sender field, and
- * hence we ignore the sender then */
- r = sd_bus_add_match(
- bus,
- &d->slot_job_removed,
- bus->bus_client ?
- "type='signal',"
- "sender='org.freedesktop.systemd1',"
- "interface='org.freedesktop.systemd1.Manager',"
- "member='JobRemoved',"
- "path='/org/freedesktop/systemd1'" :
- "type='signal',"
- "interface='org.freedesktop.systemd1.Manager',"
- "member='JobRemoved',"
- "path='/org/freedesktop/systemd1'",
- match_job_removed, d);
- if (r < 0)
- return r;
-
- r = sd_bus_add_match(
- bus,
- &d->slot_disconnected,
- "type='signal',"
- "sender='org.freedesktop.DBus.Local',"
- "interface='org.freedesktop.DBus.Local',"
- "member='Disconnected'",
- match_disconnected, d);
- if (r < 0)
- return r;
-
- *ret = d;
- d = NULL;
-
- return 0;
-}
-
-static int bus_process_wait(sd_bus *bus) {
- int r;
-
- for (;;) {
- r = sd_bus_process(bus, NULL);
- if (r < 0)
- return r;
- if (r > 0)
- return 0;
-
- r = sd_bus_wait(bus, (uint64_t) -1);
- if (r < 0)
- return r;
- }
-}
-
-static int bus_job_get_service_result(BusWaitForJobs *d, char **result) {
- _cleanup_free_ char *dbus_path = NULL;
-
- assert(d);
- assert(d->name);
- assert(result);
-
- dbus_path = unit_dbus_path_from_name(d->name);
- if (!dbus_path)
- return -ENOMEM;
-
- return sd_bus_get_property_string(d->bus,
- "org.freedesktop.systemd1",
- dbus_path,
- "org.freedesktop.systemd1.Service",
- "Result",
- NULL,
- result);
-}
-
-static const struct {
- const char *result, *explanation;
-} explanations [] = {
- { "resources", "a configured resource limit was exceeded" },
- { "timeout", "a timeout was exceeded" },
- { "exit-code", "the control process exited with error code" },
- { "signal", "a fatal signal was delivered to the control process" },
- { "core-dump", "a fatal signal was delivered causing the control process to dump core" },
- { "watchdog", "the service failed to send watchdog ping" },
- { "start-limit", "start of the service was attempted too often" }
-};
-
-static void log_job_error_with_service_result(const char* service, const char *result) {
- _cleanup_free_ char *service_shell_quoted = NULL;
-
- assert(service);
-
- service_shell_quoted = shell_maybe_quote(service);
-
- if (!isempty(result)) {
- unsigned i;
-
- for (i = 0; i < ELEMENTSOF(explanations); ++i)
- if (streq(result, explanations[i].result))
- break;
-
- if (i < ELEMENTSOF(explanations)) {
- log_error("Job for %s failed because %s. See \"systemctl status %s\" and \"journalctl -xe\" for details.\n",
- service,
- explanations[i].explanation,
- strna(service_shell_quoted));
-
- goto finish;
- }
- }
-
- log_error("Job for %s failed. See \"systemctl status %s\" and \"journalctl -xe\" for details.\n",
- service,
- strna(service_shell_quoted));
-
-finish:
- /* For some results maybe additional explanation is required */
- if (streq_ptr(result, "start-limit"))
- log_info("To force a start use \"systemctl reset-failed %1$s\" followed by \"systemctl start %1$s\" again.",
- strna(service_shell_quoted));
-}
-
-static int check_wait_response(BusWaitForJobs *d, bool quiet) {
- int r = 0;
-
- assert(d->result);
-
- if (!quiet) {
- if (streq(d->result, "canceled"))
- log_error("Job for %s canceled.", strna(d->name));
- else if (streq(d->result, "timeout"))
- log_error("Job for %s timed out.", strna(d->name));
- else if (streq(d->result, "dependency"))
- log_error("A dependency job for %s failed. See 'journalctl -xe' for details.", strna(d->name));
- else if (streq(d->result, "invalid"))
- log_error("Job for %s invalid.", strna(d->name));
- else if (streq(d->result, "assert"))
- log_error("Assertion failed on job for %s.", strna(d->name));
- else if (streq(d->result, "unsupported"))
- log_error("Operation on or unit type of %s not supported on this system.", strna(d->name));
- else if (!streq(d->result, "done") && !streq(d->result, "skipped")) {
- if (d->name) {
- int q;
- _cleanup_free_ char *result = NULL;
-
- q = bus_job_get_service_result(d, &result);
- if (q < 0)
- log_debug_errno(q, "Failed to get Result property of service %s: %m", d->name);
-
- log_job_error_with_service_result(d->name, result);
- } else
- log_error("Job failed. See \"journalctl -xe\" for details.");
- }
- }
-
- if (streq(d->result, "canceled"))
- r = -ECANCELED;
- else if (streq(d->result, "timeout"))
- r = -ETIME;
- else if (streq(d->result, "dependency"))
- r = -EIO;
- else if (streq(d->result, "invalid"))
- r = -ENOEXEC;
- else if (streq(d->result, "assert"))
- r = -EPROTO;
- else if (streq(d->result, "unsupported"))
- r = -EOPNOTSUPP;
- else if (!streq(d->result, "done") && !streq(d->result, "skipped"))
- r = -EIO;
-
- return r;
-}
-
-int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet) {
- int r = 0;
-
- assert(d);
-
- while (!set_isempty(d->jobs)) {
- int q;
-
- q = bus_process_wait(d->bus);
- if (q < 0)
- return log_error_errno(q, "Failed to wait for response: %m");
-
- if (d->result) {
- q = check_wait_response(d, quiet);
- /* Return the first error as it is most likely to be
- * meaningful. */
- if (q < 0 && r == 0)
- r = q;
-
- log_debug_errno(q, "Got result %s/%m for job %s", strna(d->result), strna(d->name));
- }
-
- free(d->name);
- d->name = NULL;
-
- free(d->result);
- d->result = NULL;
- }
-
- return r;
-}
-
-int bus_wait_for_jobs_add(BusWaitForJobs *d, const char *path) {
- int r;
-
- assert(d);
-
- r = set_ensure_allocated(&d->jobs, &string_hash_ops);
- if (r < 0)
- return r;
-
- return set_put_strdup(d->jobs, path);
-}
-
-int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, UnitFileChange **changes, unsigned *n_changes) {
- const char *type, *path, *source;
- int r;
-
- r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(sss)");
- if (r < 0)
- return bus_log_parse_error(r);
-
- while ((r = sd_bus_message_read(m, "(sss)", &type, &path, &source)) > 0) {
- if (!quiet) {
- if (streq(type, "symlink"))
- log_info("Created symlink from %s to %s.", path, source);
- else
- log_info("Removed symlink %s.", path);
- }
-
- r = unit_file_changes_add(changes, n_changes, streq(type, "symlink") ? UNIT_FILE_SYMLINK : UNIT_FILE_UNLINK, path, source);
- if (r < 0)
- return r;
- }
- if (r < 0)
- return bus_log_parse_error(r);
-
- r = sd_bus_message_exit_container(m);
- if (r < 0)
- return bus_log_parse_error(r);
-
- return 0;
-}
-
-/**
- * bus_path_encode_unique() - encode unique object path
- * @b: bus connection or NULL
- * @prefix: object path prefix
- * @sender_id: unique-name of client, or NULL
- * @external_id: external ID to be chosen by client, or NULL
- * @ret_path: storage for encoded object path pointer
- *
- * Whenever we provide a bus API that allows clients to create and manage
- * server-side objects, we need to provide a unique name for these objects. If
- * we let the server choose the name, we suffer from a race condition: If a
- * client creates an object asynchronously, it cannot destroy that object until
- * it received the method reply. It cannot know the name of the new object,
- * thus, it cannot destroy it. Furthermore, it enforces a round-trip.
- *
- * Therefore, many APIs allow the client to choose the unique name for newly
- * created objects. There're two problems to solve, though:
- * 1) Object names are usually defined via dbus object paths, which are
- * usually globally namespaced. Therefore, multiple clients must be able
- * to choose unique object names without interference.
- * 2) If multiple libraries share the same bus connection, they must be
- * able to choose unique object names without interference.
- * The first problem is solved easily by prefixing a name with the
- * unique-bus-name of a connection. The server side must enforce this and
- * reject any other name. The second problem is solved by providing unique
- * suffixes from within sd-bus.
- *
- * This helper allows clients to create unique object-paths. It uses the
- * template '/prefix/sender_id/external_id' and returns the new path in
- * @ret_path (must be freed by the caller).
- * If @sender_id is NULL, the unique-name of @b is used. If @external_id is
- * NULL, this function allocates a unique suffix via @b (by requesting a new
- * cookie). If both @sender_id and @external_id are given, @b can be passed as
- * NULL.
- *
- * Returns: 0 on success, negative error code on failure.
- */
-int bus_path_encode_unique(sd_bus *b, const char *prefix, const char *sender_id, const char *external_id, char **ret_path) {
- _cleanup_free_ char *sender_label = NULL, *external_label = NULL;
- char external_buf[DECIMAL_STR_MAX(uint64_t)], *p;
- int r;
-
- assert_return(b || (sender_id && external_id), -EINVAL);
- assert_return(object_path_is_valid(prefix), -EINVAL);
- assert_return(ret_path, -EINVAL);
-
- if (!sender_id) {
- r = sd_bus_get_unique_name(b, &sender_id);
- if (r < 0)
- return r;
- }
-
- if (!external_id) {
- xsprintf(external_buf, "%"PRIu64, ++b->cookie);
- external_id = external_buf;
- }
-
- sender_label = bus_label_escape(sender_id);
- if (!sender_label)
- return -ENOMEM;
-
- external_label = bus_label_escape(external_id);
- if (!external_label)
- return -ENOMEM;
-
- p = strjoin(prefix, "/", sender_label, "/", external_label, NULL);
- if (!p)
- return -ENOMEM;
-
- *ret_path = p;
- return 0;
-}
-
-/**
- * bus_path_decode_unique() - decode unique object path
- * @path: object path to decode
- * @prefix: object path prefix
- * @ret_sender: output parameter for sender-id label
- * @ret_external: output parameter for external-id label
- *
- * This does the reverse of bus_path_encode_unique() (see its description for
- * details). Both trailing labels, sender-id and external-id, are unescaped and
- * returned in the given output parameters (the caller must free them).
- *
- * Note that this function returns 0 if the path does not match the template
- * (see bus_path_encode_unique()), 1 if it matched.
- *
- * Returns: Negative error code on failure, 0 if the given object path does not
- * match the template (return parameters are set to NULL), 1 if it was
- * parsed successfully (return parameters contain allocated labels).
- */
-int bus_path_decode_unique(const char *path, const char *prefix, char **ret_sender, char **ret_external) {
- const char *p, *q;
- char *sender, *external;
-
- assert(object_path_is_valid(path));
- assert(object_path_is_valid(prefix));
- assert(ret_sender);
- assert(ret_external);
-
- p = object_path_startswith(path, prefix);
- if (!p) {
- *ret_sender = NULL;
- *ret_external = NULL;
- return 0;
- }
-
- q = strchr(p, '/');
- if (!q) {
- *ret_sender = NULL;
- *ret_external = NULL;
- return 0;
- }
-
- sender = bus_label_unescape_n(p, q - p);
- external = bus_label_unescape(q + 1);
- if (!sender || !external) {
- free(sender);
- free(external);
- return -ENOMEM;
- }
-
- *ret_sender = sender;
- *ret_external = external;
- return 1;
-}
-
-bool is_kdbus_wanted(void) {
- _cleanup_free_ char *value = NULL;
-#ifdef ENABLE_KDBUS
- const bool configured = true;
-#else
- const bool configured = false;
-#endif
-
- int r;
-
- if (get_proc_cmdline_key("kdbus", NULL) > 0)
- return true;
-
- r = get_proc_cmdline_key("kdbus=", &value);
- if (r <= 0)
- return configured;
-
- return parse_boolean(value) == 1;
-}
-
-bool is_kdbus_available(void) {
- _cleanup_close_ int fd = -1;
- struct kdbus_cmd cmd = { .size = sizeof(cmd), .flags = KDBUS_FLAG_NEGOTIATE };
-
- if (!is_kdbus_wanted())
- return false;
-
- fd = open("/sys/fs/kdbus/control", O_RDWR | O_CLOEXEC | O_NONBLOCK | O_NOCTTY);
- if (fd < 0)
- return false;
-
- return ioctl(fd, KDBUS_CMD_BUS_MAKE, &cmd) >= 0;
-}
diff --git a/src/libelogind/sd-bus/bus-util.h b/src/libelogind/sd-bus/bus-util.h
deleted file mode 100644
index 75b842891..000000000
--- a/src/libelogind/sd-bus/bus-util.h
+++ /dev/null
@@ -1,203 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-#pragma once
-
-/***
- This file is part of systemd.
-
- Copyright 2013 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 "sd-event.h"
-#include "sd-bus.h"
-#include "hashmap.h"
-#include "install.h"
-#include "time-util.h"
-
-typedef enum BusTransport {
- BUS_TRANSPORT_LOCAL,
- BUS_TRANSPORT_REMOTE,
- BUS_TRANSPORT_MACHINE,
- _BUS_TRANSPORT_MAX,
- _BUS_TRANSPORT_INVALID = -1
-} BusTransport;
-
-typedef int (*bus_property_set_t) (sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata);
-
-struct bus_properties_map {
- const char *member;
- const char *signature;
- bus_property_set_t set;
- size_t offset;
-};
-
-int bus_map_id128(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata);
-
-int bus_message_map_all_properties(sd_bus_message *m, const struct bus_properties_map *map, void *userdata);
-int bus_message_map_properties_changed(sd_bus_message *m, const struct bus_properties_map *map, void *userdata);
-int bus_map_all_properties(sd_bus *bus, const char *destination, const char *path, const struct bus_properties_map *map, void *userdata);
-
-int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name);
-
-typedef bool (*check_idle_t)(void *userdata);
-
-int bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t timeout, check_idle_t check_idle, void *userdata);
-
-int bus_name_has_owner(sd_bus *c, const char *name, sd_bus_error *error);
-
-int bus_check_peercred(sd_bus *c);
-
-int bus_test_polkit(sd_bus_message *call, int capability, const char *action, uid_t good_user, bool *_challenge, sd_bus_error *e);
-
-int bus_verify_polkit_async(sd_bus_message *call, int capability, const char *action, bool interactive, uid_t good_user, Hashmap **registry, sd_bus_error *error);
-void bus_verify_polkit_async_registry_free(Hashmap *registry);
-
-int bus_open_system_systemd(sd_bus **_bus);
-int bus_open_user_systemd(sd_bus **_bus);
-
-int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus);
-int bus_open_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus);
-
-int bus_print_property(const char *name, sd_bus_message *property, bool all);
-int bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, char **filter, bool all);
-
-int bus_property_get_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
-
-#define bus_property_get_usec ((sd_bus_property_get_t) NULL)
-#define bus_property_set_usec ((sd_bus_property_set_t) NULL)
-
-assert_cc(sizeof(int) == sizeof(int32_t));
-#define bus_property_get_int ((sd_bus_property_get_t) NULL)
-
-assert_cc(sizeof(unsigned) == sizeof(unsigned));
-#define bus_property_get_unsigned ((sd_bus_property_get_t) NULL)
-
-/* On 64bit machines we can use the default serializer for size_t and
- * friends, otherwise we need to cast this manually */
-#if __SIZEOF_SIZE_T__ == 8
-#define bus_property_get_size ((sd_bus_property_get_t) NULL)
-#else
-int bus_property_get_size(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
-#endif
-
-#if __SIZEOF_LONG__ == 8
-#define bus_property_get_long ((sd_bus_property_get_t) NULL)
-#define bus_property_get_ulong ((sd_bus_property_get_t) NULL)
-#else
-int bus_property_get_long(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
-int bus_property_get_ulong(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
-#endif
-
-/* uid_t and friends on Linux 32 bit. This means we can just use the
- * default serializer for 32bit unsigned, for serializing it, and map
- * it to NULL here */
-assert_cc(sizeof(uid_t) == sizeof(uint32_t));
-#define bus_property_get_uid ((sd_bus_property_get_t) NULL)
-
-assert_cc(sizeof(gid_t) == sizeof(uint32_t));
-#define bus_property_get_gid ((sd_bus_property_get_t) NULL)
-
-assert_cc(sizeof(pid_t) == sizeof(uint32_t));
-#define bus_property_get_pid ((sd_bus_property_get_t) NULL)
-
-assert_cc(sizeof(mode_t) == sizeof(uint32_t));
-#define bus_property_get_mode ((sd_bus_property_get_t) NULL)
-
-int bus_log_parse_error(int r);
-int bus_log_create_error(int r);
-
-typedef struct UnitInfo {
- const char *machine;
- const char *id;
- const char *description;
- const char *load_state;
- const char *active_state;
- const char *sub_state;
- const char *following;
- const char *unit_path;
- uint32_t job_id;
- const char *job_type;
- const char *job_path;
-} UnitInfo;
-
-int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u);
-
-DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus*, sd_bus_unref);
-DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus*, sd_bus_flush_close_unref);
-DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_slot*, sd_bus_slot_unref);
-DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_message*, sd_bus_message_unref);
-DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_creds*, sd_bus_creds_unref);
-DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_track*, sd_bus_track_unref);
-
-#define _cleanup_bus_unref_ _cleanup_(sd_bus_unrefp)
-#define _cleanup_bus_flush_close_unref_ _cleanup_(sd_bus_flush_close_unrefp)
-#define _cleanup_bus_slot_unref_ _cleanup_(sd_bus_slot_unrefp)
-#define _cleanup_bus_message_unref_ _cleanup_(sd_bus_message_unrefp)
-#define _cleanup_bus_creds_unref_ _cleanup_(sd_bus_creds_unrefp)
-#define _cleanup_bus_track_unref_ _cleanup_(sd_bus_slot_unrefp)
-#define _cleanup_bus_error_free_ _cleanup_(sd_bus_error_free)
-
-#define BUS_DEFINE_PROPERTY_GET_ENUM(function, name, type) \
- int function(sd_bus *bus, \
- const char *path, \
- const char *interface, \
- const char *property, \
- sd_bus_message *reply, \
- void *userdata, \
- sd_bus_error *error) { \
- \
- const char *value; \
- type *field = userdata; \
- int r; \
- \
- assert(bus); \
- assert(reply); \
- assert(field); \
- \
- value = strempty(name##_to_string(*field)); \
- \
- r = sd_bus_message_append_basic(reply, 's', value); \
- if (r < 0) \
- return r; \
- \
- return 1; \
- } \
- struct __useless_struct_to_allow_trailing_semicolon__
-
-#define BUS_PROPERTY_DUAL_TIMESTAMP(name, offset, flags) \
- SD_BUS_PROPERTY(name, "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, realtime), (flags)), \
- SD_BUS_PROPERTY(name "Monotonic", "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, monotonic), (flags))
-
-int bus_maybe_reply_error(sd_bus_message *m, int r, sd_bus_error *error);
-
-int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignment);
-
-typedef struct BusWaitForJobs BusWaitForJobs;
-
-int bus_wait_for_jobs_new(sd_bus *bus, BusWaitForJobs **ret);
-void bus_wait_for_jobs_free(BusWaitForJobs *d);
-int bus_wait_for_jobs_add(BusWaitForJobs *d, const char *path);
-int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet);
-
-DEFINE_TRIVIAL_CLEANUP_FUNC(BusWaitForJobs*, bus_wait_for_jobs_free);
-
-int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, UnitFileChange **changes, unsigned *n_changes);
-
-int bus_path_encode_unique(sd_bus *b, const char *prefix, const char *sender_id, const char *external_id, char **ret_path);
-int bus_path_decode_unique(const char *path, const char *prefix, char **ret_sender, char **ret_external);
-
-bool is_kdbus_wanted(void);
-bool is_kdbus_available(void);
diff --git a/src/libelogind/sd-bus/sd-bus.c b/src/libelogind/sd-bus/sd-bus.c
index 87263b74f..eb9525ed7 100644
--- a/src/libelogind/sd-bus/sd-bus.c
+++ b/src/libelogind/sd-bus/sd-bus.c
@@ -229,6 +229,8 @@ _public_ int sd_bus_set_fd(sd_bus *bus, int input_fd, int output_fd) {
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[]) {
char *p, **a;
@@ -302,6 +304,7 @@ _public_ int sd_bus_negotiate_timestamp(sd_bus *bus, int b) {
return 0;
}
+#endif // 0
_public_ int sd_bus_negotiate_creds(sd_bus *bus, int b, uint64_t mask) {
uint64_t new_flags;
@@ -342,6 +345,8 @@ _public_ int sd_bus_set_server(sd_bus *bus, int b, sd_id128_t server_id) {
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_set_anonymous(sd_bus *bus, int b) {
assert_return(bus, -EINVAL);
assert_return(bus->state == BUS_UNSET, -EPERM);
@@ -367,6 +372,7 @@ _public_ int sd_bus_set_description(sd_bus *bus, const char *description) {
return free_and_strdup(&bus->description, description);
}
+#endif // 0
_public_ int sd_bus_set_allow_interactive_authorization(sd_bus *bus, int b) {
assert_return(bus, -EINVAL);
@@ -376,12 +382,15 @@ _public_ int sd_bus_set_allow_interactive_authorization(sd_bus *bus, int b) {
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_get_allow_interactive_authorization(sd_bus *bus) {
assert_return(bus, -EINVAL);
assert_return(!bus_pid_changed(bus), -ECHILD);
return bus->allow_interactive_authorization;
}
+#endif // 0
static int hello_callback(sd_bus_message *reply, void *userdata, sd_bus_error *error) {
const char *s;
@@ -1023,10 +1032,12 @@ static int bus_start_address(sd_bus *b) {
if (b->exec_path)
r = bus_socket_exec(b);
- else if ((b->nspid > 0 || b->machine) && b->kernel)
+#if 0
+ else if ((b->nspid > 0 || b->machine) && b->kernel)
r = bus_container_connect_kernel(b);
else if ((b->nspid > 0 || b->machine) && b->sockaddr.sa.sa_family != AF_UNSPEC)
r = bus_container_connect_socket(b);
+#endif // 0
else if (b->kernel)
r = bus_kernel_connect(b);
else if (b->sockaddr.sa.sa_family != AF_UNSPEC)
@@ -1470,6 +1481,8 @@ _public_ sd_bus *sd_bus_unref(sd_bus *bus) {
return NULL;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_is_open(sd_bus *bus) {
assert_return(bus, -EINVAL);
@@ -1477,6 +1490,7 @@ _public_ int sd_bus_is_open(sd_bus *bus) {
return BUS_IS_OPEN(bus->state);
}
+#endif // 0
_public_ int sd_bus_can_send(sd_bus *bus, char type) {
int r;
@@ -1502,6 +1516,8 @@ _public_ int sd_bus_can_send(sd_bus *bus, char type) {
return bus_type_is_valid(type);
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_get_bus_id(sd_bus *bus, sd_id128_t *id) {
int r;
@@ -1516,6 +1532,7 @@ _public_ int sd_bus_get_bus_id(sd_bus *bus, sd_id128_t *id) {
*id = bus->server_id;
return 0;
}
+#endif // 0
static int bus_seal_message(sd_bus *b, sd_bus_message *m, usec_t timeout) {
assert(b);
@@ -2771,9 +2788,12 @@ _public_ int sd_bus_process(sd_bus *bus, sd_bus_message **ret) {
return bus_process_internal(bus, false, 0, ret);
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_process_priority(sd_bus *bus, int64_t priority, sd_bus_message **ret) {
return bus_process_internal(bus, true, priority, ret);
}
+#endif // 0
static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec) {
struct pollfd p[2] = {};
@@ -2992,6 +3012,8 @@ finish:
return r;
}
+/// UNNEEDED by elogind
+#if 0
int bus_remove_match_by_string(
sd_bus *bus,
const char *match,
@@ -3022,6 +3044,7 @@ finish:
return r;
}
+#endif // 0
bool bus_pid_changed(sd_bus *bus) {
assert(bus);
@@ -3267,11 +3290,14 @@ _public_ sd_bus_message* sd_bus_get_current_message(sd_bus *bus) {
return bus->current_message;
}
+/// UNNEEDED by elogind
+#if 0
_public_ sd_bus_slot* sd_bus_get_current_slot(sd_bus *bus) {
assert_return(bus, NULL);
return bus->current_slot;
}
+#endif // 0
_public_ sd_bus_message_handler_t sd_bus_get_current_handler(sd_bus *bus) {
assert_return(bus, NULL);
@@ -3358,6 +3384,8 @@ _public_ int sd_bus_default(sd_bus **ret) {
return sd_bus_default_system(ret);
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_get_tid(sd_bus *b, pid_t *tid) {
assert_return(b, -EINVAL);
assert_return(tid, -EINVAL);
@@ -3415,6 +3443,7 @@ _public_ int sd_bus_path_decode(const char *path, const char *prefix, char **ext
*external_id = ret;
return 1;
}
+#endif // 0
_public_ int sd_bus_try_close(sd_bus *bus) {
int r;
@@ -3442,6 +3471,8 @@ _public_ int sd_bus_try_close(sd_bus *bus) {
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_get_description(sd_bus *bus, const char **description) {
assert_return(bus, -EINVAL);
assert_return(description, -EINVAL);
@@ -3451,6 +3482,7 @@ _public_ int sd_bus_get_description(sd_bus *bus, const char **description) {
*description = bus->description;
return 0;
}
+#endif // 0
int bus_get_root_path(sd_bus *bus) {
int r;
@@ -3470,6 +3502,8 @@ int bus_get_root_path(sd_bus *bus) {
return r;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_bus_get_scope(sd_bus *bus, const char **scope) {
int r;
@@ -3567,3 +3601,4 @@ _public_ int sd_bus_is_monitor(sd_bus *bus) {
return !!(bus->hello_flags & KDBUS_HELLO_MONITOR);
}
+#endif // 0
diff --git a/src/libelogind/sd-daemon/sd-daemon.c b/src/libelogind/sd-daemon/sd-daemon.c
index 7bbb3517b..82ac72c72 100644
--- a/src/libelogind/sd-daemon/sd-daemon.c
+++ b/src/libelogind/sd-daemon/sd-daemon.c
@@ -307,6 +307,37 @@ _public_ int sd_is_socket_unix(int fd, int type, int listening, const char *path
return 1;
}
+_public_ int sd_is_mq(int fd, const char *path) {
+ struct mq_attr attr;
+
+ assert_return(fd >= 0, -EINVAL);
+
+ if (mq_getattr(fd, &attr) < 0)
+ return -errno;
+
+ if (path) {
+ char fpath[PATH_MAX];
+ struct stat a, b;
+
+ assert_return(path_is_absolute(path), -EINVAL);
+
+ if (fstat(fd, &a) < 0)
+ return -errno;
+
+ strncpy(stpcpy(fpath, "/dev/mqueue"), path, sizeof(fpath) - 12);
+ fpath[sizeof(fpath)-1] = 0;
+
+ if (stat(fpath, &b) < 0)
+ return -errno;
+
+ if (a.st_dev != b.st_dev ||
+ a.st_ino != b.st_ino)
+ return 0;
+ }
+
+ return 1;
+}
+
_public_ int sd_pid_notify_with_fds(pid_t pid, int unset_environment, const char *state, const int *fds, unsigned n_fds) {
union sockaddr_union sockaddr = {
.sa.sa_family = AF_UNIX,
diff --git a/src/libelogind/sd-device/device-internal.h b/src/libelogind/sd-device/device-internal.h
deleted file mode 100644
index b96441de5..000000000
--- a/src/libelogind/sd-device/device-internal.h
+++ /dev/null
@@ -1,126 +0,0 @@
-/***
- This file is part of systemd.
-
- Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
- Copyright 2014 Tom Gundersen <teg@jklm.no>
-
- 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/>.
-***/
-
-#pragma once
-
-#include "hashmap.h"
-#include "set.h"
-
-struct sd_device {
- uint64_t n_ref;
-
- sd_device *parent;
- bool parent_set; /* no need to try to reload parent */
-
- OrderedHashmap *properties;
- Iterator properties_iterator;
- uint64_t properties_generation; /* changes whenever the properties are changed */
- uint64_t properties_iterator_generation; /* generation when iteration was started */
-
- /* the subset of the properties that should be written to the db*/
- OrderedHashmap *properties_db;
-
- Hashmap *sysattr_values; /* cached sysattr values */
-
- Set *sysattrs; /* names of sysattrs */
- Iterator sysattrs_iterator;
- bool sysattrs_read; /* don't try to re-read sysattrs once read */
-
- Set *tags;
- Iterator tags_iterator;
- uint64_t tags_generation; /* changes whenever the tags are changed */
- uint64_t tags_iterator_generation; /* generation when iteration was started */
- bool property_tags_outdated; /* need to update TAGS= property */
-
- Set *devlinks;
- Iterator devlinks_iterator;
- uint64_t devlinks_generation; /* changes whenever the devlinks are changed */
- uint64_t devlinks_iterator_generation; /* generation when iteration was started */
- bool property_devlinks_outdated; /* need to update DEVLINKS= property */
- int devlink_priority;
-
- char **properties_strv; /* the properties hashmap as a strv */
- uint8_t *properties_nulstr; /* the same as a nulstr */
- size_t properties_nulstr_len;
- bool properties_buf_outdated; /* need to reread hashmap */
-
- int watch_handle;
-
- char *syspath;
- const char *devpath;
- const char *sysnum;
- char *sysname;
- bool sysname_set; /* don't reread sysname */
-
- char *devtype;
- int ifindex;
- char *devname;
- dev_t devnum;
-
- char *subsystem;
- bool subsystem_set; /* don't reread subsystem */
- char *driver;
- bool driver_set; /* don't reread driver */
-
- char *id_filename;
-
- bool is_initialized;
- uint64_t usec_initialized;
-
- mode_t devmode;
- uid_t devuid;
- gid_t devgid;
-
- bool uevent_loaded; /* don't reread uevent */
- bool db_loaded; /* don't reread db */
-
- bool sealed; /* don't read more information from uevent/db */
- bool db_persist; /* don't clean up the db when switching from initrd to real root */
-};
-
-typedef enum DeviceAction {
- DEVICE_ACTION_ADD,
- DEVICE_ACTION_REMOVE,
- DEVICE_ACTION_CHANGE,
- DEVICE_ACTION_MOVE,
- DEVICE_ACTION_ONLINE,
- DEVICE_ACTION_OFFLINE,
- _DEVICE_ACTION_MAX,
- _DEVICE_ACTION_INVALID = -1,
-} DeviceAction;
-
-int device_new_aux(sd_device **ret);
-int device_add_property_aux(sd_device *device, const char *key, const char *value, bool db);
-int device_add_property_internal(sd_device *device, const char *key, const char *value);
-int device_read_uevent_file(sd_device *device);
-int device_read_db_aux(sd_device *device, bool force);
-
-int device_set_syspath(sd_device *device, const char *_syspath, bool verify);
-int device_set_ifindex(sd_device *device, const char *ifindex);
-int device_set_devmode(sd_device *device, const char *devmode);
-int device_set_devname(sd_device *device, const char *_devname);
-int device_set_devtype(sd_device *device, const char *_devtype);
-int device_set_devnum(sd_device *device, const char *major, const char *minor);
-int device_set_subsystem(sd_device *device, const char *_subsystem);
-int device_set_driver(sd_device *device, const char *_driver);
-int device_set_usec_initialized(sd_device *device, const char *initialized);
-
-DeviceAction device_action_from_string(const char *s) _pure_;
-const char *device_action_to_string(DeviceAction a) _const_;
diff --git a/src/libelogind/sd-device/device-private.c b/src/libelogind/sd-device/device-private.c
deleted file mode 100644
index 2e6043324..000000000
--- a/src/libelogind/sd-device/device-private.c
+++ /dev/null
@@ -1,1117 +0,0 @@
-/***
- This file is part of systemd.
-
- Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
- Copyright 2014 Tom Gundersen <teg@jklm.no>
-
- 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 <ctype.h>
-#include <sys/types.h>
-#include <net/if.h>
-
-#include "util.h"
-#include "macro.h"
-#include "refcnt.h"
-#include "path-util.h"
-#include "strxcpyx.h"
-#include "fileio.h"
-#include "hashmap.h"
-#include "set.h"
-#include "strv.h"
-#include "mkdir.h"
-
-#include "sd-device.h"
-
-#include "device-util.h"
-#include "device-internal.h"
-#include "device-private.h"
-
-int device_add_property(sd_device *device, const char *key, const char *value) {
- int r;
-
- assert(device);
- assert(key);
-
- r = device_add_property_aux(device, key, value, false);
- if (r < 0)
- return r;
-
- if (key[0] != '.') {
- r = device_add_property_aux(device, key, value, true);
- if (r < 0)
- return r;
- }
-
- return 0;
-}
-
-static int device_add_property_internal_from_string(sd_device *device, const char *str) {
- _cleanup_free_ char *key = NULL;
- char *value;
-
- assert(device);
- assert(str);
-
- key = strdup(str);
- if (!key)
- return -ENOMEM;
-
- value = strchr(key, '=');
- if (!value)
- return -EINVAL;
-
- *value = '\0';
-
- if (isempty(++value))
- value = NULL;
-
- return device_add_property_internal(device, key, value);
-}
-
-static int handle_db_line(sd_device *device, char key, const char *value) {
- char *path;
- int r;
-
- assert(device);
- assert(value);
-
- switch (key) {
- case 'S':
- path = strjoina("/dev/", value);
- r = device_add_devlink(device, path);
- if (r < 0)
- return r;
-
- break;
- case 'L':
- r = safe_atoi(value, &device->devlink_priority);
- if (r < 0)
- return r;
-
- break;
- case 'E':
- r = device_add_property_internal_from_string(device, value);
- if (r < 0)
- return r;
-
- break;
- case 'G':
- r = device_add_tag(device, value);
- if (r < 0)
- return r;
-
- break;
- case 'W':
- r = safe_atoi(value, &device->watch_handle);
- if (r < 0)
- return r;
-
- break;
- case 'I':
- r = device_set_usec_initialized(device, value);
- if (r < 0)
- return r;
-
- break;
- default:
- log_debug("device db: unknown key '%c'", key);
- }
-
- return 0;
-}
-
-void device_set_devlink_priority(sd_device *device, int priority) {
- assert(device);
-
- device->devlink_priority = priority;
-}
-
-void device_set_is_initialized(sd_device *device) {
- assert(device);
-
- device->is_initialized = true;
-}
-
-int device_ensure_usec_initialized(sd_device *device, sd_device *device_old) {
- char num[DECIMAL_STR_MAX(usec_t)];
- usec_t usec_initialized;
- int r;
-
- assert(device);
-
- if (device_old && device_old->usec_initialized > 0)
- usec_initialized = device_old->usec_initialized;
- else
- usec_initialized = now(CLOCK_MONOTONIC);
-
- r = snprintf(num, sizeof(num), USEC_FMT, usec_initialized);
- if (r < 0)
- return -errno;
-
- r = device_set_usec_initialized(device, num);
- if (r < 0)
- return r;
-
- return 0;
-}
-
-static int device_read_db(sd_device *device) {
- _cleanup_free_ char *db = NULL;
- char *path;
- const char *id, *value;
- char key;
- size_t db_len;
- unsigned i;
- int r;
-
- enum {
- PRE_KEY,
- KEY,
- PRE_VALUE,
- VALUE,
- INVALID_LINE,
- } state = PRE_KEY;
-
- assert(device);
-
- if (device->db_loaded || device->sealed)
- return 0;
-
- r = device_get_id_filename(device, &id);
- if (r < 0)
- return r;
-
- path = strjoina("/run/udev/data/", id);
-
- r = read_full_file(path, &db, &db_len);
- if (r < 0) {
- if (r == -ENOENT)
- return 0;
- else {
- log_debug("sd-device: failed to read db '%s': %s", path, strerror(-r));
- return r;
- }
- }
-
- /* devices with a database entry are initialized */
- device_set_is_initialized(device);
-
- for (i = 0; i < db_len; i++) {
- switch (state) {
- case PRE_KEY:
- if (!strchr(NEWLINE, db[i])) {
- key = db[i];
-
- state = KEY;
- }
-
- break;
- case KEY:
- if (db[i] != ':') {
- log_debug("sd-device: ignoring invalid db entry with key '%c'", key);
-
- state = INVALID_LINE;
- } else {
- db[i] = '\0';
-
- state = PRE_VALUE;
- }
-
- break;
- case PRE_VALUE:
- value = &db[i];
-
- state = VALUE;
-
- break;
- case INVALID_LINE:
- if (strchr(NEWLINE, db[i]))
- state = PRE_KEY;
-
- break;
- case VALUE:
- if (strchr(NEWLINE, db[i])) {
- db[i] = '\0';
- r = handle_db_line(device, key, value);
- if (r < 0)
- log_debug("sd-device: failed to handle db entry '%c:%s': %s", key, value, strerror(-r));
-
- state = PRE_KEY;
- }
-
- break;
- default:
- assert_not_reached("invalid state when parsing db");
- }
- }
-
- device->db_loaded = true;
-
- return 0;
-}
-
-uint64_t device_get_properties_generation(sd_device *device) {
- assert(device);
-
- return device->properties_generation;
-}
-
-uint64_t device_get_tags_generation(sd_device *device) {
- assert(device);
-
- return device->tags_generation;
-}
-
-uint64_t device_get_devlinks_generation(sd_device *device) {
- assert(device);
-
- return device->devlinks_generation;
-}
-
-int device_get_devnode_mode(sd_device *device, mode_t *mode) {
- int r;
-
- assert(device);
- assert(mode);
-
- r = device_read_db(device);
- if (r < 0)
- return r;
-
- *mode = device->devmode;
-
- return 0;
-}
-
-int device_get_devnode_uid(sd_device *device, uid_t *uid) {
- int r;
-
- assert(device);
- assert(uid);
-
- r = device_read_db(device);
- if (r < 0)
- return r;
-
- *uid = device->devuid;
-
- return 0;
-}
-
-static int device_set_devuid(sd_device *device, const char *uid) {
- unsigned u;
- int r;
-
- assert(device);
- assert(uid);
-
- r = safe_atou(uid, &u);
- if (r < 0)
- return r;
-
- r = device_add_property_internal(device, "DEVUID", uid);
- if (r < 0)
- return r;
-
- device->devuid = u;
-
- return 0;
-}
-
-int device_get_devnode_gid(sd_device *device, gid_t *gid) {
- int r;
-
- assert(device);
- assert(gid);
-
- r = device_read_db(device);
- if (r < 0)
- return r;
-
- *gid = device->devgid;
-
- return 0;
-}
-
-static int device_set_devgid(sd_device *device, const char *gid) {
- unsigned g;
- int r;
-
- assert(device);
- assert(gid);
-
- r = safe_atou(gid, &g);
- if (r < 0)
- return r;
-
- r = device_add_property_internal(device, "DEVGID", gid);
- if (r < 0)
- return r;
-
- device->devgid = g;
-
- return 0;
-}
-
-static int device_amend(sd_device *device, const char *key, const char *value) {
- int r;
-
- assert(device);
- assert(key);
- assert(value);
-
- if (streq(key, "DEVPATH")) {
- char *path;
-
- path = strjoina("/sys", value);
-
- /* the caller must verify or trust this data (e.g., if it comes from the kernel) */
- r = device_set_syspath(device, path, false);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not set syspath to '%s': %m", path);
- } else if (streq(key, "SUBSYSTEM")) {
- r = device_set_subsystem(device, value);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not set subsystem to '%s': %m", value);
- } else if (streq(key, "DEVTYPE")) {
- r = device_set_devtype(device, value);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not set devtype to '%s': %m", value);
- } else if (streq(key, "DEVNAME")) {
- r = device_set_devname(device, value);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not set devname to '%s': %m", value);
- } else if (streq(key, "USEC_INITIALIZED")) {
- r = device_set_usec_initialized(device, value);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not set usec-initialized to '%s': %m", value);
- } else if (streq(key, "DRIVER")) {
- r = device_set_driver(device, value);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not set driver to '%s': %m", value);
- } else if (streq(key, "IFINDEX")) {
- r = device_set_ifindex(device, value);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not set ifindex to '%s': %m", value);
- } else if (streq(key, "DEVMODE")) {
- r = device_set_devmode(device, value);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not set devmode to '%s': %m", value);
- } else if (streq(key, "DEVUID")) {
- r = device_set_devuid(device, value);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not set devuid to '%s': %m", value);
- } else if (streq(key, "DEVGID")) {
- r = device_set_devgid(device, value);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not set devgid to '%s': %m", value);
- } else if (streq(key, "DEVLINKS")) {
- const char *word, *state;
- size_t l;
-
- FOREACH_WORD(word, l, value, state) {
- char devlink[l + 1];
-
- strncpy(devlink, word, l);
- devlink[l] = '\0';
-
- r = device_add_devlink(device, devlink);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not add devlink '%s': %m", devlink);
- }
- } else if (streq(key, "TAGS")) {
- const char *word, *state;
- size_t l;
-
- FOREACH_WORD_SEPARATOR(word, l, value, ":", state) {
- char tag[l + 1];
-
- (void)strncpy(tag, word, l);
- tag[l] = '\0';
-
- r = device_add_tag(device, tag);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not add tag '%s': %m", tag);
- }
- } else {
- r = device_add_property_internal(device, key, value);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not add property '%s=%s': %m", key, value);
- }
-
- return 0;
-}
-
-static const char* const device_action_table[_DEVICE_ACTION_MAX] = {
- [DEVICE_ACTION_ADD] = "add",
- [DEVICE_ACTION_REMOVE] = "remove",
- [DEVICE_ACTION_CHANGE] = "change",
- [DEVICE_ACTION_MOVE] = "move",
- [DEVICE_ACTION_ONLINE] = "online",
- [DEVICE_ACTION_OFFLINE] = "offline",
-};
-
-DEFINE_STRING_TABLE_LOOKUP(device_action, DeviceAction);
-
-static int device_append(sd_device *device, char *key, const char **_major, const char **_minor, uint64_t *_seqnum,
- DeviceAction *_action) {
- DeviceAction action = _DEVICE_ACTION_INVALID;
- uint64_t seqnum = 0;
- const char *major = NULL, *minor = NULL;
- char *value;
- int r;
-
- assert(device);
- assert(key);
- assert(_major);
- assert(_minor);
- assert(_seqnum);
- assert(_action);
-
- value = strchr(key, '=');
- if (!value) {
- log_debug("sd-device: not a key-value pair: '%s'", key);
- return -EINVAL;
- }
-
- *value = '\0';
-
- value++;
-
- if (streq(key, "MAJOR"))
- major = value;
- else if (streq(key, "MINOR"))
- minor = value;
- else {
- if (streq(key, "ACTION")) {
- action = device_action_from_string(value);
- if (action == _DEVICE_ACTION_INVALID)
- return -EINVAL;
- } else if (streq(key, "SEQNUM")) {
- r = safe_atou64(value, &seqnum);
- if (r < 0)
- return r;
- else if (seqnum == 0)
- /* kernel only sends seqnum > 0 */
- return -EINVAL;
- }
-
- r = device_amend(device, key, value);
- if (r < 0)
- return r;
- }
-
- if (major != 0)
- *_major = major;
-
- if (minor != 0)
- *_minor = minor;
-
- if (action != _DEVICE_ACTION_INVALID)
- *_action = action;
-
- if (seqnum > 0)
- *_seqnum = seqnum;
-
- return 0;
-}
-
-void device_seal(sd_device *device) {
- assert(device);
-
- device->sealed = true;
-}
-
-static int device_verify(sd_device *device, DeviceAction action, uint64_t seqnum) {
- assert(device);
-
- if (!device->devpath || !device->subsystem || action == _DEVICE_ACTION_INVALID || seqnum == 0) {
- log_debug("sd-device: device created from strv lacks devpath, subsystem, action or seqnum");
- return -EINVAL;
- }
-
- device->sealed = true;
-
- return 0;
-}
-
-int device_new_from_strv(sd_device **ret, char **strv) {
- _cleanup_device_unref_ sd_device *device = NULL;
- char **key;
- const char *major = NULL, *minor = NULL;
- DeviceAction action = _DEVICE_ACTION_INVALID;
- uint64_t seqnum;
- int r;
-
- assert(ret);
- assert(strv);
-
- r = device_new_aux(&device);
- if (r < 0)
- return r;
-
- STRV_FOREACH(key, strv) {
- r = device_append(device, *key, &major, &minor, &seqnum, &action);
- if (r < 0)
- return r;
- }
-
- if (major) {
- r = device_set_devnum(device, major, minor);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not set devnum %s:%s: %m", major, minor);
- }
-
- r = device_verify(device, action, seqnum);
- if (r < 0)
- return r;
-
- *ret = device;
- device = NULL;
-
- return 0;
-}
-
-int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len) {
- _cleanup_device_unref_ sd_device *device = NULL;
- const char *major = NULL, *minor = NULL;
- DeviceAction action = _DEVICE_ACTION_INVALID;
- uint64_t seqnum;
- unsigned i = 0;
- int r;
-
- assert(ret);
- assert(nulstr);
- assert(len);
-
- r = device_new_aux(&device);
- if (r < 0)
- return r;
-
- while (i < len) {
- char *key;
- const char *end;
-
- key = (char*)&nulstr[i];
- end = memchr(key, '\0', len - i);
- if (!end) {
- log_debug("sd-device: failed to parse nulstr");
- return -EINVAL;
- }
- i += end - key + 1;
-
- r = device_append(device, key, &major, &minor, &seqnum, &action);
- if (r < 0)
- return r;
- }
-
- if (major) {
- r = device_set_devnum(device, major, minor);
- if (r < 0)
- return log_debug_errno(r, "sd-device: could not set devnum %s:%s: %m", major, minor);
- }
-
- r = device_verify(device, action, seqnum);
- if (r < 0)
- return r;
-
- *ret = device;
- device = NULL;
-
- return 0;
-}
-
-static int device_update_properties_bufs(sd_device *device) {
- const char *val, *prop;
- _cleanup_free_ char **buf_strv = NULL;
- _cleanup_free_ uint8_t *buf_nulstr = NULL;
- size_t allocated_nulstr = 0;
- size_t nulstr_len = 0, num = 0, i = 0;
-
- assert(device);
-
- if (!device->properties_buf_outdated)
- return 0;
-
- FOREACH_DEVICE_PROPERTY(device, prop, val) {
- size_t len = 0;
-
- len = strlen(prop) + 1 + strlen(val);
-
- buf_nulstr = GREEDY_REALLOC0(buf_nulstr, allocated_nulstr, nulstr_len + len + 2);
- if (!buf_nulstr)
- return -ENOMEM;
-
- strscpyl((char *)buf_nulstr + nulstr_len, len + 1, prop, "=", val, NULL);
- nulstr_len += len + 1;
- ++num;
- }
-
- /* build buf_strv from buf_nulstr */
- buf_strv = new0(char *, num + 1);
- if (!buf_strv)
- return -ENOMEM;
-
- NULSTR_FOREACH(val, (char*) buf_nulstr) {
- buf_strv[i] = (char *) val;
- assert(i < num);
- i++;
- }
-
- free(device->properties_nulstr);
- device->properties_nulstr = buf_nulstr;
- buf_nulstr = NULL;
- device->properties_nulstr_len = nulstr_len;
- free(device->properties_strv);
- device->properties_strv = buf_strv;
- buf_strv = NULL;
-
- device->properties_buf_outdated = false;
-
- return 0;
-}
-
-int device_get_properties_nulstr(sd_device *device, const uint8_t **nulstr, size_t *len) {
- int r;
-
- assert(device);
- assert(nulstr);
- assert(len);
-
- r = device_update_properties_bufs(device);
- if (r < 0)
- return r;
-
- *nulstr = device->properties_nulstr;
- *len = device->properties_nulstr_len;
-
- return 0;
-}
-
-int device_get_properties_strv(sd_device *device, char ***strv) {
- int r;
-
- assert(device);
- assert(strv);
-
- r = device_update_properties_bufs(device);
- if (r < 0)
- return r;
-
- *strv = device->properties_strv;
-
- return 0;
-}
-
-int device_get_devlink_priority(sd_device *device, int *priority) {
- int r;
-
- assert(device);
- assert(priority);
-
- r = device_read_db(device);
- if (r < 0)
- return r;
-
- *priority = device->devlink_priority;
-
- return 0;
-}
-
-int device_get_watch_handle(sd_device *device, int *handle) {
- int r;
-
- assert(device);
- assert(handle);
-
- r = device_read_db(device);
- if (r < 0)
- return r;
-
- *handle = device->watch_handle;
-
- return 0;
-}
-
-void device_set_watch_handle(sd_device *device, int handle) {
- assert(device);
-
- device->watch_handle = handle;
-}
-
-int device_rename(sd_device *device, const char *name) {
- _cleanup_free_ char *dirname = NULL;
- char *new_syspath;
- const char *interface;
- int r;
-
- assert(device);
- assert(name);
-
- dirname = dirname_malloc(device->syspath);
- if (!dirname)
- return -ENOMEM;
-
- new_syspath = strjoina(dirname, "/", name);
-
- /* the user must trust that the new name is correct */
- r = device_set_syspath(device, new_syspath, false);
- if (r < 0)
- return r;
-
- r = sd_device_get_property_value(device, "INTERFACE", &interface);
- if (r >= 0) {
- r = device_add_property_internal(device, "INTERFACE", name);
- if (r < 0)
- return r;
-
- /* like DEVPATH_OLD, INTERFACE_OLD is not saved to the db, but only stays around for the current event */
- r = device_add_property_internal(device, "INTERFACE_OLD", interface);
- if (r < 0)
- return r;
- } else if (r != -ENOENT)
- return r;
-
- return 0;
-}
-
-int device_shallow_clone(sd_device *old_device, sd_device **new_device) {
- _cleanup_device_unref_ sd_device *ret = NULL;
- int r;
-
- assert(old_device);
- assert(new_device);
-
- r = device_new_aux(&ret);
- if (r < 0)
- return r;
-
- r = device_set_syspath(ret, old_device->syspath, false);
- if (r < 0)
- return r;
-
- r = device_set_subsystem(ret, old_device->subsystem);
- if (r < 0)
- return r;
-
- ret->devnum = old_device->devnum;
-
- *new_device = ret;
- ret = NULL;
-
- return 0;
-}
-
-int device_clone_with_db(sd_device *old_device, sd_device **new_device) {
- _cleanup_device_unref_ sd_device *ret = NULL;
- int r;
-
- assert(old_device);
- assert(new_device);
-
- r = device_shallow_clone(old_device, &ret);
- if (r < 0)
- return r;
-
- r = device_read_db(ret);
- if (r < 0)
- return r;
-
- ret->sealed = true;
-
- *new_device = ret;
- ret = NULL;
-
- return 0;
-}
-
-int device_new_from_synthetic_event(sd_device **new_device, const char *syspath, const char *action) {
- _cleanup_device_unref_ sd_device *ret = NULL;
- int r;
-
- assert(new_device);
- assert(syspath);
- assert(action);
-
- r = sd_device_new_from_syspath(&ret, syspath);
- if (r < 0)
- return r;
-
- r = device_read_uevent_file(ret);
- if (r < 0)
- return r;
-
- r = device_add_property_internal(ret, "ACTION", action);
- if (r < 0)
- return r;
-
- *new_device = ret;
- ret = NULL;
-
- return 0;
-}
-
-int device_copy_properties(sd_device *device_dst, sd_device *device_src) {
- const char *property, *value;
- int r;
-
- assert(device_dst);
- assert(device_src);
-
- FOREACH_DEVICE_PROPERTY(device_src, property, value) {
- r = device_add_property(device_dst, property, value);
- if (r < 0)
- return r;
- }
-
- return 0;
-}
-
-void device_cleanup_tags(sd_device *device) {
- assert(device);
-
- set_free_free(device->tags);
- device->tags = NULL;
- device->property_tags_outdated = true;
- device->tags_generation ++;
-}
-
-void device_cleanup_devlinks(sd_device *device) {
- assert(device);
-
- set_free_free(device->devlinks);
- device->devlinks = NULL;
- device->property_devlinks_outdated = true;
- device->devlinks_generation ++;
-}
-
-void device_remove_tag(sd_device *device, const char *tag) {
- assert(device);
- assert(tag);
-
- free(set_remove(device->tags, tag));
- device->property_tags_outdated = true;
- device->tags_generation ++;
-}
-
-static int device_tag(sd_device *device, const char *tag, bool add) {
- const char *id;
- char *path;
- int r;
-
- assert(device);
- assert(tag);
-
- r = device_get_id_filename(device, &id);
- if (r < 0)
- return r;
-
- path = strjoina("/run/udev/tags/", tag, "/", id);
-
- if (add) {
- r = touch_file(path, true, USEC_INFINITY, UID_INVALID, GID_INVALID, 0444);
- if (r < 0)
- return r;
- } else {
- r = unlink(path);
- if (r < 0 && errno != ENOENT)
- return -errno;
- }
-
- return 0;
-}
-
-int device_tag_index(sd_device *device, sd_device *device_old, bool add) {
- const char *tag;
- int r = 0, k;
-
- if (add && device_old) {
- /* delete possible left-over tags */
- FOREACH_DEVICE_TAG(device_old, tag) {
- if (!sd_device_has_tag(device, tag)) {
- k = device_tag(device_old, tag, false);
- if (r >= 0 && k < 0)
- r = k;
- }
- }
- }
-
- FOREACH_DEVICE_TAG(device, tag) {
- k = device_tag(device, tag, add);
- if (r >= 0 && k < 0)
- r = k;
- }
-
- return r;
-}
-
-static bool device_has_info(sd_device *device) {
- assert(device);
-
- if (!set_isempty(device->devlinks))
- return true;
-
- if (device->devlink_priority != 0)
- return true;
-
- if (!ordered_hashmap_isempty(device->properties_db))
- return true;
-
- if (!set_isempty(device->tags))
- return true;
-
- if (device->watch_handle >= 0)
- return true;
-
- return false;
-}
-
-void device_set_db_persist(sd_device *device) {
- assert(device);
-
- device->db_persist = true;
-}
-
-int device_update_db(sd_device *device) {
- const char *id;
- char *path;
- _cleanup_fclose_ FILE *f = NULL;
- _cleanup_free_ char *path_tmp = NULL;
- bool has_info;
- int r;
-
- assert(device);
-
- has_info = device_has_info(device);
-
- r = device_get_id_filename(device, &id);
- if (r < 0)
- return r;
-
- path = strjoina("/run/udev/data/", id);
-
- /* do not store anything for otherwise empty devices */
- if (!has_info && major(device->devnum) == 0 && device->ifindex == 0) {
- r = unlink(path);
- if (r < 0 && errno != ENOENT)
- return -errno;
-
- return 0;
- }
-
- /* write a database file */
- r = mkdir_parents(path, 0755);
- if (r < 0)
- return r;
-
- r = fopen_temporary(path, &f, &path_tmp);
- if (r < 0)
- return r;
-
- /*
- * set 'sticky' bit to indicate that we should not clean the
- * database when we transition from initramfs to the real root
- */
- if (device->db_persist) {
- r = fchmod(fileno(f), 01644);
- if (r < 0) {
- r = -errno;
- goto fail;
- }
- } else {
- r = fchmod(fileno(f), 0644);
- if (r < 0) {
- r = -errno;
- goto fail;
- }
- }
-
- if (has_info) {
- const char *property, *value, *tag;
- Iterator i;
-
- if (major(device->devnum) > 0) {
- const char *devlink;
-
- FOREACH_DEVICE_DEVLINK(device, devlink)
- fprintf(f, "S:%s\n", devlink + strlen("/dev/"));
-
- if (device->devlink_priority != 0)
- fprintf(f, "L:%i\n", device->devlink_priority);
-
- if (device->watch_handle >= 0)
- fprintf(f, "W:%i\n", device->watch_handle);
- }
-
- if (device->usec_initialized > 0)
- fprintf(f, "I:"USEC_FMT"\n", device->usec_initialized);
-
- ORDERED_HASHMAP_FOREACH_KEY(value, property, device->properties_db, i)
- fprintf(f, "E:%s=%s\n", property, value);
-
- FOREACH_DEVICE_TAG(device, tag)
- fprintf(f, "G:%s\n", tag);
- }
-
- r = fflush_and_check(f);
- if (r < 0)
- goto fail;
-
- r = rename(path_tmp, path);
- if (r < 0) {
- r = -errno;
- goto fail;
- }
-
- log_debug("created %s file '%s' for '%s'", has_info ? "db" : "empty",
- path, device->devpath);
-
- return 0;
-
-fail:
- log_error_errno(r, "failed to create %s file '%s' for '%s'", has_info ? "db" : "empty",
- path, device->devpath);
- unlink(path);
- unlink(path_tmp);
-
- return r;
-}
-
-int device_delete_db(sd_device *device) {
- const char *id;
- char *path;
- int r;
-
- assert(device);
-
- r = device_get_id_filename(device, &id);
- if (r < 0)
- return r;
-
- path = strjoina("/run/udev/data/", id);
-
- r = unlink(path);
- if (r < 0 && errno != ENOENT)
- return -errno;
-
- return 0;
-}
-
-int device_read_db_force(sd_device *device) {
- assert(device);
-
- return device_read_db_aux(device, true);
-}
diff --git a/src/libelogind/sd-device/device-private.h b/src/libelogind/sd-device/device-private.h
deleted file mode 100644
index 49a7b66a2..000000000
--- a/src/libelogind/sd-device/device-private.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-#pragma once
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Tom Gundersen <teg@jklm.no>
-
- 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/>.
-***/
-
-int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len);
-int device_new_from_strv(sd_device **ret, char **strv);
-
-int device_get_id_filename(sd_device *device, const char **ret);
-
-int device_get_devlink_priority(sd_device *device, int *priority);
-int device_get_watch_handle(sd_device *device, int *handle);
-int device_get_devnode_mode(sd_device *device, mode_t *mode);
-int device_get_devnode_uid(sd_device *device, uid_t *uid);
-int device_get_devnode_gid(sd_device *device, gid_t *gid);
-
-void device_seal(sd_device *device);
-void device_set_is_initialized(sd_device *device);
-void device_set_watch_handle(sd_device *device, int fd);
-void device_set_db_persist(sd_device *device);
-void device_set_devlink_priority(sd_device *device, int priority);
-int device_ensure_usec_initialized(sd_device *device, sd_device *device_old);
-int device_add_devlink(sd_device *device, const char *devlink);
-int device_add_property(sd_device *device, const char *property, const char *value);
-int device_add_tag(sd_device *device, const char *tag);
-void device_remove_tag(sd_device *device, const char *tag);
-void device_cleanup_tags(sd_device *device);
-void device_cleanup_devlinks(sd_device *device);
-
-uint64_t device_get_properties_generation(sd_device *device);
-uint64_t device_get_tags_generation(sd_device *device);
-uint64_t device_get_devlinks_generation(sd_device *device);
-
-int device_get_properties_nulstr(sd_device *device, const uint8_t **nulstr, size_t *len);
-int device_get_properties_strv(sd_device *device, char ***strv);
-
-int device_rename(sd_device *device, const char *name);
-int device_shallow_clone(sd_device *old_device, sd_device **new_device);
-int device_clone_with_db(sd_device *old_device, sd_device **new_device);
-int device_copy_properties(sd_device *device_dst, sd_device *device_src);
-int device_new_from_synthetic_event(sd_device **new_device, const char *syspath, const char *action);
-
-int device_tag_index(sd_device *dev, sd_device *dev_old, bool add);
-int device_update_db(sd_device *device);
-int device_delete_db(sd_device *device);
-int device_read_db_force(sd_device *device);
diff --git a/src/libelogind/sd-device/device-util.h b/src/libelogind/sd-device/device-util.h
deleted file mode 100644
index 9b05a2498..000000000
--- a/src/libelogind/sd-device/device-util.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-#pragma once
-
-/***
- This file is part of systemd.
-
- Copyright 2014-2015 Tom Gundersen <teg@jklm.no>
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-#include "util.h"
-
-DEFINE_TRIVIAL_CLEANUP_FUNC(sd_device*, sd_device_unref);
-#define _cleanup_device_unref_ _cleanup_(sd_device_unrefp)
-
-DEFINE_TRIVIAL_CLEANUP_FUNC(sd_device_enumerator*, sd_device_enumerator_unref);
-#define _cleanup_device_enumerator_unref_ _cleanup_(sd_device_enumerator_unrefp)
-
-#define FOREACH_DEVICE_PROPERTY(device, key, value) \
- for (key = sd_device_get_property_first(device, &(value)); \
- key; \
- key = sd_device_get_property_next(device, &(value)))
-
-#define FOREACH_DEVICE_TAG(device, tag) \
- for (tag = sd_device_get_tag_first(device); \
- tag; \
- tag = sd_device_get_tag_next(device))
-
-#define FOREACH_DEVICE_SYSATTR(device, attr) \
- for (attr = sd_device_get_sysattr_first(device); \
- attr; \
- attr = sd_device_get_sysattr_next(device))
-
-#define FOREACH_DEVICE_DEVLINK(device, devlink) \
- for (devlink = sd_device_get_devlink_first(device); \
- devlink; \
- devlink = sd_device_get_devlink_next(device))
-
-#define FOREACH_DEVICE(enumerator, device) \
- for (device = sd_device_enumerator_get_device_first(enumerator); \
- device; \
- device = sd_device_enumerator_get_device_next(enumerator))
-
-#define FOREACH_SUBSYSTEM(enumerator, device) \
- for (device = sd_device_enumerator_get_subsystem_first(enumerator); \
- device; \
- device = sd_device_enumerator_get_subsystem_next(enumerator))
diff --git a/src/libelogind/sd-event/sd-event.c b/src/libelogind/sd-event/sd-event.c
index 76964aa0c..629f78032 100644
--- a/src/libelogind/sd-event/sd-event.c
+++ b/src/libelogind/sd-event/sd-event.c
@@ -517,6 +517,8 @@ static int source_io_register(
return 0;
}
+/// UNNEEDED by elogind
+#if 0
static clockid_t event_source_type_to_clock(EventSourceType t) {
switch (t) {
@@ -540,6 +542,7 @@ static clockid_t event_source_type_to_clock(EventSourceType t) {
return (clockid_t) -1;
}
}
+#endif // 0
static EventSourceType clock_to_event_source_type(clockid_t clock) {
@@ -1229,6 +1232,8 @@ _public_ int sd_event_add_exit(
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ sd_event_source* sd_event_source_ref(sd_event_source *s) {
assert_return(s, NULL);
@@ -1237,6 +1242,7 @@ _public_ sd_event_source* sd_event_source_ref(sd_event_source *s) {
return s;
}
+#endif // 0
_public_ sd_event_source* sd_event_source_unref(sd_event_source *s) {
@@ -1274,6 +1280,8 @@ _public_ int sd_event_source_set_description(sd_event_source *s, const char *des
return free_and_strdup(&s->description, description);
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_event_source_get_description(sd_event_source *s, const char **description) {
assert_return(s, -EINVAL);
assert_return(description, -EINVAL);
@@ -1283,6 +1291,7 @@ _public_ int sd_event_source_get_description(sd_event_source *s, const char **de
*description = s->description;
return 0;
}
+#endif // 0
_public_ sd_event *sd_event_source_get_event(sd_event_source *s) {
assert_return(s, NULL);
@@ -1290,6 +1299,8 @@ _public_ sd_event *sd_event_source_get_event(sd_event_source *s) {
return s->event;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_event_source_get_pending(sd_event_source *s) {
assert_return(s, -EINVAL);
assert_return(s->type != SOURCE_EXIT, -EDOM);
@@ -1306,6 +1317,7 @@ _public_ int sd_event_source_get_io_fd(sd_event_source *s) {
return s->io.fd;
}
+#endif // 0
_public_ int sd_event_source_set_io_fd(sd_event_source *s, int fd) {
int r;
@@ -1343,6 +1355,8 @@ _public_ int sd_event_source_set_io_fd(sd_event_source *s, int fd) {
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_event_source_get_io_events(sd_event_source *s, uint32_t* events) {
assert_return(s, -EINVAL);
assert_return(events, -EINVAL);
@@ -1352,6 +1366,7 @@ _public_ int sd_event_source_get_io_events(sd_event_source *s, uint32_t* events)
*events = s->io.events;
return 0;
}
+#endif // 0
_public_ int sd_event_source_set_io_events(sd_event_source *s, uint32_t events) {
int r;
@@ -1378,6 +1393,8 @@ _public_ int sd_event_source_set_io_events(sd_event_source *s, uint32_t events)
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_event_source_get_io_revents(sd_event_source *s, uint32_t* revents) {
assert_return(s, -EINVAL);
assert_return(revents, -EINVAL);
@@ -1403,6 +1420,7 @@ _public_ int sd_event_source_get_priority(sd_event_source *s, int64_t *priority)
return s->priority;
}
+#endif // 0
_public_ int sd_event_source_set_priority(sd_event_source *s, int64_t priority) {
assert_return(s, -EINVAL);
@@ -1426,6 +1444,8 @@ _public_ int sd_event_source_set_priority(sd_event_source *s, int64_t priority)
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_event_source_get_enabled(sd_event_source *s, int *m) {
assert_return(s, -EINVAL);
assert_return(m, -EINVAL);
@@ -1434,6 +1454,7 @@ _public_ int sd_event_source_get_enabled(sd_event_source *s, int *m) {
*m = s->enabled;
return 0;
}
+#endif // 0
_public_ int sd_event_source_set_enabled(sd_event_source *s, int m) {
int r;
@@ -1640,6 +1661,8 @@ _public_ int sd_event_source_set_time(sd_event_source *s, uint64_t usec) {
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_event_source_get_time_accuracy(sd_event_source *s, uint64_t *usec) {
assert_return(s, -EINVAL);
assert_return(usec, -EINVAL);
@@ -1694,6 +1717,7 @@ _public_ int sd_event_source_get_child_pid(sd_event_source *s, pid_t *pid) {
*pid = s->child.pid;
return 0;
}
+#endif // 0
_public_ int sd_event_source_set_prepare(sd_event_source *s, sd_event_handler_t callback) {
int r;
@@ -1727,6 +1751,8 @@ _public_ int sd_event_source_set_prepare(sd_event_source *s, sd_event_handler_t
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ void* sd_event_source_get_userdata(sd_event_source *s) {
assert_return(s, NULL);
@@ -1743,6 +1769,7 @@ _public_ void *sd_event_source_set_userdata(sd_event_source *s, void *userdata)
return ret;
}
+#endif // 0
static usec_t sleep_between(sd_event *e, usec_t a, usec_t b) {
usec_t c;
@@ -2507,6 +2534,8 @@ _public_ int sd_event_run(sd_event *e, uint64_t timeout) {
return r;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_event_loop(sd_event *e) {
int r;
@@ -2536,6 +2565,7 @@ _public_ int sd_event_get_fd(sd_event *e) {
return e->epoll_fd;
}
+#endif // 0
_public_ int sd_event_get_state(sd_event *e) {
assert_return(e, -EINVAL);
@@ -2567,6 +2597,8 @@ _public_ int sd_event_exit(sd_event *e, int code) {
return 0;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_event_now(sd_event *e, clockid_t clock, uint64_t *usec) {
assert_return(e, -EINVAL);
assert_return(usec, -EINVAL);
@@ -2595,6 +2627,7 @@ _public_ int sd_event_now(sd_event *e, clockid_t clock, uint64_t *usec) {
return 0;
}
+#endif // 0
_public_ int sd_event_default(sd_event **ret) {
@@ -2687,9 +2720,12 @@ fail:
return r;
}
+/// UNNEEDED by elogind
+#if 0
_public_ int sd_event_get_watchdog(sd_event *e) {
assert_return(e, -EINVAL);
assert_return(!event_pid_changed(e), -ECHILD);
return e->watchdog;
}
+#endif // 0
diff --git a/src/libelogind/sd-hwdb/hwdb-internal.h b/src/libelogind/sd-hwdb/hwdb-internal.h
deleted file mode 100644
index fedccdec7..000000000
--- a/src/libelogind/sd-hwdb/hwdb-internal.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/***
- This file is part of systemd.
-
- Copyright 2012 Kay Sievers <kay@vrfy.org>
-
- 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/>.
-***/
-#pragma once
-
-#include "sparse-endian.h"
-
-#define HWDB_SIG { 'K', 'S', 'L', 'P', 'H', 'H', 'R', 'H' }
-
-/* on-disk trie objects */
-struct trie_header_f {
- uint8_t signature[8];
-
- /* version of tool which created the file */
- le64_t tool_version;
- le64_t file_size;
-
- /* size of structures to allow them to grow */
- le64_t header_size;
- le64_t node_size;
- le64_t child_entry_size;
- le64_t value_entry_size;
-
- /* offset of the root trie node */
- le64_t nodes_root_off;
-
- /* size of the nodes and string section */
- le64_t nodes_len;
- le64_t strings_len;
-} _packed_;
-
-struct trie_node_f {
- /* prefix of lookup string, shared by all children */
- le64_t prefix_off;
- /* size of children entry array appended to the node */
- uint8_t children_count;
- uint8_t padding[7];
- /* size of value entry array appended to the node */
- le64_t values_count;
-} _packed_;
-
-/* array of child entries, follows directly the node record */
-struct trie_child_entry_f {
- /* index of the child node */
- uint8_t c;
- uint8_t padding[7];
- /* offset of the child node */
- le64_t child_off;
-} _packed_;
-
-/* array of value entries, follows directly the node record/child array */
-struct trie_value_entry_f {
- le64_t key_off;
- le64_t value_off;
-} _packed_;
diff --git a/src/libelogind/sd-hwdb/sd-hwdb.c b/src/libelogind/sd-hwdb/sd-hwdb.c
deleted file mode 100644
index 40aa77ee5..000000000
--- a/src/libelogind/sd-hwdb/sd-hwdb.c
+++ /dev/null
@@ -1,470 +0,0 @@
-/***
- This file is part of systemd.
-
- Copyright 2012 Kay Sievers <kay@vrfy.org>
- Copyright 2008 Alan Jenkins <alan.christopher.jenkins@googlemail.com>
- Copyright 2014 Tom Gundersen <teg@jklm.no>
-
- 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 <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <inttypes.h>
-#include <stdlib.h>
-#include <fnmatch.h>
-#include <sys/mman.h>
-
-#include "sd-hwdb.h"
-
-#include "hashmap.h"
-#include "refcnt.h"
-
-#include "hwdb-util.h"
-#include "hwdb-internal.h"
-
-struct sd_hwdb {
- RefCount n_ref;
- int refcount;
-
- FILE *f;
- struct stat st;
- union {
- struct trie_header_f *head;
- const char *map;
- };
-
- char *modalias;
-
- OrderedHashmap *properties;
- Iterator properties_iterator;
- bool properties_modified;
-};
-
-struct linebuf {
- char bytes[LINE_MAX];
- size_t size;
- size_t len;
-};
-
-static void linebuf_init(struct linebuf *buf) {
- buf->size = 0;
- buf->len = 0;
-}
-
-static const char *linebuf_get(struct linebuf *buf) {
- if (buf->len + 1 >= sizeof(buf->bytes))
- return NULL;
- buf->bytes[buf->len] = '\0';
- return buf->bytes;
-}
-
-static bool linebuf_add(struct linebuf *buf, const char *s, size_t len) {
- if (buf->len + len >= sizeof(buf->bytes))
- return false;
- memcpy(buf->bytes + buf->len, s, len);
- buf->len += len;
- return true;
-}
-
-static bool linebuf_add_char(struct linebuf *buf, char c)
-{
- if (buf->len + 1 >= sizeof(buf->bytes))
- return false;
- buf->bytes[buf->len++] = c;
- return true;
-}
-
-static void linebuf_rem(struct linebuf *buf, size_t count) {
- assert(buf->len >= count);
- buf->len -= count;
-}
-
-static void linebuf_rem_char(struct linebuf *buf) {
- linebuf_rem(buf, 1);
-}
-
-static const struct trie_child_entry_f *trie_node_children(sd_hwdb *hwdb, const struct trie_node_f *node) {
- return (const struct trie_child_entry_f *)((const char *)node + le64toh(hwdb->head->node_size));
-}
-
-static const struct trie_value_entry_f *trie_node_values(sd_hwdb *hwdb, const struct trie_node_f *node) {
- const char *base = (const char *)node;
-
- base += le64toh(hwdb->head->node_size);
- base += node->children_count * le64toh(hwdb->head->child_entry_size);
- return (const struct trie_value_entry_f *)base;
-}
-
-static const struct trie_node_f *trie_node_from_off(sd_hwdb *hwdb, le64_t off) {
- return (const struct trie_node_f *)(hwdb->map + le64toh(off));
-}
-
-static const char *trie_string(sd_hwdb *hwdb, le64_t off) {
- return hwdb->map + le64toh(off);
-}
-
-static int trie_children_cmp_f(const void *v1, const void *v2) {
- const struct trie_child_entry_f *n1 = v1;
- const struct trie_child_entry_f *n2 = v2;
-
- return n1->c - n2->c;
-}
-
-static const struct trie_node_f *node_lookup_f(sd_hwdb *hwdb, const struct trie_node_f *node, uint8_t c) {
- struct trie_child_entry_f *child;
- struct trie_child_entry_f search;
-
- search.c = c;
- child = bsearch(&search, trie_node_children(hwdb, node), node->children_count,
- le64toh(hwdb->head->child_entry_size), trie_children_cmp_f);
- if (child)
- return trie_node_from_off(hwdb, child->child_off);
- return NULL;
-}
-
-static int hwdb_add_property(sd_hwdb *hwdb, const char *key, const char *value) {
- int r;
-
- assert(hwdb);
- assert(key);
- assert(value);
-
- /*
- * Silently ignore all properties which do not start with a
- * space; future extensions might use additional prefixes.
- */
- if (key[0] != ' ')
- return 0;
-
- key++;
-
- r = ordered_hashmap_ensure_allocated(&hwdb->properties, &string_hash_ops);
- if (r < 0)
- return r;
-
- r = ordered_hashmap_replace(hwdb->properties, key, (char*)value);
- if (r < 0)
- return r;
-
- hwdb->properties_modified = true;
-
- return 0;
-}
-
-static int trie_fnmatch_f(sd_hwdb *hwdb, const struct trie_node_f *node, size_t p,
- struct linebuf *buf, const char *search) {
- size_t len;
- size_t i;
- const char *prefix;
- int err;
-
- prefix = trie_string(hwdb, node->prefix_off);
- len = strlen(prefix + p);
- linebuf_add(buf, prefix + p, len);
-
- for (i = 0; i < node->children_count; i++) {
- const struct trie_child_entry_f *child = &trie_node_children(hwdb, node)[i];
-
- linebuf_add_char(buf, child->c);
- err = trie_fnmatch_f(hwdb, trie_node_from_off(hwdb, child->child_off), 0, buf, search);
- if (err < 0)
- return err;
- linebuf_rem_char(buf);
- }
-
- if (le64toh(node->values_count) && fnmatch(linebuf_get(buf), search, 0) == 0)
- for (i = 0; i < le64toh(node->values_count); i++) {
- err = hwdb_add_property(hwdb, trie_string(hwdb, trie_node_values(hwdb, node)[i].key_off),
- trie_string(hwdb, trie_node_values(hwdb, node)[i].value_off));
- if (err < 0)
- return err;
- }
-
- linebuf_rem(buf, len);
- return 0;
-}
-
-static int trie_search_f(sd_hwdb *hwdb, const char *search) {
- struct linebuf buf;
- const struct trie_node_f *node;
- size_t i = 0;
- int err;
-
- linebuf_init(&buf);
-
- node = trie_node_from_off(hwdb, hwdb->head->nodes_root_off);
- while (node) {
- const struct trie_node_f *child;
- size_t p = 0;
-
- if (node->prefix_off) {
- uint8_t c;
-
- for (; (c = trie_string(hwdb, node->prefix_off)[p]); p++) {
- if (c == '*' || c == '?' || c == '[')
- return trie_fnmatch_f(hwdb, node, p, &buf, search + i + p);
- if (c != search[i + p])
- return 0;
- }
- i += p;
- }
-
- child = node_lookup_f(hwdb, node, '*');
- if (child) {
- linebuf_add_char(&buf, '*');
- err = trie_fnmatch_f(hwdb, child, 0, &buf, search + i);
- if (err < 0)
- return err;
- linebuf_rem_char(&buf);
- }
-
- child = node_lookup_f(hwdb, node, '?');
- if (child) {
- linebuf_add_char(&buf, '?');
- err = trie_fnmatch_f(hwdb, child, 0, &buf, search + i);
- if (err < 0)
- return err;
- linebuf_rem_char(&buf);
- }
-
- child = node_lookup_f(hwdb, node, '[');
- if (child) {
- linebuf_add_char(&buf, '[');
- err = trie_fnmatch_f(hwdb, child, 0, &buf, search + i);
- if (err < 0)
- return err;
- linebuf_rem_char(&buf);
- }
-
- if (search[i] == '\0') {
- size_t n;
-
- for (n = 0; n < le64toh(node->values_count); n++) {
- err = hwdb_add_property(hwdb, trie_string(hwdb, trie_node_values(hwdb, node)[n].key_off),
- trie_string(hwdb, trie_node_values(hwdb, node)[n].value_off));
- if (err < 0)
- return err;
- }
- return 0;
- }
-
- child = node_lookup_f(hwdb, node, search[i]);
- node = child;
- i++;
- }
- return 0;
-}
-
-static const char hwdb_bin_paths[] =
- "/etc/systemd/hwdb/hwdb.bin\0"
- "/etc/udev/hwdb.bin\0"
- "/usr/lib/systemd/hwdb/hwdb.bin\0"
-#ifdef HAVE_SPLIT_USR
- "/lib/systemd/hwdb/hwdb.bin\0"
-#endif
- UDEVLIBEXECDIR "/hwdb.bin\0";
-
-_public_ int sd_hwdb_new(sd_hwdb **ret) {
- _cleanup_hwdb_unref_ sd_hwdb *hwdb = NULL;
- const char *hwdb_bin_path;
- const char sig[] = HWDB_SIG;
-
- assert_return(ret, -EINVAL);
-
- hwdb = new0(sd_hwdb, 1);
- if (!hwdb)
- return -ENOMEM;
-
- hwdb->n_ref = REFCNT_INIT;
-
- /* find hwdb.bin in hwdb_bin_paths */
- NULSTR_FOREACH(hwdb_bin_path, hwdb_bin_paths) {
- hwdb->f = fopen(hwdb_bin_path, "re");
- if (hwdb->f)
- break;
- else if (errno == ENOENT)
- continue;
- else
- return log_debug_errno(errno, "error reading %s: %m", hwdb_bin_path);
- }
-
- if (!hwdb->f) {
- log_debug("hwdb.bin does not exist, please run udevadm hwdb --update");
- return -ENOENT;
- }
-
- if (fstat(fileno(hwdb->f), &hwdb->st) < 0 ||
- (size_t)hwdb->st.st_size < offsetof(struct trie_header_f, strings_len) + 8)
- return log_debug_errno(errno, "error reading %s: %m", hwdb_bin_path);
-
- hwdb->map = mmap(0, hwdb->st.st_size, PROT_READ, MAP_SHARED, fileno(hwdb->f), 0);
- if (hwdb->map == MAP_FAILED)
- return log_debug_errno(errno, "error mapping %s: %m", hwdb_bin_path);
-
- if (memcmp(hwdb->map, sig, sizeof(hwdb->head->signature)) != 0 ||
- (size_t)hwdb->st.st_size != le64toh(hwdb->head->file_size)) {
- log_debug("error recognizing the format of %s", hwdb_bin_path);
- return -EINVAL;
- }
-
- log_debug("=== trie on-disk ===");
- log_debug("tool version: %"PRIu64, le64toh(hwdb->head->tool_version));
- log_debug("file size: %8"PRIi64" bytes", hwdb->st.st_size);
- log_debug("header size %8"PRIu64" bytes", le64toh(hwdb->head->header_size));
- log_debug("strings %8"PRIu64" bytes", le64toh(hwdb->head->strings_len));
- log_debug("nodes %8"PRIu64" bytes", le64toh(hwdb->head->nodes_len));
-
- *ret = hwdb;
- hwdb = NULL;
-
- return 0;
-}
-
-_public_ sd_hwdb *sd_hwdb_ref(sd_hwdb *hwdb) {
- assert_return(hwdb, NULL);
-
- assert_se(REFCNT_INC(hwdb->n_ref) >= 2);
-
- return hwdb;
-}
-
-_public_ sd_hwdb *sd_hwdb_unref(sd_hwdb *hwdb) {
- if (hwdb && REFCNT_DEC(hwdb->n_ref) == 0) {
- if (hwdb->map)
- munmap((void *)hwdb->map, hwdb->st.st_size);
- if (hwdb->f)
- fclose(hwdb->f);
- free(hwdb->modalias);
- ordered_hashmap_free(hwdb->properties);
- free(hwdb);
- }
-
- return NULL;
-}
-
-bool hwdb_validate(sd_hwdb *hwdb) {
- bool found = false;
- const char* p;
- struct stat st;
-
- if (!hwdb)
- return false;
- if (!hwdb->f)
- return false;
-
- /* if hwdb.bin doesn't exist anywhere, we need to update */
- NULSTR_FOREACH(p, hwdb_bin_paths) {
- if (stat(p, &st) >= 0) {
- found = true;
- break;
- }
- }
- if (!found)
- return true;
-
- if (timespec_load(&hwdb->st.st_mtim) != timespec_load(&st.st_mtim))
- return true;
- return false;
-}
-
-static int properties_prepare(sd_hwdb *hwdb, const char *modalias) {
- _cleanup_free_ char *mod = NULL;
- int r;
-
- assert(hwdb);
- assert(modalias);
-
- if (streq_ptr(modalias, hwdb->modalias))
- return 0;
-
- mod = strdup(modalias);
- if (!mod)
- return -ENOMEM;
-
- ordered_hashmap_clear(hwdb->properties);
-
- hwdb->properties_modified = true;
-
- r = trie_search_f(hwdb, modalias);
- if (r < 0)
- return r;
-
- free(hwdb->modalias);
- hwdb->modalias = mod;
- mod = NULL;
-
- return 0;
-}
-
-_public_ int sd_hwdb_get(sd_hwdb *hwdb, const char *modalias, const char *key, const char **_value) {
- const char *value;
- int r;
-
- assert_return(hwdb, -EINVAL);
- assert_return(hwdb->f, -EINVAL);
- assert_return(modalias, -EINVAL);
- assert_return(_value, -EINVAL);
-
- r = properties_prepare(hwdb, modalias);
- if (r < 0)
- return r;
-
- value = ordered_hashmap_get(hwdb->properties, key);
- if (!value)
- return -ENOENT;
-
- *_value = value;
-
- return 0;
-}
-
-_public_ int sd_hwdb_seek(sd_hwdb *hwdb, const char *modalias) {
- int r;
-
- assert_return(hwdb, -EINVAL);
- assert_return(hwdb->f, -EINVAL);
- assert_return(modalias, -EINVAL);
-
- r = properties_prepare(hwdb, modalias);
- if (r < 0)
- return r;
-
- hwdb->properties_modified = false;
- hwdb->properties_iterator = ITERATOR_FIRST;
-
- return 0;
-}
-
-_public_ int sd_hwdb_enumerate(sd_hwdb *hwdb, const char **key, const char **value) {
- const void *k;
- void *v;
-
- assert_return(hwdb, -EINVAL);
- assert_return(key, -EINVAL);
- assert_return(value, -EINVAL);
-
- if (hwdb->properties_modified)
- return -EAGAIN;
-
- ordered_hashmap_iterate(hwdb->properties, &hwdb->properties_iterator, &v, &k);
- if (!k)
- return 0;
-
- *key = k;
- *value = v;
-
- return 1;
-}
diff --git a/src/libelogind/sd-hwdb/Makefile b/src/libelogind/sd-netlink/Makefile
index 94aaae2c4..94aaae2c4 120000
--- a/src/libelogind/sd-hwdb/Makefile
+++ b/src/libelogind/sd-netlink/Makefile
diff --git a/src/libelogind/sd-rtnl/rtnl-types.h b/src/libelogind/sd-netlink/netlink-types.h
index de1544bf3..bf7c64154 100644
--- a/src/libelogind/sd-rtnl/rtnl-types.h
+++ b/src/libelogind/sd-netlink/netlink-types.h
@@ -22,18 +22,18 @@
***/
enum {
- NLA_UNSPEC,
- NLA_META,
- NLA_U8,
- NLA_U16,
- NLA_U32,
- NLA_U64,
- NLA_STRING,
- NLA_IN_ADDR,
- NLA_ETHER_ADDR,
- NLA_CACHE_INFO,
- NLA_NESTED,
- NLA_UNION,
+ NETLINK_TYPE_UNSPEC,
+ NETLINK_TYPE_U8, /* NLA_U8 */
+ NETLINK_TYPE_U16, /* NLA_U16 */
+ NETLINK_TYPE_U32, /* NLA_U32 */
+ NETLINK_TYPE_U64, /* NLA_U64 */
+ NETLINK_TYPE_STRING, /* NLA_STRING */
+ NETLINK_TYPE_FLAG, /* NLA_FLAG */
+ NETLINK_TYPE_IN_ADDR,
+ NETLINK_TYPE_ETHER_ADDR,
+ NETLINK_TYPE_CACHE_INFO,
+ NETLINK_TYPE_NESTED, /* NLA_NESTED */
+ NETLINK_TYPE_UNION,
};
typedef enum NLMatchType {
@@ -53,18 +53,14 @@ struct NLTypeSystemUnion {
const NLTypeSystem *type_systems;
};
-struct NLTypeSystem {
- uint16_t max;
- const NLType *types;
-};
+extern const NLTypeSystem type_system_root;
-struct NLType {
- uint16_t type;
- size_t size;
- const NLTypeSystem *type_system;
- const NLTypeSystemUnion *type_system_union;
-};
+uint16_t type_get_type(const NLType *type);
+size_t type_get_size(const NLType *type);
+void type_get_type_system(const NLType *type, const NLTypeSystem **ret);
+void type_get_type_system_union(const NLType *type, const NLTypeSystemUnion **ret);
+uint16_t type_system_get_count(const NLTypeSystem *type_system);
int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, uint16_t type);
int type_system_get_type_system(const NLTypeSystem *type_system, const NLTypeSystem **ret, uint16_t type);
int type_system_get_type_system_union(const NLTypeSystem *type_system, const NLTypeSystemUnion **ret, uint16_t type);
@@ -78,6 +74,7 @@ typedef enum NLUnionLinkInfoData {
NL_UNION_LINK_INFO_DATA_VETH,
NL_UNION_LINK_INFO_DATA_DUMMY,
NL_UNION_LINK_INFO_DATA_MACVLAN,
+ NL_UNION_LINK_INFO_DATA_MACVTAP,
NL_UNION_LINK_INFO_DATA_IPVLAN,
NL_UNION_LINK_INFO_DATA_VXLAN,
NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL,
@@ -95,25 +92,3 @@ typedef enum NLUnionLinkInfoData {
const char *nl_union_link_info_data_to_string(NLUnionLinkInfoData p) _const_;
NLUnionLinkInfoData nl_union_link_info_data_from_string(const char *p) _pure_;
-
-/* Maximum ARP IP target defined in kernel */
-#define BOND_MAX_ARP_TARGETS 16
-
-typedef enum BondArpTargets {
- BOND_ARP_TARGETS_0,
- BOND_ARP_TARGETS_1,
- BOND_ARP_TARGETS_2,
- BOND_ARP_TARGETS_3,
- BOND_ARP_TARGETS_4,
- BOND_ARP_TARGETS_5,
- BOND_ARP_TARGETS_6,
- BOND_ARP_TARGETS_7,
- BOND_ARP_TARGETS_8,
- BOND_ARP_TARGETS_9,
- BOND_ARP_TARGETS_10,
- BOND_ARP_TARGETS_11,
- BOND_ARP_TARGETS_12,
- BOND_ARP_TARGETS_13,
- BOND_ARP_TARGETS_14,
- BOND_ARP_TARGETS_MAX = BOND_MAX_ARP_TARGETS,
-} BondArpTargets;
diff --git a/src/libelogind/sd-network/network-util.c b/src/libelogind/sd-network/network-util.c
deleted file mode 100644
index 48958e8a9..000000000
--- a/src/libelogind/sd-network/network-util.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 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 "strv.h"
-#include "network-util.h"
-
-bool network_is_online(void) {
- _cleanup_free_ char *state = NULL;
- int r;
-
- r = sd_network_get_operational_state(&state);
- if (r < 0) /* if we don't know anything, we consider the system online */
- return true;
-
- if (STR_IN_SET(state, "routable", "degraded"))
- return true;
-
- return false;
-}
diff --git a/src/libelogind/sd-network/network-util.h b/src/libelogind/sd-network/network-util.h
deleted file mode 100644
index 11a001234..000000000
--- a/src/libelogind/sd-network/network-util.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-#pragma once
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Thomas Hindø Paabøl Andersen
-
- 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 "sd-network.h"
-
-DEFINE_TRIVIAL_CLEANUP_FUNC(sd_network_monitor*, sd_network_monitor_unref);
-#define _cleanup_network_monitor_unref_ _cleanup_(sd_network_monitor_unrefp)
-
-bool network_is_online(void);
diff --git a/src/libelogind/sd-network/sd-network.c b/src/libelogind/sd-network/sd-network.c
deleted file mode 100644
index b63fdf8fc..000000000
--- a/src/libelogind/sd-network/sd-network.c
+++ /dev/null
@@ -1,422 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2011 Lennart Poettering
- Copyright 2014 Tom Gundersen
-
- 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 <string.h>
-#include <errno.h>
-#include <sys/inotify.h>
-#include <poll.h>
-
-#include "util.h"
-#include "macro.h"
-#include "strv.h"
-#include "fileio.h"
-#include "sd-network.h"
-
-_public_ int sd_network_get_operational_state(char **state) {
- _cleanup_free_ char *s = NULL;
- int r;
-
- assert_return(state, -EINVAL);
-
- r = parse_env_file("/run/systemd/netif/state", NEWLINE, "OPER_STATE", &s, NULL);
- if (r == -ENOENT)
- return -ENODATA;
- if (r < 0)
- return r;
- if (isempty(s))
- return -ENODATA;
-
- *state = s;
- s = NULL;
-
- return 0;
-}
-
-static int network_get_strv(const char *key, char ***ret) {
- _cleanup_strv_free_ char **a = NULL;
- _cleanup_free_ char *s = NULL;
- int r;
-
- assert_return(ret, -EINVAL);
-
- r = parse_env_file("/run/systemd/netif/state", NEWLINE, key, &s, NULL);
- if (r == -ENOENT)
- return -ENODATA;
- if (r < 0)
- return r;
- if (isempty(s)) {
- *ret = NULL;
- return 0;
- }
-
- a = strv_split(s, " ");
- if (!a)
- return -ENOMEM;
-
- strv_uniq(a);
- r = strv_length(a);
-
- *ret = a;
- a = NULL;
-
- return r;
-}
-
-_public_ int sd_network_get_dns(char ***ret) {
- return network_get_strv("DNS", ret);
-}
-
-_public_ int sd_network_get_ntp(char ***ret) {
- return network_get_strv("NTP", ret);
-}
-
-_public_ int sd_network_get_domains(char ***ret) {
- return network_get_strv("DOMAINS", ret);
-}
-
-_public_ int sd_network_link_get_setup_state(int ifindex, char **state) {
- _cleanup_free_ char *s = NULL, *p = NULL;
- int r;
-
- assert_return(ifindex > 0, -EINVAL);
- assert_return(state, -EINVAL);
-
- if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
- return -ENOMEM;
-
- r = parse_env_file(p, NEWLINE, "ADMIN_STATE", &s, NULL);
- if (r == -ENOENT)
- return -ENODATA;
- if (r < 0)
- return r;
- if (isempty(s))
- return -ENODATA;
-
- *state = s;
- s = NULL;
-
- return 0;
-}
-
-_public_ int sd_network_link_get_network_file(int ifindex, char **filename) {
- _cleanup_free_ char *s = NULL, *p = NULL;
- int r;
-
- assert_return(ifindex > 0, -EINVAL);
- assert_return(filename, -EINVAL);
-
- if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
- return -ENOMEM;
-
- r = parse_env_file(p, NEWLINE, "NETWORK_FILE", &s, NULL);
- if (r == -ENOENT)
- return -ENODATA;
- if (r < 0)
- return r;
- if (isempty(s))
- return -ENODATA;
-
- *filename = s;
- s = NULL;
-
- return 0;
-}
-
-_public_ int sd_network_link_get_operational_state(int ifindex, char **state) {
- _cleanup_free_ char *s = NULL, *p = NULL;
- int r;
-
- assert_return(ifindex > 0, -EINVAL);
- assert_return(state, -EINVAL);
-
- if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
- return -ENOMEM;
-
- r = parse_env_file(p, NEWLINE, "OPER_STATE", &s, NULL);
- if (r == -ENOENT)
- return -ENODATA;
- if (r < 0)
- return r;
- if (isempty(s))
- return -ENODATA;
-
- *state = s;
- s = NULL;
-
- return 0;
-}
-
-_public_ int sd_network_link_get_llmnr(int ifindex, char **llmnr) {
- _cleanup_free_ char *s = NULL, *p = NULL;
- int r;
-
- assert_return(ifindex > 0, -EINVAL);
- assert_return(llmnr, -EINVAL);
-
- if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
- return -ENOMEM;
-
- r = parse_env_file(p, NEWLINE, "LLMNR", &s, NULL);
- if (r == -ENOENT)
- return -ENODATA;
- if (r < 0)
- return r;
- if (isempty(s))
- return -ENODATA;
-
- *llmnr = s;
- s = NULL;
-
- return 0;
-}
-
-_public_ int sd_network_link_get_lldp(int ifindex, char **lldp) {
- _cleanup_free_ char *s = NULL, *p = NULL;
- size_t size;
- int r;
-
- assert_return(ifindex > 0, -EINVAL);
- assert_return(lldp, -EINVAL);
-
- if (asprintf(&p, "/run/systemd/netif/lldp/%d", ifindex) < 0)
- return -ENOMEM;
-
- r = read_full_file(p, &s, &size);
- if (r == -ENOENT)
- return -ENODATA;
- if (r < 0)
- return r;
- if (size <= 0)
- return -ENODATA;
-
- *lldp = s;
- s = NULL;
-
- return 0;
-}
-
-
-static int network_get_link_strv(const char *key, int ifindex, char ***ret) {
- _cleanup_free_ char *p = NULL, *s = NULL;
- _cleanup_strv_free_ char **a = NULL;
- int r;
-
- assert_return(ifindex > 0, -EINVAL);
- assert_return(ret, -EINVAL);
-
- if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
- return -ENOMEM;
-
- r = parse_env_file(p, NEWLINE, key, &s, NULL);
- if (r == -ENOENT)
- return -ENODATA;
- if (r < 0)
- return r;
- if (isempty(s)) {
- *ret = NULL;
- return 0;
- }
-
- a = strv_split(s, " ");
- if (!a)
- return -ENOMEM;
-
- strv_uniq(a);
- r = strv_length(a);
-
- *ret = a;
- a = NULL;
-
- return r;
-}
-
-_public_ int sd_network_link_get_dns(int ifindex, char ***ret) {
- return network_get_link_strv("DNS", ifindex, ret);
-}
-
-_public_ int sd_network_link_get_ntp(int ifindex, char ***ret) {
- return network_get_link_strv("NTP", ifindex, ret);
-}
-
-_public_ int sd_network_link_get_domains(int ifindex, char ***ret) {
- return network_get_link_strv("DOMAINS", ifindex, ret);
-}
-
-_public_ int sd_network_link_get_carrier_bound_to(int ifindex, char ***ret) {
- return network_get_link_strv("CARRIER_BOUND_TO", ifindex, ret);
-}
-
-_public_ int sd_network_link_get_carrier_bound_by(int ifindex, char ***ret) {
- return network_get_link_strv("CARRIER_BOUND_BY", ifindex, ret);
-}
-
-_public_ int sd_network_link_get_wildcard_domain(int ifindex) {
- int r;
- _cleanup_free_ char *p = NULL, *s = NULL;
-
- assert_return(ifindex > 0, -EINVAL);
-
- if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
- return -ENOMEM;
-
- r = parse_env_file(p, NEWLINE, "WILDCARD_DOMAIN", &s, NULL);
- if (r == -ENOENT)
- return -ENODATA;
- if (r < 0)
- return r;
- if (isempty(s))
- return -ENODATA;
-
- return parse_boolean(s);
-}
-
-static inline int MONITOR_TO_FD(sd_network_monitor *m) {
- return (int) (unsigned long) m - 1;
-}
-
-static inline sd_network_monitor* FD_TO_MONITOR(int fd) {
- return (sd_network_monitor*) (unsigned long) (fd + 1);
-}
-
-static int monitor_add_inotify_watch(int fd) {
- int k;
-
- k = inotify_add_watch(fd, "/run/systemd/netif/links/", IN_MOVED_TO|IN_DELETE);
- if (k >= 0)
- return 0;
- else if (errno != ENOENT)
- return -errno;
-
- k = inotify_add_watch(fd, "/run/systemd/netif/", IN_CREATE|IN_ISDIR);
- if (k >= 0)
- return 0;
- else if (errno != ENOENT)
- return -errno;
-
- k = inotify_add_watch(fd, "/run/systemd/", IN_CREATE|IN_ISDIR);
- if (k < 0)
- return -errno;
-
- return 0;
-}
-
-_public_ int sd_network_monitor_new(sd_network_monitor **m, const char *category) {
- _cleanup_close_ int fd = -1;
- int k;
- bool good = false;
-
- assert_return(m, -EINVAL);
-
- fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
- if (fd < 0)
- return -errno;
-
- if (!category || streq(category, "links")) {
- k = monitor_add_inotify_watch(fd);
- if (k < 0)
- return k;
-
- good = true;
- }
-
- if (!good)
- return -EINVAL;
-
- *m = FD_TO_MONITOR(fd);
- fd = -1;
-
- return 0;
-}
-
-_public_ sd_network_monitor* sd_network_monitor_unref(sd_network_monitor *m) {
- int fd;
-
- if (m) {
- fd = MONITOR_TO_FD(m);
- close_nointr(fd);
- }
-
- return NULL;
-}
-
-_public_ int sd_network_monitor_flush(sd_network_monitor *m) {
- union inotify_event_buffer buffer;
- struct inotify_event *e;
- ssize_t l;
- int fd, k;
-
- assert_return(m, -EINVAL);
-
- fd = MONITOR_TO_FD(m);
-
- l = read(fd, &buffer, sizeof(buffer));
- if (l < 0) {
- if (errno == EAGAIN || errno == EINTR)
- return 0;
-
- return -errno;
- }
-
- FOREACH_INOTIFY_EVENT(e, buffer, l) {
- if (e->mask & IN_ISDIR) {
- k = monitor_add_inotify_watch(fd);
- if (k < 0)
- return k;
-
- k = inotify_rm_watch(fd, e->wd);
- if (k < 0)
- return -errno;
- }
- }
-
- return 0;
-}
-
-_public_ int sd_network_monitor_get_fd(sd_network_monitor *m) {
-
- assert_return(m, -EINVAL);
-
- return MONITOR_TO_FD(m);
-}
-
-_public_ int sd_network_monitor_get_events(sd_network_monitor *m) {
-
- assert_return(m, -EINVAL);
-
- /* For now we will only return POLLIN here, since we don't
- * need anything else ever for inotify. However, let's have
- * this API to keep our options open should we later on need
- * it. */
- return POLLIN;
-}
-
-_public_ int sd_network_monitor_get_timeout(sd_network_monitor *m, uint64_t *timeout_usec) {
-
- assert_return(m, -EINVAL);
- assert_return(timeout_usec, -EINVAL);
-
- /* For now we will only return (uint64_t) -1, since we don't
- * need any timeout. However, let's have this API to keep our
- * options open should we later on need it. */
- *timeout_usec = (uint64_t) -1;
- return 0;
-}
diff --git a/src/libelogind/sd-resolve/Makefile b/src/libelogind/sd-resolve/Makefile
deleted file mode 120000
index 94aaae2c4..000000000
--- a/src/libelogind/sd-resolve/Makefile
+++ /dev/null
@@ -1 +0,0 @@
-../../Makefile \ No newline at end of file
diff --git a/src/libelogind/sd-rtnl/Makefile b/src/libelogind/sd-rtnl/Makefile
deleted file mode 120000
index 94aaae2c4..000000000
--- a/src/libelogind/sd-rtnl/Makefile
+++ /dev/null
@@ -1 +0,0 @@
-../../Makefile \ No newline at end of file
diff --git a/src/libelogind/sd-rtnl/local-addresses.h b/src/libelogind/sd-rtnl/local-addresses.h
deleted file mode 100644
index bdc28d351..000000000
--- a/src/libelogind/sd-rtnl/local-addresses.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-#pragma once
-
-/***
- This file is part of systemd.
-
- Copyright 2008-2011 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 "sd-rtnl.h"
-#include "in-addr-util.h"
-
-struct local_address {
- int family, ifindex;
- unsigned char scope;
- uint32_t metric;
- union in_addr_union address;
-};
-
-int local_addresses(sd_rtnl *rtnl, int ifindex, int af, struct local_address **ret);
-
-int local_gateways(sd_rtnl *rtnl, int ifindex, int af, struct local_address **ret);
diff --git a/src/libelogind/sd-rtnl/rtnl-internal.h b/src/libelogind/sd-rtnl/rtnl-internal.h
deleted file mode 100644
index 05b88b1ad..000000000
--- a/src/libelogind/sd-rtnl/rtnl-internal.h
+++ /dev/null
@@ -1,135 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-#pragma once
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Tom Gundersen <teg@jklm.no>
-
- 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 <linux/netlink.h>
-
-#include "refcnt.h"
-#include "prioq.h"
-#include "list.h"
-
-#include "sd-rtnl.h"
-
-#include "rtnl-types.h"
-
-#define RTNL_DEFAULT_TIMEOUT ((usec_t) (25 * USEC_PER_SEC))
-
-#define RTNL_WQUEUE_MAX 1024
-#define RTNL_RQUEUE_MAX 64*1024
-
-#define RTNL_CONTAINER_DEPTH 32
-
-struct reply_callback {
- sd_rtnl_message_handler_t callback;
- void *userdata;
- usec_t timeout;
- uint64_t serial;
- unsigned prioq_idx;
-};
-
-struct match_callback {
- sd_rtnl_message_handler_t callback;
- uint16_t type;
- void *userdata;
-
- LIST_FIELDS(struct match_callback, match_callbacks);
-};
-
-struct sd_rtnl {
- RefCount n_ref;
-
- int fd;
-
- union {
- struct sockaddr sa;
- struct sockaddr_nl nl;
- } sockaddr;
-
- sd_rtnl_message **rqueue;
- unsigned rqueue_size;
- size_t rqueue_allocated;
-
- sd_rtnl_message **rqueue_partial;
- unsigned rqueue_partial_size;
- size_t rqueue_partial_allocated;
-
- sd_rtnl_message **wqueue;
- unsigned wqueue_size;
- size_t wqueue_allocated;
-
- struct nlmsghdr *rbuffer;
- size_t rbuffer_allocated;
-
- bool processing:1;
-
- uint32_t serial;
-
- struct Prioq *reply_callbacks_prioq;
- Hashmap *reply_callbacks;
-
- LIST_HEAD(struct match_callback, match_callbacks);
-
- pid_t original_pid;
-
- sd_event_source *io_event_source;
- sd_event_source *time_event_source;
- sd_event_source *exit_event_source;
- sd_event *event;
-};
-
-struct sd_rtnl_message {
- RefCount n_ref;
-
- sd_rtnl *rtnl;
-
- struct nlmsghdr *hdr;
- const struct NLTypeSystem *(container_type_system[RTNL_CONTAINER_DEPTH]); /* the type of the container and all its parents */
- size_t container_offsets[RTNL_CONTAINER_DEPTH]; /* offset from hdr to each container's start */
- unsigned n_containers; /* number of containers */
- size_t next_rta_offset; /* offset from hdr to next rta */
- size_t *rta_offset_tb[RTNL_CONTAINER_DEPTH];
- unsigned short rta_tb_size[RTNL_CONTAINER_DEPTH];
- bool sealed:1;
- bool broadcast:1;
-
- sd_rtnl_message *next; /* next in a chain of multi-part messages */
-};
-
-int message_new(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t type);
-
-int socket_write_message(sd_rtnl *nl, sd_rtnl_message *m);
-int socket_read_message(sd_rtnl *nl);
-
-int rtnl_rqueue_make_room(sd_rtnl *rtnl);
-int rtnl_rqueue_partial_make_room(sd_rtnl *rtnl);
-
-int rtnl_message_read_internal(sd_rtnl_message *m, unsigned short type, void **data);
-int rtnl_message_parse(sd_rtnl_message *m,
- size_t **rta_offset_tb,
- unsigned short *rta_tb_size,
- int max,
- struct rtattr *rta,
- unsigned int rt_len);
-
-/* Make sure callbacks don't destroy the rtnl connection */
-#define RTNL_DONT_DESTROY(rtnl) \
- _cleanup_rtnl_unref_ _unused_ sd_rtnl *_dont_destroy_##rtnl = sd_rtnl_ref(rtnl)
diff --git a/src/libelogind/sd-rtnl/rtnl-types.c b/src/libelogind/sd-rtnl/rtnl-types.c
deleted file mode 100644
index ab456c34f..000000000
--- a/src/libelogind/sd-rtnl/rtnl-types.c
+++ /dev/null
@@ -1,561 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Tom Gundersen <teg@jklm.no>
-
- 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 <stdint.h>
-#include <sys/socket.h>
-#include <linux/netlink.h>
-#include <linux/rtnetlink.h>
-#include <linux/in6.h>
-#include <linux/veth.h>
-#include <linux/if_bridge.h>
-#include <linux/if_addr.h>
-#include <linux/if.h>
-
-#include <linux/ip.h>
-#include <linux/if_link.h>
-#include <linux/if_tunnel.h>
-
-#include "macro.h"
-#include "util.h"
-
-#include "rtnl-types.h"
-#include "missing.h"
-
-static const NLTypeSystem rtnl_link_type_system;
-
-static const NLType rtnl_link_info_data_veth_types[VETH_INFO_MAX + 1] = {
- [VETH_INFO_PEER] = { .type = NLA_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
-};
-
-static const NLType rtnl_link_info_data_ipvlan_types[IFLA_IPVLAN_MAX + 1] = {
- [IFLA_IPVLAN_MODE] = { .type = NLA_U16 },
-};
-
-static const NLType rtnl_link_info_data_macvlan_types[IFLA_MACVLAN_MAX + 1] = {
- [IFLA_MACVLAN_MODE] = { .type = NLA_U32 },
- [IFLA_MACVLAN_FLAGS] = { .type = NLA_U16 },
-};
-
-static const NLType rtnl_link_info_data_bridge_types[IFLA_BRIDGE_MAX + 1] = {
- [IFLA_BRIDGE_FLAGS] = { .type = NLA_U16 },
- [IFLA_BRIDGE_MODE] = { .type = NLA_U16 },
-/*
- [IFLA_BRIDGE_VLAN_INFO] = { .type = NLA_BINARY,
- .len = sizeof(struct bridge_vlan_info), },
-*/
-};
-
-static const NLType rtnl_link_info_data_vlan_types[IFLA_VLAN_MAX + 1] = {
- [IFLA_VLAN_ID] = { .type = NLA_U16 },
-/*
- [IFLA_VLAN_FLAGS] = { .len = sizeof(struct ifla_vlan_flags) },
- [IFLA_VLAN_EGRESS_QOS] = { .type = NLA_NESTED },
- [IFLA_VLAN_INGRESS_QOS] = { .type = NLA_NESTED },
-*/
- [IFLA_VLAN_PROTOCOL] = { .type = NLA_U16 },
-};
-
-static const NLType rtnl_link_info_data_vxlan_types[IFLA_VXLAN_MAX+1] = {
- [IFLA_VXLAN_ID] = { .type = NLA_U32 },
- [IFLA_VXLAN_GROUP] = {.type = NLA_IN_ADDR },
- [IFLA_VXLAN_LINK] = { .type = NLA_U32 },
- [IFLA_VXLAN_LOCAL] = { .type = NLA_U32},
- [IFLA_VXLAN_TTL] = { .type = NLA_U8 },
- [IFLA_VXLAN_TOS] = { .type = NLA_U8 },
- [IFLA_VXLAN_LEARNING] = { .type = NLA_U8 },
- [IFLA_VXLAN_AGEING] = { .type = NLA_U32 },
- [IFLA_VXLAN_LIMIT] = { .type = NLA_U32 },
- [IFLA_VXLAN_PORT_RANGE] = { .type = NLA_U32},
- [IFLA_VXLAN_PROXY] = { .type = NLA_U8 },
- [IFLA_VXLAN_RSC] = { .type = NLA_U8 },
- [IFLA_VXLAN_L2MISS] = { .type = NLA_U8 },
- [IFLA_VXLAN_L3MISS] = { .type = NLA_U8 },
-};
-
-static const NLType rtnl_bond_arp_target_types[BOND_ARP_TARGETS_MAX + 1] = {
- [BOND_ARP_TARGETS_0] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_1] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_2] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_3] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_4] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_5] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_6] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_7] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_8] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_9] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_10] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_11] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_12] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_13] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_14] = { .type = NLA_U32 },
- [BOND_ARP_TARGETS_MAX] = { .type = NLA_U32 },
-};
-
-static const NLTypeSystem rtnl_bond_arp_type_system = {
- .max = ELEMENTSOF(rtnl_bond_arp_target_types) - 1,
- .types = rtnl_bond_arp_target_types,
-};
-
-static const NLType rtnl_link_info_data_bond_types[IFLA_BOND_MAX + 1] = {
- [IFLA_BOND_MODE] = { .type = NLA_U8 },
- [IFLA_BOND_ACTIVE_SLAVE] = { .type = NLA_U32 },
- [IFLA_BOND_MIIMON] = { .type = NLA_U32 },
- [IFLA_BOND_UPDELAY] = { .type = NLA_U32 },
- [IFLA_BOND_DOWNDELAY] = { .type = NLA_U32 },
- [IFLA_BOND_USE_CARRIER] = { .type = NLA_U8 },
- [IFLA_BOND_ARP_INTERVAL] = { .type = NLA_U32 },
- [IFLA_BOND_ARP_IP_TARGET] = { .type = NLA_NESTED, .type_system = &rtnl_bond_arp_type_system },
- [IFLA_BOND_ARP_VALIDATE] = { .type = NLA_U32 },
- [IFLA_BOND_ARP_ALL_TARGETS] = { .type = NLA_U32 },
- [IFLA_BOND_PRIMARY] = { .type = NLA_U32 },
- [IFLA_BOND_PRIMARY_RESELECT] = { .type = NLA_U8 },
- [IFLA_BOND_FAIL_OVER_MAC] = { .type = NLA_U8 },
- [IFLA_BOND_XMIT_HASH_POLICY] = { .type = NLA_U8 },
- [IFLA_BOND_RESEND_IGMP] = { .type = NLA_U32 },
- [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NLA_U8 },
- [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NLA_U8 },
- [IFLA_BOND_MIN_LINKS] = { .type = NLA_U32 },
- [IFLA_BOND_LP_INTERVAL] = { .type = NLA_U32 },
- [IFLA_BOND_PACKETS_PER_SLAVE] = { .type = NLA_U32 },
- [IFLA_BOND_AD_LACP_RATE] = { .type = NLA_U8 },
- [IFLA_BOND_AD_SELECT] = { .type = NLA_U8 },
- [IFLA_BOND_AD_INFO] = { .type = NLA_NESTED },
-};
-
-static const NLType rtnl_link_info_data_iptun_types[IFLA_IPTUN_MAX + 1] = {
- [IFLA_IPTUN_LINK] = { .type = NLA_U32 },
- [IFLA_IPTUN_LOCAL] = { .type = NLA_IN_ADDR },
- [IFLA_IPTUN_REMOTE] = { .type = NLA_IN_ADDR },
- [IFLA_IPTUN_TTL] = { .type = NLA_U8 },
- [IFLA_IPTUN_TOS] = { .type = NLA_U8 },
- [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
- [IFLA_IPTUN_FLAGS] = { .type = NLA_U16 },
- [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
- [IFLA_IPTUN_6RD_PREFIX] = { .type = NLA_IN_ADDR },
- [IFLA_IPTUN_6RD_RELAY_PREFIX] = { .type = NLA_U32 },
- [IFLA_IPTUN_6RD_PREFIXLEN] = { .type = NLA_U16 },
- [IFLA_IPTUN_6RD_RELAY_PREFIXLEN] = { .type = NLA_U16 },
-};
-
-static const NLType rtnl_link_info_data_ipgre_types[IFLA_GRE_MAX + 1] = {
- [IFLA_GRE_LINK] = { .type = NLA_U32 },
- [IFLA_GRE_IFLAGS] = { .type = NLA_U16 },
- [IFLA_GRE_OFLAGS] = { .type = NLA_U16 },
- [IFLA_GRE_IKEY] = { .type = NLA_U32 },
- [IFLA_GRE_OKEY] = { .type = NLA_U32 },
- [IFLA_GRE_LOCAL] = { .type = NLA_IN_ADDR },
- [IFLA_GRE_REMOTE] = { .type = NLA_IN_ADDR },
- [IFLA_GRE_TTL] = { .type = NLA_U8 },
- [IFLA_GRE_TOS] = { .type = NLA_U8 },
- [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
-};
-
-static const NLType rtnl_link_info_data_ipvti_types[IFLA_VTI_MAX + 1] = {
- [IFLA_VTI_LINK] = { .type = NLA_U32 },
- [IFLA_VTI_IKEY] = { .type = NLA_U32 },
- [IFLA_VTI_OKEY] = { .type = NLA_U32 },
- [IFLA_VTI_LOCAL] = { .type = NLA_IN_ADDR },
- [IFLA_VTI_REMOTE] = { .type = NLA_IN_ADDR },
-};
-
-static const NLType rtnl_link_info_data_ip6tnl_types[IFLA_IPTUN_MAX + 1] = {
- [IFLA_IPTUN_LINK] = { .type = NLA_U32 },
- [IFLA_IPTUN_LOCAL] = { .type = NLA_IN_ADDR },
- [IFLA_IPTUN_REMOTE] = { .type = NLA_IN_ADDR },
- [IFLA_IPTUN_TTL] = { .type = NLA_U8 },
- [IFLA_IPTUN_FLAGS] = { .type = NLA_U32 },
- [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
- [IFLA_IPTUN_ENCAP_LIMIT] = { .type = NLA_U8 },
- [IFLA_IPTUN_FLOWINFO] = { .type = NLA_U32},
-};
-
-/* these strings must match the .kind entries in the kernel */
-static const char* const nl_union_link_info_data_table[_NL_UNION_LINK_INFO_DATA_MAX] = {
- [NL_UNION_LINK_INFO_DATA_BOND] = "bond",
- [NL_UNION_LINK_INFO_DATA_BRIDGE] = "bridge",
- [NL_UNION_LINK_INFO_DATA_VLAN] = "vlan",
- [NL_UNION_LINK_INFO_DATA_VETH] = "veth",
- [NL_UNION_LINK_INFO_DATA_DUMMY] = "dummy",
- [NL_UNION_LINK_INFO_DATA_MACVLAN] = "macvlan",
- [NL_UNION_LINK_INFO_DATA_IPVLAN] = "ipvlan",
- [NL_UNION_LINK_INFO_DATA_VXLAN] = "vxlan",
- [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = "ipip",
- [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = "gre",
- [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = "gretap",
- [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = "ip6gre",
- [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = "ip6gretap",
- [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = "sit",
- [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = "vti",
- [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = "vti6",
- [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = "ip6tnl",
-};
-
-DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data, NLUnionLinkInfoData);
-
-static const NLTypeSystem rtnl_link_info_data_type_systems[_NL_UNION_LINK_INFO_DATA_MAX] = {
- [NL_UNION_LINK_INFO_DATA_BOND] = { .max = ELEMENTSOF(rtnl_link_info_data_bond_types) - 1,
- .types = rtnl_link_info_data_bond_types },
- [NL_UNION_LINK_INFO_DATA_BRIDGE] = { .max = ELEMENTSOF(rtnl_link_info_data_bridge_types) - 1,
- .types = rtnl_link_info_data_bridge_types },
- [NL_UNION_LINK_INFO_DATA_VLAN] = { .max = ELEMENTSOF(rtnl_link_info_data_vlan_types) - 1,
- .types = rtnl_link_info_data_vlan_types },
- [NL_UNION_LINK_INFO_DATA_VETH] = { .max = ELEMENTSOF(rtnl_link_info_data_veth_types) - 1,
- .types = rtnl_link_info_data_veth_types },
- [NL_UNION_LINK_INFO_DATA_MACVLAN] = { .max = ELEMENTSOF(rtnl_link_info_data_macvlan_types) - 1,
- .types = rtnl_link_info_data_macvlan_types },
- [NL_UNION_LINK_INFO_DATA_IPVLAN] = { .max = ELEMENTSOF(rtnl_link_info_data_ipvlan_types) - 1,
- .types = rtnl_link_info_data_ipvlan_types },
- [NL_UNION_LINK_INFO_DATA_VXLAN] = { .max = ELEMENTSOF(rtnl_link_info_data_vxlan_types) - 1,
- .types = rtnl_link_info_data_vxlan_types },
- [NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = { .max = ELEMENTSOF(rtnl_link_info_data_iptun_types) - 1,
- .types = rtnl_link_info_data_iptun_types },
- [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = { .max = ELEMENTSOF(rtnl_link_info_data_ipgre_types) - 1,
- .types = rtnl_link_info_data_ipgre_types },
- [NL_UNION_LINK_INFO_DATA_IPGRETAP_TUNNEL] = { .max = ELEMENTSOF(rtnl_link_info_data_ipgre_types) - 1,
- .types = rtnl_link_info_data_ipgre_types },
- [NL_UNION_LINK_INFO_DATA_IP6GRE_TUNNEL] = { .max = ELEMENTSOF(rtnl_link_info_data_ipgre_types) - 1,
- .types = rtnl_link_info_data_ipgre_types },
- [NL_UNION_LINK_INFO_DATA_IP6GRETAP_TUNNEL] = { .max = ELEMENTSOF(rtnl_link_info_data_ipgre_types) - 1,
- .types = rtnl_link_info_data_ipgre_types },
- [NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = { .max = ELEMENTSOF(rtnl_link_info_data_iptun_types) - 1,
- .types = rtnl_link_info_data_iptun_types },
- [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = { .max = ELEMENTSOF(rtnl_link_info_data_ipvti_types) - 1,
- .types = rtnl_link_info_data_ipvti_types },
- [NL_UNION_LINK_INFO_DATA_VTI6_TUNNEL] = { .max = ELEMENTSOF(rtnl_link_info_data_ipvti_types) - 1,
- .types = rtnl_link_info_data_ipvti_types },
- [NL_UNION_LINK_INFO_DATA_IP6TNL_TUNNEL] = { .max = ELEMENTSOF(rtnl_link_info_data_ip6tnl_types) - 1,
- .types = rtnl_link_info_data_ip6tnl_types },
-
-};
-
-static const NLTypeSystemUnion rtnl_link_info_data_type_system_union = {
- .num = _NL_UNION_LINK_INFO_DATA_MAX,
- .lookup = nl_union_link_info_data_from_string,
- .type_systems = rtnl_link_info_data_type_systems,
- .match_type = NL_MATCH_SIBLING,
- .match = IFLA_INFO_KIND,
-};
-
-static const NLType rtnl_link_info_types[IFLA_INFO_MAX + 1] = {
- [IFLA_INFO_KIND] = { .type = NLA_STRING },
- [IFLA_INFO_DATA] = { .type = NLA_UNION, .type_system_union = &rtnl_link_info_data_type_system_union},
-/*
- [IFLA_INFO_XSTATS],
- [IFLA_INFO_SLAVE_KIND] = { .type = NLA_STRING },
- [IFLA_INFO_SLAVE_DATA] = { .type = NLA_NESTED },
-*/
-};
-
-static const NLTypeSystem rtnl_link_info_type_system = {
- .max = ELEMENTSOF(rtnl_link_info_types) - 1,
- .types = rtnl_link_info_types,
-};
-
-static const struct NLType rtnl_prot_info_bridge_port_types[IFLA_BRPORT_MAX + 1] = {
- [IFLA_BRPORT_STATE] = { .type = NLA_U8 },
- [IFLA_BRPORT_COST] = { .type = NLA_U32 },
- [IFLA_BRPORT_PRIORITY] = { .type = NLA_U16 },
- [IFLA_BRPORT_MODE] = { .type = NLA_U8 },
- [IFLA_BRPORT_GUARD] = { .type = NLA_U8 },
- [IFLA_BRPORT_PROTECT] = { .type = NLA_U8 },
- [IFLA_BRPORT_LEARNING] = { .type = NLA_U8 },
- [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NLA_U8 },
-};
-
-static const NLTypeSystem rtnl_prot_info_type_systems[AF_MAX] = {
- [AF_BRIDGE] = { .max = ELEMENTSOF(rtnl_prot_info_bridge_port_types) - 1,
- .types = rtnl_prot_info_bridge_port_types },
-};
-
-static const NLTypeSystemUnion rtnl_prot_info_type_system_union = {
- .num = AF_MAX,
- .type_systems = rtnl_prot_info_type_systems,
- .match_type = NL_MATCH_PROTOCOL,
-};
-
-static const struct NLType rtnl_af_spec_inet6_types[IFLA_INET6_MAX + 1] = {
- [IFLA_INET6_FLAGS] = { .type = NLA_U32 },
-/*
- IFLA_INET6_CONF,
- IFLA_INET6_STATS,
- IFLA_INET6_MCAST,
- IFLA_INET6_CACHEINFO,
- IFLA_INET6_ICMP6STATS,
-*/
- [IFLA_INET6_TOKEN] = { .type = NLA_IN_ADDR },
- [IFLA_INET6_ADDR_GEN_MODE] = { .type = NLA_U8 },
-};
-
-static const NLTypeSystem rtnl_af_spec_inet6_type_system = {
- .max = ELEMENTSOF(rtnl_af_spec_inet6_types) - 1,
- .types = rtnl_af_spec_inet6_types,
-};
-
-static const NLType rtnl_af_spec_types[AF_MAX + 1] = {
- [AF_INET6] = { .type = NLA_NESTED, .type_system = &rtnl_af_spec_inet6_type_system },
-};
-
-static const NLTypeSystem rtnl_af_spec_type_system = {
- .max = ELEMENTSOF(rtnl_af_spec_types) - 1,
- .types = rtnl_af_spec_types,
-};
-
-static const NLType rtnl_link_types[IFLA_MAX + 1 ] = {
- [IFLA_ADDRESS] = { .type = NLA_ETHER_ADDR, },
- [IFLA_BROADCAST] = { .type = NLA_ETHER_ADDR, },
- [IFLA_IFNAME] = { .type = NLA_STRING, .size = IFNAMSIZ - 1, },
- [IFLA_MTU] = { .type = NLA_U32 },
- [IFLA_LINK] = { .type = NLA_U32 },
-/*
- [IFLA_QDISC],
- [IFLA_STATS],
- [IFLA_COST],
- [IFLA_PRIORITY],
-*/
- [IFLA_MASTER] = { .type = NLA_U32 },
-/*
- [IFLA_WIRELESS],
-*/
- [IFLA_PROTINFO] = { .type = NLA_UNION, .type_system_union = &rtnl_prot_info_type_system_union },
- [IFLA_TXQLEN] = { .type = NLA_U32 },
-/*
- [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) },
-*/
- [IFLA_WEIGHT] = { .type = NLA_U32 },
- [IFLA_OPERSTATE] = { .type = NLA_U8 },
- [IFLA_LINKMODE] = { .type = NLA_U8 },
- [IFLA_LINKINFO] = { .type = NLA_NESTED, .type_system = &rtnl_link_info_type_system },
- [IFLA_NET_NS_PID] = { .type = NLA_U32 },
- [IFLA_IFALIAS] = { .type = NLA_STRING, .size = IFALIASZ - 1 },
-/*
- [IFLA_NUM_VF],
- [IFLA_VFINFO_LIST] = {. type = NLA_NESTED, },
- [IFLA_STATS64],
- [IFLA_VF_PORTS] = { .type = NLA_NESTED },
- [IFLA_PORT_SELF] = { .type = NLA_NESTED },
-*/
- [IFLA_AF_SPEC] = { .type = NLA_NESTED, .type_system = &rtnl_af_spec_type_system },
-/*
- [IFLA_VF_PORTS],
- [IFLA_PORT_SELF],
- [IFLA_AF_SPEC],
-*/
- [IFLA_GROUP] = { .type = NLA_U32 },
- [IFLA_NET_NS_FD] = { .type = NLA_U32 },
- [IFLA_EXT_MASK] = { .type = NLA_U32 },
- [IFLA_PROMISCUITY] = { .type = NLA_U32 },
- [IFLA_NUM_TX_QUEUES] = { .type = NLA_U32 },
- [IFLA_NUM_RX_QUEUES] = { .type = NLA_U32 },
- [IFLA_CARRIER] = { .type = NLA_U8 },
-/*
- [IFLA_PHYS_PORT_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_PORT_ID_LEN },
-*/
-};
-
-static const NLTypeSystem rtnl_link_type_system = {
- .max = ELEMENTSOF(rtnl_link_types) - 1,
- .types = rtnl_link_types,
-};
-
-/* IFA_FLAGS was defined in kernel 3.14, but we still support older
- * kernels where IFA_MAX is lower. */
-static const NLType rtnl_address_types[CONST_MAX(IFA_MAX, IFA_FLAGS) + 1] = {
- [IFA_ADDRESS] = { .type = NLA_IN_ADDR },
- [IFA_LOCAL] = { .type = NLA_IN_ADDR },
- [IFA_LABEL] = { .type = NLA_STRING, .size = IFNAMSIZ - 1 },
- [IFA_BROADCAST] = { .type = NLA_IN_ADDR }, /* 6? */
- [IFA_CACHEINFO] = { .type = NLA_CACHE_INFO, .size = sizeof(struct ifa_cacheinfo) },
-/*
- [IFA_ANYCAST],
- [IFA_MULTICAST],
- [IFA_FLAGS] = { .type = NLA_U32 },
-*/
-};
-
-static const NLTypeSystem rtnl_address_type_system = {
- .max = ELEMENTSOF(rtnl_address_types) - 1,
- .types = rtnl_address_types,
-};
-
-static const NLType rtnl_route_types[RTA_MAX + 1] = {
- [RTA_DST] = { .type = NLA_IN_ADDR }, /* 6? */
- [RTA_SRC] = { .type = NLA_IN_ADDR }, /* 6? */
- [RTA_IIF] = { .type = NLA_U32 },
- [RTA_OIF] = { .type = NLA_U32 },
- [RTA_GATEWAY] = { .type = NLA_IN_ADDR },
- [RTA_PRIORITY] = { .type = NLA_U32 },
- [RTA_PREFSRC] = { .type = NLA_IN_ADDR }, /* 6? */
-/*
- [RTA_METRICS] = { .type = NLA_NESTED },
- [RTA_MULTIPATH] = { .len = sizeof(struct rtnexthop) },
-*/
- [RTA_FLOW] = { .type = NLA_U32 }, /* 6? */
-/*
- RTA_CACHEINFO,
- RTA_TABLE,
- RTA_MARK,
- RTA_MFC_STATS,
-*/
-};
-
-static const NLTypeSystem rtnl_route_type_system = {
- .max = ELEMENTSOF(rtnl_route_types) - 1,
- .types = rtnl_route_types,
-};
-
-static const NLType rtnl_neigh_types[NDA_MAX + 1] = {
- [NDA_DST] = { .type = NLA_IN_ADDR },
- [NDA_LLADDR] = { .type = NLA_ETHER_ADDR },
- [NDA_CACHEINFO] = { .type = NLA_CACHE_INFO, .size = sizeof(struct nda_cacheinfo) },
- [NDA_PROBES] = { .type = NLA_U32 },
- [NDA_VLAN] = { .type = NLA_U16 },
- [NDA_PORT] = { .type = NLA_U16 },
- [NDA_VNI] = { .type = NLA_U32 },
- [NDA_IFINDEX] = { .type = NLA_U32 },
-};
-
-static const NLTypeSystem rtnl_neigh_type_system = {
- .max = ELEMENTSOF(rtnl_neigh_types) - 1,
- .types = rtnl_neigh_types,
-};
-
-static const NLType rtnl_types[RTM_MAX + 1] = {
- [NLMSG_DONE] = { .type = NLA_META, .size = 0 },
- [NLMSG_ERROR] = { .type = NLA_META, .size = sizeof(struct nlmsgerr) },
- [RTM_NEWLINK] = { .type = NLA_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
- [RTM_DELLINK] = { .type = NLA_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
- [RTM_GETLINK] = { .type = NLA_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
- [RTM_SETLINK] = { .type = NLA_NESTED, .type_system = &rtnl_link_type_system, .size = sizeof(struct ifinfomsg) },
- [RTM_NEWADDR] = { .type = NLA_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
- [RTM_DELADDR] = { .type = NLA_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
- [RTM_GETADDR] = { .type = NLA_NESTED, .type_system = &rtnl_address_type_system, .size = sizeof(struct ifaddrmsg) },
- [RTM_NEWROUTE] = { .type = NLA_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
- [RTM_DELROUTE] = { .type = NLA_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
- [RTM_GETROUTE] = { .type = NLA_NESTED, .type_system = &rtnl_route_type_system, .size = sizeof(struct rtmsg) },
- [RTM_NEWNEIGH] = { .type = NLA_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
- [RTM_DELNEIGH] = { .type = NLA_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
- [RTM_GETNEIGH] = { .type = NLA_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
-};
-
-const NLTypeSystem rtnl_type_system = {
- .max = ELEMENTSOF(rtnl_types) - 1,
- .types = rtnl_types,
-};
-
-int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, uint16_t type) {
- const NLType *nl_type;
-
- assert(ret);
-
- if (!type_system)
- type_system = &rtnl_type_system;
-
- assert(type_system->types);
-
- if (type > type_system->max)
- return -EOPNOTSUPP;
-
- nl_type = &type_system->types[type];
-
- if (nl_type->type == NLA_UNSPEC)
- return -EOPNOTSUPP;
-
- *ret = nl_type;
-
- return 0;
-}
-
-int type_system_get_type_system(const NLTypeSystem *type_system, const NLTypeSystem **ret, uint16_t type) {
- const NLType *nl_type;
- int r;
-
- assert(ret);
-
- r = type_system_get_type(type_system, &nl_type, type);
- if (r < 0)
- return r;
-
- assert(nl_type->type == NLA_NESTED);
- assert(nl_type->type_system);
-
- *ret = nl_type->type_system;
-
- return 0;
-}
-
-int type_system_get_type_system_union(const NLTypeSystem *type_system, const NLTypeSystemUnion **ret, uint16_t type) {
- const NLType *nl_type;
- int r;
-
- assert(ret);
-
- r = type_system_get_type(type_system, &nl_type, type);
- if (r < 0)
- return r;
-
- assert(nl_type->type == NLA_UNION);
- assert(nl_type->type_system_union);
-
- *ret = nl_type->type_system_union;
-
- return 0;
-}
-
-int type_system_union_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, const char *key) {
- int type;
-
- assert(type_system_union);
- assert(type_system_union->match_type == NL_MATCH_SIBLING);
- assert(type_system_union->lookup);
- assert(type_system_union->type_systems);
- assert(ret);
- assert(key);
-
- type = type_system_union->lookup(key);
- if (type < 0)
- return -EOPNOTSUPP;
-
- assert(type < type_system_union->num);
-
- *ret = &type_system_union->type_systems[type];
-
- return 0;
-}
-
-int type_system_union_protocol_get_type_system(const NLTypeSystemUnion *type_system_union, const NLTypeSystem **ret, uint16_t protocol) {
- const NLTypeSystem *type_system;
-
- assert(type_system_union);
- assert(type_system_union->type_systems);
- assert(type_system_union->match_type == NL_MATCH_PROTOCOL);
- assert(ret);
-
- if (protocol >= type_system_union->num)
- return -EOPNOTSUPP;
-
- type_system = &type_system_union->type_systems[protocol];
- if (type_system->max == 0)
- return -EOPNOTSUPP;
-
- *ret = type_system;
-
- return 0;
-}
diff --git a/src/libelogind/sd-rtnl/rtnl-util.h b/src/libelogind/sd-rtnl/rtnl-util.h
deleted file mode 100644
index 9e4bdb867..000000000
--- a/src/libelogind/sd-rtnl/rtnl-util.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-#pragma once
-
-/***
- This file is part of systemd.
-
- Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-
-#include "util.h"
-#include "sd-rtnl.h"
-
-int rtnl_message_new_synthetic_error(int error, uint32_t serial, sd_rtnl_message **ret);
-uint32_t rtnl_message_get_serial(sd_rtnl_message *m);
-void rtnl_message_seal(sd_rtnl_message *m);
-
-bool rtnl_message_type_is_link(uint16_t type);
-bool rtnl_message_type_is_addr(uint16_t type);
-bool rtnl_message_type_is_route(uint16_t type);
-bool rtnl_message_type_is_neigh(uint16_t type);
-
-int rtnl_set_link_name(sd_rtnl **rtnl, int ifindex, const char *name);
-int rtnl_set_link_properties(sd_rtnl **rtnl, int ifindex, const char *alias, const struct ether_addr *mac, unsigned mtu);
-
-int rtnl_log_parse_error(int r);
-int rtnl_log_create_error(int r);
-
-DEFINE_TRIVIAL_CLEANUP_FUNC(sd_rtnl*, sd_rtnl_unref);
-DEFINE_TRIVIAL_CLEANUP_FUNC(sd_rtnl_message*, sd_rtnl_message_unref);
-
-#define _cleanup_rtnl_unref_ _cleanup_(sd_rtnl_unrefp)
-#define _cleanup_rtnl_message_unref_ _cleanup_(sd_rtnl_message_unrefp)
diff --git a/src/libelogind/sd-utf8/Makefile b/src/libelogind/sd-utf8/Makefile
deleted file mode 120000
index 94aaae2c4..000000000
--- a/src/libelogind/sd-utf8/Makefile
+++ /dev/null
@@ -1 +0,0 @@
-../../Makefile \ No newline at end of file
diff --git a/src/libelogind/sd-utf8/sd-utf8.c b/src/libelogind/sd-utf8/sd-utf8.c
deleted file mode 100644
index 6f2aa6064..000000000
--- a/src/libelogind/sd-utf8/sd-utf8.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2013 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 "util.h"
-#include "utf8.h"
-#include "sd-utf8.h"
-
-_public_ const char *sd_utf8_is_valid(const char *s) {
- assert_return(s, NULL);
-
- return utf8_is_valid(s);
-}
-
-_public_ const char *sd_ascii_is_valid(const char *s) {
- assert_return(s, NULL);
-
- return ascii_is_valid(s);
-}