(nano)sleep not nterrupted by alarm (Ubuntu 11.04 64-bit)

Discussions about using Linux guests in VirtualBox.
Post Reply
krthie
Posts: 13
Joined: 22. Aug 2011, 13:37
Primary OS: MS Windows XP
VBox Version: OSE other
Guest OSses: ubuntu

(nano)sleep not nterrupted by alarm (Ubuntu 11.04 64-bit)

Post by krthie »

Hi

I'm trying to build octave from source, but its configure hangs on "checking for working nanosleep". Closer investigation shows that nanosleep itself works fine, but that the test also checks if it gets interrupted by first scheduling an interrupt with alarm(1). As this never happens, and the configure test askes for a huge sleep-period (which is a bit silly), it appears as if the test hangs.

I can reproduce this by simply compiling and running the code below, which is based on the conftest.c file that configure creates (see end of post).

I've tried to put APIC off, but that doesn't help. Of course, I'm not 100% sure this is a vbox issue, but I didn't find any relevant posts regarding ubuntu on this issue.

My host is Windows 7, latest Virtualbox 4.1.4.

Code: Select all

$ uname -a
Linux splinter-ubuntu64 2.6.38-11-generic #50-Ubuntu SMP Mon Sep 12 21:17:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
I don't have a problem with the 32-bit version of Ubuntu on another machine (Windows XP host), virtualbox 4.1.2.

here is the test code

Code: Select all

          #include <errno.h>
          #include <limits.h>
          #include <signal.h>
          #if HAVE_SYS_TIME_H
           #include <sys/time.h>
          #endif
          #include <time.h>
          #include <unistd.h>
          #include <stdio.h>
          static void
          check_for_SIGALRM (int sig)
          {
            if (sig != SIGALRM)
              _exit (1);
          }

          int
          main ()
          {
            static struct timespec ts_sleep;
            static struct timespec ts_remaining;
            static struct sigaction act;
            if (! nanosleep)
              return 2;
            act.sa_handler = check_for_SIGALRM;
            sigemptyset (&act.sa_mask);
            sigaction (SIGALRM, &act, NULL);
            ts_sleep.tv_sec=12; /* changed this to 2 secs (original test uses MAX_INT) */
            ts_sleep.tv_nsec = 999999999;
            alarm (1);
            if (nanosleep (&ts_sleep, &ts_remaining) != -1)
              {
                printf("\nAfter nanosleep, but no interrupt\n"); return 4;
             }
            else
               printf("\nAfter nanosleep and interrupted\n"); 
            if (errno != EINTR)
              return 5;
            if (ts_remaining.tv_sec <= ts_sleep.tv_sec - 10)
              return 6;
            return 0;
          }

On my system, execution gives the following

Code: Select all

$ gcc -g -o confnano confnano.c 
$ time ./confnano 

After nanosleep, but no interrupt

real	0m13.004s
user	0m0.000s
sys	0m0.000s
 
The expected behaviour (observed for instance when I compile and run this on my host under cygwin) is

Code: Select all

$ time ./confnano

After nanosleep and interrupted

real    0m1.131s
user    0m0.030s
sys     0m0.031s
and the program exits with status 0.

By the way, if I disable the nanosleep test in the configure script, it goes on to test sleep() in a similar fashion, and hangs there as well.
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: (nano)sleep not nterrupted by alarm (Ubuntu 11.04 64-bit

Post by Sasquatch »

To be sure it's a VB issue, or not, boot the system with a live CD and replicate the build environment. You can do that all in a live CD environment, without installing the OS itself. If it hangs there as well, then it's not a VB problem, but either Ubuntu or of the source code that fails when ran on a 64 bit system. As you said, it does work on a 32 bit Guest. Using Cygwin on Windows is not a viable test, as you only check a small part (timing a process execution time).
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
free-variation
Posts: 1
Joined: 10. Feb 2012, 01:08

Re: (nano)sleep not nterrupted by alarm (Ubuntu 11.04 64-bit

Post by free-variation »

On my system the nanosleep freeze happens with both 32bit and 64 bit Ubuntu 11.10. Setup is MacOSX 10.7.3 host and VB 4.1.8 with Guest additions installed. However, if I *uninstall* the guest additions, then the test goes through (in my case it's on building the coreutils). So there's some issue with alarm() and the VB kernel modules.
krthie
Posts: 13
Joined: 22. Aug 2011, 13:37
Primary OS: MS Windows XP
VBox Version: OSE other
Guest OSses: ubuntu

Re: (nano)sleep not nterrupted by alarm (Ubuntu 11.04 64-bit

Post by krthie »

Sasquatch wrote:To be sure it's a VB issue, or not, boot the system with a live CD and replicate the build environment. You can do that all in a live CD environment, without installing the OS itself. If it hangs there as well, then it's not a VB problem, but either Ubuntu or of the source code that fails when ran on a 64 bit system.
sorry for huge delay in testing this with an Ubuntu 11.10 LiveCD on the same laptop. With that setup (i.e. without VB), the conftest.c quoted in my original post works as expected, i.e. it gets interrupted by the scheduled alarm and it exists after 1 sec.

Therefore, this is a VB bug as far as I can see. I will post it to the bugtracker.

My host: Windows 7
VB 4.1.22
Guest OS Ubuntu 11.10
$ uname -a
Linux splinter-ubuntu64 3.0.0-19-generic #33-Ubuntu SMP Thu Apr 19 19:05:14 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
subConscious
Posts: 1
Joined: 19. Oct 2013, 12:59

Re: (nano)sleep not nterrupted by alarm (Ubuntu 11.04 64-bit

Post by subConscious »

Holy thread resurrection Batman...

I am creating a toolchain from scratch (base OS is Debian Sid) in VirtualBox, had the same problem with the latest version.

The solution for me was to switch to a tty not running X/gdm. Strange but true... Give CTRL-ALT-F2 a try, then login/cd/re-run the configure command.
Post Reply