summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-02-27 18:50:41 +0100
committerLennart Poettering <lennart@poettering.net>2013-02-27 18:50:41 +0100
commit26d04f86a36595e3565c74d67863e076c3e3c773 (patch)
tree374ba1bdf5dfc95a9c05df1232ffc44d8bd98397 /src/shared
parent416389f7ae262ae7a0848302e7a6516597f9fad1 (diff)
unit: rework resource management API
This introduces a new static list of known attributes and their special semantics. This means that cgroup attribute values can now be automatically translated from user to kernel notation for command line set settings, too. This also adds proper support for multi-line attributes.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/path-lookup.c9
-rw-r--r--src/shared/strv.c25
-rw-r--r--src/shared/strv.h1
3 files changed, 33 insertions, 2 deletions
diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c
index fa4995ceea..ffdc5367cb 100644
--- a/src/shared/path-lookup.c
+++ b/src/shared/path-lookup.c
@@ -41,21 +41,26 @@ DEFINE_STRING_TABLE_LOOKUP(systemd_running_as, SystemdRunningAs);
int user_config_home(char **config_home) {
const char *e;
+ char *r;
e = getenv("XDG_CONFIG_HOME");
if (e) {
- if (asprintf(config_home, "%s/systemd/user", e) < 0)
+ r = strappend(e, "/systemd/user");
+ if (!r)
return -ENOMEM;
+ *config_home = r;
return 1;
} else {
const char *home;
home = getenv("HOME");
if (home) {
- if (asprintf(config_home, "%s/.config/systemd/user", home) < 0)
+ r = strappend(home, "/.config/systemd/user");
+ if (!r)
return -ENOMEM;
+ *config_home = r;
return 1;
}
}
diff --git a/src/shared/strv.c b/src/shared/strv.c
index ec25755289..60c4762572 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -305,6 +305,31 @@ char **strv_split_quoted(const char *s) {
return r;
}
+char **strv_split_newlines(const char *s) {
+ char **l;
+ unsigned n;
+
+ assert(s);
+
+ /* Special version of strv_split() that splits on newlines and
+ * suppresses an empty string at the end */
+
+ l = strv_split(s, NEWLINE);
+ if (!l)
+ return NULL;
+
+ n = strv_length(l);
+ if (n <= 0)
+ return l;
+
+ if (isempty(l[n-1])) {
+ free(l[n-1]);
+ l[n-1] = NULL;
+ }
+
+ return l;
+}
+
char *strv_join(char **l, const char *separator) {
char *r, *e;
char **s;
diff --git a/src/shared/strv.h b/src/shared/strv.h
index b3802a7a3f..623f10216d 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -58,6 +58,7 @@ static inline bool strv_isempty(char **l) {
char **strv_split(const char *s, const char *separator) _malloc_;
char **strv_split_quoted(const char *s) _malloc_;
+char **strv_split_newlines(const char *s) _malloc_;
char *strv_join(char **l, const char *separator) _malloc_;