/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that if the message queue is full and O_NONBLOCK is not set, * mq_timedsend() will block until it is interrupted by a signal. * * Have a child send signals until it starts to block. At that point, have * the parent send a signal to the child. Test passes if send was interrupted * by the signal. */ #include #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 5 #define CHILDPASS 1 #define CHILDFAIL 0 char gqname[NAMESIZE]; mqd_t gqueue; /* * This handler is just used to catch the signal and stop sleep (so the * parent knows the child is still busy sending signals). */ void justreturn_handler(int signo) { return; } int main() { int pid; const char *msgptr = MSGSTR; struct mq_attr attr; struct sigaction act; sprintf(gqname, "/mq_timedsend_5-2_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; gqueue = mq_open(gqname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (gqueue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } /* parent and child use justreturn_handler to just return out of * situations -- parent uses to stop it's sleep and wait again for * the child; child uses to stop its mq_timedsend */ act.sa_handler=justreturn_handler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGABRT, &act, 0); if ((pid = fork()) == 0) { /* child here */ int i; struct timespec ts; /* set up timeout to be as long as possible */ ts.tv_sec=INT32_MAX; ts.tv_nsec=0; sleep(1); // give parent time to set up handler for (i=0; i