On Wed, Mar 27, 2013 at 11:31 AM, Irek Szczesniak <[email protected]> wrote:
[snip]
>>> BTW: The patch currently doesn't cover passing SIGCHLD siginfo data to
>>> the shell traps (this needs to be done in |job_waitsafe()| ... but
>>> that may be tricky).
>>
>> Could you add.sh.status (Exit value or signal) and .sh.pid for CHLD
>> traps, please?
>
> Appending to this RFE:
> We like to have .sh.code for CHLD traps too, with .sh.code being a
> STRING returning one of the CLD_* codes defined in
> http://pubs.opengroup.org/onlinepubs/7908799/xsh/signal.h.html (i.e.
> this is defined by X/OPEN and POSIX and therefore should be applicable
> as shell extension).

Erm... do you mean that you want to be able to write a ksh93 version
of the following C code ?
-- snip --
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>

static
const char *sicode2str(int si_code)
{
        const char *str;
        switch(si_code)
        {
#define STRSYM(sym) \
        case (sym): str = #sym ; break;
                STRSYM(CLD_EXITED)
                STRSYM(CLD_KILLED)
                STRSYM(CLD_DUMPED)
                STRSYM(CLD_TRAPPED)
                STRSYM(CLD_STOPPED)
                STRSYM(CLD_CONTINUED)
                default:
                        str="<unknown>";
                        break;
        }
        return str;
}


static
void chld_handler (int signum, siginfo_t *si,
        void *context)
{
        printf("#SIGCHLD, si_code=%d/%s handler\n",
                si->si_code,
                sicode2str(si->si_code));
}


static
void chsleep(void)
{
        int i;
        for (i=0 ; i < 120 ; i++)
                usleep(10000);
}


int main(int ac, char *av[])
{
        struct sigaction new_action;
        pid_t pid;

        /* Setting-up the sigchld handler */
        new_action.sa_sigaction = chld_handler;
        sigemptyset (&new_action.sa_mask);
        new_action.sa_flags = SA_SIGINFO;
        sigaction (SIGCHLD, &new_action, NULL);

        pid = fork(); /*FIXME: Need error handling*/

        if (pid == 0)
        {
                /* Child process */
                
                puts("# child process "
                        "(stopping now...)");
                raise(SIGSTOP);

                puts("# child continues...");

                _exit(0);
        }
        else
        {
                /* Parent process */

                chsleep();
                puts("# parent waking child...");
                kill(pid, SIGCONT);
                chsleep();
        }

        return EXIT_SUCCESS;
}
-- snip --

The output should look like this:
-- snip --
# child process (stopping now...)
#SIGCHLD, si_code=5/CLD_STOPPED handler
# parent waking child...
# child continues...
#SIGCHLD, si_code=6/CLD_CONTINUED handler
#SIGCHLD, si_code=1/CLD_EXITED handler
-- snip --

This should be technically possible to implement in ksh93... but for
which purpose are you interested in the |CLD_STOPPED|&co. codes ?

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers

Reply via email to