service: add func for string config change check
authorYousong Zhou <yszhou4tech@gmail.com>
Sun, 11 Feb 2018 09:17:08 +0000 (17:17 +0800)
committerYousong Zhou <yszhou4tech@gmail.com>
Wed, 28 Mar 2018 09:29:49 +0000 (17:29 +0800)
To also prepare for following commits introducing more string value
change detection

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
service/instance.c

index ecbb6ea41e78523d288d4d38db38885011c671d0..74c47fac36cabc4b1e762c6f2c099a112920eb8c 100644 (file)
@@ -587,6 +587,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)
 {
@@ -614,14 +619,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)