OpenBSD: crashing

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/osmocom-sdr@lists.osmocom.org/.

Stuart Henderson stu at spacehopper.org
Fri Apr 19 12:37:18 UTC 2013


On 2013-04-17, Alan Corey <alancorey at yahoo.com> wrote:
> This is with a version of rtl-sdr I got by git last night and OpenBSD
> 5.2 (current release). 5.2 has some pthreads fixing so I waited until
> I bought another computer and loaded it. Are the crashes related to
> threads? I don't know, but possibly. It didn't work with OpenBSD 5.0
> either.
> 
> rtl_fm crashes and uses threads                      
> rtl_adsb crashes and uses threads                    
> rtl_tcp doesn't crash, uses threads, actually stops on ctrl-c
> rtl_test doesn't crash, doesn't use threads, won't stop
> rtl_eeprom doesn't crash, doesn't use threads, ends normally

[snip]

I've just got hold of a card and looking into this.

> (gdb) bt
> #0  0x0abbd98d in kill () from /usr/lib/libc.so.65.0
> #1  0x0ac29545 in abort () at /usr/src/lib/libc/stdlib/abort.c:68
> #2  0x005e9298 in pthread_mutex_unlock (mutexp=0x3c003d8c)
>     at /usr/src/lib/librthread/rthread_sync.c:218
> #3  0x1c00266e in full_demod (fm=0xcfa2de5c)
>     at /usr/src/misc/osmocom/2013-04-15/rtl-sdr/src/rtl_fm.c:583
> #4  0x1c0028ff in demod_thread_fn (arg=0xcfa2de5c)
>     at /usr/src/misc/osmocom/2013-04-15/rtl-sdr/src/rtl_fm.c:641
> #5  0x005ebc2e in _rthread_start (v=0x84da4c00)
>     at /usr/src/lib/librthread/rthread.c:111
> #6  0x0aba62e9 in __tfork_thread () from /usr/lib/libc.so.65.0

By specification, pthread_mutex_unlock() has undefined behaviour when
unlocking a mutex which is already unlocked.

Currently OpenBSD's "undefined behaviour" in this case is to immediately
abort(), which has helped debug problems with some threaded programs.

You can change this behaviour by hacking librthread/rthread_sync.c:218
and building/installing new librthread, this gets rid of the crash but
does not make things work properly; like rtl_test, rtl_fm doesn't stop
when you ^C. I don't get any output from rtl_fm instead I get high
system cpu usage. I suspect this is some issue (quite possibly kernel
driver) with bulk transfers.

rtl_test doesn't work well for me. It starts up but

$ rtl_test                              
Found 1 device(s):
  0:  ezcap USB 2.0 DVB-T/DAB/FM dongle

Using device 0: ezcap USB 2.0 DVB-T/DAB/FM dongle
Found Rafael Micro R820T tuner
Supported gain values (29): 0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6 

Info: This tool will continuously read from the device, and report if
samples get lost. If you observe no further output, everything is fine.

Reading samples in async mode...
lost at least 1228 bytes
lost at least 1924 bytes
lost at least 1892 bytes
lost at least 2588 bytes
lost at least 1648 bytes
[...]

Notably the two programs which do seem to work correctly are rtl_eeprom
and rtl_tcp (at least I get some data from rtl_tcp but don't have
anything setup to use it yet) - notably these two do *not* use
rtlsdr_read_sync i.e. bulk transfers.


> I'd also like to get the -lrt of of the cmake files. OpenBSD doesn't
> use or have lrt, it works without. I can edit it out and compile, but
> every time I run cmake again, I have to edit the files again.

OpenBSD isn't the only system which has the realtime functions
in libc; this might be more generally applicable but note I have
not tested it on a system which *does* have librt.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6b23395..2afb494 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -101,12 +101,21 @@ target_link_libraries(rtl_adsb rtlsdr_shared
 if(UNIX)
 target_link_libraries(rtl_fm m)
 target_link_libraries(rtl_adsb m)
-if(APPLE)
-    target_link_libraries(rtl_test m)
-else()
-    target_link_libraries(rtl_test m rt)
-endif()
-endif()
+
+include(CheckFunctionExists)
+check_function_exists(clock_gettime LIBRT_LIBC_HAS_CLOCK_GETTIME)
+if(LIBRT_LIBC_HAS_CLOCK_GETTIME)
+    set(LIBRT_LIBRARIES)
+    set(LIBRT_LIB_FOUND TRUE)
+else(LIBRT_LIBC_HAS_CLOCK_GETTIME)
+    find_library(LIBRT_LIBRARIES NAMES rt )
+    if(LIBRT_LIBRARIES)
+        set(LIBRT_LIBRARIES TRUE)
+    endif(LIBRT_LIBRARIES)
+endif(LIBRT_LIBC_HAS_CLOCK_GETTIME)
+
+target_link_libraries(rtl_test m ${LIBRT_LIBRARIES})
+endif(UNIX)
 
 if(WIN32)
 target_link_libraries(rtl_sdr libgetopt_static)
diff --git a/src/rtl_test.c b/src/rtl_test.c
index f5a56b8..f84d453 100644
--- a/src/rtl_test.c
+++ b/src/rtl_test.c
@@ -131,7 +131,7 @@ static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx)
 	}
 	ppm_count += (int64_t)len;
 #ifndef _WIN32
-	#ifndef __APPLE__
+	#ifdef CLOCK_REALTIME
 	clock_gettime(CLOCK_REALTIME, &ppm_now);
 	#else
 	gettimeofday(&tv, NULL);
@@ -143,7 +143,7 @@ static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx)
 		ns += (int64_t)(ppm_now.tv_nsec - ppm_recent.tv_nsec);
 		printf("real sample rate: %i\n",
 		(int)((1000000000L * ppm_count / 2L) / ns));
-		#ifndef __APPLE__
+		#ifdef CLOCK_REALTIME
 		clock_gettime(CLOCK_REALTIME, &ppm_recent);
 		#else
 		gettimeofday(&tv, NULL);






More information about the osmocom-sdr mailing list