summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-08-21 16:22:34 +0200
committerLennart Poettering <lennart@poettering.net>2014-08-21 17:24:21 +0200
commit28849dbadb7cd127f7f89e8892ec94c6a05070da (patch)
treef147f6937402f82c88b6a207a5c6492ff5d89be4 /src/core
parentf49650cee2c5256dc0491432e1f12a4ae19be6c5 (diff)
service,strv: introduce strv_find_startswith() and make use of it
Unlike strv_find_prefix() the new call will return a pointer to the suffix of the item we found, instead of the whole item. This is more closer inline with what startswith() does, and allows us to simplify a couple of invocations.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/service.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/src/core/service.c b/src/core/service.c
index fc952e848f..262a40cc8b 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -2526,12 +2526,13 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
}
/* Interpret MAINPID= */
- e = strv_find_prefix(tags, "MAINPID=");
+ e = strv_find_startswith(tags, "MAINPID=");
if (e && IN_SET(s->state, SERVICE_START, SERVICE_START_POST, SERVICE_RUNNING, SERVICE_RELOAD)) {
- if (parse_pid(e + 8, &pid) < 0)
+ if (parse_pid(e, &pid) < 0)
log_warning_unit(u->id, "Failed to parse MAINPID= field in notification message: %s", e);
else {
- log_debug_unit(u->id, "%s: got %s", u->id, e);
+ log_debug_unit(u->id, "%s: got MAINPID=%s", u->id, e);
+
service_set_main_pid(s, pid);
unit_watch_pid(UNIT(s), pid);
notify_dbus = true;
@@ -2546,44 +2547,41 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
}
/* Interpret STATUS= */
- e = strv_find_prefix(tags, "STATUS=");
+ e = strv_find_startswith(tags, "STATUS=");
if (e) {
- char *t;
+ _cleanup_free_ char *t = NULL;
- if (e[7]) {
- if (!utf8_is_valid(e+7)) {
+ if (!isempty(e)) {
+ if (!utf8_is_valid(e))
log_warning_unit(u->id, "Status message in notification is not UTF-8 clean.");
- return;
- }
+ else {
+ log_debug_unit(u->id, "%s: got STATUS=%s", u->id, e);
- log_debug_unit(u->id, "%s: got %s", u->id, e);
-
- t = strdup(e+7);
- if (!t) {
- log_oom();
- return;
+ t = strdup(e);
+ if (!t)
+ log_oom();
}
-
- } else
- t = NULL;
+ }
if (!streq_ptr(s->status_text, t)) {
+
free(s->status_text);
s->status_text = t;
+ t = NULL;
+
notify_dbus = true;
- } else
- free(t);
+ }
}
/* Interpret ERRNO= */
- e = strv_find_prefix(tags, "ERRNO=");
+ e = strv_find_startswith(tags, "ERRNO=");
if (e) {
int status_errno;
- if (safe_atoi(e + 6, &status_errno) < 0 || status_errno < 0)
+ if (safe_atoi(e, &status_errno) < 0 || status_errno < 0)
log_warning_unit(u->id, "Failed to parse ERRNO= field in notification message: %s", e);
else {
- log_debug_unit(u->id, "%s: got %s", u->id, e);
+ log_debug_unit(u->id, "%s: got ERRNO=%s", u->id, e);
if (s->status_errno != status_errno) {
s->status_errno = status_errno;