From 6ed7fcf7971b73098a2c13b0257b26de5198d28c Mon Sep 17 00:00:00 2001 From: anserper Date: Mon, 13 Apr 2009 23:51:24 +0000 Subject: [PATCH] b=18951 i=Nathan Rutman i=Vladimir Saveliev fix for a specific race in multiop --- lustre/tests/Makefile.am | 2 +- lustre/tests/multiop.c | 33 +++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lustre/tests/Makefile.am b/lustre/tests/Makefile.am index c7eadff..5bdf9ab 100644 --- a/lustre/tests/Makefile.am +++ b/lustre/tests/Makefile.am @@ -58,7 +58,7 @@ mmap_sanity_SOURCES= mmap_sanity.c LIBLUSTREAPI := $(top_builddir)/lustre/utils/liblustreapi.a ll_getstripe_info_LDADD=$(LIBLUSTREAPI) -multiop_LDADD=$(LIBLUSTREAPI) +multiop_LDADD=$(LIBLUSTREAPI) -lrt ll_dirstripe_verify_SOURCES= ll_dirstripe_verify.c ll_dirstripe_verify_LDADD= -L$(top_builddir)/lustre/utils -llustreapi diff --git a/lustre/tests/multiop.c b/lustre/tests/multiop.c index cecba49..0765c5f 100755 --- a/lustre/tests/multiop.c +++ b/lustre/tests/multiop.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #define T1 "write data before unlink\n" @@ -55,6 +56,7 @@ char msg[] = "yabba dabba doo, I'm coming for you, I live in a shoe, I don't know what to do.\n'Bigger, bigger,and bigger yet!' cried the Creator. 'You are not yet substantial enough for my boundless intents!' And ever greater and greater the object became, until all was lost 'neath its momentus bulk.\n"; char *buf, *buf_align; int bufsize = 0; +sem_t sem; #define ALIGN 65535 char usage[] = @@ -87,10 +89,19 @@ char usage[] = " z[num] seek [optional position, default 0]\n" " _ wait for signal\n"; -static int usr1_received; void usr1_handler(int unused) { - usr1_received = 1; + int saved_errno = errno; + + /* + * signal(7): POSIX.1-2004 ...requires an implementation to guarantee + * that the following functions can be safely called inside a signal + * handler: + * sem_post() + */ + sem_post(&sem); + + errno = saved_errno; } static const char * @@ -189,22 +200,20 @@ int main(int argc, char **argv) } memset(&st, 0, sizeof(st)); - signal(SIGUSR1, usr1_handler); - + sem_init(&sem, 0, 0); + /* use sigaction instead of signal to avoid SA_ONESHOT semantics */ + sigaction(SIGUSR1, &(const struct sigaction){.sa_handler = &usr1_handler}, + NULL); fname = argv[1]; for (commands = argv[2]; *commands; commands++) { switch (*commands) { case '_': - if (usr1_received == 0) { - if (verbose) { - printf("PAUSING %u\n", getpid()); - fflush(stdout); - } - pause(); + if (verbose) { + printf("PAUSING\n"); + fflush(stdout); } - usr1_received = 0; - signal(SIGUSR1, usr1_handler); + while (sem_wait(&sem) == -1 && errno == EINTR); break; case 'c': if (close(fd) == -1) { -- 1.8.3.1