Back to index

glibc  2.9
Defines | Functions | Variables
tst-mqueue7.c File Reference
#include <errno.h>
#include <fcntl.h>
#include <mqueue.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define OPT_AFTEREXEC   20000
#define CMDLINE_OPTIONS   { "after-exec", required_argument, NULL, OPT_AFTEREXEC },
#define CMDLINE_PROCESS

Functions

static int do_after_exec (void)
static int do_test (int argc, char **argv)

Variables

static mqd_t after_exec = (mqd_t) -1

Define Documentation

#define CMDLINE_OPTIONS   { "after-exec", required_argument, NULL, OPT_AFTEREXEC },

Definition at line 35 of file tst-mqueue7.c.

#define CMDLINE_PROCESS
Value:
case OPT_AFTEREXEC:                              \
    after_exec = (mqd_t) strtoul (optarg, NULL, 0);     \
    break;

Definition at line 38 of file tst-mqueue7.c.

#define OPT_AFTEREXEC   20000

Definition at line 31 of file tst-mqueue7.c.


Function Documentation

static int do_after_exec ( void  ) [static]

Definition at line 44 of file tst-mqueue7.c.

{
  int result = 0;

  struct mq_attr attr;
  if (mq_getattr (after_exec, &attr) == 0)
    {
      puts ("mq_getattr after exec unexpectedly succeeded");
      result = 1;
    }
  else if (errno != EBADF)
    {
      printf ("mq_getattr after exec did not fail with EBADF: %m\n");
      result = 1;
    }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int do_test ( int  argc,
char **  argv 
) [static]

Definition at line 64 of file tst-mqueue7.c.

{
  if (after_exec != (mqd_t) -1)
    return do_after_exec ();

  char name[sizeof "/tst-mqueue7-" + sizeof (pid_t) * 3];
  snprintf (name, sizeof (name), "/tst-mqueue7-%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);

  if (q == (mqd_t) -1)
    {
      printf ("mq_open failed with: %m\n");
      return 0;
    }
  else if (mq_unlink (name) != 0)
    {
      printf ("mq_unlink failed with: %m\n");
      return 1;
    }

  if (mq_getattr (q, &attr) != 0)
    {
      printf ("mq_getattr failed: %m\n");
      return 1;
    }

  char after_exec_arg[sizeof "--after-exec=0x" + sizeof (long) * 3];
  snprintf (after_exec_arg, sizeof (after_exec_arg),
           "--after-exec=0x%lx", (long) q);

  const char *newargv[argc + 2];
  for (int i = 1; i < argc; ++i)
    newargv[i - 1] = argv[i];
  newargv[argc - 1] = "--direct";
  newargv[argc] = after_exec_arg;
  newargv[argc + 1] = NULL;

  /* Verify that exec* has the effect of mq_close (q).  */
  execv (newargv[0], (char * const *) newargv);
  printf ("execv failed: %m\n");
  return 1;
}

Here is the call graph for this function:


Variable Documentation

mqd_t after_exec = (mqd_t) -1 [static]

Definition at line 33 of file tst-mqueue7.c.