src/rrd_daemon.c: Remove another `goto'.
[rrdtool.git] / src / rrd_daemon.c
index a5e8e55..75e7af0 100644 (file)
@@ -1156,7 +1156,10 @@ static int handle_request_wrote (int fd __attribute__((unused)), /* {{{ */
 
   ci = g_tree_lookup(cache_tree, file);
   if (ci == NULL)
-    goto out;
+  {
+    pthread_mutex_unlock(&cache_lock);
+    return (0);
+  }
 
   if (ci->values)
   {
@@ -1168,10 +1171,9 @@ static int handle_request_wrote (int fd __attribute__((unused)), /* {{{ */
 
   _wipe_ci_values(ci, time(NULL));
 
-out:
   pthread_mutex_unlock(&cache_lock);
-  return 0;
-}
+  return (0);
+} /* }}} int handle_request_wrote */
 
 /* if fd < 0, we are in journal replay mode */
 static int handle_request (int fd, char *buffer, size_t buffer_size) /* {{{ */
@@ -1752,9 +1754,7 @@ static void *listen_thread_main (void *args __attribute__((unused))) /* {{{ */
 
 static int daemonize (void) /* {{{ */
 {
-  pid_t child;
   int status;
-  char *base_dir;
 
   /* These structures are static, because `sigaction' behaves weird if the are
    * overwritten.. */
@@ -1762,44 +1762,46 @@ static int daemonize (void) /* {{{ */
   static struct sigaction sa_term;
   static struct sigaction sa_pipe;
 
-  if (stay_foreground)
-    goto child_startup;
-
-  child = fork ();
-  if (child < 0)
+  if (!stay_foreground)
   {
-    fprintf (stderr, "daemonize: fork(2) failed.\n");
-    return (-1);
-  }
-  else if (child > 0)
-  {
-    return (1);
-  }
+    pid_t child;
+    char *base_dir;
 
-  /* Change into the /tmp directory. */
-  base_dir = (config_base_dir != NULL)
-    ? config_base_dir
-    : "/tmp";
-  status = chdir (base_dir);
-  if (status != 0)
-  {
-    fprintf (stderr, "daemonize: chdir (%s) failed.\n", base_dir);
-    return (-1);
-  }
+    child = fork ();
+    if (child < 0)
+    {
+      fprintf (stderr, "daemonize: fork(2) failed.\n");
+      return (-1);
+    }
+    else if (child > 0)
+    {
+      return (1);
+    }
+
+    /* Change into the /tmp directory. */
+    base_dir = (config_base_dir != NULL)
+      ? config_base_dir
+      : "/tmp";
+    status = chdir (base_dir);
+    if (status != 0)
+    {
+      fprintf (stderr, "daemonize: chdir (%s) failed.\n", base_dir);
+      return (-1);
+    }
 
-  /* Become session leader */
-  setsid ();
+    /* Become session leader */
+    setsid ();
 
-  /* Open the first three file descriptors to /dev/null */
-  close (2);
-  close (1);
-  close (0);
+    /* Open the first three file descriptors to /dev/null */
+    close (2);
+    close (1);
+    close (0);
 
-  open ("/dev/null", O_RDWR);
-  dup (0);
-  dup (0);
+    open ("/dev/null", O_RDWR);
+    dup (0);
+    dup (0);
+  } /* if (!stay_foreground) */
 
-child_startup:
   /* Install signal handlers */
   memset (&sa_int, 0, sizeof (sa_int));
   sa_int.sa_handler = sig_int_handler;