$OpenBSD: patch-src_file_convert_c,v 1.1 2007/11/22 22:46:42 ckuethe Exp $
--- src/file_convert.c.orig	Sun Nov 18 11:25:06 2007
+++ src/file_convert.c	Sun Nov 18 11:34:35 2007
@@ -33,6 +33,10 @@
 #   include <config.h>
 #endif
 
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/wait.h>
 #include "display_itdb.h"
 #include "file_convert.h"
 #include "info.h"
@@ -43,9 +47,6 @@
 #include <glib/gstdio.h>
 #include <signal.h>
 #include <string.h>
-#include <sys/types.h>
-#include <sys/types.h>
-#include <sys/wait.h>
 #include <unistd.h>
 
 #undef DEBUG_CONV
@@ -216,7 +217,7 @@ struct _ConvTrack
     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  mystderr;         /* 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   */
@@ -624,6 +625,8 @@ static void conversion_prefs_changed (Conversion *conv
     gboolean background_transfer;
     gdouble maxsize;
     GList *gl;
+    int mib[2], ncpus;
+    size_t len;
 
     g_return_if_fail (conv);
 
@@ -645,13 +648,16 @@ static void conversion_prefs_changed (Conversion *conv
     }
 
     conv->max_threads_num = prefs_get_int (FILE_CONVERT_MAX_THREADS_NUM);
+    mib[0] = CTL_HW;
+    mib[1] = HW_NCPU;
+    len = sizeof(ncpus);
     if (conv->max_threads_num == 0)
     {   /* set to maximum available number of processors */
-	conv->max_threads_num = sysconf (_SC_NPROCESSORS_ONLN);
-	/* paranoia mode on */
-	if (conv->max_threads_num <= 0)
-	{
+	if ((sysctl(mib, 2, &ncpus, &len, NULL, 0) == -1) || (ncpus < 1)){
+	    /* paranoia mode on */
 	    conv->max_threads_num = 1;
+	} else {
+	    conv->max_threads_num = ncpus;
 	}
     }
 
@@ -2296,7 +2302,7 @@ static gboolean conversion_convert_track (Conversion *
 				  &ctr->pid,    /* child's PID    */
 				  NULL,         /* child's stdin  */
 				  NULL,         /* child's stdout */
-				  &ctr->stderr, /* child's stderr */
+				  &ctr->mystderr, /* child's stderr */
 				  &error);
 
 	    child_pid = ctr->pid;
@@ -2322,7 +2328,7 @@ static gboolean conversion_convert_track (Conversion *
 		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->mystderr);
 		g_io_channel_set_flags (ctr->gio_channel,
 					G_IO_FLAG_NONBLOCK, NULL);
 		g_io_channel_set_close_on_unref (ctr->gio_channel, TRUE);
