|
Packit Service |
82fcde |
/* Common code for message queue passing tests.
|
|
Packit Service |
82fcde |
Copyright (C) 2004-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
Packit Service |
82fcde |
Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
82fcde |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License as published by the Free Software Foundation; either
|
|
Packit Service |
82fcde |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
82fcde |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
82fcde |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
82fcde |
Lesser General Public License for more details.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License along with the GNU C Library; if not, see
|
|
Packit Service |
82fcde |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <mqueue.h>
|
|
Packit Service |
82fcde |
#include <search.h>
|
|
Packit Service |
82fcde |
#include <stdlib.h>
|
|
Packit Service |
82fcde |
#include <stdio.h>
|
|
Packit Service |
82fcde |
#include <string.h>
|
|
Packit Service |
82fcde |
#include <sys/uio.h>
|
|
Packit Service |
82fcde |
#include <unistd.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static int temp_mq_fd;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Add temporary files in list. */
|
|
Packit Service |
82fcde |
static void
|
|
Packit Service |
82fcde |
__attribute__ ((unused))
|
|
Packit Service |
82fcde |
add_temp_mq (const char *name)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
struct iovec iov[2];
|
|
Packit Service |
82fcde |
iov[0].iov_base = (char *) name;
|
|
Packit Service |
82fcde |
iov[0].iov_len = strlen (name);
|
|
Packit Service |
82fcde |
iov[1].iov_base = (char *) "\n";
|
|
Packit Service |
82fcde |
iov[1].iov_len = 1;
|
|
Packit Service |
82fcde |
if (writev (temp_mq_fd, iov, 2) != iov[0].iov_len + 1)
|
|
Packit Service |
82fcde |
printf ("Could not record temp mq filename %s\n", name);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Delete all temporary message queues. */
|
|
Packit Service |
82fcde |
static void
|
|
Packit Service |
82fcde |
do_cleanup (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (lseek (temp_mq_fd, 0, SEEK_SET) != 0)
|
|
Packit Service |
82fcde |
return;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
FILE *f = fdopen (temp_mq_fd, "r");
|
|
Packit Service |
82fcde |
if (f == NULL)
|
|
Packit Service |
82fcde |
return;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
char *line = NULL;
|
|
Packit Service |
82fcde |
size_t n = 0;
|
|
Packit Service |
82fcde |
ssize_t rets;
|
|
Packit Service |
82fcde |
while ((rets = getline (&line, &n, f)) > 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (line[rets - 1] != '\n')
|
|
Packit Service |
82fcde |
continue;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
line[rets - 1] = '\0';
|
|
Packit Service |
82fcde |
mq_unlink (line);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
fclose (f);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static void
|
|
Packit Service |
82fcde |
do_prepare (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
char name [] = "/tmp/tst-mqueueN.XXXXXX";
|
|
Packit Service |
82fcde |
temp_mq_fd = mkstemp (name);
|
|
Packit Service |
82fcde |
if (temp_mq_fd == -1)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("Could not create temporary file %s: %m\n", name);
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
unlink (name);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define PREPARE(argc, argv) do_prepare ()
|
|
Packit Service |
82fcde |
#define CLEANUP_HANDLER do_cleanup ()
|