From a7addf32a529e56ee8a7f146042047884fa61b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 24 Mar 2020 11:28:25 +0100 Subject: [PATCH] sd-path,strv: add simple helper to wrap oom handling around strv_split_nulstr() --- src/basic/strv.h | 10 ++++++++++ src/libsystemd/sd-path/sd-path.c | 11 +++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/basic/strv.h b/src/basic/strv.h index e7c2b1a604f..dd3323c2235 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -87,6 +87,16 @@ char **strv_parse_nulstr(const char *s, size_t l); char **strv_split_nulstr(const char *s); int strv_make_nulstr(char * const *l, char **p, size_t *n); +static inline int strv_from_nulstr(char ***a, const char *nulstr) { + char **t; + + t = strv_split_nulstr(nulstr); + if (!t) + return -ENOMEM; + *a = t; + return 0; +} + bool strv_overlap(char * const *a, char * const *b) _pure_; #define STRV_FOREACH(s, l) \ diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index 5797f55c75a..eed8229f5b8 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -536,16 +536,11 @@ static int get_search(uint64_t type, char ***list) { "/etc", NULL); - case SD_PATH_SEARCH_BINARIES_DEFAULT: { - char **t; + case SD_PATH_SEARCH_BINARIES_DEFAULT: + return strv_from_nulstr(list, DEFAULT_PATH_NULSTR); - t = strv_split_nulstr(DEFAULT_PATH_NULSTR); - if (!t) - return -ENOMEM; - *list = t; - return 0; - }} + } return -EOPNOTSUPP; }