Back to index

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

Go to the source code of this file.

Defines

#define TEST_FUNCTION   do_test ()
#define PREPARE(argc, argv)   do_prepare ()

Functions

static int do_test (void)
static void do_prepare (void)

Variables

char * tmpdirname

Define Documentation

#define PREPARE (   argc,
  argv 
)    do_prepare ()

Definition at line 34 of file tst-vfork3.c.

#define TEST_FUNCTION   do_test ()

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


Function Documentation

static void do_prepare ( void  ) [static]

Definition at line 173 of file tst-vfork3.c.

{
  size_t len = strlen (test_dir) + sizeof ("/tst-vfork3.XXXXXX");
  tmpdirname = malloc (len);
  char *script1 = malloc (len + sizeof "/script1.sh");
  char *script2 = malloc (len + sizeof "/script2.sh");
  if (tmpdirname == NULL || script1 == NULL || script2 == NULL)
    {
      puts ("out of memory");
      exit (1);
    }
  strcpy (stpcpy (tmpdirname, test_dir), "/tst-vfork3.XXXXXX");

  tmpdirname = mkdtemp (tmpdirname);
  if (tmpdirname == NULL)
    {
      puts ("could not create temporary directory");
      exit (1);
    }

  strcpy (stpcpy (script1, tmpdirname), "/script1.sh");
  strcpy (stpcpy (script2, tmpdirname), "/script2.sh");

  /* Need to make sure tmpdirname is at the end of the linked list.  */
  add_temp_file (script1);
  add_temp_file (tmpdirname);
  add_temp_file (script2);

  const char content1[] = "#!/bin/sh\necho script $1\n";
  int fd = open (script1, O_WRONLY | O_CREAT, 0700);
  if (fd < 0
      || TEMP_FAILURE_RETRY (write (fd, content1, sizeof content1))
        != sizeof content1
      || fchmod (fd, S_IRUSR | S_IXUSR) < 0)
    {
      printf ("Could not write %s\n", script1);
      exit (1);
    }
  close (fd);

  const char content2[] = "echo script $1\n";
  fd = open (script2, O_WRONLY | O_CREAT, 0700);
  if (fd < 0
      || TEMP_FAILURE_RETRY (write (fd, content2, sizeof content2))
        != sizeof content2
      || fchmod (fd, S_IRUSR | S_IXUSR) < 0)
    {
      printf ("Could not write %s\n", script2);
      exit (1);
    }
  close (fd);
}

Here is the call graph for this function:

static int do_test ( void  ) [static]

Variable Documentation

char* tmpdirname

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