1/*
2 * Copyright (c) 2002, Intel Corporation. All rights reserved.
3 * Created by:  rolla.n.selbak REMOVE-THIS AT intel DOT com
4 * This file is licensed under the GPL license.  For the full content
5 * of this license, see the COPYING file at the top level of this
6 * source tree.
7 *
8 * int pthread_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void))
9 *
10 * If no handling is desired at one or more of these three points, the corresponding fork
11 * handler address(es) may be set to NULL.
12 *
13 * STEPS:
14 * 1. Call pthread_atfork() with all NULL paramters
15 * 2. Check to make sure the function returns success
16 *
17 */
18
19#include <pthread.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <errno.h>
24#include <unistd.h>
25#include <sys/wait.h>
26#include <sys/types.h>
27#include "posixtest.h"
28
29int main(void)
30{
31	pid_t pid;
32	int ret;
33
34	/* Set up the fork handlers */
35	ret = pthread_atfork(NULL, NULL, NULL);
36	if (ret != 0) {
37		if (ret == ENOMEM) {
38			printf("Error: ran out of memory\n");
39			return PTS_UNRESOLVED;
40		}
41
42		printf
43		    ("Test FAILED: Expected return value success, instead received %d\n",
44		     ret);
45		return PTS_FAIL;
46	}
47
48	/* Now call fork() to make sure everything goes smoothly */
49	pid = fork();
50
51	if (pid < 0) {
52		perror("Error in fork()\n");
53		return PTS_UNRESOLVED;
54	}
55	if (pid == 0) {
56		/* Child process */
57		pthread_exit(0);
58	} else {
59		/* Parent process */
60		wait(NULL);
61	}
62
63	printf("Test PASSED\n");
64	return PTS_PASS;
65}
66