/* Test message queue passing.
- Copyright (C) 2004 Free Software Foundation, Inc.
+ Copyright (C) 2004-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
#include <errno.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
+#include <stdint.h>
#include "tst-mqueue.h"
static int
if (attr->mq_maxmsg != 10 || attr->mq_msgsize != 1)
{
printf ("attributes don't match those passed to mq_open\n"
- "mq_maxmsg %ld, mq_msgsize %ld\n",
- attr->mq_maxmsg, attr->mq_msgsize);
+ "mq_maxmsg %jd, mq_msgsize %jd\n",
+ (intmax_t) attr->mq_maxmsg, (intmax_t) attr->mq_msgsize);
result = 1;
}
if ((attr->mq_flags & O_NONBLOCK) != nonblock)
{
- printf ("mq_flags %lx != %x\n", (attr->mq_flags & O_NONBLOCK), nonblock);
+ printf ("mq_flags %jx != %x\n",
+ (intmax_t) (attr->mq_flags & O_NONBLOCK), nonblock);
result = 1;
}
if (attr->mq_curmsgs != cnt)
{
- printf ("mq_curmsgs %ld != %ld\n", attr->mq_curmsgs, cnt);
+ printf ("mq_curmsgs %jd != %ld\n", (intmax_t) attr->mq_curmsgs, cnt);
result = 1;
}
result = 1;
}
else
- result = check_attrs (&attr, nonblock, 0);
+ result |= check_attrs (&attr, nonblock, 0);
- if (mq_receive (q, &v[0], 1, NULL) != -1)
+ if (mq_receive (q, (char *) &v[0], 1, NULL) != -1)
{
puts ("mq_receive on O_WRONLY mqd_t unexpectedly succeeded");
result = 1;
for (int i = 0; i < 10; ++i)
{
if (i & 1)
- ret = mq_send (q, &v[i], 1, v[i] >> 4);
+ ret = mq_send (q, (char *) &v[i], 1, v[i] >> 4);
else
- ret = mq_timedsend (q, &v[i], 1, v[i] >> 4, &ts);
+ ret = mq_timedsend (q, (char *) &v[i], 1, v[i] >> 4, &ts);
if (ret)
{
}
}
- ret = mq_timedsend (q, &v[10], 1, 8, &ts);
+ ret = mq_timedsend (q, (char *) &v[10], 1, 8, &ts);
if (ret != -1)
{
puts ("mq_timedsend on full queue did not fail");
if (nonblock)
{
- ret = mq_send (q, &v[10], 1, 8);
+ ret = mq_send (q, (char *) &v[10], 1, 8);
if (ret != -1)
{
puts ("mq_send on full non-blocking queue did not fail");
result = 1;
}
else
- result = check_attrs (&attr, nonblock, 10);
+ result |= check_attrs (&attr, nonblock, 10);
pid_t pid = fork ();
if (pid == -1)
result = 1;
}
else
- result = check_attrs (&attr, nonblock, 10);
+ result |= check_attrs (&attr, nonblock, 10);
unsigned char vr[11] = { };
unsigned int prio;
ssize_t rets;
- if (mq_send (q, &v[0], 1, 1) != -1)
+ if (mq_send (q, (char *) &v[0], 1, 1) != -1)
{
puts ("mq_send on O_RDONLY mqd_t unexpectedly succeeded");
result = 1;
for (int i = 0; i < 10; ++i)
{
if (i & 1)
- rets = mq_receive (q, &vr[i], 1, &prio);
+ rets = mq_receive (q, (char *) &vr[i], 1, &prio);
else
- rets = mq_timedreceive (q, &vr[i], 1, &prio, &ts);
+ rets = mq_timedreceive (q, (char *) &vr[i], 1, &prio, &ts);
if (rets != 1)
{
result = 1;
}
- rets = mq_timedreceive (q, &vr[10], 1, &prio, &ts);
+ rets = mq_timedreceive (q, (char *) &vr[10], 1, &prio, &ts);
if (rets != -1)
{
puts ("mq_timedreceive on empty queue did not fail");
if (nonblock)
{
- ret = mq_receive (q, &vr[10], 1, &prio);
+ ret = mq_receive (q, (char *) &vr[10], 1, &prio);
if (ret != -1)
{
puts ("mq_receive on empty non-blocking queue did not fail");
result = 1;
}
else
- result = check_attrs (&attr, nonblock, 0);
+ result |= check_attrs (&attr, nonblock, 0);
if (mq_close (q) != 0)
{
}
int status;
- if (waitpid (pid, &status, 0) != pid)
+ if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
{
printf ("waitpid failed: %m\n");
+ kill (pid, SIGKILL);
result = 1;
}
else if (!WIFEXITED (status) || WEXITSTATUS (status))
result = 1;
}
else
- result = check_attrs (&attr, nonblock, 0);
+ result |= check_attrs (&attr, nonblock, 0);
return result;
}
{
int result = 0;
- char name[sizeof "/tst-mqueue-" + sizeof (pid_t) * 3];
- snprintf (name, sizeof (name), "/tst-mqueue-%u", getpid ());
+ char name[sizeof "/tst-mqueue1-" + sizeof (pid_t) * 3];
+ snprintf (name, sizeof (name), "/tst-mqueue1-%u", getpid ());
struct mq_attr attr = { .mq_maxmsg = 10, .mq_msgsize = 1 };
mqd_t q = mq_open (name, O_CREAT | O_EXCL | O_WRONLY, 0600, &attr);
else
add_temp_mq (name);
- result = do_one_test (q, name, 0);
+ result |= do_one_test (q, name, 0);
mqd_t q2 = mq_open (name, O_WRONLY | O_NONBLOCK);
if (q2 == (mqd_t) -1)