Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / unit / atf-src / atf-c / detail / process_helpers.c
blobaf8f92c556907654f3a9e05569028890f828c660
1 /* $NetBSD: process_helpers.c,v 1.3 2014/12/10 04:38:03 christos Exp $ */
3 /*
4 * Automated Testing Framework (atf)
6 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
19 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
29 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/types.h>
34 #include <assert.h> /* NO_CHECK_STYLE */
35 #include <signal.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <unistd.h>
41 static
42 int
43 h_echo(const char *msg)
45 printf("%s\n", msg);
46 return EXIT_SUCCESS;
49 static
50 int
51 h_exit_failure(void)
53 return EXIT_FAILURE;
56 static
57 int
58 h_exit_signal(void)
60 kill(getpid(), SIGKILL);
61 assert(0); /* NO_CHECK_STYLE */
62 return EXIT_FAILURE;
65 static
66 int
67 h_exit_success(void)
69 return EXIT_SUCCESS;
72 static
73 int
74 h_stdout_stderr(const char *id)
76 fprintf(stdout, "Line 1 to stdout for %s\n", id);
77 fprintf(stdout, "Line 2 to stdout for %s\n", id);
78 fprintf(stderr, "Line 1 to stderr for %s\n", id);
79 fprintf(stderr, "Line 2 to stderr for %s\n", id);
81 return EXIT_SUCCESS;
84 static
85 void
86 check_args(const int argc, const char *const argv[], const int required)
88 if (argc < required) {
89 fprintf(stderr, "Usage: %s helper-name [args]\n", argv[0]);
90 exit(EXIT_FAILURE);
94 int
95 main(int argc, const char *const argv[])
97 int exitcode;
99 check_args(argc, argv, 2);
101 if (strcmp(argv[1], "echo") == 0) {
102 check_args(argc, argv, 3);
103 exitcode = h_echo(argv[2]);
104 } else if (strcmp(argv[1], "exit-failure") == 0)
105 exitcode = h_exit_failure();
106 else if (strcmp(argv[1], "exit-signal") == 0)
107 exitcode = h_exit_signal();
108 else if (strcmp(argv[1], "exit-success") == 0)
109 exitcode = h_exit_success();
110 else if (strcmp(argv[1], "stdout-stderr") == 0) {
111 check_args(argc, argv, 3);
112 exitcode = h_stdout_stderr(argv[2]);
113 } else {
114 fprintf(stderr, "%s: Unknown helper %s\n", argv[0], argv[1]);
115 exitcode = EXIT_FAILURE;
118 return exitcode;