[systemd-commits] 2 commits - src/login src/systemd

Lennart Poettering lennart at kemper.freedesktop.org
Thu Jan 12 15:49:30 PST 2012


 src/login/sd-login.c      |   33 +++++++++++++++++++++++++++++----
 src/systemd/sd-id128.h    |    8 ++++++++
 src/systemd/sd-journal.h  |    8 ++++++++
 src/systemd/sd-login.h    |    8 ++++++++
 src/systemd/sd-messages.h |    8 ++++++++
 5 files changed, 61 insertions(+), 4 deletions(-)

New commits:
commit f9873976499de5c90c703e04a3bee96848fc90c8
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 13 00:49:21 2012 +0100

    api: add C++ guards to all headers

diff --git a/src/systemd/sd-id128.h b/src/systemd/sd-id128.h
index 22fcb93..af2841e 100644
--- a/src/systemd/sd-id128.h
+++ b/src/systemd/sd-id128.h
@@ -26,6 +26,10 @@
 #include <stdbool.h>
 #include <string.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef union sd_id128 sd_id128_t;
 
 union sd_id128 {
@@ -58,4 +62,8 @@ static inline bool sd_id128_equal(sd_id128_t a, sd_id128_t b) {
         return memcmp(&a, &b, 16) == 0;
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/src/systemd/sd-journal.h b/src/systemd/sd-journal.h
index c635df3..8737a4c 100644
--- a/src/systemd/sd-journal.h
+++ b/src/systemd/sd-journal.h
@@ -29,6 +29,10 @@
 
 #include <systemd/sd-id128.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* TODO:
  *
  *   - OR of matches is borked...
@@ -122,4 +126,8 @@ int sd_journal_process(sd_journal *j);
 #define SD_JOURNAL_FOREACH_UNIQUE(j, data, l)                           \
         for (sd_journal_restart_unique(j); sd_journal_enumerate_data((j), &(data), &(l)) > 0; )
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h
index 7d76f9a..7746c74 100644
--- a/src/systemd/sd-login.h
+++ b/src/systemd/sd-login.h
@@ -24,6 +24,10 @@
 
 #include <sys/types.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * A few points:
  *
@@ -125,4 +129,8 @@ int sd_login_monitor_flush(sd_login_monitor *m);
 /* Get FD from monitor */
 int sd_login_monitor_get_fd(sd_login_monitor *m);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/src/systemd/sd-messages.h b/src/systemd/sd-messages.h
index 8e52d95..5fd1aa7 100644
--- a/src/systemd/sd-messages.h
+++ b/src/systemd/sd-messages.h
@@ -24,8 +24,16 @@
 
 #include <systemd/sd-id128.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define SD_MESSAGE_JOURNAL_START   SD_ID128_MAKE(f7,73,79,a8,49,0b,40,8b,be,5f,69,40,50,5a,77,7b)
 #define SD_MESSAGE_JOURNAL_STOP    SD_ID128_MAKE(d9,3f,b3,c9,c2,4d,45,1a,97,ce,a6,15,ce,59,c0,0b)
 #define SD_MESSAGE_JOURNAL_DROPPED SD_ID128_MAKE(a5,96,d6,fe,7b,fa,49,94,82,8e,72,30,9e,95,d6,1e)
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif

commit ebda471d898063887008ede9811ffbe1acbc38e5
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 13 00:49:02 2012 +0100

    sd-login: teach sd_pid_get_unit() proper handling of instantiated services

diff --git a/src/login/sd-login.c b/src/login/sd-login.c
index ed98412..eb1a4b9 100644
--- a/src/login/sd-login.c
+++ b/src/login/sd-login.c
@@ -123,7 +123,8 @@ _public_ int sd_pid_get_session(pid_t pid, char **session) {
 
 _public_ int sd_pid_get_unit(pid_t pid, char **unit) {
         int r;
-        char *cgroup, *p;
+        char *cgroup, *p, *at, *b;
+        size_t k;
 
         if (!unit)
                 return -EINVAL;
@@ -138,13 +139,37 @@ _public_ int sd_pid_get_unit(pid_t pid, char **unit) {
         }
 
         p = cgroup + 8;
-        p = strndup(p, strcspn(p, "/"));
+        k = strcspn(p, "/");
+
+        at = memchr(p, '@', k);
+        if (at && at[1] == '.') {
+                size_t j;
+
+                /* This is a templated service */
+                if (p[k] != '/') {
+                        free(cgroup);
+                        return -EIO;
+                }
+
+                j = strcspn(p+k+1, "/");
+
+                b = malloc(k + j + 1);
+
+                if (b) {
+                        memcpy(b, p, at - p + 1);
+                        memcpy(b + (at - p) + 1, p + k + 1, j);
+                        memcpy(b + (at - p) + 1 + j, at + 1, k - (at - p) - 1);
+                        b[k+j] = 0;
+                }
+        } else
+                  b = strndup(p, k);
+
         free(cgroup);
 
-        if (!p)
+        if (!b)
                 return -ENOMEM;
 
-        *unit = p;
+        *unit = b;
         return 0;
 }
 



More information about the systemd-commits mailing list