diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-07-11 03:15:21 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-07-11 03:15:21 +0200 |
commit | cabb0bc6b1a4ec57e108dc99364687d7c4f9670f (patch) | |
tree | 72346552835783c0b7954d7c45473655899dc5a1 /src/libsystemd | |
parent | 2de30868edab5b099cb1e5413e47ed11ded4cc63 (diff) |
nss-mymachines: add new NSS module for automatically resolving addresses of all local containers
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/libsystemd.sym.m4 | 7 | ||||
-rw-r--r-- | src/libsystemd/sd-login/sd-login.c | 43 |
2 files changed, 49 insertions, 1 deletions
diff --git a/src/libsystemd/libsystemd.sym.m4 b/src/libsystemd/libsystemd.sym.m4 index 39e1f51f7c..48572cc0b3 100644 --- a/src/libsystemd/libsystemd.sym.m4 +++ b/src/libsystemd/libsystemd.sym.m4 @@ -148,6 +148,11 @@ global: sd_pid_notifyf; } LIBSYSTEMD_213; +LIBSYSTEMD_216 { +global: + sd_machine_get_ifindexes; +} LIBSYSTEMD_214; + m4_ifdef(`ENABLE_KDBUS', LIBSYSTEMD_FUTURE { global: @@ -444,5 +449,5 @@ global: /* sd-path */ sd_path_home; sd_path_search; -} LIBSYSTEMD_214; +} LIBSYSTEMD_216; ) diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index d1478ddb78..83d6449241 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -786,6 +786,49 @@ _public_ int sd_machine_get_class(const char *machine, char **class) { return 0; } +_public_ int sd_machine_get_ifindexes(const char *machine, int **ifindexes) { + _cleanup_free_ char *netif = NULL; + size_t l, allocated = 0, nr = 0; + char *w, *state; + int *ni = NULL; + const char *p; + int r; + + assert_return(machine_name_is_valid(machine), -EINVAL); + assert_return(ifindexes, -EINVAL); + + p = strappenda("/run/systemd/machines/", machine); + r = parse_env_file(p, NEWLINE, "NETIF", &netif, NULL); + if (r < 0) + return r; + if (!netif) { + *ifindexes = NULL; + return 0; + } + + FOREACH_WORD(w, l, netif, state) { + char buf[l+1]; + int ifi; + + *(char*) (mempcpy(buf, w, l)) = 0; + + if (safe_atoi(buf, &ifi) < 0) + continue; + if (ifi <= 0) + continue; + + if (!GREEDY_REALLOC(ni, allocated, nr+1)) { + free(ni); + return -ENOMEM; + } + + ni[nr++] = ifi; + } + + *ifindexes = ni; + return nr; +} + static inline int MONITOR_TO_FD(sd_login_monitor *m) { return (int) (unsigned long) m - 1; } |