core: add support for naming file descriptors passed using socket activation
This adds support for naming file descriptors passed using socket activation. The names are passed in a new $LISTEN_FDNAMES= environment variable, that matches the existign $LISTEN_FDS= one and contains a colon-separated list of names. This also adds support for naming fds submitted to the per-service fd store using FDNAME= in the sd_notify() message. This also adds a new FileDescriptorName= setting for socket unit files to set the name for fds created by socket units. This also adds a new call sd_listen_fds_with_names(), that is similar to sd_listen_fds(), but also returns the names of the fds. systemd-activate gained the new --fdname= switch to specify a name for testing socket activation. This is based on #1247 by Maciej Wereski. Fixes #1247.
This commit is contained in:
+15
-2
@@ -21,9 +21,22 @@
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "systemd/sd-daemon.h"
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#include "strv.h"
|
||||
|
||||
int main(int argc, char*argv[]) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
int n, i;
|
||||
|
||||
n = sd_listen_fds_with_names(false, &l);
|
||||
if (n < 0) {
|
||||
log_error_errno(n, "Failed to get listening fds: %m");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
log_info("fd=%i name=%s\n", SD_LISTEN_FDS_START + i, l[i]);
|
||||
|
||||
sd_notify(0,
|
||||
"STATUS=Starting up");
|
||||
@@ -49,5 +62,5 @@ int main(int argc, char*argv[]) {
|
||||
"STOPPING=1");
|
||||
sleep(5);
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
+32
-4
@@ -155,7 +155,7 @@ static void test_strv_join(void) {
|
||||
|
||||
static void test_strv_quote_unquote(const char* const *split, const char *quoted) {
|
||||
_cleanup_free_ char *p;
|
||||
_cleanup_strv_free_ char **s;
|
||||
_cleanup_strv_free_ char **s = NULL;
|
||||
char **t;
|
||||
int r;
|
||||
|
||||
@@ -166,7 +166,7 @@ static void test_strv_quote_unquote(const char* const *split, const char *quoted
|
||||
assert_se(streq(p, quoted));
|
||||
|
||||
r = strv_split_extract(&s, quoted, WHITESPACE, EXTRACT_QUOTES);
|
||||
assert_se(r == 0);
|
||||
assert_se(r == (int) strv_length(s));
|
||||
assert_se(s);
|
||||
STRV_FOREACH(t, s) {
|
||||
assert_se(*t);
|
||||
@@ -183,7 +183,7 @@ static void test_strv_unquote(const char *quoted, char **list) {
|
||||
int r;
|
||||
|
||||
r = strv_split_extract(&s, quoted, WHITESPACE, EXTRACT_QUOTES);
|
||||
assert_se(r == 0);
|
||||
assert_se(r == (int) strv_length(list));
|
||||
assert_se(s);
|
||||
j = strv_join(s, " | ");
|
||||
assert_se(j);
|
||||
@@ -225,7 +225,7 @@ static void test_strv_split_extract(void) {
|
||||
int r;
|
||||
|
||||
r = strv_split_extract(&l, str, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
|
||||
assert_se(r == 0);
|
||||
assert_se(r == (int) strv_length(l));
|
||||
assert_se(streq_ptr(l[0], ""));
|
||||
assert_se(streq_ptr(l[1], "foo:bar"));
|
||||
assert_se(streq_ptr(l[2], ""));
|
||||
@@ -591,6 +591,33 @@ static void test_strv_skip(void) {
|
||||
test_strv_skip_one(STRV_MAKE(NULL), 55, STRV_MAKE(NULL));
|
||||
}
|
||||
|
||||
static void test_strv_extend_n(void) {
|
||||
_cleanup_strv_free_ char **v = NULL;
|
||||
|
||||
v = strv_new("foo", "bar", NULL);
|
||||
assert_se(v);
|
||||
|
||||
assert_se(strv_extend_n(&v, "waldo", 3) >= 0);
|
||||
assert_se(strv_extend_n(&v, "piep", 2) >= 0);
|
||||
|
||||
assert_se(streq(v[0], "foo"));
|
||||
assert_se(streq(v[1], "bar"));
|
||||
assert_se(streq(v[2], "waldo"));
|
||||
assert_se(streq(v[3], "waldo"));
|
||||
assert_se(streq(v[4], "waldo"));
|
||||
assert_se(streq(v[5], "piep"));
|
||||
assert_se(streq(v[6], "piep"));
|
||||
assert_se(v[7] == NULL);
|
||||
|
||||
v = strv_free(v);
|
||||
|
||||
assert_se(strv_extend_n(&v, "foo", 1) >= 0);
|
||||
assert_se(strv_extend_n(&v, "bar", 0) >= 0);
|
||||
|
||||
assert_se(streq(v[0], "foo"));
|
||||
assert_se(v[1] == NULL);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_specifier_printf();
|
||||
test_strv_foreach();
|
||||
@@ -650,6 +677,7 @@ int main(int argc, char *argv[]) {
|
||||
test_strv_reverse();
|
||||
test_strv_shell_escape();
|
||||
test_strv_skip();
|
||||
test_strv_extend_n();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user