Bug 167971

Summary: [PATCH] audio/jack: ALSA driver is broken
Product: Ports & Packages Reporter: Dmitry Marakasov <amdmi3>
Component: Individual Port(s)Assignee: freebsd-multimedia (Nobody) <multimedia>
Status: Closed FIXED    
Severity: Affects Only Me CC: multimedia
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   

Description Dmitry Marakasov 2012-05-16 17:20:02 UTC
ALSA driver is broken:

---
% jackd -d alsa
jackd 0.121.3
Copyright 2001-2009 Paul Davis, Stephane Letz, Jack O'Quinn, Torben Hohn and others.
jackd comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details

could not open driver .so '/usr/local/lib/jack/jack_alsa.so': /usr/local/lib/jack/jack_alsa.so: Undefined symbol "clock_nanosleep"

could not open driver .so '/usr/local/lib/jack/jack_alsa_midi.so': /usr/local/lib/jack/jack_alsa_midi.so: Undefined symbol "clock_nanosleep"

jackd: unknown driver 'alsa'
---

The cause:

---
% grep -R clock_nanosleep work
work/jack-audio-connection-kit-0.121.3/drivers/alsa-midi/alsa_rawmidi.c:                     clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
---

but this function is not supported on FreeBSD:

---
% grep clock_nanosleep /usr/include/time.h 
/* XXX missing: clock_nanosleep() */
---

and though jack builds:

---
/bin/sh ../../libtool --tag=CC   --mode=compile cc -DHAVE_CONFIG_H -I. -I../..   -I/usr/local/include -I../../config -I../.. -I../.. -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -Wall  -g -O2 -pipe -march=nocona  -fno-strict-aliasing -I../../config -I../.. -I../.. -D_
REENTRANT -D_POSIX_PTHREAD_SEMANTICS -Wall  -g -MT alsa_rawmidi.lo -MD -MP -MF .deps/alsa_rawmidi.Tpo -c -o alsa_rawmidi.lo alsa_rawmidi.c
libtool: compile:  cc -DHAVE_CONFIG_H -I. -I../.. -I/usr/local/include -I../../config -I../.. -I../.. -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -Wall -g -O2 -pipe -march=nocona -fno-strict-aliasing -I../../config -I../.. -I../.. -D_REENTRANT -D_POSIX_PTHREAD_SEMANT
ICS -Wall -g -MT alsa_rawmidi.lo -MD -MP -MF .deps/alsa_rawmidi.Tpo -c alsa_rawmidi.c  -fPIC -DPIC -o .libs/alsa_rawmidi.o
alsa_rawmidi.c: In function 'midi_thread':
alsa_rawmidi.c:856: warning: implicit declaration of function 'clock_nanosleep'
---

the driver is unuseable.

Port maintainer (multimedia@FreeBSD.org) is cc'd.

Generated with FreeBSD Port Tools 0.99_6 (mode: change, diff: CVS)

Fix: 

Since the second argument of clock_nanosleep (flags) is 0, ts still specifies a relative time, so theoretically the call may be replaced with simple nanosleep(&ts, NULL). I'm, however, unaware of differences between CLOCK_MONOTONIC and other clock types, as well as which of them is used by FreeBSD's nanosleep(), so it may have implications.
How-To-Repeat: Try to use ALSA driver
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2012-05-16 17:20:17 UTC
Responsible Changed
From-To: freebsd-ports-bugs->freebsd-multimedia

Over to maintainer (via the GNATS Auto Assign Tool)
Comment 2 Dmitry Marakasov 2012-05-16 18:28:37 UTC
* Dmitry Marakasov (amdmi3@amdmi3.ru) wrote:
> Since the second argument of clock_nanosleep (flags) is 0, ts still specifies a relative time, so theoretically the call may be replaced with simple nanosleep(&ts, NULL). I'm, however, unaware of differences between CLOCK_MONOTONIC and other clock types, as well as which of them is used by FreeBSD's nanosleep(), so it may have implications.

NB: the same fix is used in multimedia/gavl
file:///usr/ports/multimedia/gavl/files/patch-gavl-time.c

and, judging from Linux man it should be safe:

http://linux.die.net/man/2/nanosleep:
---
POSIX.1 specifies that nanosleep() should measure time against the
CLOCK_REALTIME clock. However, Linux measures the time using the
CLOCK_MONOTONIC clock. This probably does not matter, since the POSIX.1
specification for clock_settime(2) says that discontinuous changes in
CLOCK_REALTIME should not affect nanosleep()
---

Thus, if FreeBSD nanosleep conforms to POSIX.1, it shouldn't matter for
FreeBSD as well, so clock_nanosleep(CLOCK_MONOTONIC, 0, ...) ->
nanosleep(...) replacement is safe.

Thus, the PR is fixed by this patch
(http://people.freebsd.org/~amdmi3/patch-drivers-alsa-midi-alsa_rawmidi.c):

--- ./drivers/alsa-midi/alsa_rawmidi.c.orig	2008-05-29 16:26:07.000000000 +0400
+++ ./drivers/alsa-midi/alsa_rawmidi.c	2012-05-16 20:10:24.645166068 +0400
@@ -853,7 +853,7 @@
 			struct timespec ts;
 			ts.tv_sec = 0;
 			ts.tv_nsec = wait_nanosleep;
-			clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
+			nanosleep(&ts, NULL);
 		}
 		int res = poll((struct pollfd*)&pfds, npfds, poll_timeout);
 		//debug_log("midi_thread(%s): poll exit: %d", str->name, res);

-- 
Dmitry Marakasov   .   55B5 0596 FF1E 8D84 5F56  9510 D35A 80DD F9D2 F77D
amdmi3@amdmi3.ru  ..:  jabber: amdmi3@jabber.ru    http://www.amdmi3.ru
Comment 3 dfilter service freebsd_committer freebsd_triage 2012-05-24 20:36:10 UTC
nox         2012-05-24 19:35:56 UTC

  FreeBSD ports repository

  Modified files:
    audio/jack           Makefile 
  Added files:
    audio/jack/files     patch-drivers-alsa-midi-alsa_rawmidi.c 
  Log:
  - Fix alsa driver.
  - Bump PORTREVISION.
  
  PR:             ports/167971
  Submitted by:   amdmi3
  
  Revision  Changes    Path
  1.65      +1 -1      ports/audio/jack/Makefile
  1.1       +11 -0     ports/audio/jack/files/patch-drivers-alsa-midi-alsa_rawmidi.c (new)
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 4 Juergen Lock freebsd_committer freebsd_triage 2012-05-24 20:36:42 UTC
State Changed
From-To: open->closed

Committed. Thanks!