Subject: pkg/37652: two fixes for gtkpod
To: None <pkg-manager@netbsd.org, gnats-admin@netbsd.org,>
From: None <charlie@tigress.com>
List: pkgsrc-bugs
Date: 12/31/2007 16:10:03
>Number:         37652
>Category:       pkg
>Synopsis:       mutex unlocking on unlocked mutex / undefined parameter of sysconf call
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Dec 31 16:10:03 +0000 2007
>Originator:     Karl Uwe Lockhoff
>Release:        NetBSD 4.0
>Environment:
System: NetBSD radagast 4.0 NetBSD 4.0 (GENERIC_LAPTOP) #0: Sun Dec 16 00:27:57 PST 2007 builds@wb34:/home/builds/ab/netbsd-4-0-RELEASE/i386/200712160005Z-obj/home/builds/ab/netbsd-4-0-RELEASE/src/sys/arch/i386/compile/GENERIC_LAPTOP i386
Architecture: i386
Machine: i386
>Description:
1. The lock count of conv->mutex in file_convert.c may get zero, which results 
in coredump. I'am not sure if you need the mpeg4ip option to enabaled, so this
called.

2. The sysconf call with _SC_NPROCESSORS_ONLN will not compile on many
systems. Actual the original code is as bad as the fix.

I've included a patch. 

>How-To-Repeat:
1. Try to synchronize an Ipod
2. Try to compile
>Fix:
--- src/file_convert.c.orig	2007-12-18 04:37:43.000000000 +0000
+++ src/file_convert.c	2007-12-31 14:29:36.000000000 +0000
@@ -216,7 +216,7 @@
     gchar *fname_root;      /* filename root of converted file          */
     gchar *fname_extension; /* filename extension of converted file     */
     GPid  pid;              /* PID of child doing the conversion        */
-    gint  stderr;           /* stderr of child doing the conversion     */
+    gint  Cstderr;          /* stderr of child doing the conversion     */
     Track *track;           /* for reference, don't access inside threads! */
     iTunesDB *itdb;         /* for reference, don't access inside threads! */
     gint  threadnum;        /* number of thread working on this track   */
@@ -647,7 +647,11 @@
     conv->max_threads_num = prefs_get_int (FILE_CONVERT_MAX_THREADS_NUM);
     if (conv->max_threads_num == 0)
     {   /* set to maximum available number of processors */
+#if defined(__DragonFly__) || defined(__NetBSD__)
+	conv->max_threads_num = 1;
+#else
 	conv->max_threads_num = sysconf (_SC_NPROCESSORS_ONLN);
+#endif
 	/* paranoia mode on */
 	if (conv->max_threads_num <= 0)
 	{
@@ -2308,7 +2312,7 @@
 				  &ctr->pid,    /* child's PID    */
 				  NULL,         /* child's stdin  */
 				  NULL,         /* child's stdout */
-				  &ctr->stderr, /* child's stderr */
+				  &ctr->Cstderr,/* child's stderr */
 				  &error);
 
 	    child_pid = ctr->pid;
@@ -2334,7 +2338,7 @@
 		gint status;
 
 		/* set up i/o channel to main thread */
-		ctr->gio_channel = g_io_channel_unix_new (ctr->stderr);
+		ctr->gio_channel = g_io_channel_unix_new (ctr->Cstderr);
 		g_io_channel_set_flags (ctr->gio_channel,
 					G_IO_FLAG_NONBLOCK, NULL);
 		g_io_channel_set_close_on_unref (ctr->gio_channel, TRUE);
@@ -3027,7 +3031,7 @@
 	return result;
     }
 
-    g_mutex_unlock (conv->mutex);
+    /* g_mutex_unlock (conv->mutex); */
 
     copy_success = itdb_cp (source_file, dest_file, &error);