You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/17 14:45:12 UTC

svn commit: r816172 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/ main/native/ main/native/include/arch/unix/ main/native/os/unix/ main/native/shared/ test/org/apache/commons/runtime/

Author: mturk
Date: Thu Sep 17 12:45:11 2009
New Revision: 816172

URL: http://svn.apache.org/viewvc?rev=816172&view=rev
Log:
Wrap up Signal API

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalAction.java   (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalHandler.java   (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalHandlerWrapper.java   (with props)
    commons/sandbox/runtime/trunk/src/main/native/shared/sigaction.c   (with props)
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSignal.java   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.in
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/configure
    commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/signals.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalAction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalAction.java?rev=816172&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalAction.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalAction.java Thu Sep 17 12:45:11 2009
@@ -0,0 +1,140 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+import java.util.EnumMap;
+import java.util.Map;
+import org.apache.commons.runtime.exception.UnsupportedOperatingSystemException;
+import org.apache.commons.runtime.io.Status;
+
+
+/**
+ * SignalAction.
+ *
+ * @since Runtime 1.0
+ *
+ */
+public final class SignalAction
+{
+
+    private static EnumMap<Signal, SignalHandlerWrapper> sa = new EnumMap<Signal, SignalHandlerWrapper>(Signal.class);
+    private static final class Err implements SignalHandler {
+        public Err()
+        {
+            // Nothing
+        }
+        public void handler(Signal signo)
+            throws Exception
+        {
+            throw new RuntimeException("Error signal(" + signo + ") handler");
+        }
+    }
+    private static final class Dfl implements SignalHandler {
+        public Dfl()
+        {
+            // Nothing
+        }
+        public void handler(Signal signo)
+            throws Exception
+        {
+            switch (signo) {
+                case UNKNOWN:
+                    throw new RuntimeException("Unknown default signal(" + signo + ") handler");
+                default:
+                break;
+            }
+        }
+    }
+    private static final class Ign implements SignalHandler {
+        public Ign()
+        {
+            // Nothing
+        }
+        public void handler(Signal signo)
+            throws Exception
+        {
+            // Ignore
+        }
+    }
+    private static final class Get implements SignalHandler {
+        public Get()
+        {
+            // Nothing
+        }
+        public void handler(Signal signo)
+            throws Exception
+        {
+            throw new RuntimeException("Non executable signal(" + signo + ") handler");
+        }
+    }
+
+    public  static final SignalHandler ERR = new Err();
+    public  static final SignalHandler DFL = new Dfl();
+    public  static final SignalHandler IGN = new Ign();
+    public  static final SignalHandler GET = new Get();
+
+    private static final int SIG_IGN   = 0;
+    private static final int SIG_DFL   = 1;
+    private static final int SIG_ERR   = 2;
+    private static final int SIG_SET   = 3;
+
+    static {
+        sa.put(Signal.UNKNOWN, new SignalHandlerWrapper(ERR));
+
+    }
+    private SignalAction()
+    {
+        // No instance.
+    }
+
+    private static int nm(SignalHandler action)
+    {
+        if (action == IGN)
+            return SIG_IGN;
+        else if (action == DFL)
+            return SIG_DFL;
+        else if (action == ERR)
+            return SIG_ERR;
+        else
+            return SIG_SET;
+    }
+
+    public static native int signal0(int signo, int mode, Callback cb);
+    public static synchronized SignalHandler handler(Signal signo,
+                                                     SignalHandler action)
+        throws RuntimeException
+    {
+        SignalHandlerWrapper org = sa.get(signo);
+        if (org != null && org.handler() == ERR)
+            return ERR;
+        if (action != GET) {
+            SignalHandlerWrapper set = new SignalHandlerWrapper(action);
+            /* Set the native signal callback.
+             * TODO: Check the returned value and throw an exception
+             */
+            int rc = signal0(signo.valueOf(), nm(action), set);
+            if (rc != Status.OK) {
+                throw new RuntimeException(Status.describe(rc));
+            }
+            sa.put(signo, set);
+        }
+        if (org == null)
+            return IGN;
+        else
+            return org.handler();
+    }
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalHandler.java?rev=816172&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalHandler.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalHandler.java Thu Sep 17 12:45:11 2009
@@ -0,0 +1,35 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+/**
+ * SignalHandler interface.
+ * <p>
+ * Specifies the action to be associated with {@code Signal}.
+ * </p>
+ *
+ * @since Runtime 1.0
+ */
+public interface SignalHandler
+{
+    /** Action to be taken when a signal arrives.
+     * @param signo The {@code Signal} that was raised.
+     */
+    public void handler(Signal signo)
+        throws Exception;
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalHandlerWrapper.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalHandlerWrapper.java?rev=816172&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalHandlerWrapper.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalHandlerWrapper.java Thu Sep 17 12:45:11 2009
@@ -0,0 +1,56 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+/**
+ * SignalHandlerWrapper
+ * <p>
+ * Implements default signal actions.
+ * </p>
+ * @since Runtime 1.0
+ *
+ */
+class SignalHandlerWrapper implements Callback
+{
+    SignalHandler handler;
+    public SignalHandlerWrapper(SignalHandler handler)
+    {
+        this.handler = handler;
+    }
+
+    /* Called by the native on signal.
+     * <p>
+     * In case SignalHanlder throws an exception the
+     * callback is invalidated and never called again.
+     * Native method then switches to SIG_DFL for that particular signal
+     * </p>
+     */
+    public int handler(Object data, int status)
+    {
+        try {
+            handler.handler(Signal.valueOf(status));
+            return 0;
+        } catch (Throwable e) {
+            return 1;
+        }
+    }
+
+    public SignalHandler handler()
+    {
+        return handler;
+    }
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SignalHandlerWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=816172&r1=816171&r2=816172&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Thu Sep 17 12:45:11 2009
@@ -107,6 +107,7 @@
 	$(SRCDIR)/shared/sha2.$(OBJ) \
 	$(SRCDIR)/shared/sbuf.$(OBJ) \
 	$(SRCDIR)/shared/sema.$(OBJ) \
+	$(SRCDIR)/shared/sigaction.$(OBJ) \
 	$(SRCDIR)/shared/shm.$(OBJ) \
 	$(SRCDIR)/shared/string.$(OBJ) \
 	$(SRCDIR)/shared/system.$(OBJ) \

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=816172&r1=816171&r2=816172&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Thu Sep 17 12:45:11 2009
@@ -97,6 +97,7 @@
 	$(SRCDIR)/shared/sha2.$(OBJ) \
 	$(SRCDIR)/shared/sbuf.$(OBJ) \
 	$(SRCDIR)/shared/sema.$(OBJ) \
+	$(SRCDIR)/shared/sigaction.$(OBJ) \
 	$(SRCDIR)/shared/shm.$(OBJ) \
 	$(SRCDIR)/shared/string.$(OBJ) \
 	$(SRCDIR)/shared/system.$(OBJ) \

Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=816172&r1=816171&r2=816172&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Thu Sep 17 12:45:11 2009
@@ -49,10 +49,6 @@
 )
 
 if [ "x$1" != "x__running_the_bash_shell@" ]; then
-    echo ""
-    echo "[ERROR] Configure requires the BASH compatible shell."
-    echo "        Make sure the bash is installed and accessible"
-    echo ""
     exit
 fi
 shift

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h?rev=816172&r1=816171&r2=816172&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h Thu Sep 17 12:45:11 2009
@@ -203,6 +203,16 @@
     return p;
 }
 
+#if defined(NSIG)
+#define ACR_NUMSIG  NSIG
+#elif defined(_NSIG)
+#define ACR_NUMSIG  _NSIG
+#elif defined(__NSIG)
+#define ACR_NUMSIG  __NSIG
+#else
+#define ACR_NUMSIG  33
+#endif
+
 /* Initialize signal handling subsytem.
  * ACR private used during init stage
  */

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/signals.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/signals.c?rev=816172&r1=816171&r2=816172&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/signals.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/signals.c Thu Sep 17 12:45:11 2009
@@ -26,16 +26,6 @@
 #include "acr_crypto.h"
 #include "acr_signals.h"
 
-#if defined(NSIG)
-#define ACR_NUMSIG  NSIG
-#elif defined(_NSIG)
-#define ACR_NUMSIG  _NSIG
-#elif defined(__NSIG)
-#define ACR_NUMSIG  __NSIG
-#else
-#define ACR_NUMSIG  33
-#endif
-
 int acr_SignalsInit()
 {
     int rc = 0;
@@ -65,3 +55,38 @@
     else
         return 0;
 }
+
+#if defined(__NetBSD__) || defined(DARWIN)
+static void avoid_zombies(int signo)
+{
+    int exit_status;
+
+    while (waitpid(-1, &exit_status, WNOHANG) > 0) {
+        /* do nothing */
+    }
+}
+#endif /* DARWIN */
+
+ACR_DECLARE(acr_sigfunc_t *) ACR_Signal(int signo, acr_sigfunc_t *func)
+{
+    struct sigaction act, oact;
+
+    act.sa_handler = func;
+    sigemptyset(&act.sa_mask);
+    act.sa_flags = 0;
+#ifdef SA_INTERRUPT             /* SunOS */
+    act.sa_flags |= SA_INTERRUPT;
+#endif
+#if defined(__NetBSD__) || defined(DARWIN)
+    /* ignoring SIGCHLD or leaving the default disposition doesn't avoid zombies,
+     * and there is no SA_NOCLDWAIT flag, so catch the signal and reap status in
+     * the handler to avoid zombies
+     */
+    if ((signo == SIGCHLD) && (func == SIG_IGN)) {
+        act.sa_handler = avoid_zombies;
+    }
+#endif
+    if (sigaction(signo, &act, &oact) < 0)
+        return SIG_ERR;
+    return oact.sa_handler;
+}

Added: commons/sandbox/runtime/trunk/src/main/native/shared/sigaction.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/sigaction.c?rev=816172&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/sigaction.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/sigaction.c Thu Sep 17 12:45:11 2009
@@ -0,0 +1,286 @@
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_port.h"
+#include "acr_clazz.h"
+#include "acr_error.h"
+#include "acr_memory.h"
+#include "acr_string.h"
+#include "acr_descriptor.h"
+#include "acr_callback.h"
+#include "acr_signals.h"
+
+#define ACR_JSIG_IGN   0
+#define ACR_JSIG_DFL   1
+#define ACR_JSIG_ERR   2
+#define ACR_JSIG_SET   3
+
+#define ACR_JUNKNOWN    0
+#define ACR_JSIGHUP     1
+#define ACR_JSIGINT     2
+#define ACR_JSIGQUIT    3
+#define ACR_JSIGILL     4
+#define ACR_JSIGTRAP    5
+#define ACR_JSIGABRT    6
+#define ACR_JSIGIOT     6
+#define ACR_JSIGBUS     7
+#define ACR_JSIGFPE     8
+#define ACR_JSIGKILL    9
+#define ACR_JSIGUSR1    10
+#define ACR_JSIGSEGV    11
+#define ACR_JSIGUSR2    12
+#define ACR_JSIGPIPE    13
+#define ACR_JSIGALRM    14
+#define ACR_JSIGTERM    15
+#define ACR_JSIGSTKFLT  16
+#define ACR_JSIGCHLD    17
+#define ACR_JSIGCONT    18
+#define ACR_JSIGSTOP    19
+#define ACR_JSIGTSTP    20
+#define ACR_JSIGTTIN    21
+#define ACR_JSIGTTOU    22
+#define ACR_JSIGURG     23
+#define ACR_JSIGXCPU    24
+#define ACR_JSIGXFSZ    25
+#define ACR_JSIGVTALRM  26
+#define ACR_JSIGPROF    27
+#define ACR_JSIGWINCH   28
+#define ACR_JSIGIO      29
+#define ACR_JSIGPWR     30
+#define ACR_JSIGSYS     31
+
+#define SIG_ENOTIMPL    -1
+static int _sig_translate[] = {
+    0,
+#if defined(SIGHUP)
+    SIGHUP,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGINT)
+    SIGINT,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGQUIT)
+    SIGQUIT,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGILL)
+    SIGILL,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGTRAP)
+    SIGTRAP,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGABRT)
+    SIGABRT,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGIOT)
+    SIGIOT,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGBUS)
+    SIGBUS,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGFPE)
+    SIGFPE,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGKILL)
+    SIGKILL,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGUSR1)
+    SIGUSR1,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGSEGV)
+    SIGSEGV,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGUSR2)
+    SIGUSR2,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGPIPE)
+    SIGPIPE,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGALRM)
+    SIGALRM,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGTERM)
+    SIGTERM,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGSTKFLT)
+    SIGSTKFLT,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGCHLD)
+    SIGCHLD,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGCONT)
+    SIGCONT,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGSTOP)
+    SIGSTOP,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGTSTP)
+    SIGTSTP,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGTTIN)
+    SIGTTIN,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGTTOU)
+    SIGTTOU,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGURG)
+    SIGURG,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGXCPU)
+    SIGXCPU,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGXFSZ)
+    SIGXFSZ,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGVTALRM)
+    SIGVTALRM,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGPROF)
+    SIGPROF,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGWINCH)
+    SIGWINCH,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGIO)
+    SIGIO,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGPWR)
+    SIGPWR,
+#else
+    SIG_ENOTIMPL,
+#endif
+#if defined(SIGSYS)
+    SIGSYS,
+#else
+    SIG_ENOTIMPL,
+#endif
+    0
+};
+
+static acr_callback_t *_callbacks[ACR_NUMSIG];
+static void _sig_handler(int signo)
+{
+    if (signo > 0 && signo < ACR_NUMSIG) {
+        acr_callback_t *cb = _callbacks[signo];
+        if (cb) {
+            int rc;
+            int rv;
+            int sc;
+            int sn  = 0;
+            for (sc = 0; sc < ACR_COUNTOF(_sig_translate); sc++) {
+                if (_sig_translate[sc] == signo) {
+                    sn = sc;
+                    break;
+                }
+            }
+            rc = ACR_CallbackRun(NULL, cb, NULL, sn, &rv);
+            if (rc || rv) {
+                /* TODO: Restore the callback
+                 */
+            }
+        }
+    }
+}
+
+ACR_JNI_EXPORT_DECLARE(jint, SignalAction, signal0)(ACR_JNISTDARGS, jint sig,
+                                                    jint mode, jobject callback)
+{
+    acr_sigfunc_t *handler;
+    int signum;
+
+    fprintf(stdout, "Setting signal %d for %d\n", signum, getpid());
+    fflush(stdout);
+    if (sig > 0 && sig < ACR_NUMSIG)
+        signum = _sig_translate[sig];
+    else
+        return ACR_EINVAL;
+    if (signum < 0)
+        return ACR_ENOTIMPL;
+    if (_callbacks[signum]) {
+        ACR_CallbackFree(_E, _callbacks[signum]);
+    }
+    _callbacks[signum] = NULL;
+    fprintf(stdout, "Setting signal mode %d\n", mode);
+    fflush(stdout);
+    switch (mode) {
+        case ACR_JSIG_IGN:
+            handler = SIG_IGN;
+        break;
+        case ACR_JSIG_DFL:
+            handler = SIG_DFL;
+        break;
+        case ACR_JSIG_SET:
+            handler = _sig_handler;
+            _callbacks[signum] = ACR_CallbackAttach(_E, callback, NULL, 0, ACR_CALLBACK_SYNC, NULL);
+            if (_callbacks[signum] == NULL)
+                return ACR_GET_OS_ERROR();
+        break;
+        default:
+            handler = SIG_ERR;
+        break;
+    }
+    fprintf(stdout, "Inited signal %d for %d\n", signum, getpid());
+    fflush(stdout);
+    if (ACR_Signal(signum, handler) == SIG_ERR)
+        return ACR_GET_OS_ERROR();
+    else
+        return 0;
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/sigaction.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java?rev=816172&r1=816171&r2=816172&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java Thu Sep 17 12:45:11 2009
@@ -50,6 +50,7 @@
         suite.addTest(TestCallback.suite());
         suite.addTest(TestObserver.suite());
         suite.addTest(TestSystem.suite());
+        suite.addTest(TestSignal.suite());
         return suite;
     }
 

Added: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSignal.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSignal.java?rev=816172&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSignal.java (added)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSignal.java Thu Sep 17 12:45:11 2009
@@ -0,0 +1,68 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+import org.apache.commons.runtime.io.Status;
+import junit.framework.*;
+
+/**
+ * Signals Test.
+ *
+ */
+public class TestSignal extends TestCase
+{
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite(TestSignal.class);
+        return suite;
+    }
+
+    protected void setUp()
+        throws Exception
+    {
+        System.loadLibrary("acr");
+    }
+
+    private static final class Handler implements SignalHandler {
+        public Handler()
+        {
+            // Nothing
+        }
+        public void handler(Signal signo)
+            throws Exception
+        {
+            System.out.println();
+            System.out.println("Received signal(" + signo + ") continuing...");
+        }
+    }
+
+    public void testSignal()
+        throws Exception
+    {
+        Handler h = new Handler();
+        SignalAction.handler(Signal.SIGINT, h);
+        System.out.println("Handler initialized...");
+        for (int i = 0; i < 10; i++) {
+        try {
+            Thread.sleep(1000);
+        } catch (Throwable e) {
+            // Ignore
+        }
+        }
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSignal.java
------------------------------------------------------------------------------
    svn:eol-style = native