]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Fix a warning about ending a funrtion without a return value.
authorMike Brady <mikebrady@eircom.net>
Mon, 15 Apr 2019 10:13:14 +0000 (11:13 +0100)
committerMike Brady <mikebrady@eircom.net>
Mon, 15 Apr 2019 10:13:14 +0000 (11:13 +0100)
mdns_external.c

index 2eae8204252aaed3851cd2dfb93de16b5f8125ca..2ae23c61f4235a350c905e4be23aa7d9a35dd4ac 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * mDNS registration handler. This file is part of Shairport.
  * Copyright (c) Paul Lietar 2013
+ * Amendments and updates copyright (c) Mike Brady 2014 -- 2019
  * All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person
@@ -24,8 +25,8 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-#include "common.h"
 #include "mdns.h"
+#include "common.h"
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -41,45 +42,42 @@ int mdns_pid = 0;
  */
 static int fork_execvp(const char *file, char *const argv[]) {
   int execpipe[2];
-  int pid = 0;
-  if (pipe(execpipe) < 0) {
-    return -1;
-  }
-
-  if (fcntl(execpipe[1], F_SETFD, fcntl(execpipe[1], F_GETFD) | FD_CLOEXEC) < 0) {
-    close(execpipe[0]);
-    close(execpipe[1]);
-    return -1;
-  }
-
-  pid = fork();
-  if (pid < 0) {
-    close(execpipe[0]);
-    close(execpipe[1]);
-    return -1;
-  } else if (pid == 0) { // Child
-    close(execpipe[0]);  // Close the read end
-    execvp(file, argv);
-
-    // If we reach this point then execve has failed.
-    // Write erno's value into the pipe and exit.
-    if (write(execpipe[1], &errno, sizeof(errno)) != sizeof(errno))
-      debug(1, "Execve has failed and there was a further error writing an error message, duh.");
-    die("mdns_external: execve has failed.");
-    // return 0;           // Just to make the compiler happy.
-  } else {              // Parent
-    close(execpipe[1]); // Close the write end
-
-    int childErrno;
-    // Block until child closes the pipe or sends errno.
-    if (read(execpipe[0], &childErrno, sizeof(childErrno)) ==
-        sizeof(childErrno)) { // We received errno
-      errno = childErrno;
-      return -1;
-    } else { // Child closed the pipe. execvp was successful.
-      return pid;
+  int response = -1;
+  if (pipe(execpipe) >= 0) {
+
+    if (fcntl(execpipe[1], F_SETFD, fcntl(execpipe[1], F_GETFD) | FD_CLOEXEC) < 0) {
+      close(execpipe[0]);
+      close(execpipe[1]);
+    } else {
+
+      int pid = fork();
+      if (pid < 0) {
+        close(execpipe[0]);
+        close(execpipe[1]);
+      } else if (pid == 0) { // Child
+        close(execpipe[0]);  // Close the read end
+        execvp(file, argv);
+        // If we reach this point then execve has failed.
+        // Write erno's value into the pipe and exit.
+        if (write(execpipe[1], &errno, sizeof(errno)) != sizeof(errno))
+          debug(1,
+                "Execve has failed and there was a further error writing an error message, duh.");
+        die("mdns_external: execve has failed.");
+      } else {              // Parent
+        close(execpipe[1]); // Close the write end
+
+        int childErrno;
+        // Block until child closes the pipe or sends errno.
+        if (read(execpipe[0], &childErrno, sizeof(childErrno)) ==
+            sizeof(childErrno)) { // We received errno
+          errno = childErrno;
+        } else {
+          response = pid;
+        }
+      }
     }
   }
+  return response;
 }
 
 static int mdns_external_avahi_register(char *apname, __attribute__((unused)) int port) {