> -----Original Message----- > From: Martin Sebor [mailto:[EMAIL PROTECTED] > Sent: Thursday, November 30, 2006 12:05 AM > To: stdcxx-dev@incubator.apache.org > Subject: Re: svn commit: r472469 - in > /incubator/stdcxx/trunk/tests: include/rw_process.h > self/0.process.cpp src/process.cpp > > This change is causing link failures Solaris builds. > See for example (search for nanosleep): > http://people.apache.org/~sebor/stdcxx/results/solaris-10-spar > cv9-sunpro-64b-5.8-11s-log.gz.txt > > On Solaris, the function is defined in the realtime library, > librt.so, which we don't link with: > http://docs.sun.com/app/docs/doc/816-5171/6mbb6dcoe?a=view#ind > exterm-87 > > Please note that nanosleep() is an optional (REALTIME) > feature of POSIX that's not required to be provided by > conforming implementations, so we can't assume it will be > available everywhere: > http://www.opengroup.org/onlinepubs/009695399/functions/nanosleep.html
sleep() can be used instead of nanosleep()? ChangeLog: * process.cpp: Removed unused #include <time.h> (rw_waitpid): Used sleep() instead of nanosleep() (rw_process_kill): Corrected timeout value to 1 second Farid.
Index: process.cpp =================================================================== --- process.cpp (revision 480885) +++ process.cpp (working copy) @@ -152,10 +152,9 @@ # include <sys/types.h> # include <sys/wait.h> // for waitpid() -# include <unistd.h> // for fork(), execv(), access() +# include <unistd.h> // for fork(), execv(), access(), sleep() # include <setjmp.h> // for setjmp(), longjmp() # include <signal.h> // for signal() -# include <time.h> // for nanosleep() /**************************************************************************/ @@ -509,37 +508,30 @@ if (0 < timeout && 0 == ret) { // process still active, wait sig_handler_t* old_handler = signal (SIGCHLD, sig_handler); - timespec rem = { timeout, 0 }; + unsigned utimeout = unsigned (timeout); + do { - timespec req = rem; - if (-1 == nanosleep (&req, &rem)) { - if (EINTR == errno) { - // possible that the child has exited - ret = waitpid (pid, &status, WNOHANG); - if (-1 == ret) { - rw_error (0, __FILE__, __LINE__, - "waitpid (%{P}, %#p, WNOHANG) failed: " - "errno = %{#m} (%{m})", - pid, &status); - } - else if (0 == ret) { - // child still active - continue; - } - else { - // child has exited - RW_ASSERT (pid == ret); - } - } - else { + rw_info (0, 0, 0, "before sleep: %u", utimeout); + utimeout = sleep (utimeout); + rw_info (0, 0, 0, "after sleep: %u", utimeout); + if (utimeout) { + // possible that the child has exited + ret = waitpid (pid, &status, WNOHANG); + if (-1 == ret) { rw_error (0, __FILE__, __LINE__, - "nanosleep (&{%i, 0}, %#p) failed: " + "waitpid (%{P}, %#p, WNOHANG) failed: " "errno = %{#m} (%{m})", - timeout, &rem); - - ret = -1; + pid, &status); } + else if (0 == ret) { + // child still active + continue; + } + else { + // child has exited + RW_ASSERT (pid == ret); + } } else { // timeout elapsed @@ -590,7 +582,7 @@ rw_process_kill (rw_pid_t pid, int signo) { // timeout for rw_wait_pid - const int timeout = 1000; + const int timeout = 1; #if defined (_WIN32)