[systemd-commits] 3 commits - Makefile-man.am TODO man/sd_bus_creds_get_pid.xml man/sd_bus_creds_new_from_pid.xml src/libsystemd src/shared src/systemd src/test
Lennart Poettering
lennart at kemper.freedesktop.org
Tue Dec 9 09:18:27 PST 2014
Makefile-man.am | 5 -
TODO | 2
man/sd_bus_creds_get_pid.xml | 11 ---
man/sd_bus_creds_new_from_pid.xml | 3
src/libsystemd/libsystemd.sym.m4 | 1
src/libsystemd/sd-bus/bus-control.c | 8 --
src/libsystemd/sd-bus/bus-creds.c | 30 ---------
src/libsystemd/sd-bus/bus-creds.h | 1
src/libsystemd/sd-bus/bus-dump.c | 4 -
src/libsystemd/sd-bus/bus-kernel.c | 17 +----
src/libsystemd/sd-bus/bus-message.c | 94 ++++++++++++++++++-----------
src/libsystemd/sd-bus/bus-message.h | 3
src/libsystemd/sd-bus/kdbus.h | 11 +--
src/libsystemd/sd-bus/test-bus-zero-copy.c | 14 +++-
src/shared/util.c | 50 ---------------
src/shared/util.h | 1
src/systemd/sd-bus.h | 66 +++++++++-----------
src/test/test-util.c | 4 -
18 files changed, 118 insertions(+), 207 deletions(-)
New commits:
commit e82959c0e335b4078d48d4a848679ac6a6d99feb
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Dec 9 18:17:35 2014 +0100
update TODO
diff --git a/TODO b/TODO
index 2de6bd4..cb76087 100644
--- a/TODO
+++ b/TODO
@@ -2,8 +2,6 @@ Preparations for 218:
* port libmount hookup to use API's own inotify interface
-* rhbz
-
* Backport: git notes
* cgroup delegation issues
commit 32802361561403cb6441198c82d9c499e0513863
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Dec 9 18:16:54 2014 +0100
sd-bus: get rid of PID starttime concept
As kdbus no longer exports this, remove all traces from sd-bus too
diff --git a/Makefile-man.am b/Makefile-man.am
index acd3d32..6a40b76 100644
--- a/Makefile-man.am
+++ b/Makefile-man.am
@@ -781,7 +781,6 @@ MANPAGES_ALIAS += \
man/sd_bus_creds_get_gid.3 \
man/sd_bus_creds_get_mask.3 \
man/sd_bus_creds_get_owner_uid.3 \
- man/sd_bus_creds_get_pid_starttime.3 \
man/sd_bus_creds_get_selinux_context.3 \
man/sd_bus_creds_get_session.3 \
man/sd_bus_creds_get_slice.3 \
@@ -850,7 +849,6 @@ man/sd_bus_creds_get_exe.3: man/sd_bus_creds_get_pid.3
man/sd_bus_creds_get_gid.3: man/sd_bus_creds_get_pid.3
man/sd_bus_creds_get_mask.3: man/sd_bus_creds_new_from_pid.3
man/sd_bus_creds_get_owner_uid.3: man/sd_bus_creds_get_pid.3
-man/sd_bus_creds_get_pid_starttime.3: man/sd_bus_creds_get_pid.3
man/sd_bus_creds_get_selinux_context.3: man/sd_bus_creds_get_pid.3
man/sd_bus_creds_get_session.3: man/sd_bus_creds_get_pid.3
man/sd_bus_creds_get_slice.3: man/sd_bus_creds_get_pid.3
@@ -939,9 +937,6 @@ man/sd_bus_creds_get_mask.html: man/sd_bus_creds_new_from_pid.html
man/sd_bus_creds_get_owner_uid.html: man/sd_bus_creds_get_pid.html
$(html-alias)
-man/sd_bus_creds_get_pid_starttime.html: man/sd_bus_creds_get_pid.html
- $(html-alias)
-
man/sd_bus_creds_get_selinux_context.html: man/sd_bus_creds_get_pid.html
$(html-alias)
diff --git a/man/sd_bus_creds_get_pid.xml b/man/sd_bus_creds_get_pid.xml
index e0f8909..d61ec19 100644
--- a/man/sd_bus_creds_get_pid.xml
+++ b/man/sd_bus_creds_get_pid.xml
@@ -44,7 +44,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
<refnamediv>
<refname>sd_bus_creds_get_pid</refname>
- <refname>sd_bus_creds_get_pid_starttime</refname>
<refname>sd_bus_creds_get_tid</refname>
<refname>sd_bus_creds_get_uid</refname>
<refname>sd_bus_creds_get_gid</refname>
@@ -83,12 +82,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
</funcprototype>
<funcprototype>
- <funcdef>int <function>sd_bus_creds_get_pid_starttime</function></funcdef>
- <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
- <paramdef>uint64_t *<parameter>usec</parameter></paramdef>
- </funcprototype>
-
- <funcprototype>
<funcdef>int <function>sd_bus_creds_get_tid</function></funcdef>
<paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
<paramdef>pid_t *<parameter>tid</parameter></paramdef>
@@ -245,10 +238,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
<para><function>sd_bus_creds_get_pid()</function> will retrieve the
PID (process identifier).</para>
- <para><function>sd_bus_creds_get_pid_starttime()</function> will
- retrieve the time since the start of the epoch in microseconds
- since the process was started.</para>
-
<para><function>sd_bus_creds_get_tid()</function> will retrieve the
TID (thread identifier).</para>
diff --git a/man/sd_bus_creds_new_from_pid.xml b/man/sd_bus_creds_new_from_pid.xml
index 1935d94..b012d15 100644
--- a/man/sd_bus_creds_new_from_pid.xml
+++ b/man/sd_bus_creds_new_from_pid.xml
@@ -80,7 +80,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
<para>
<constant>SD_BUS_CREDS_PID</constant>,
- <constant>SD_BUS_CREDS_PID_STARTTIME</constant>,
<constant>SD_BUS_CREDS_TID</constant>,
<constant>SD_BUS_CREDS_UID</constant>,
<constant>SD_BUS_CREDS_GID</constant>,
@@ -118,7 +117,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
<para>The information that will be stored is determined by
<parameter>creds_mask</parameter>. It may contain a subset of ORed
constants <constant>SD_BUS_CREDS_PID</constant>,
- <constant>SD_BUS_CREDS_PID_STARTTIME</constant>,
<constant>SD_BUS_CREDS_TID</constant>,
<constant>SD_BUS_CREDS_UID</constant>,
<constant>SD_BUS_CREDS_GID</constant>,
@@ -246,7 +244,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
<citerefentry><refentrytitle>sd_bus_creds_ref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_creds_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_creds_get_pid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
- <citerefentry><refentrytitle>sd_bus_creds_get_pid_starttime</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_creds_get_tid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_creds_get_uid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_creds_get_gid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
diff --git a/src/libsystemd/libsystemd.sym.m4 b/src/libsystemd/libsystemd.sym.m4
index baa1a6f..de8bec3 100644
--- a/src/libsystemd/libsystemd.sym.m4
+++ b/src/libsystemd/libsystemd.sym.m4
@@ -318,7 +318,6 @@ global:
sd_bus_creds_get_uid;
sd_bus_creds_get_gid;
sd_bus_creds_get_pid;
- sd_bus_creds_get_pid_starttime;
sd_bus_creds_get_tid;
sd_bus_creds_get_comm;
sd_bus_creds_get_tid_comm;
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index 261cf0d..813c97f 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -405,11 +405,6 @@ static int bus_populate_creds_from_items(
c->mask |= SD_BUS_CREDS_TID;
}
- if (mask & SD_BUS_CREDS_PID_STARTTIME && item->pids.starttime > 0) {
- c->pid_starttime = item->pids.starttime;
- c->mask |= SD_BUS_CREDS_PID_STARTTIME;
- }
-
break;
case KDBUS_ITEM_CREDS:
@@ -751,8 +746,7 @@ static int bus_get_name_creds_dbus1(
if ((mask & SD_BUS_CREDS_PID) ||
((mask & SD_BUS_CREDS_AUGMENT) &&
- (mask & (SD_BUS_CREDS_PID_STARTTIME|
- SD_BUS_CREDS_EUID|SD_BUS_CREDS_SUID|SD_BUS_CREDS_FSUID|
+ (mask & (SD_BUS_CREDS_EUID|SD_BUS_CREDS_SUID|SD_BUS_CREDS_FSUID|
SD_BUS_CREDS_GID|SD_BUS_CREDS_EGID|SD_BUS_CREDS_SGID|SD_BUS_CREDS_FSGID|
SD_BUS_CREDS_COMM|SD_BUS_CREDS_EXE|SD_BUS_CREDS_CMDLINE|
SD_BUS_CREDS_CGROUP|SD_BUS_CREDS_UNIT|SD_BUS_CREDS_USER_UNIT|SD_BUS_CREDS_SLICE|SD_BUS_CREDS_SESSION|SD_BUS_CREDS_OWNER_UID|
diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c
index 886e212..9978ddf 100644
--- a/src/libsystemd/sd-bus/bus-creds.c
+++ b/src/libsystemd/sd-bus/bus-creds.c
@@ -294,18 +294,6 @@ _public_ int sd_bus_creds_get_tid(sd_bus_creds *c, pid_t *tid) {
return 0;
}
-_public_ int sd_bus_creds_get_pid_starttime(sd_bus_creds *c, uint64_t *usec) {
- assert_return(c, -EINVAL);
- assert_return(usec, -EINVAL);
-
- if (!(c->mask & SD_BUS_CREDS_PID_STARTTIME))
- return -ENODATA;
-
- assert(c->pid_starttime > 0);
- *usec = c->pid_starttime;
- return 0;
-}
-
_public_ int sd_bus_creds_get_selinux_context(sd_bus_creds *c, const char **ret) {
assert_return(c, -EINVAL);
@@ -859,19 +847,6 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
}
}
- if (missing & (SD_BUS_CREDS_PID_STARTTIME)) {
- unsigned long long st;
-
- r = get_starttime_of_pid(pid, &st);
- if (r < 0) {
- if (r != -EPERM && r != -EACCES)
- return r;
- } else {
- c->pid_starttime = ((usec_t) st * USEC_PER_SEC) / (usec_t) sysconf(_SC_CLK_TCK);
- c->mask |= SD_BUS_CREDS_PID_STARTTIME;
- }
- }
-
if (missing & SD_BUS_CREDS_SELINUX_CONTEXT) {
const char *p;
@@ -1052,11 +1027,6 @@ int bus_creds_extend_by_pid(sd_bus_creds *c, uint64_t mask, sd_bus_creds **ret)
n->mask |= SD_BUS_CREDS_TID;
}
- if (c->mask & mask & SD_BUS_CREDS_PID_STARTTIME) {
- n->pid_starttime = c->pid_starttime;
- n->mask |= SD_BUS_CREDS_PID_STARTTIME;
- }
-
if (c->mask & mask & SD_BUS_CREDS_COMM) {
n->comm = strdup(c->comm);
if (!n->comm)
diff --git a/src/libsystemd/sd-bus/bus-creds.h b/src/libsystemd/sd-bus/bus-creds.h
index 5267170..48453e2 100644
--- a/src/libsystemd/sd-bus/bus-creds.h
+++ b/src/libsystemd/sd-bus/bus-creds.h
@@ -44,7 +44,6 @@ struct sd_bus_creds {
unsigned n_supplementary_gids;
pid_t pid;
- usec_t pid_starttime;
pid_t tid;
char *comm;
diff --git a/src/libsystemd/sd-bus/bus-dump.c b/src/libsystemd/sd-bus/bus-dump.c
index 722a654..9d2aaa8 100644
--- a/src/libsystemd/sd-bus/bus-dump.c
+++ b/src/libsystemd/sd-bus/bus-dump.c
@@ -346,12 +346,10 @@ int bus_creds_dump(sd_bus_creds *c, FILE *f, bool terse) {
if (c->mask & SD_BUS_CREDS_PID)
fprintf(f, "%sPID=%s"PID_FMT"%s", prefix, color, c->pid, suffix);
- if (c->mask & SD_BUS_CREDS_PID_STARTTIME)
- fprintf(f, "%sPIDStartTime=%s"USEC_FMT"%s", prefix, color, c->pid_starttime, suffix);
if (c->mask & SD_BUS_CREDS_TID)
fprintf(f, "%sTID=%s"PID_FMT"%s", prefix, color, c->tid, suffix);
- if (terse && ((c->mask & (SD_BUS_CREDS_PID|SD_BUS_CREDS_PID_STARTTIME|SD_BUS_CREDS_TID))))
+ if (terse && ((c->mask & (SD_BUS_CREDS_PID|SD_BUS_CREDS_TID))))
fputs("\n", f);
if (c->mask & SD_BUS_CREDS_UID)
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index 98fd4fd..6cb279e 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -553,22 +553,17 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
case KDBUS_ITEM_PIDS:
- /* The PID starttime/TID might be missing,
- * when the data is faked by some data bus
- * proxy and it lacks that information about
- * the real client since SO_PEERCRED is used
- * for that. */
+ /* The PID/TID might be missing, when the data
+ * is faked by some data bus proxy and it
+ * lacks that information about the real
+ * client since SO_PEERCRED is used for
+ * that. */
if (d->pids.pid > 0) {
m->creds.pid = (pid_t) d->pids.pid;
m->creds.mask |= SD_BUS_CREDS_PID & bus->creds_mask;
}
- if (d->pids.starttime > 0) {
- m->creds.pid_starttime = d->pids.starttime / NSEC_PER_USEC;
- m->creds.mask |= SD_BUS_CREDS_PID_STARTTIME & bus->creds_mask;
- }
-
if (d->pids.tid > 0) {
m->creds.tid = (pid_t) d->pids.tid;
m->creds.mask |= SD_BUS_CREDS_TID & bus->creds_mask;
@@ -1421,7 +1416,7 @@ uint64_t attach_flags_to_kdbus(uint64_t mask) {
SD_BUS_CREDS_GID|SD_BUS_CREDS_EGID|SD_BUS_CREDS_SGID|SD_BUS_CREDS_FSGID))
m |= KDBUS_ATTACH_CREDS;
- if (mask & (SD_BUS_CREDS_PID|SD_BUS_CREDS_PID_STARTTIME|SD_BUS_CREDS_TID))
+ if (mask & (SD_BUS_CREDS_PID|SD_BUS_CREDS_TID))
m |= KDBUS_ATTACH_PIDS;
if (mask & SD_BUS_CREDS_COMM)
diff --git a/src/libsystemd/sd-bus/kdbus.h b/src/libsystemd/sd-bus/kdbus.h
index 2bfd0f9..e2262de 100644
--- a/src/libsystemd/sd-bus/kdbus.h
+++ b/src/libsystemd/sd-bus/kdbus.h
@@ -84,12 +84,8 @@ struct kdbus_creds {
* struct kdbus_pids - process identifiers
* @pid: Process ID
* @tid: Thread ID
- * @starttime: Starttime of the process
*
- * The PID, TID and starttime of a process. The start tmie is useful to detect
- * PID overruns from the client side. i.e. if you use the PID to look something
- * up in /proc/$PID/ you can afterwards check the starttime field of it, to
- * ensure you didn't run into a PID overrun.
+ * The PID and TID of a process.
*
* Attached to:
* KDBUS_ITEM_PIDS
@@ -97,7 +93,6 @@ struct kdbus_creds {
struct kdbus_pids {
__u64 pid;
__u64 tid;
- __u64 starttime;
};
/**
@@ -773,6 +768,7 @@ enum kdbus_name_list_flags {
* @offset: The returned offset in the caller's pool buffer.
* The user must use KDBUS_CMD_FREE to free the
* allocated memory.
+ * @size: Output buffer to report size of data at @offset.
*
* This structure is used with the KDBUS_CMD_NAME_LIST ioctl.
*/
@@ -780,6 +776,7 @@ struct kdbus_cmd_name_list {
__u64 flags;
__u64 kernel_flags;
__u64 offset;
+ __u64 size;
} __attribute__((aligned(8)));
/**
@@ -806,6 +803,7 @@ struct kdbus_name_list {
* @offset: Returned offset in the caller's pool buffer where the
* kdbus_info struct result is stored. The user must
* use KDBUS_CMD_FREE to free the allocated memory.
+ * @info_size: Output buffer to report size of data at @offset.
* @items: The optional item list, containing the
* well-known name to look up as a KDBUS_ITEM_NAME.
* Only needed in case @id is zero.
@@ -820,6 +818,7 @@ struct kdbus_cmd_info {
__u64 kernel_flags;
__u64 id;
__u64 offset;
+ __u64 info_size;
struct kdbus_item items[0];
} __attribute__((aligned(8)));
diff --git a/src/shared/util.c b/src/shared/util.c
index f01cdd7..8c1cf52 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -618,56 +618,6 @@ int get_parent_of_pid(pid_t pid, pid_t *_ppid) {
return 0;
}
-int get_starttime_of_pid(pid_t pid, unsigned long long *st) {
- int r;
- _cleanup_free_ char *line = NULL;
- const char *p;
-
- assert(pid >= 0);
- assert(st);
-
- p = procfs_file_alloca(pid, "stat");
- r = read_one_line_file(p, &line);
- if (r < 0)
- return r;
-
- /* Let's skip the pid and comm fields. The latter is enclosed
- * in () but does not escape any () in its value, so let's
- * skip over it manually */
-
- p = strrchr(line, ')');
- if (!p)
- return -EIO;
-
- p++;
-
- if (sscanf(p, " "
- "%*c " /* state */
- "%*d " /* ppid */
- "%*d " /* pgrp */
- "%*d " /* session */
- "%*d " /* tty_nr */
- "%*d " /* tpgid */
- "%*u " /* flags */
- "%*u " /* minflt */
- "%*u " /* cminflt */
- "%*u " /* majflt */
- "%*u " /* cmajflt */
- "%*u " /* utime */
- "%*u " /* stime */
- "%*d " /* cutime */
- "%*d " /* cstime */
- "%*d " /* priority */
- "%*d " /* nice */
- "%*d " /* num_threads */
- "%*d " /* itrealvalue */
- "%llu " /* starttime */,
- st) != 1)
- return -EIO;
-
- return 0;
-}
-
int fchmod_umask(int fd, mode_t m) {
mode_t u;
int r;
diff --git a/src/shared/util.h b/src/shared/util.h
index 0b7c77b..b6fdf83 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -263,7 +263,6 @@ const char* split(const char **state, size_t *l, const char *separator, bool quo
for ((state) = (s), (word) = split(&(state), &(length), (separator), (quoted)); (word); (word) = split(&(state), &(length), (separator), (quoted)))
pid_t get_parent_of_pid(pid_t pid, pid_t *ppid);
-int get_starttime_of_pid(pid_t pid, unsigned long long *st);
char *strappend(const char *s, const char *suffix);
char *strnappend(const char *s, const char *suffix, size_t length);
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 3636d66..c27537f 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -55,37 +55,36 @@ typedef struct {
enum {
SD_BUS_CREDS_PID = 1ULL << 0,
- SD_BUS_CREDS_PID_STARTTIME = 1ULL << 1,
- SD_BUS_CREDS_TID = 1ULL << 2,
- SD_BUS_CREDS_UID = 1ULL << 3,
- SD_BUS_CREDS_EUID = 1ULL << 4,
- SD_BUS_CREDS_SUID = 1ULL << 5,
- SD_BUS_CREDS_FSUID = 1ULL << 6,
- SD_BUS_CREDS_GID = 1ULL << 7,
- SD_BUS_CREDS_EGID = 1ULL << 8,
- SD_BUS_CREDS_SGID = 1ULL << 9,
- SD_BUS_CREDS_FSGID = 1ULL << 10,
- SD_BUS_CREDS_SUPPLEMENTARY_GIDS = 1ULL << 11,
- SD_BUS_CREDS_COMM = 1ULL << 12,
- SD_BUS_CREDS_TID_COMM = 1ULL << 13,
- SD_BUS_CREDS_EXE = 1ULL << 14,
- SD_BUS_CREDS_CMDLINE = 1ULL << 15,
- SD_BUS_CREDS_CGROUP = 1ULL << 16,
- SD_BUS_CREDS_UNIT = 1ULL << 17,
- SD_BUS_CREDS_USER_UNIT = 1ULL << 18,
- SD_BUS_CREDS_SLICE = 1ULL << 19,
- SD_BUS_CREDS_SESSION = 1ULL << 20,
- SD_BUS_CREDS_OWNER_UID = 1ULL << 21,
- SD_BUS_CREDS_EFFECTIVE_CAPS = 1ULL << 22,
- SD_BUS_CREDS_PERMITTED_CAPS = 1ULL << 23,
- SD_BUS_CREDS_INHERITABLE_CAPS = 1ULL << 24,
- SD_BUS_CREDS_BOUNDING_CAPS = 1ULL << 25,
- SD_BUS_CREDS_SELINUX_CONTEXT = 1ULL << 26,
- SD_BUS_CREDS_AUDIT_SESSION_ID = 1ULL << 27,
- SD_BUS_CREDS_AUDIT_LOGIN_UID = 1ULL << 28,
- SD_BUS_CREDS_UNIQUE_NAME = 1ULL << 29,
- SD_BUS_CREDS_WELL_KNOWN_NAMES = 1ULL << 30,
- SD_BUS_CREDS_DESCRIPTION = 1ULL << 31,
+ SD_BUS_CREDS_TID = 1ULL << 1,
+ SD_BUS_CREDS_UID = 1ULL << 2,
+ SD_BUS_CREDS_EUID = 1ULL << 3,
+ SD_BUS_CREDS_SUID = 1ULL << 4,
+ SD_BUS_CREDS_FSUID = 1ULL << 5,
+ SD_BUS_CREDS_GID = 1ULL << 6,
+ SD_BUS_CREDS_EGID = 1ULL << 7,
+ SD_BUS_CREDS_SGID = 1ULL << 8,
+ SD_BUS_CREDS_FSGID = 1ULL << 9,
+ SD_BUS_CREDS_SUPPLEMENTARY_GIDS = 1ULL << 10,
+ SD_BUS_CREDS_COMM = 1ULL << 11,
+ SD_BUS_CREDS_TID_COMM = 1ULL << 12,
+ SD_BUS_CREDS_EXE = 1ULL << 13,
+ SD_BUS_CREDS_CMDLINE = 1ULL << 14,
+ SD_BUS_CREDS_CGROUP = 1ULL << 15,
+ SD_BUS_CREDS_UNIT = 1ULL << 16,
+ SD_BUS_CREDS_USER_UNIT = 1ULL << 17,
+ SD_BUS_CREDS_SLICE = 1ULL << 18,
+ SD_BUS_CREDS_SESSION = 1ULL << 19,
+ SD_BUS_CREDS_OWNER_UID = 1ULL << 20,
+ SD_BUS_CREDS_EFFECTIVE_CAPS = 1ULL << 21,
+ SD_BUS_CREDS_PERMITTED_CAPS = 1ULL << 22,
+ SD_BUS_CREDS_INHERITABLE_CAPS = 1ULL << 23,
+ SD_BUS_CREDS_BOUNDING_CAPS = 1ULL << 24,
+ SD_BUS_CREDS_SELINUX_CONTEXT = 1ULL << 25,
+ SD_BUS_CREDS_AUDIT_SESSION_ID = 1ULL << 26,
+ SD_BUS_CREDS_AUDIT_LOGIN_UID = 1ULL << 27,
+ SD_BUS_CREDS_UNIQUE_NAME = 1ULL << 28,
+ SD_BUS_CREDS_WELL_KNOWN_NAMES = 1ULL << 29,
+ SD_BUS_CREDS_DESCRIPTION = 1ULL << 30,
SD_BUS_CREDS_AUGMENT = 1ULL << 63, /* special flag, if on sd-bus will augment creds struct, in a potentially race-full way. */
_SD_BUS_CREDS_ALL = (1ULL << 32) -1,
};
@@ -327,7 +326,6 @@ sd_bus_creds *sd_bus_creds_unref(sd_bus_creds *c);
uint64_t sd_bus_creds_get_mask(const sd_bus_creds *c);
int sd_bus_creds_get_pid(sd_bus_creds *c, pid_t *pid);
-int sd_bus_creds_get_pid_starttime(sd_bus_creds *c, uint64_t *usec);
int sd_bus_creds_get_tid(sd_bus_creds *c, pid_t *tid);
int sd_bus_creds_get_uid(sd_bus_creds *c, uid_t *uid);
int sd_bus_creds_get_euid(sd_bus_creds *c, uid_t *euid);
diff --git a/src/test/test-util.c b/src/test/test-util.c
index 1602aa6..20e711d 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -492,7 +492,6 @@ static void test_get_process_comm(void) {
struct stat st;
_cleanup_free_ char *a = NULL, *c = NULL, *d = NULL, *f = NULL, *i = NULL, *cwd = NULL, *root = NULL;
_cleanup_free_ char *env = NULL;
- unsigned long long b;
pid_t e;
uid_t u;
gid_t g;
@@ -507,9 +506,6 @@ static void test_get_process_comm(void) {
log_warning("/proc/1/comm does not exist.");
}
- assert_se(get_starttime_of_pid(1, &b) >= 0);
- log_info("pid1 starttime: '%llu'", b);
-
assert_se(get_process_cmdline(1, 0, true, &c) >= 0);
log_info("pid1 cmdline: '%s'", c);
commit 7dcd79c295fb1f4bcdda5ead43739acf34100ef8
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Dec 9 18:07:46 2014 +0100
sd-bus: properly support passing memfds around with offset/size parameters
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
index ad417c0..06d8d77 100644
--- a/src/libsystemd/sd-bus/bus-message.c
+++ b/src/libsystemd/sd-bus/bus-message.c
@@ -69,13 +69,13 @@ static void message_free_part(sd_bus_message *m, struct bus_body_part *part) {
bus_kernel_push_memfd(m->bus, part->memfd, part->data, part->mapped, part->allocated);
else {
if (part->mapped > 0)
- assert_se(munmap(part->data, part->mapped) == 0);
+ assert_se(munmap(part->mmap_begin, part->mapped) == 0);
safe_close(part->memfd);
}
} else if (part->munmap_this)
- munmap(part->data, part->mapped);
+ munmap(part->mmap_begin, part->mapped);
else if (part->free_this)
free(part->data);
@@ -1126,17 +1126,18 @@ static int part_make_space(
psz = PAGE_ALIGN(sz > 0 ? sz : 1);
if (part->mapped <= 0)
- n = mmap(NULL, psz, PROT_READ|PROT_WRITE, MAP_SHARED, part->memfd, part->memfd_offset);
+ n = mmap(NULL, psz, PROT_READ|PROT_WRITE, MAP_SHARED, part->memfd, 0);
else
- n = mremap(part->data, part->mapped, psz, MREMAP_MAYMOVE);
+ n = mremap(part->mmap_begin, part->mapped, psz, MREMAP_MAYMOVE);
if (n == MAP_FAILED) {
m->poisoned = true;
return -errno;
}
+ part->mmap_begin = part->data = n;
part->mapped = psz;
- part->data = n;
+ part->memfd_offset = 0;
}
part->munmap_this = true;
@@ -2503,10 +2504,11 @@ _public_ int sd_bus_message_append_array_space(
return 0;
}
-_public_ int sd_bus_message_append_array(sd_bus_message *m,
- char type,
- const void *ptr,
- size_t size) {
+_public_ int sd_bus_message_append_array(
+ sd_bus_message *m,
+ char type,
+ const void *ptr,
+ size_t size) {
int r;
void *p;
@@ -2562,26 +2564,26 @@ _public_ int sd_bus_message_append_array_iovec(
return 0;
}
-_public_ int sd_bus_message_append_array_memfd(sd_bus_message *m,
- char type,
- int memfd) {
+_public_ int sd_bus_message_append_array_memfd(
+ sd_bus_message *m,
+ char type,
+ int memfd,
+ uint64_t offset,
+ uint64_t size) {
+
_cleanup_close_ int copy_fd = -1;
struct bus_body_part *part;
ssize_t align, sz;
- uint64_t size;
+ uint64_t real_size;
void *a;
int r;
- if (!m)
- return -EINVAL;
- if (memfd < 0)
- return -EINVAL;
- if (m->sealed)
- return -EPERM;
- if (!bus_type_is_trivial(type))
- return -EINVAL;
- if (m->poisoned)
- return -ESTALE;
+ assert_return(m, -EINVAL);
+ assert_return(memfd >= 0, -EINVAL);
+ assert_return(bus_type_is_trivial(type), -EINVAL);
+ assert_return(size > 0, -EINVAL);
+ assert_return(!m->sealed, -EPERM);
+ assert_return(!m->poisoned, -ESTALE);
r = memfd_set_sealed(memfd);
if (r < 0)
@@ -2591,16 +2593,24 @@ _public_ int sd_bus_message_append_array_memfd(sd_bus_message *m,
if (copy_fd < 0)
return copy_fd;
- r = memfd_get_size(memfd, &size);
+ r = memfd_get_size(memfd, &real_size);
if (r < 0)
return r;
+ if (offset == 0 && size == (uint64_t) -1)
+ size = real_size;
+ else if (offset + size > real_size)
+ return -EMSGSIZE;
+
align = bus_type_get_alignment(type);
sz = bus_type_get_size(type);
assert_se(align > 0);
assert_se(sz > 0);
+ if (offset % align != 0)
+ return -EINVAL;
+
if (size % sz != 0)
return -EINVAL;
@@ -2620,7 +2630,7 @@ _public_ int sd_bus_message_append_array_memfd(sd_bus_message *m,
return -ENOMEM;
part->memfd = copy_fd;
- part->memfd_offset = 0;
+ part->memfd_offset = offset;
part->sealed = true;
part->size = size;
copy_fd = -1;
@@ -2631,16 +2641,22 @@ _public_ int sd_bus_message_append_array_memfd(sd_bus_message *m,
return sd_bus_message_close_container(m);
}
-_public_ int sd_bus_message_append_string_memfd(sd_bus_message *m, int memfd) {
+_public_ int sd_bus_message_append_string_memfd(
+ sd_bus_message *m,
+ int memfd,
+ uint64_t offset,
+ uint64_t size) {
+
_cleanup_close_ int copy_fd = -1;
struct bus_body_part *part;
struct bus_container *c;
- uint64_t size;
+ uint64_t real_size;
void *a;
int r;
assert_return(m, -EINVAL);
assert_return(memfd >= 0, -EINVAL);
+ assert_return(size > 0, -EINVAL);
assert_return(!m->sealed, -EPERM);
assert_return(!m->poisoned, -ESTALE);
@@ -2652,10 +2668,15 @@ _public_ int sd_bus_message_append_string_memfd(sd_bus_message *m, int memfd) {
if (copy_fd < 0)
return copy_fd;
- r = memfd_get_size(memfd, &size);
+ r = memfd_get_size(memfd, &real_size);
if (r < 0)
return r;
+ if (offset == 0 && size == (uint64_t) -1)
+ size = real_size;
+ else if (offset + size > real_size)
+ return -EMSGSIZE;
+
/* We require this to be NUL terminated */
if (size == 0)
return -EINVAL;
@@ -2696,7 +2717,7 @@ _public_ int sd_bus_message_append_string_memfd(sd_bus_message *m, int memfd) {
return -ENOMEM;
part->memfd = copy_fd;
- part->memfd_offset = 0;
+ part->memfd_offset = offset;
part->sealed = true;
part->size = size;
copy_fd = -1;
@@ -2860,7 +2881,7 @@ int bus_message_seal(sd_bus_message *m, uint64_t cookie, usec_t timeout) {
int bus_body_part_map(struct bus_body_part *part) {
void *p;
- size_t psz;
+ size_t psz, shift;
assert_se(part);
@@ -2877,10 +2898,11 @@ int bus_body_part_map(struct bus_body_part *part) {
return 0;
}
- psz = PAGE_ALIGN(part->size);
+ shift = part->memfd_offset - ((part->memfd_offset / page_size()) * page_size());
+ psz = PAGE_ALIGN(part->size + shift);
if (part->memfd >= 0)
- p = mmap(NULL, psz, PROT_READ, MAP_PRIVATE, part->memfd, part->memfd_offset);
+ p = mmap(NULL, psz, PROT_READ, MAP_PRIVATE, part->memfd, part->memfd_offset - shift);
else if (part->is_zero)
p = mmap(NULL, psz, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
else
@@ -2890,7 +2912,8 @@ int bus_body_part_map(struct bus_body_part *part) {
return -errno;
part->mapped = psz;
- part->data = p;
+ part->mmap_begin = p;
+ part->data = (uint8_t*) p + shift;
part->munmap_this = true;
return 0;
@@ -2903,14 +2926,15 @@ void bus_body_part_unmap(struct bus_body_part *part) {
if (part->memfd < 0)
return;
- if (!part->data)
+ if (!part->mmap_begin)
return;
if (!part->munmap_this)
return;
- assert_se(munmap(part->data, part->mapped) == 0);
+ assert_se(munmap(part->mmap_begin, part->mapped) == 0);
+ part->mmap_begin = NULL;
part->data = NULL;
part->mapped = 0;
part->munmap_this = false;
diff --git a/src/libsystemd/sd-bus/bus-message.h b/src/libsystemd/sd-bus/bus-message.h
index db5f90c..4dd280d 100644
--- a/src/libsystemd/sd-bus/bus-message.h
+++ b/src/libsystemd/sd-bus/bus-message.h
@@ -55,10 +55,11 @@ struct bus_container {
struct bus_body_part {
struct bus_body_part *next;
void *data;
+ void *mmap_begin;
size_t size;
size_t mapped;
size_t allocated;
- size_t memfd_offset;
+ uint64_t memfd_offset;
int memfd;
bool free_this:1;
bool munmap_this:1;
diff --git a/src/libsystemd/sd-bus/test-bus-zero-copy.c b/src/libsystemd/sd-bus/test-bus-zero-copy.c
index 2cc671b..a054f74 100644
--- a/src/libsystemd/sd-bus/test-bus-zero-copy.c
+++ b/src/libsystemd/sd-bus/test-bus-zero-copy.c
@@ -48,6 +48,7 @@ int main(int argc, char *argv[]) {
uint32_t u32;
size_t i, l;
char *s;
+ _cleanup_close_ int sfd = -1;
log_set_max_level(LOG_DEBUG);
@@ -107,7 +108,7 @@ int main(int argc, char *argv[]) {
assert_se(r >= 0);
assert_se(sz == STRING_SIZE);
- r = sd_bus_message_append_string_memfd(m, f);
+ r = sd_bus_message_append_string_memfd(m, f, 0, (uint64_t) -1);
assert_se(r >= 0);
close(f);
@@ -124,7 +125,7 @@ int main(int argc, char *argv[]) {
assert_se(r >= 0);
assert_se(sz == SECOND_ARRAY);
- r = sd_bus_message_append_array_memfd(m, 'y', f);
+ r = sd_bus_message_append_array_memfd(m, 'y', f, 0, (uint64_t) -1);
assert_se(r >= 0);
close(f);
@@ -135,6 +136,11 @@ int main(int argc, char *argv[]) {
r = sd_bus_message_append(m, "u", 4711);
assert_se(r >= 0);
+ assert_se((sfd = memfd_new_and_map(NULL, 6, (void**) &p)) >= 0);
+ memcpy(p, "abcd\0", 6);
+ munmap(p, 6);
+ assert_se(sd_bus_message_append_string_memfd(m, sfd, 1, 4) >= 0);
+
r = bus_message_seal(m, 55, 99*USEC_PER_SEC);
assert_se(r >= 0);
@@ -188,6 +194,10 @@ int main(int argc, char *argv[]) {
assert_se(r > 0);
assert_se(u32 == 4711);
+ r = sd_bus_message_read(m, "s", &s);
+ assert_se(r > 0);
+ assert_se(streq_ptr(s, "bcd"));
+
sd_bus_message_unref(m);
sd_bus_unref(a);
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index f5fd37a..3636d66 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -261,10 +261,10 @@ int sd_bus_message_append_basic(sd_bus_message *m, char type, const void *p);
int sd_bus_message_append_array(sd_bus_message *m, char type, const void *ptr, size_t size);
int sd_bus_message_append_array_space(sd_bus_message *m, char type, size_t size, void **ptr);
int sd_bus_message_append_array_iovec(sd_bus_message *m, char type, const struct iovec *iov, unsigned n);
-int sd_bus_message_append_array_memfd(sd_bus_message *m, char type, int memfd);
+int sd_bus_message_append_array_memfd(sd_bus_message *m, char type, int memfd, uint64_t offset, uint64_t size);
int sd_bus_message_append_string_space(sd_bus_message *m, size_t size, char **s);
int sd_bus_message_append_string_iovec(sd_bus_message *m, const struct iovec *iov, unsigned n);
-int sd_bus_message_append_string_memfd(sd_bus_message *m, int memfd);
+int sd_bus_message_append_string_memfd(sd_bus_message *m, int memfd, uint64_t offset, uint64_t size);
int sd_bus_message_append_strv(sd_bus_message *m, char **l);
int sd_bus_message_open_container(sd_bus_message *m, char type, const char *contents);
int sd_bus_message_close_container(sd_bus_message *m);
More information about the systemd-commits
mailing list