1 /*
2 *
3 * Copyright (c) 2003 The Regents of the University of California. All
4 * rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * - Neither the name of the University nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 */
30
31
32 /*
33 *
34 * zombietest.c: A test program as part of FUSD.
35 *
36 * This regression test program checks to make sure that clients see a
37 * valid close(), even if the device has zombified.
38 *
39 * $Id: zombietest.c,v 1.4 2004-02-11 09:41:07 jelson Exp $
40 */
41
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <unistd.h>
45 #include <fcntl.h>
46 #include <errno.h>
47 #include <sys/wait.h>
48 #include <signal.h>
49 #include <string.h>
50
51 #include "fusd.h"
52
53 #define DEVNAME "/dev/testfusd/zombietest"
54
55 #define ITERATIONS 1
56
57 #define FORK \
58 tmp = fork(); \
59 if (tmp < 0) { perror("can't fork"); exit(1); } \
60 if (tmp == 0)
61
62 int n;
63
64 void done(int signo)
65 {
66 static int num_done = 0;
67 int status;
68 pid_t pid;
69
70 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
71 printf("pid [%d] done\n", pid);
72 num_done++;
73 }
74
75 /* if all N clients, plus the server, are done... we're done */
76 if (num_done == n+1) {
77 printf("test complete\n");
78 exit(0);
79 }
80 }
81
82
83
84 int _open(struct fusd_file_info *file)
85 {
86 printf("[%d] responding to open request and exiting\n", getpid());
87 fusd_return(file, 0);
88 exit(1);
89 }
90
91
92 int main(int argc, char *argv[])
93 {
94 int tmp;
95
96 n = 1;
97
98 printf("master is pid %d\n", getpid());
99 signal(SIGCHLD, done);
100
101 /* fork server */
102 FORK {
103 fusd_file_operations_t fops = {
104 open: _open
105 };
106 int fd;
107
108 if ((fd = fusd_register(DEVNAME, 0666, 0, &fops)) < 0) {
109 perror("Register failed");
110 exit(1);
111 }
112 printf("[%d] register succeeded, running...\n", getpid());
113 fusd_run();
114 exit(1);
115 }
116
117 sleep(3);
118
119 FORK {
120 int fd;
121
122 printf("[%d] trying to open...\n", getpid());
123 fd = open(DEVNAME, O_RDWR);
124 printf("[%d] got %d (%m)\n", getpid(), fd);
125 sleep(2);
126 printf("[%d] trying to close\n", getpid());
127 fd = close(fd);
128 printf("[%d] got %d (%m)\n", getpid(), fd);
129 exit(1);
130 }
131
132 /* parent: wait for children to all exit */
133 while (1)
134 pause();
135 }
136
137
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.