Re: Add pselect, ppoll system calls.

From: Michael Kerrisk
Date: Fri Aug 05 2005 - 07:50:22 EST


Hi David,

Not sure if your message below was meant as a reply-all or not,
but I've brought it back onto the list.

There are some problems with your test program --
it's not actually using pselect() in proper way, which is:

/* Block signals that will be later unblocked by pselect() */

sigemptyset(&block);
sigaddset(&block, SIGINT);
sigprocmask(SIG_BLOCK, &block, NULL);

sigemptyset(&set);
status = my_pselect(1, &s, NULL, NULL, &timeout, &set);

If I change your program to do something like the above, I also
do not see a message from the handler -- i.e., it is not being
called, and I'm pretty sure it should be.

Below, is my modified version of your program -- it uses SIGINT.

Cheers,

Michael

#define _GNU_SOURCE
#include <syscall.h>
#include <unistd.h>
#include <signal.h>
#include <sys/select.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>

#define __NR_pselect6 289

static int my_pselect(int n,
fd_set *readfds, fd_set *writefds, fd_set
*exceptfds, const struct timespec *timeout, sigset_t *sigmask)
{
struct {
sigset_t *set;
size_t size;
} __attribute__((packed)) arg6;

arg6.size = 8;
arg6.set = sigmask;
return syscall(__NR_pselect6, n, readfds, writefds,
exceptfds, timeout, &arg6);
}

static void usr1_handler(int signo)
{
write(1, "handler called\n", 20);
}


int main(void)
{
fd_set s;
int status;
sigset_t set, block;
struct timespec timeout;

timeout.tv_sec = 30;
timeout.tv_nsec = 0;

FD_ZERO(&s);
FD_SET(0, &s);

signal(SIGINT, usr1_handler);

sigemptyset(&block);
sigaddset(&block, SIGINT);
sigprocmask(SIG_BLOCK, &block, NULL);

sigemptyset(&set);
status = my_pselect(1, &s, NULL, NULL, &timeout, &set);
printf("status=%d\n", status);
if (status == -1) perror("pselect");
}

--- Weitergeleitete Nachricht ---
Von: David Woodhouse <dwmw2@xxxxxxxxxxxxx>
An: Michael Kerrisk <mtk-lkml@xxxxxxx>
Betreff: Re: Add pselect, ppoll system calls.
Datum: Fri, 05 Aug 2005 13:03:14 +0100

This is the test program I used. I send it SIGUSR1 manually.

#define __USE_MISC
#include <unistd.h>
#include <signal.h>
#include <sys/select.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>

#define __NR_pselect6 273

int my_pselect(int n, fd_set *readfds, fd_set *writefds, fd_set
*exceptfds, const struct timespec *timeout, const sigset_t *sigmask)
{
struct {
sigset_t *set;
size_t size;
} __attribute__((packed)) arg6;

arg6.size = 8;
arg6.set = sigmask;
return syscall(__NR_pselect6, n, readfds, writefds, exceptfds,
timeout, &arg6);
}

void usr1_handler(int signo)
{
write(1, "usr1_handler called\n", 20);
}
int main(void)
{
fd_set s;
int p;
char buf[80];
sigset_t set;
fcntl(0, F_SETFL, O_NONBLOCK | fcntl(0, F_GETFL));

FD_ZERO(&s);
FD_SET(0, &s);

sigfillset(&set);

signal(SIGUSR1, usr1_handler);

printf("I am %d\n", getpid());

while (1) {
printf("Block usr1\n");
fflush(stdout);
sigaddset(&set, SIGUSR1);
my_pselect(1, &s, NULL, NULL, NULL, &set);
read(0, buf, 80);
printf("Allow usr1\n");
fflush(stdout);
sigdelset(&set, SIGUSR1);
my_pselect(1, &s, NULL, NULL, NULL, &set);
read(0, buf, 80);
}

}


--
5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail
+++ GMX - die erste Adresse für Mail, Message, More +++
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/