aboutsummaryrefslogtreecommitdiff
path: root/tests/recvfd.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/recvfd.c')
-rw-r--r--tests/recvfd.c55
1 files changed, 39 insertions, 16 deletions
diff --git a/tests/recvfd.c b/tests/recvfd.c
index 82455c7..4da42ca 100644
--- a/tests/recvfd.c
+++ b/tests/recvfd.c
@@ -30,13 +30,13 @@
30char const *progname; 30char const *progname;
31 31
32void 32void
33usage (void) 33usage (FILE *fp, int status)
34{ 34{
35 fprintf (stderr, "usage: %s SOCKET COMMAND ARGS...\n", progname); 35 fprintf (fp, "usage: %s [-s SOCKET] COMMAND ARGS...\n", progname);
36 fprintf (stderr, "Test tool for pass-fd pies components.\n"); 36 fprintf (fp, "Test tool for accept and pass-fd pies components.\n");
37 fprintf (stderr, "Listens on the file descriptor obtained from SOCKET.\n"); 37 fprintf (fp, "Listens on the file descriptor, either 0 or obtained from SOCKET.\n");
38 fprintf (stderr, "For each connection, execs COMMAND ARGS as a separate process.\n"); 38 fprintf (fp, "For each connection, execs COMMAND ARGS as a separate process.\n");
39 exit (64); 39 exit (status);
40} 40}
41 41
42static int 42static int
@@ -162,21 +162,44 @@ sigquit (int sig)
162int 162int
163main (int argc, char **argv) 163main (int argc, char **argv)
164{ 164{
165 int sfd, fd; 165 int c;
166 int fd;
167 char *socket_name = NULL;
166 168
167 progname = argv[0]; 169 progname = argv[0];
168 170
169 if (argc < 3) 171 while ((c = getopt (argc, argv, "hs:")) != EOF)
170 usage (); 172 {
171 173 switch (c)
172 sfd = listen_socket (argv[1]); 174 {
173 175 case 'h':
174 argc -= 2; 176 usage (stdout, 0);
175 argv += 2; 177 break;
176 178
177 fd = get_fd (sfd); 179 case 's':
178 close (sfd); 180 socket_name = optarg;
181 break;
179 182
183 default:
184 exit (64);
185 }
186 }
187
188 argc -= optind;
189 argv += optind;
190
191 if (argc == 0)
192 usage (stderr, 64);
193
194 if (socket_name)
195 {
196 int sfd = listen_socket (socket_name);
197 fd = get_fd (sfd);
198 close (sfd);
199 }
200 else
201 fd = 0;
202
180 signal (SIGCHLD, sigchld); 203 signal (SIGCHLD, sigchld);
181 signal (SIGTERM, sigquit); 204 signal (SIGTERM, sigquit);
182 signal (SIGHUP, sigquit); 205 signal (SIGHUP, sigquit);

Return to:

Send suggestions and report system problems to the System administrator.