[systemd-commits] 2 commits - TODO src/libsystemd-bus src/shared src/systemctl src/systemd
Lennart Poettering
lennart at kemper.freedesktop.org
Mon Apr 15 20:06:17 PDT 2013
TODO | 2 +
src/libsystemd-bus/bus-message.c | 76 +++++++++++++++++++++++++++++++++++++++
src/libsystemd-bus/bus-message.h | 4 ++
src/shared/cgroup-show.c | 13 ------
src/shared/util.h | 26 +++++++------
src/systemctl/systemctl.c | 2 -
src/systemd/sd-bus.h | 3 +
7 files changed, 101 insertions(+), 25 deletions(-)
New commits:
commit 82da66fb750c91f06e713ff23a5e5c57ff05c2a8
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Apr 16 05:04:53 2013 +0200
util: replace decimal_str_max() by a typesafe macro DECIMAL_STR_WIDTH()
DECIMAL_STR_WIDTH() now works on any numeric type, and is easier to
distingish from DECIMAL_STR_MAX().
This also replaces another manual implementaiton of ulog10 by this macro.
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
index 9ee532c..0e82375 100644
--- a/src/shared/cgroup-show.c
+++ b/src/shared/cgroup-show.c
@@ -40,17 +40,6 @@ static int compare(const void *a, const void *b) {
return 0;
}
-static unsigned ilog10(unsigned long ul) {
- int n = 0;
-
- while (ul > 0) {
- n++;
- ul /= 10;
- }
-
- return n;
-}
-
static void show_pid_array(int pids[], unsigned n_pids, const char *prefix, unsigned n_columns, bool extra, bool more, bool kernel_threads, OutputFlags flags) {
unsigned i, m, pid_width;
pid_t biggest = 0;
@@ -71,7 +60,7 @@ static void show_pid_array(int pids[], unsigned n_pids, const char *prefix, unsi
pids[m++] = pids[i];
}
n_pids = m;
- pid_width = ilog10(biggest);
+ pid_width = DECIMAL_STR_WIDTH(biggest);
/* And sort */
qsort(pids, n_pids, sizeof(pid_t), compare);
diff --git a/src/shared/util.h b/src/shared/util.h
index b33fdb5..683ff5a 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -649,19 +649,21 @@ static inline bool logind_running(void) {
return access("/run/systemd/seats/", F_OK) >= 0;
}
-static inline unsigned decimal_str_max(unsigned x) {
- unsigned ans = 1;
- while (x /= 10)
- ans ++;
- return ans;
-}
+#define DECIMAL_STR_WIDTH(x) \
+ ({ \
+ typeof(x) _x_ = (x); \
+ unsigned ans = 1; \
+ while (_x_ /= 10) \
+ ans++; \
+ ans; \
+ })
int unlink_noerrno(const char *path);
-#define alloca0(n) \
- ({ \
- char *__new; \
- size_t __len = n; \
- __new = alloca(__len); \
- (void *) memset(__new, 0, __len); \
+#define alloca0(n) \
+ ({ \
+ char *_new_; \
+ size_t _len_ = n; \
+ _new_ = alloca(_len_); \
+ (void *) memset(_new_, 0, _len_); \
})
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 3656722..2f43052 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -1178,7 +1178,7 @@ static void list_jobs_print(struct job_info* jobs, size_t n) {
for (i = 0, j = jobs; i < n; i++, j++) {
assert(j->name && j->type && j->state);
- l0 = MAX(l0, decimal_str_max(j->id));
+ l0 = MAX(l0, DECIMAL_STR_WIDTH(j->id));
l1 = MAX(l1, strlen(j->name));
l2 = MAX(l2, strlen(j->type));
l3 = MAX(l3, strlen(j->state));
commit d8d3d8a781031d6b1ee4e5f57ec21f16c20a4cf2
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Apr 16 04:54:46 2013 +0200
bus: parse unit/user unit/session from cgroup path
diff --git a/TODO b/TODO
index 4ffdd3e..f90c66b 100644
--- a/TODO
+++ b/TODO
@@ -38,6 +38,8 @@ Fedora 19:
Features:
+* move session owner code from sd-login.c to cgroup-util.c
+
* decimal_str_max() should become a type-safe macro
* show-cgroup.c uses its own ulog10 implementation
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index b78d34b..8134d77 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -26,6 +26,7 @@
#include "utf8.h"
#include "strv.h"
#include "time-util.h"
+#include "cgroup-util.h"
#include "sd-bus.h"
#include "bus-message.h"
@@ -76,6 +77,10 @@ static void message_free(sd_bus_message *m) {
free(m->root_container.signature);
free(m->peeked_signature);
+
+ free(m->unit);
+ free(m->user_unit);
+ free(m->session);
free(m);
}
@@ -796,6 +801,66 @@ int sd_bus_message_get_cgroup(sd_bus_message *m, const char **ret) {
return 0;
}
+int sd_bus_message_get_unit(sd_bus_message *m, const char **ret) {
+ int r;
+
+ if (!m)
+ return -EINVAL;
+ if (!ret)
+ return -EINVAL;
+ if (!m->cgroup)
+ return -ESRCH;
+
+ if (!m->unit) {
+ r = cg_path_get_unit(m->cgroup, &m->unit);
+ if (r < 0)
+ return r;
+ }
+
+ *ret = m->unit;
+ return 0;
+}
+
+int sd_bus_message_get_user_unit(sd_bus_message *m, const char **ret) {
+ int r;
+
+ if (!m)
+ return -EINVAL;
+ if (!ret)
+ return -EINVAL;
+ if (!m->cgroup)
+ return -ESRCH;
+
+ if (!m->user_unit) {
+ r = cg_path_get_user_unit(m->cgroup, &m->user_unit);
+ if (r < 0)
+ return r;
+ }
+
+ *ret = m->user_unit;
+ return 0;
+}
+
+int sd_bus_message_get_session(sd_bus_message *m, const char **ret) {
+ int r;
+
+ if (!m)
+ return -EINVAL;
+ if (!ret)
+ return -EINVAL;
+ if (!m->cgroup)
+ return -ESRCH;
+
+ if (!m->session) {
+ r = cg_path_get_session(m->cgroup, &m->session);
+ if (r < 0)
+ return r;
+ }
+
+ *ret = m->session;
+ return 0;
+}
+
int sd_bus_message_get_cmdline(sd_bus_message *m, char ***cmdline) {
size_t n, i;
const char *p;
@@ -3004,6 +3069,7 @@ int sd_bus_message_set_destination(sd_bus_message *m, const char *destination) {
}
int bus_message_dump(sd_bus_message *m) {
+ const char *u = NULL, *uu = NULL, *s = NULL;
char **cmdline = NULL;
unsigned level = 1;
int r;
@@ -3074,6 +3140,16 @@ int bus_message_dump(sd_bus_message *m) {
if (m->cgroup)
printf("\tcgroup=[%s]\n", m->cgroup);
+ sd_bus_message_get_unit(m, &u);
+ if (u)
+ printf("\tunit=[%s]\n", u);
+ sd_bus_message_get_user_unit(m, &uu);
+ if (uu)
+ printf("\tuser_unit=[%s]\n", uu);
+ sd_bus_message_get_session(m, &s);
+ if (s)
+ printf("\tsession=[%s]\n", s);
+
if (sd_bus_message_get_cmdline(m, &cmdline) >= 0) {
char **c;
diff --git a/src/libsystemd-bus/bus-message.h b/src/libsystemd-bus/bus-message.h
index 2cd1ef2..9440bbe 100644
--- a/src/libsystemd-bus/bus-message.h
+++ b/src/libsystemd-bus/bus-message.h
@@ -115,6 +115,10 @@ struct sd_bus_message {
const char *cmdline;
size_t cmdline_length;
char **cmdline_array;
+
+ char *session;
+ char *unit;
+ char *user_unit;
};
#define BUS_MESSAGE_NEED_BSWAP(m) ((m)->header->endian != SD_BUS_NATIVE_ENDIAN)
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 5d082f2..1352acc 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -136,6 +136,9 @@ int sd_bus_message_get_tid_comm(sd_bus_message *m, const char **r);
int sd_bus_message_get_exe(sd_bus_message *m, const char **r);
int sd_bus_message_get_cgroup(sd_bus_message *m, const char **r);
int sd_bus_message_get_cmdline(sd_bus_message *m, char ***cmdline);
+int sd_bus_message_get_unit(sd_bus_message *m, const char **unit);
+int sd_bus_message_get_user_unit(sd_bus_message *m, const char **unit);
+int sd_bus_message_get_session(sd_bus_message *m, const char **session);
int sd_bus_message_is_signal(sd_bus_message *m, const char *interface, const char *member);
int sd_bus_message_is_method_call(sd_bus_message *m, const char *interface, const char *member);
More information about the systemd-commits
mailing list