1
/* $Id: fork.c 425 2007-03-06 20:13:31Z steve-beattie $ */
4
* Copyright (C) 2002-2005 Novell/SUSE
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License as
8
* published by the Free Software Foundation, version 2 of the
15
#include <sys/types.h>
28
#define max(x,y) (x) > (y) ? (x) : (y)
32
int (*pass)[MAX_FILES];
34
void test_files(int num_files, char *files[], int index)
38
for (i = 0; i < num_files; i++) {
39
fd = open(files[i], O_RDWR);
42
if (errno == ENOENT) {
54
int main(int argc, char *argv[])
56
int num_files, i, shmid;
58
struct shmid_ds shm_desc;
61
fprintf(stderr, "usage: %s program [args] \n", argv[0]);
65
num_files = max(argc - 1, MAX_FILES);
67
shmid = shmget(IPC_PRIVATE, sizeof(int[2][MAX_FILES]), IPC_CREAT);
69
fprintf(stderr, "FAIL: shmget failed %s\n", strerror(errno));
73
pass = (int(*)[MAX_FILES])shmat(shmid, NULL, 0);
75
if (pass == (void *)-1) {
76
fprintf(stderr, "FAIL: shmat failed %s\n", strerror(errno));
82
if (pid) { /* parent */
86
test_files(argc - 1, &argv[1], 0);
88
while (wait(&status) != pid) ;
90
for (i = 0; i < argc - 1; i++) {
91
if (pass[0][i] != pass[1][i] ||
92
pass[0][i] == -1 || pass[1][i] == -1) {
94
fprintf(stderr, "FAILED:");
98
fprintf(stderr, " file%d(%d:%d)",
99
i + 1, pass[0][i], pass[1][i]);
106
fprintf(stderr, "\n");
110
shmctl(shmid, IPC_RMID, &shm_desc);
113
test_files(argc - 1, &argv[1], 1);