--- phasex/src/phasex.c.orig 2009-09-29 14:09:57.000000000 -0700 +++ phasex/src/phasex.c 2009-09-30 14:28:00.000000000 -0700 @@ -384,9 +384,16 @@ char **envp = environ; char *argvend = (char *)argv; int argsize; + int saved_errno; /* lock down memory (rt hates page faults) */ - mlockall (MCL_CURRENT | MCL_FUTURE); + if (mlockall (MCL_CURRENT | MCL_FUTURE) != 0) { + saved_errno = errno; + if (debug) { + fprintf (stderr, "Unable to unlock memory: errno=%d (%s)\n", + saved_errno, strerror (saved_errno)); + } + } /* get instance number */ phasex_instance = get_instance_num(); @@ -621,7 +628,18 @@ /* start midi thread */ init_rt_mutex (&midi_ready_mutex, 1); if ((ret = pthread_create (&midi_thread_p, NULL, &midi_thread, NULL)) != 0) { - phasex_shutdown ("Unable to start MIDI thread.\n"); + saved_errno = errno; + if (debug) { + fprintf (stderr, "Unable to start MIDI thread: error %d (%s).\n errno=%d (%s)\n", + ret, + (ret == EAGAIN) ? "EAGAIN" : + (ret == EINVAL) ? "EINVAL" : + (ret == EPERM) ? "EPERM" : "", + saved_errno, + strerror (saved_errno)); + phasex_shutdown ("Unrecoverable error. Shutting down.\n"); + } + phasex_shutdown ("Unable to start MIDI thread. Shutting down.\n"); } /* Build filter and envelope tables now that sample rate is known */