From: Mike Brady Date: Mon, 15 Apr 2019 10:13:14 +0000 (+0100) Subject: Fix a warning about ending a funrtion without a return value. X-Git-Tag: 3.3rc4~2^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=042dd0d03670ace193dbf4163f7e25c8232edeb3;p=thirdparty%2Fshairport-sync.git Fix a warning about ending a funrtion without a return value. --- diff --git a/mdns_external.c b/mdns_external.c index 2eae8204..2ae23c61 100644 --- a/mdns_external.c +++ b/mdns_external.c @@ -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 #include #include @@ -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) {