From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Fri, 11 Sep 2020 15:54:34 +0000 (+0100) Subject: Ensure the metadata pipe is created, if necessary, when the --with-metadata option... X-Git-Tag: 3.3.8~16^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46c47c01a6cda645bc60569cf528a7940fa9e64e;p=thirdparty%2Fshairport-sync.git Ensure the metadata pipe is created, if necessary, when the --with-metadata option is chosen without dbus or mpris --- diff --git a/common.c b/common.c index c1deea32..cdd4d031 100644 --- a/common.c +++ b/common.c @@ -170,15 +170,18 @@ int create_log_file(const char *path) { int flags = fcntl(fd, F_GETFL); if (flags == -1) { // strerror_r(errno, (char - //*)errorstring, sizeof(errorstring)); debug(1, "create_log_file -- error %d (\"%s\") - //getting flags of pipe: \"%s\".", errno, (char *)errorstring, pathname); + //*)errorstring, sizeof(errorstring)); + //debug(1, "create_log_file -- error %d (\"%s\") getting flags of pipe: \"%s\".", + // errno, + // (char *)errorstring, pathname); } else { flags = fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); // if (flags == -1) { // strerror_r(errno, - //(char *)errorstring, sizeof(errorstring)); debug(1, "create_log_file -- error %d - //(\"%s\") unsetting NONBLOCK of pipe: \"%s\".", errno, (char *)errorstring, - //pathname); + //(char *)errorstring, sizeof(errorstring)); + //debug(1, "create_log_file -- error %d + //(\"%s\") unsetting NONBLOCK of pipe: \"%s\".", errno, + //(char *)errorstring, pathname); } } } diff --git a/configure.ac b/configure.ac index 81b62972..97fc87d1 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.50]) -AC_INIT([shairport-sync], [3.3.7d18], [4265913+mikebrady@users.noreply.github.com]) +AC_INIT([shairport-sync], [3.3.7d19], [4265913+mikebrady@users.noreply.github.com]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([shairport.c]) AC_CONFIG_HEADERS([config.h]) diff --git a/rtsp.c b/rtsp.c index af9e9706..a1eeff13 100644 --- a/rtsp.c +++ b/rtsp.c @@ -1320,7 +1320,6 @@ void metadata_create_multicast_socket(void) { } else { int buffer_size = METADATA_SNDBUF; setsockopt(metadata_sock, SOL_SOCKET, SO_SNDBUF, &buffer_size, sizeof(buffer_size)); - fcntl(fd, F_SETFL, O_NONBLOCK); bzero((char *)&metadata_sockaddr, sizeof(metadata_sockaddr)); metadata_sockaddr.sin_family = AF_INET; metadata_sockaddr.sin_addr.s_addr = inet_addr(config.metadata_sockaddr); @@ -1584,32 +1583,6 @@ void metadata_hub_thread_cleanup_function(__attribute__((unused)) void *arg) { void *metadata_hub_thread_function(__attribute__((unused)) void *ignore) { - // create the fifo, if necessary - size_t pl = strlen(config.metadata_pipename) + 1; - char *path = malloc(pl + 1); - snprintf(path, pl + 1, "%s", config.metadata_pipename); - - mode_t oldumask = umask(000); - if (mkfifo(path, 0666) && errno != EEXIST) - die("Could not create metadata pipe \"%s\".", path); - umask(oldumask); - debug(1, "metadata pipe name is \"%s\".", path); - - // try to open it - fd = try_to_open_pipe_for_writing(path); - // we check that it's not a "real" error. From the "man 2 open" page: - // "ENXIO O_NONBLOCK | O_WRONLY is set, the named file is a FIFO, and no process has the FIFO - // open for reading." Which is okay. - if ((fd == -1) && (errno != ENXIO)) { - char errorstring[1024]; - strerror_r(errno, (char *)errorstring, sizeof(errorstring)); - debug(1, "metadata_hub_thread_function -- error %d (\"%s\") opening pipe: \"%s\".", errno, - (char *)errorstring, path); - warn("can not open metadata pipe -- error %d (\"%s\") opening pipe: \"%s\".", errno, - (char *)errorstring, path); - } - free(path); - // create a pc_queue for passing information to a threaded metadata handler pc_queue_init(&metadata_hub_queue, (char *)&metadata_hub_queue_items, sizeof(metadata_package), metadata_hub_queue_size, "hub"); @@ -1675,6 +1648,33 @@ void *metadata_mqtt_thread_function(__attribute__((unused)) void *ignore) { #endif void metadata_init(void) { + + // create the metadata pipe, if necessary + size_t pl = strlen(config.metadata_pipename) + 1; + char *path = malloc(pl + 1); + snprintf(path, pl + 1, "%s", config.metadata_pipename); + + mode_t oldumask = umask(000); + if (mkfifo(path, 0666) && errno != EEXIST) + die("Could not create metadata pipe \"%s\".", path); + umask(oldumask); + debug(1, "metadata pipe name is \"%s\".", path); + + // try to open it + fd = try_to_open_pipe_for_writing(path); + // we check that it's not a "real" error. From the "man 2 open" page: + // "ENXIO O_NONBLOCK | O_WRONLY is set, the named file is a FIFO, and no process has the FIFO + // open for reading." Which is okay. + if ((fd == -1) && (errno != ENXIO)) { + char errorstring[1024]; + strerror_r(errno, (char *)errorstring, sizeof(errorstring)); + debug(1, "metadata_hub_thread_function -- error %d (\"%s\") opening pipe: \"%s\".", errno, + (char *)errorstring, path); + warn("can not open metadata pipe -- error %d (\"%s\") opening pipe: \"%s\".", errno, + (char *)errorstring, path); + } + free(path); + int ret = pthread_create(&metadata_thread, NULL, metadata_thread_function, NULL); if (ret) debug(1, "Failed to create metadata thread!");