tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: SIGIO, siginfo



hi,

> On Jan 13,  1:30pm, yamt%mwd.biglobe.ne.jp@localhost (YAMAMOTO Takashi) wrote:
> -- Subject: SIGIO, siginfo
> 
> | hi,
> | 
> | i have a few questions about our SIGIO/siginfo.
> | 
> | - is there any documentation about how our kernel fills siginfo for SIGIO?
> |   is it intended to be compatible with something?  eg. linux?
> 
> The documentation is in siginfo(2), do you have a more specific question,
> or is that documentation lacking?

"man siginfo|grep -i sigio" shows nothing.

i'm wondering why it's this different from linux.
see the attached code.

> | - siginfo.h and siginfo(2) mention SIGPOLL which actually does not exist.
> |   should they be just removed?
> 
> I think we should alias SIGPOLL to SIGIO since it is a mentioned extension
> to POSIX.

isn't SIGPOLL something for STREAMS?
are they supposed to be same?

> | - why did you make POLL_HUP == POLL_ERR?
> 
> Bug. I fixed it.

thanks.
i think it's better to unifdef pipeselwakeup then.

YAMAMOTO Takashi

> 
> christos
/*      $NetBSD$        */

/*-
 * Copyright (c)2009 YAMAMOTO Takashi,
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#if defined(__linux__)
#define _GNU_SOURCE
#endif /* defined(__linux__) */

#include <sys/poll.h>

#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int pipefds[2];
int fd;

int sig;
siginfo_t si;
sig_atomic_t done;

int main(int argc, char *argv[]);

static void
h(int _sig, siginfo_t *_si, void *ctx)
{

        sig = _sig;
        si = *_si;
        done = 1;
}

int
main(int argc, char *argv[])
{
        struct sigaction sa;
        int ret;
        int flags;
        sigset_t ss;
        sigset_t oss;

        memset(&sa, 0, sizeof(sa));
        sigemptyset(&sa.sa_mask);
        sigaddset(&sa.sa_mask, SIGIO);
        sa.sa_sigaction = h;
        sa.sa_flags = SA_SIGINFO;
        ret = sigaction(SIGIO, &sa, NULL);
        assert(ret == 0);

        ret = pipe(pipefds);
        assert(ret == 0);

        fd = dup(pipefds[0]);
        assert(fd != -1);
        ret = fcntl(fd, F_SETOWN, getpid());
        assert(ret == 0);
#if defined(__linux__)
        ret = fcntl(fd, F_SETSIG, SIGIO);
        assert(ret == 0);
#endif /* defined(__linux__) */
        flags = fcntl(fd, F_GETFL);
        ret = fcntl(fd, F_SETFL, flags | FASYNC);
        assert(ret == 0);
        ret = write(pipefds[1], "x", 1);
        assert(ret == 1);

        sigemptyset(&ss);
        ret = sigprocmask(SIG_BLOCK, &ss, &oss);
        assert(ret == 0);
        while (!done) {
                ret = sigsuspend(&oss);
                assert(ret == -1);
                assert(errno == EINTR);
        }
        ret = sigprocmask(SIG_SETMASK, &oss, NULL);
        assert(ret == 0);

        printf("pipefds[0] = %d\n", pipefds[0]);
        printf("pipefds[1] = %d\n", pipefds[1]);
        printf("fd = %d\n", fd);
        printf("sig = %d\n", sig);
        printf("si_signo = %d\n", si.si_signo);
        printf("si_code = %d\n", si.si_code);
        printf("si_band = %ld\n", si.si_band);
        printf("si_fd = %d\n", si.si_fd);
        assert(sig == SIGIO);
        assert(sig == si.si_signo);
#if defined(__linux__)
        assert(si.si_code == POLL_IN);
        assert(si.si_band == (POLLIN|POLLRDNORM));
        assert(si.si_fd == fd);
#else /* defined(__linux__) */
        assert(si.si_code == POLL_OUT);
        assert(si.si_band == (POLLOUT|POLLWRNORM));
        assert(si.si_fd == pipefds[0]);
#endif /* defined(__linux__) */

        exit(EXIT_SUCCESS);
}


Home | Main Index | Thread Index | Old Index