stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: [PATCH] to get exec utility to compile with EDG eccp/Linux
Date Fri, 26 Oct 2007 18:21:35 GMT

Okay, since there are no objections or comments this is in:
http://svn.apache.org/viewvc?view=rev&revision=588734


Martin Sebor wrote:
> 
> The attached patch makes changes to get the exec utility to compile
> with the EDG eccp demo. It resolves STDCXX-414 in addition to a few
> other related or similar issues that popped up once I fixed it. The
> patch isn't "beautiful" but given the super-strict mode we turn on
> when using the compiler in (the pure "C" headers that declare only
> the symbols specified by the C++ '03 standard and nothing else, not
> even any POSIX names), it's the best I could come up with.
> An alternative apporach would be to avoid compiling the utility in
> C++ more or with our own headers which seems far too invasive for
> 4.2.1.
> 
> The ChangeLog is below. Comments appreciated.
> 
> 2007-10-23  Martin Sebor  <sebor@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>.
> 
> 
> Index: /home/sebor/stdcxx-4.2.x/util/util.h
> ===================================================================
> --- /home/sebor/stdcxx-4.2.x/util/util.h	(revision 587687)
> +++ /home/sebor/stdcxx-4.2.x/util/util.h	(working copy)
> @@ -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 */
> Index: /home/sebor/stdcxx-4.2.x/util/exec.cpp
> ===================================================================
> --- /home/sebor/stdcxx-4.2.x/util/exec.cpp	(revision 587687)
> +++ /home/sebor/stdcxx-4.2.x/util/exec.cpp	(working copy)
> @@ -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,32 +504,20 @@
>      /* Clear timeout */
>      alarm_timeout = 0;
>  
> -    /* Set handler (if needed).  Need to use sigaction rather than signal
> due
> -       to linux glitch
> +    /* Set handler (if needed).
>      */
> -    memset (&act, 0, sizeof act);
> -
> -    /* avoid extern "C"/"C++" mismatch due to an HP aCC 6 bug
> -       (see STDCXX-291)
> -    */
> -    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);
> +    rw_signal (SIGHUP, handle_term_signal);
> +    rw_signal (SIGINT, handle_term_signal);
> +    rw_signal (SIGQUIT, handle_term_signal);
> +    rw_signal (SIGTERM, handle_term_signal);
>  
> -    sigaction (SIGHUP, &act, 0);
> -    sigaction (SIGINT, &act, 0);
> -    sigaction (SIGQUIT, &act, 0);
> -    sigaction (SIGTERM, &act, 0);
> -
>      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",
> Index: /home/sebor/stdcxx-4.2.x/util/cmdopt.cpp
> ===================================================================
> --- /home/sebor/stdcxx-4.2.x/util/cmdopt.cpp	(revision 587687)
> +++ /home/sebor/stdcxx-4.2.x/util/cmdopt.cpp	(working copy)
> @@ -160,60 +160,7 @@
>      "    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.
>  
> Index: /home/sebor/stdcxx-4.2.x/util/util.cpp
> ===================================================================
> --- /home/sebor/stdcxx-4.2.x/util/util.cpp	(revision 587687)
> +++ /home/sebor/stdcxx-4.2.x/util/util.cpp	(working copy)
> @@ -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 */
> 
> 

-- 
View this message in context: http://www.nabble.com/-PATCH--to-get-exec-utility-to-compile-with-EDG-eccp-Linux-tf4681425.html#a13432793
Sent from the stdcxx-dev mailing list archive at Nabble.com.


Mime
View raw message