ports/157173: audio/musicpd: wait --kill to finish (FreeBSD-only)
Zhihao Yuan
lichray at gmail.com
Thu May 19 08:10:11 UTC 2011
>Number: 157173
>Category: ports
>Synopsis: audio/musicpd: wait --kill to finish (FreeBSD-only)
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Thu May 19 08:10:10 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator: Zhihao Yuan
>Release: FreeBSD 8.2-STABLE amd64
>Organization:
>Environment:
System: FreeBSD compaq.yuetime 8.2-STABLE FreeBSD 8.2-STABLE #1 r221793M: Wed May 11 21:44:19 CDT 2011 lichray at compaq.yuetime:/home/lichray/temp/obj/home/lichray/devel/freebsd-stable/sys/HOUKAGO amd64
>Description:
mpd does not report its pid/pidfile, while it offers a --kill option. But this option only sends the signal, which makes the `rc.d/musicpd restart` always fails (well... may not be always).
>How-To-Repeat:
>Fix:
I wrote a function to use kevent to wait for the pid. I just make it FreeBSD-specific since I don't want to spend time on autotools.
The idea is borrowed from src/bin/pwait.c
--- musicpd_2-pwait.patch begins here ---
diff -ruN --exclude=CVS /usr/ports/audio/musicpd.orig/Makefile /usr/ports/audio/musicpd/Makefile
--- /usr/ports/audio/musicpd.orig/Makefile 2011-05-16 08:32:35.000000000 -0500
+++ /usr/ports/audio/musicpd/Makefile 2011-05-19 01:11:44.814689280 -0500
@@ -7,7 +7,7 @@
PORTNAME= musicpd
PORTVERSION= 0.16.2
-PORTREVISION= 1
+PORTREVISION= 2
CATEGORIES= audio ipv6
MASTER_SITES= SF/${PORTNAME}/mpd/${PORTVERSION}
DISTNAME= mpd-${PORTVERSION}
diff -ruN --exclude=CVS /usr/ports/audio/musicpd.orig/files/patch-src_daemon.c /usr/ports/audio/musicpd/files/patch-src_daemon.c
--- /usr/ports/audio/musicpd.orig/files/patch-src_daemon.c 1969-12-31 18:00:00.000000000 -0600
+++ /usr/ports/audio/musicpd/files/patch-src_daemon.c 2011-05-19 01:11:29.428807721 -0500
@@ -0,0 +1,45 @@
+--- src/daemon.c.orig 2011-05-19 00:57:23.647296897 -0500
++++ src/daemon.c 2011-05-19 01:10:01.251176681 -0500
+@@ -37,6 +37,11 @@
+ #include <grp.h>
+ #endif
+
++#ifdef __FreeBSD__
++#include <sys/event.h>
++#include <sys/wait.h>
++#endif
++
+ #undef G_LOG_DOMAIN
+ #define G_LOG_DOMAIN "daemon"
+
+@@ -58,6 +63,18 @@ static char *pidfile;
+ static bool had_group = false;
+
+
++int pwait(pid_t pid)
++{
++ int kq = kqueue();
++ struct kevent kev;
++ EV_SET(&kev, pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL);
++ if (kevent(kq, &kev, 1, NULL, 0, NULL) == -1)
++ return -1;
++ if (kevent(kq, NULL, 0, &kev, 1, NULL))
++ return WEXITSTATUS(kev.data);
++ return 1;
++}
++
+ void
+ daemonize_kill(void)
+ {
+@@ -79,7 +96,11 @@ daemonize_kill(void)
+ fclose(fp);
+
+ ret = kill(pid, SIGTERM);
++#ifdef __FreeBSD__
++ if (ret < 0 || pwait(pid) < 0)
++#else
+ if (ret < 0)
++#endif
+ MPD_ERROR("unable to kill proccess %i: %s",
+ pid, g_strerror(errno));
+
--- musicpd_2-pwait.patch ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list