summaryrefslogtreecommitdiffabout
path: root/tests/recvfd.c
Side-by-side diff
Diffstat (limited to 'tests/recvfd.c') (more/less context) (ignore whitespace changes)
-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 @@
char const *progname;
void
-usage (void)
+usage (FILE *fp, int status)
{
- fprintf (stderr, "usage: %s SOCKET COMMAND ARGS...\n", progname);
- fprintf (stderr, "Test tool for pass-fd pies components.\n");
- fprintf (stderr, "Listens on the file descriptor obtained from SOCKET.\n");
- fprintf (stderr, "For each connection, execs COMMAND ARGS as a separate process.\n");
- exit (64);
+ fprintf (fp, "usage: %s [-s SOCKET] COMMAND ARGS...\n", progname);
+ fprintf (fp, "Test tool for accept and pass-fd pies components.\n");
+ fprintf (fp, "Listens on the file descriptor, either 0 or obtained from SOCKET.\n");
+ fprintf (fp, "For each connection, execs COMMAND ARGS as a separate process.\n");
+ exit (status);
}
static int
@@ -162,21 +162,44 @@ sigquit (int sig)
int
main (int argc, char **argv)
{
- int sfd, fd;
+ int c;
+ int fd;
+ char *socket_name = NULL;
progname = argv[0];
- if (argc < 3)
- usage ();
-
- sfd = listen_socket (argv[1]);
-
- argc -= 2;
- argv += 2;
+ while ((c = getopt (argc, argv, "hs:")) != EOF)
+ {
+ switch (c)
+ {
+ case 'h':
+ usage (stdout, 0);
+ break;
- fd = get_fd (sfd);
- close (sfd);
+ case 's':
+ socket_name = optarg;
+ break;
+ default:
+ exit (64);
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc == 0)
+ usage (stderr, 64);
+
+ if (socket_name)
+ {
+ int sfd = listen_socket (socket_name);
+ fd = get_fd (sfd);
+ close (sfd);
+ }
+ else
+ fd = 0;
+
signal (SIGCHLD, sigchld);
signal (SIGTERM, sigquit);
signal (SIGHUP, sigquit);

Return to:

Send suggestions and report system problems to the System administrator.