Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package usbmuxd for openSUSE:Factory checked in at 2021-04-27 21:35:02 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/usbmuxd (Old) and /work/SRC/openSUSE:Factory/.usbmuxd.new.12324 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "usbmuxd" Tue Apr 27 21:35:02 2021 rev:34 rq:888624 version:1.1.1 Changes: -------- --- /work/SRC/openSUSE:Factory/usbmuxd/usbmuxd.changes 2021-02-04 20:24:52.722899755 +0100 +++ /work/SRC/openSUSE:Factory/.usbmuxd.new.12324/usbmuxd.changes 2021-04-27 21:35:24.836058036 +0200 @@ -1,0 +2,10 @@ +Fri Apr 23 17:17:18 UTC 2021 - Michael Gorse <[email protected]> + +- Add usbmuxd-add-socket-option.patch: allow socket to be + specified via the command line. Backported from upstream. +- Add usbmuxd-add-pid-option.patch: allow the pid file to be + specified via the command line. Taken from upstream. +- Add usbmuxd-run-dir.patch: use /run, rather than /var/run, for + the socket and pid file (bsc#1185186). + +------------------------------------------------------------------- New: ---- usbmuxd-add-pid-option.patch usbmuxd-add-socket-option.patch usbmuxd-run-dir.patch ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ usbmuxd.spec ++++++ --- /var/tmp/diff_new_pack.9Vc37Z/_old 2021-04-27 21:35:25.304058806 +0200 +++ /var/tmp/diff_new_pack.9Vc37Z/_new 2021-04-27 21:35:25.308058813 +0200 @@ -26,6 +26,9 @@ URL: https://github.com/libimobiledevice/usbmuxd Source: https://github.com/libimobiledevice/usbmuxd/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz Source99: baselibs.conf +Patch0: usbmuxd-add-socket-option.patch +Patch1: usbmuxd-add-pid-option.patch +Patch2: usbmuxd-run-dir.patch BuildRequires: autoconf BuildRequires: automake BuildRequires: gcc-c++ @@ -48,7 +51,7 @@ multiplexing several conversations onto a single pair of wires. %prep -%autosetup +%autosetup -p1 %build autoreconf -fiv ++++++ usbmuxd-add-pid-option.patch ++++++ >From 4b3847cc977c4c4fd9973abb772d9dba64911b70 Mon Sep 17 00:00:00 2001 From: Nikias Bassen <[email protected]> Date: Mon, 11 Jan 2021 05:07:45 +0100 Subject: [PATCH 3/3] Add option to allow changing the location of or disabling the pidfile --- src/main.c | 96 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 59 insertions(+), 37 deletions(-) diff --git a/src/main.c b/src/main.c index c1d1edf..8702a4b 100644 --- a/src/main.c +++ b/src/main.c @@ -54,7 +54,8 @@ #include "conf.h" static const char *socket_path = "/var/run/usbmuxd"; -static const char *lockfile = "/var/run/usbmuxd.pid"; +#define DEFAULT_LOCKFILE "/var/run/usbmuxd.pid" +static const char *lockfile = DEFAULT_LOCKFILE; // Global state used in other files int should_exit; @@ -519,6 +520,8 @@ static void usage() printf(" -S, --socket ADDR:PORT | PATH Specify source ADDR and PORT or a UNIX\n"); printf(" \t\tsocket PATH to use for the listening socket.\n"); printf(" \t\tDefault: %s\n", socket_path); + printf(" -P, --pidfile PATH\tSpecify a different location for the pid file, or pass\n"); + printf(" \t\tNONE to disable. Default: %s\n", DEFAULT_LOCKFILE); printf(" -x, --exit\t\tNotify a running instance to exit if there are no devices\n"); printf(" \t\tconnected (sends SIGUSR1 to running instance) and exit.\n"); printf(" -X, --force-exit\tNotify a running instance to exit even if there are still\n"); @@ -547,6 +550,7 @@ static void parse_opts(int argc, char **argv) {"systemd", no_argument, NULL, 's'}, #endif {"socket", required_argument, NULL, 'S'}, + {"pidfile", required_argument, NULL, 'P'}, {"exit", no_argument, NULL, 'x'}, {"force-exit", no_argument, NULL, 'X'}, {"logfile", required_argument, NULL, 'l'}, @@ -556,11 +560,11 @@ static void parse_opts(int argc, char **argv) int c; #ifdef HAVE_SYSTEMD - const char* opts_spec = "hfvVuU:xXsnzl:pS:"; + const char* opts_spec = "hfvVuU:xXsnzl:pS:P:"; #elif HAVE_UDEV - const char* opts_spec = "hfvVuU:xXnzl:pS:"; + const char* opts_spec = "hfvVuU:xXnzl:pS:P:"; #else - const char* opts_spec = "hfvVU:xXnzl:pS:"; + const char* opts_spec = "hfvVU:xXnzl:pS:P:"; #endif while (1) { @@ -615,6 +619,18 @@ static void parse_opts(int argc, char **argv) } listen_addr = optarg; break; + case 'P': + if (!*optarg || *optarg == '-') { + usbmuxd_log(LL_FATAL, "ERROR: --pidfile requires an argument"); + usage(); + exit(2); + } + if (!strcmp(optarg, "NONE")) { + lockfile = NULL; + } else { + lockfile = optarg; + } + break; case 'x': opt_exit = 1; exit_signal = SIGUSR1; @@ -676,19 +692,21 @@ int main(int argc, char *argv[]) set_signal_handlers(); signal(SIGPIPE, SIG_IGN); - res = lfd = open(lockfile, O_WRONLY|O_CREAT, 0644); - if(res == -1) { - usbmuxd_log(LL_FATAL, "Could not open lockfile"); - goto terminate; + if (lockfile) { + res = lfd = open(lockfile, O_WRONLY|O_CREAT, 0644); + if(res == -1) { + usbmuxd_log(LL_FATAL, "Could not open lockfile"); + goto terminate; + } + lock.l_type = F_WRLCK; + lock.l_whence = SEEK_SET; + lock.l_start = 0; + lock.l_len = 0; + lock.l_pid = 0; + fcntl(lfd, F_GETLK, &lock); + close(lfd); } - lock.l_type = F_WRLCK; - lock.l_whence = SEEK_SET; - lock.l_start = 0; - lock.l_len = 0; - lock.l_pid = 0; - fcntl(lfd, F_GETLK, &lock); - close(lfd); - if (lock.l_type != F_UNLCK) { + if (lockfile && lock.l_type != F_UNLCK) { if (opt_exit) { if (lock.l_pid && !kill(lock.l_pid, 0)) { usbmuxd_log(LL_NOTICE, "Sending signal %d to instance with pid %d", exit_signal, lock.l_pid); @@ -724,7 +742,9 @@ int main(int argc, char *argv[]) goto terminate; } } - unlink(lockfile); + if (lockfile) { + unlink(lockfile); + } if (opt_exit) { usbmuxd_log(LL_NOTICE, "No running instance found, none killed. Exiting."); @@ -739,26 +759,28 @@ int main(int argc, char *argv[]) } } - // now open the lockfile and place the lock - res = lfd = open(lockfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644); - if(res < 0) { - usbmuxd_log(LL_FATAL, "Could not open lockfile"); - goto terminate; - } - lock.l_type = F_WRLCK; - lock.l_whence = SEEK_SET; - lock.l_start = 0; - lock.l_len = 0; - if ((res = fcntl(lfd, F_SETLK, &lock)) < 0) { - usbmuxd_log(LL_FATAL, "Lockfile locking failed!"); - goto terminate; - } - sprintf(pids, "%d", getpid()); - if ((size_t)(res = write(lfd, pids, strlen(pids))) != strlen(pids)) { - usbmuxd_log(LL_FATAL, "Could not write pidfile!"); - if(res >= 0) - res = -2; - goto terminate; + if (lockfile) { + // now open the lockfile and place the lock + res = lfd = open(lockfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644); + if(res < 0) { + usbmuxd_log(LL_FATAL, "Could not open pidfile '%s'", lockfile); + goto terminate; + } + lock.l_type = F_WRLCK; + lock.l_whence = SEEK_SET; + lock.l_start = 0; + lock.l_len = 0; + if ((res = fcntl(lfd, F_SETLK, &lock)) < 0) { + usbmuxd_log(LL_FATAL, "Locking pidfile '%s' failed!", lockfile); + goto terminate; + } + sprintf(pids, "%d", getpid()); + if ((size_t)(res = write(lfd, pids, strlen(pids))) != strlen(pids)) { + usbmuxd_log(LL_FATAL, "Could not write pidfile!"); + if(res >= 0) + res = -2; + goto terminate; + } } // set number of file descriptors to higher value -- 2.31.1 ++++++ usbmuxd-add-socket-option.patch ++++++ diff -urp usbmuxd-1.1.1.orig/src/main.c usbmuxd-1.1.1/src/main.c --- usbmuxd-1.1.1.orig/src/main.c 2020-06-15 13:21:24.000000000 -0500 +++ usbmuxd-1.1.1/src/main.c 2021-04-23 11:30:58.872929406 -0500 @@ -1,7 +1,7 @@ /* * main.c * - * Copyright (C) 2009-2019 Nikias Bassen <[email protected]> + * Copyright (C) 2009-2021 Nikias Bassen <[email protected]> * Copyright (C) 2013-2014 Martin Szulecki <[email protected]> * Copyright (C) 2009 Hector Martin <[email protected]> * Copyright (C) 2009 Paul Sladen <[email protected]> @@ -36,6 +36,9 @@ #include <unistd.h> #include <sys/socket.h> #include <sys/un.h> +#include <netinet/in.h> +#include <netdb.h> +#include <arpa/inet.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/resource.h> @@ -69,22 +72,162 @@ static int opt_enable_exit = 0; static int opt_exit = 0; static int exit_signal = 0; static int daemon_pipe; +static const char *listen_addr = NULL; static int report_to_parent = 0; -static int create_socket(void) { - struct sockaddr_un bind_addr; +static int create_socket(void) +{ int listenfd; + const char* socket_addr = socket_path; + const char* tcp_port; + char listen_addr_str[256]; + + if (listen_addr) { + socket_addr = listen_addr; + } + tcp_port = strrchr(socket_addr, ':'); + if (tcp_port) { + tcp_port++; + size_t nlen = tcp_port - socket_addr; + char* hostname = malloc(nlen); + struct addrinfo hints; + struct addrinfo *result, *rp; + int yes = 1; + int res; + + strncpy(hostname, socket_addr, nlen-1); + hostname[nlen-1] = '\0'; + + memset(&hints, '\0', sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV; + hints.ai_protocol = IPPROTO_TCP; + + res = getaddrinfo(hostname, tcp_port, &hints, &result); + free(hostname); + if (res != 0) { + usbmuxd_log(LL_FATAL, "%s: getaddrinfo() failed: %s\n", __func__, gai_strerror(res)); + return -1; + } - if(unlink(socket_path) == -1 && errno != ENOENT) { - usbmuxd_log(LL_FATAL, "unlink(%s) failed: %s", socket_path, strerror(errno)); - return -1; - } + for (rp = result; rp != NULL; rp = rp->ai_next) { + listenfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); + if (listenfd == -1) { + listenfd = -1; + continue; + } - listenfd = socket(AF_UNIX, SOCK_STREAM, 0); - if (listenfd == -1) { - usbmuxd_log(LL_FATAL, "socket() failed: %s", strerror(errno)); - return -1; + if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (void*)&yes, sizeof(int)) == -1) { + usbmuxd_log(LL_ERROR, "%s: setsockopt(): %s", __func__, strerror(errno)); + close(listenfd); + listenfd = -1; + continue; + } + +#ifdef SO_NOSIGPIPE + if (setsockopt(listenfd, SOL_SOCKET, SO_NOSIGPIPE, (void*)&yes, sizeof(int)) == -1) { + usbmuxd_log(LL_ERROR, "%s: setsockopt(): %s", __func__, strerror(errno)); + close(listenfd); + listenfd = -1; + continue; + } +#endif + +#if defined(AF_INET6) && defined(IPV6_V6ONLY) + if (rp->ai_family == AF_INET6) { + if (setsockopt(listenfd, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&yes, sizeof(int)) == -1) { + usbmuxd_log(LL_ERROR, "%s: setsockopt() IPV6_V6ONLY: %s", __func__, strerror(errno)); + } + } +#endif + + if (bind(listenfd, rp->ai_addr, rp->ai_addrlen) < 0) { + usbmuxd_log(LL_FATAL, "%s: bind() failed: %s", __func__, strerror(errno)); + close(listenfd); + listenfd = -1; + continue; + } + + const void *addrdata = NULL; + if (rp->ai_family == AF_INET) { + addrdata = &((struct sockaddr_in*)rp->ai_addr)->sin_addr; + } +#ifdef AF_INET6 + else if (rp->ai_family == AF_INET6) { + addrdata = &((struct sockaddr_in6*)rp->ai_addr)->sin6_addr; + } +#endif + if (addrdata) { + char* endp = NULL; + uint16_t listen_port = 0; + if (rp->ai_family == AF_INET) { + listen_port = ntohs(((struct sockaddr_in*)rp->ai_addr)->sin_port); + if (inet_ntop(AF_INET, addrdata, listen_addr_str, sizeof(listen_addr_str)-6)) { + endp = &listen_addr_str[0] + strlen(listen_addr_str); + } + } +#ifdef AF_INET6 + else if (rp->ai_family == AF_INET6) { + listen_port = ntohs(((struct sockaddr_in6*)rp->ai_addr)->sin6_port); + listen_addr_str[0] = '['; + if (inet_ntop(AF_INET6, addrdata, listen_addr_str+1, sizeof(listen_addr_str)-8)) { + endp = &listen_addr_str[0] + strlen(listen_addr_str); + } + if (endp) { + *endp = ']'; + endp++; + } + } +#endif + if (endp) { + sprintf(endp, ":%u", listen_port); + } + } + break; + } + freeaddrinfo(result); + if (listenfd == -1) { + usbmuxd_log(LL_FATAL, "%s: Failed to create listening socket", __func__); + return -1; + } + } else { + struct sockaddr_un bind_addr; + + if (strcmp(socket_addr, socket_path) != 0) { + struct stat fst; + if (stat(socket_addr, &fst) == 0) { + if (!S_ISSOCK(fst.st_mode)) { + usbmuxd_log(LL_FATAL, "FATAL: File '%s' already exists and is not a socket file. Refusing to continue.", socket_addr); + return -1; + } + } + } + + if (unlink(socket_addr) == -1 && errno != ENOENT) { + usbmuxd_log(LL_FATAL, "%s: unlink(%s) failed: %s", __func__, socket_addr, strerror(errno)); + return -1; + } + + listenfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (listenfd == -1) { + usbmuxd_log(LL_FATAL, "socket() failed: %s", strerror(errno)); + return -1; + } + + bzero(&bind_addr, sizeof(bind_addr)); + bind_addr.sun_family = AF_UNIX; + strncpy(bind_addr.sun_path, socket_addr, sizeof(bind_addr.sun_path)); + bind_addr.sun_path[sizeof(bind_addr.sun_path) - 1] = '\0'; + + if (bind(listenfd, (struct sockaddr*)&bind_addr, sizeof(bind_addr)) != 0) { + usbmuxd_log(LL_FATAL, "bind() failed: %s", strerror(errno)); + return -1; + } + chmod(socket_addr, 0666); + + snprintf(listen_addr_str, sizeof(listen_addr_str), "%s", socket_addr); } int flags = fcntl(listenfd, F_GETFL, 0); @@ -96,21 +239,13 @@ static int create_socket(void) { } } - bzero(&bind_addr, sizeof(bind_addr)); - bind_addr.sun_family = AF_UNIX; - strcpy(bind_addr.sun_path, socket_path); - if (bind(listenfd, (struct sockaddr*)&bind_addr, sizeof(bind_addr)) != 0) { - usbmuxd_log(LL_FATAL, "bind() failed: %s", strerror(errno)); - return -1; - } - // Start listening if (listen(listenfd, 5) != 0) { usbmuxd_log(LL_FATAL, "listen() failed: %s", strerror(errno)); return -1; } - chmod(socket_path, 0666); + usbmuxd_log(LL_INFO, "Listening on %s", listen_addr_str); return listenfd; } @@ -381,6 +516,9 @@ static void usage() #ifdef HAVE_SYSTEMD printf(" -s, --systemd\t\tRun in systemd operation mode (implies -z and -f).\n"); #endif + printf(" -S, --socket ADDR:PORT | PATH Specify source ADDR and PORT or a UNIX\n"); + printf(" \t\tsocket PATH to use for the listening socket.\n"); + printf(" \t\tDefault: %s\n", socket_path); printf(" -x, --exit\t\tNotify a running instance to exit if there are no devices\n"); printf(" \t\tconnected (sends SIGUSR1 to running instance) and exit.\n"); printf(" -X, --force-exit\tNotify a running instance to exit even if there are still\n"); @@ -408,6 +546,7 @@ static void parse_opts(int argc, char ** #ifdef HAVE_SYSTEMD {"systemd", no_argument, NULL, 's'}, #endif + {"socket", required_argument, NULL, 'S'}, {"exit", no_argument, NULL, 'x'}, {"force-exit", no_argument, NULL, 'X'}, {"logfile", required_argument, NULL, 'l'}, @@ -417,11 +556,11 @@ static void parse_opts(int argc, char ** int c; #ifdef HAVE_SYSTEMD - const char* opts_spec = "hfvVuU:xXsnzl:p"; + const char* opts_spec = "hfvVuU:xXsnzl:pS:"; #elif HAVE_UDEV - const char* opts_spec = "hfvVuU:xXnzl:p"; + const char* opts_spec = "hfvVuU:xXnzl:pS:"; #else - const char* opts_spec = "hfvVU:xXnzl:p"; + const char* opts_spec = "hfvVU:xXnzl:pS:"; #endif while (1) { @@ -468,6 +607,14 @@ static void parse_opts(int argc, char ** case 'z': opt_enable_exit = 1; break; + case 'S': + if (!*optarg || *optarg == '-') { + usbmuxd_log(LL_FATAL, "ERROR: --socket requires an argument"); + usage(); + exit(2); + } + listen_addr = optarg; + break; case 'x': opt_exit = 1; exit_signal = SIGUSR1; ++++++ usbmuxd-run-dir.patch ++++++ diff -urp usbmuxd-1.1.1.orig/systemd/usbmuxd.service.in usbmuxd-1.1.1/systemd/usbmuxd.service.in --- usbmuxd-1.1.1.orig/systemd/usbmuxd.service.in 2020-06-15 13:21:24.000000000 -0500 +++ usbmuxd-1.1.1/systemd/usbmuxd.service.in 2021-04-23 12:15:34.863057718 -0500 @@ -3,5 +3,5 @@ Description=Socket daemon for the usbmux Documentation=man:usbmuxd(8) [Service] -ExecStart=@sbindir@/usbmuxd --user usbmux --systemd -PIDFile=@localstatedir@/run/usbmuxd.pid +ExecStart=@sbindir@/usbmuxd --user usbmux --systemd -S /run/usbmuxd -P /run/usbmuxd.pid +PIDFile=/run/usbmuxd.pid
