diff mbox series

[LEDE-DEV,v2,procd,1/2] service: add func for string config change check

Message ID 1518404425-50957-1-git-send-email-yszhou4tech@gmail.com
State Accepted
Delegated to: John Crispin
Headers show
Series [LEDE-DEV,v2,procd,1/2] service: add func for string config change check | expand

Commit Message

Yousong Zhou Feb. 12, 2018, 3 a.m. UTC
To also prepare for following commits introducing more string value
change detection

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
---
 service/instance.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/service/instance.c b/service/instance.c
index 12c2efe..c3f8b56 100644
--- a/service/instance.c
+++ b/service/instance.c
@@ -588,6 +588,11 @@  instance_restart(struct service_instance *in)
 	uloop_timeout_set(&in->timeout, in->term_timeout * 1000);
 }
 
+static bool string_changed(const char *a, const char *b)
+{
+	return !((!a && !b) || (a && b && !strcmp(a, b)));
+}
+
 static bool
 instance_config_changed(struct service_instance *in, struct service_instance *in_new)
 {
@@ -615,14 +620,7 @@  instance_config_changed(struct service_instance *in, struct service_instance *in
 	if (in->gid != in_new->gid)
 		return true;
 
-	if (in->pidfile && in_new->pidfile)
-		if (strcmp(in->pidfile, in_new->pidfile))
-			return true;
-
-	if (in->pidfile && !in_new->pidfile)
-		return true;
-
-	if (!in->pidfile && in_new->pidfile)
+	if (string_changed(in->pidfile, in_new->pidfile))
 		return true;
 
 	if (in->respawn_retry != in_new->respawn_retry)