You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2007/10/26 20:17:56 UTC
svn commit: r588734 - in /incubator/stdcxx/branches/4.2.x/util: cmdopt.cpp
exec.cpp util.cpp util.h
Author: sebor
Date: Fri Oct 26 11:17:55 2007
New Revision: 588734
URL: http://svn.apache.org/viewvc?rev=588734&view=rev
Log:
2007-10-26 Martin Sebor <se...@roguewave.com>
* util.h (rw_sleep, rw_signal): Declared helper functions.
* cmdopt.cpp (rw_sleep, rw_signal): Moved formerly static
functions from here...
* util.cpp: ...to here and declared extern.
* exec.cpp (SIGHUP, SIGQUIT, SIGKILL, SIGALRM, ESRCH, EINTR,
ECHILD, EINVAL): #defined macros when they're not #defined
in system headers.
[!_RWSTD_NO_PURE_C_HEADERS] (kill, fdopen): Declared.
(wait_for_child): Called rw_signal() instead of sigaction()
directly.
STDCXX-414
* util.cpp: [!_RWSTD_NO_PURE_C_HEADERS] (rw_signal): Implemented
in terms of signal() instead of sigaction() so as to avoid
a dependency on POSIX symbols in <signal.h>.
Modified:
incubator/stdcxx/branches/4.2.x/util/cmdopt.cpp
incubator/stdcxx/branches/4.2.x/util/exec.cpp
incubator/stdcxx/branches/4.2.x/util/util.cpp
incubator/stdcxx/branches/4.2.x/util/util.h
Modified: incubator/stdcxx/branches/4.2.x/util/cmdopt.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.x/util/cmdopt.cpp?rev=588734&r1=588733&r2=588734&view=diff
==============================================================================
--- incubator/stdcxx/branches/4.2.x/util/cmdopt.cpp (original)
+++ incubator/stdcxx/branches/4.2.x/util/cmdopt.cpp Fri Oct 26 11:17:55 2007
@@ -160,59 +160,6 @@
" xlc IBM XLC++\n"
};
-#if !defined (_WIN32) && !defined (_WIN64)
-
-static void
-rw_sleep (int seconds)
-{
- sleep (seconds);
-}
-
-
-#ifdef __cplusplus
-
-extern "C" {
-
-#endif /* __cplusplus */
-
-static int
-rw_signal (int signo, void (*func)(int))
-{
- struct sigaction act;
- memset (&act, 0, sizeof act);
-
- /* avoid extern "C"/"C++" mismatch due to an HP aCC 6 bug
- (see STDCXX-291) */
- if (func)
- memcpy (&act.sa_handler, &func, sizeof func);
- else
- act.sa_handler = 0;
-
- return 0 > sigaction (signo, &act, 0);
-}
-
-#ifdef __cplusplus
-
-} /* extern "C" */
-
-#endif /* __cplusplus */
-
-#else /* if defined (_WIN32) || defined (_WIN64) */
-
-static void
-rw_sleep (int seconds)
-{
- Sleep (seconds * 1000);
-}
-
-
-static int
-rw_signal (int signo, void (*func)(int))
-{
- return SIG_ERR == signal (signo, func);
-}
-
-#endif /* _WIN{32,64}*/
/**
Display command line switches for program and terminate.
Modified: incubator/stdcxx/branches/4.2.x/util/exec.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.x/util/exec.cpp?rev=588734&r1=588733&r2=588734&view=diff
==============================================================================
--- incubator/stdcxx/branches/4.2.x/util/exec.cpp (original)
+++ incubator/stdcxx/branches/4.2.x/util/exec.cpp Fri Oct 26 11:17:55 2007
@@ -71,6 +71,34 @@
# define STATUS_INVALID_CRUNTIME_PARAMETER ((DWORD)0xC0000417L)
# endif
#endif
+
+#ifndef SIGHUP
+# define SIGHUP 1 /* Linux value */
+#endif
+#ifndef SIGQUIT
+# define SIGQUIT 3 /* Linux value */
+#endif
+#ifndef SIGKILL
+# define SIGKILL 9 /* Linux value */
+#endif
+#ifndef SIGALRM
+# define SIGALRM 14 /* Linux value */
+#endif
+
+
+#ifndef ESRCH
+# define ESRCH 3 /* Linux value */
+#endif
+#ifndef EINTR
+# define EINTR 4 /* Linux value */
+#endif
+#ifndef ECHILD
+# define ECHILD 10 /* Linux value */
+#endif
+#ifndef EINVAL
+# define EINVAL 22 /* Linux value */
+#endif
+
#include <sys/stat.h> /* for S_* */
#include <sys/types.h>
@@ -80,6 +108,21 @@
#include "exec.h"
+#ifndef _RWSTD_NO_PURE_C_HEADERS
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+int kill (pid_t pid, int sig);
+
+FILE* fdopen (int fd, const char *mode);
+
+# ifdef __cplusplus
+} /* extern "C" */
+# endif
+#endif /* _RWSTD_NO_PURE_C_HEADERS */
+
+
/**
Status flag used to comunicate that an alarm has triggered.
@@ -444,8 +487,6 @@
static const unsigned sigcount = sizeof (signals) / sizeof (int);
- struct sigaction act;
-
unsigned siginx = 0;
int stopped = 0;
@@ -463,31 +504,19 @@
/* Clear timeout */
alarm_timeout = 0;
- /* Set handler (if needed). Need to use sigaction rather than signal due
- to linux glitch
- */
- memset (&act, 0, sizeof act);
-
- /* avoid extern "C"/"C++" mismatch due to an HP aCC 6 bug
- (see STDCXX-291)
+ /* Set handler (if needed).
*/
- alarm_handler phandler = handle_alrm;
- memcpy (&act.sa_handler, &phandler, sizeof act.sa_handler);
-
- sigaction (SIGALRM, &act, 0);
+ rw_signal (SIGALRM, handle_alrm);
/* Set handlers for SIGHUP, SIGINT, SIGQUIT, SIGTERM so we can kill the
child process prior to dieing.
*/
kill_signal = 0;
- phandler = handle_term_signal;
- memcpy (&act.sa_handler, &phandler, sizeof act.sa_handler);
-
- sigaction (SIGHUP, &act, 0);
- sigaction (SIGINT, &act, 0);
- sigaction (SIGQUIT, &act, 0);
- sigaction (SIGTERM, &act, 0);
+ rw_signal (SIGHUP, handle_term_signal);
+ rw_signal (SIGINT, handle_term_signal);
+ rw_signal (SIGQUIT, handle_term_signal);
+ rw_signal (SIGTERM, handle_term_signal);
if (timeout > 0)
alarm (timeout);
@@ -623,11 +652,10 @@
/* Check if we were signaled to quit. */
if (kill_signal) {
/* Reset the handlers to normal */
- act.sa_handler = SIG_DFL;
- sigaction (SIGHUP, &act, 0);
- sigaction (SIGINT, &act, 0);
- sigaction (SIGQUIT, &act, 0);
- sigaction (SIGTERM, &act, 0);
+ rw_signal (SIGHUP, SIG_DFL);
+ rw_signal (SIGINT, SIG_DFL);
+ rw_signal (SIGQUIT, SIG_DFL);
+ rw_signal (SIGTERM, SIG_DFL);
if (0 > raise (kill_signal))
terminate (1, "raise(%s) failed: %s\n",
Modified: incubator/stdcxx/branches/4.2.x/util/util.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.x/util/util.cpp?rev=588734&r1=588733&r2=588734&view=diff
==============================================================================
--- incubator/stdcxx/branches/4.2.x/util/util.cpp (original)
+++ incubator/stdcxx/branches/4.2.x/util/util.cpp Fri Oct 26 11:17:55 2007
@@ -26,6 +26,7 @@
#include <assert.h> /* for assert */
#include <errno.h> /* for errno */
+#include <signal.h> /* for sigaction(), signal() */
#include <stdio.h> /* for vfprintf */
#include <stdlib.h> /* for exit, malloc */
#include <stdarg.h> /* for va_* */
@@ -34,6 +35,13 @@
#include <sys/stat.h> /* for stat() */
#include <sys/types.h> /* for size_t */
+#ifndef _WIN32
+# include <unistd.h> /* for sleep() */
+#else
+# include <windows.h> /* for Sleep() */
+#endif /* _WIN{32,64} */
+
+
#include "cmdopt.h" /* for exe_name, target_name */
#include "util.h"
@@ -228,3 +236,80 @@
memcpy (tmp_name + exe_len + 1, suffix, sfx_len + 1);
return tmp_name;
}
+
+
+#ifndef _WIN32
+
+void
+rw_sleep (int seconds)
+{
+ sleep (seconds);
+}
+
+
+# ifdef _RWSTD_NO_PURE_C_HEADERS
+
+# ifdef __cplusplus
+
+extern "C" {
+
+# endif /* __cplusplus */
+
+int
+rw_signal (int signo, void (*func)(int))
+{
+ struct sigaction act;
+ memset (&act, 0, sizeof act);
+
+ /* avoid extern "C"/"C++" mismatch due to an HP aCC 6 bug
+ (see STDCXX-291) */
+ if (func)
+ memcpy (&act.sa_handler, &func, sizeof func);
+ else
+ act.sa_handler = 0;
+
+ return 0 > sigaction (signo, &act, 0);
+}
+
+# ifdef __cplusplus
+
+} /* extern "C" */
+
+# endif /* __cplusplus */
+
+# else /* if defined (_RWSTD_NO_PURE_C_HEADERS) */
+
+# ifdef __cplusplus
+
+extern "C" {
+
+# endif /* __cplusplus */
+
+int
+rw_signal (int signo, void (*func)(int))
+{
+ return SIG_ERR == signal (signo, func);
+}
+
+# ifdef __cplusplus
+
+} /* extern "C" */
+
+# endif /* __cplusplus */
+# endif /* _RWSTD_NO_PURE_C_HEADERS */
+#else /* if defined (_WIN32) || defined (_WIN64) */
+
+void
+rw_sleep (int seconds)
+{
+ Sleep (seconds * 1000);
+}
+
+
+int
+rw_signal (int signo, void (*func)(int))
+{
+ return SIG_ERR == signal (signo, func);
+}
+
+#endif /* _WIN32 */
Modified: incubator/stdcxx/branches/4.2.x/util/util.h
URL: http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.x/util/util.h?rev=588734&r1=588733&r2=588734&view=diff
==============================================================================
--- incubator/stdcxx/branches/4.2.x/util/util.h (original)
+++ incubator/stdcxx/branches/4.2.x/util/util.h Fri Oct 26 11:17:55 2007
@@ -118,4 +118,31 @@
*/
char* output_name (const char* target);
+
+/**
+ Portability interface to sleep.
+
+ @param seconds the number of seconds to sleep
+ */
+void rw_sleep (int seconds);
+
+
+/**
+ Portability interface to signal or sigaction.
+
+ @param signo signal number
+ @param func signal handler
+ @return 0 on success, -1 otherwise
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int rw_signal (int signo, void (*func)(int));
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
#endif /* RW_UTIL_H */