11.2Sandvar/* $NetBSD: h_spawnattr.c,v 1.3 2021/11/07 15:46:20 christos Exp $ */ 21.1Smartin 31.1Smartin/*- 41.1Smartin * Copyright (c) 2012 The NetBSD Foundation, Inc. 51.1Smartin * All rights reserved. 61.1Smartin * 71.1Smartin * This code is derived from software contributed to The NetBSD Foundation 81.1Smartin * by Charles Zhang <charles@NetBSD.org> and 91.1Smartin * Martin Husemann <martin@NetBSD.org>. 101.1Smartin * 111.1Smartin * Redistribution and use in source and binary forms, with or without 121.1Smartin * modification, are permitted provided that the following conditions 131.1Smartin * are met: 141.1Smartin * 1. Redistributions of source code must retain the above copyright 151.1Smartin * notice, this list of conditions and the following disclaimer. 161.1Smartin * 2. Redistributions in binary form must reproduce the above copyright 171.1Smartin * notice, this list of conditions and the following disclaimer in the 181.1Smartin * documentation and/or other materials provided with the distribution. 191.1Smartin * 201.1Smartin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 211.1Smartin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 221.1Smartin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 231.1Smartin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 241.1Smartin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 251.1Smartin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 261.1Smartin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 271.1Smartin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 281.1Smartin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 291.1Smartin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 301.1Smartin * POSSIBILITY OF SUCH DAMAGE. 311.1Smartin */ 321.3Schristos#include <sys/cdefs.h> 331.3Schristos__RCSID("$NetBSD: h_spawnattr.c,v 1.3 2021/11/07 15:46:20 christos Exp $"); 341.1Smartin 351.1Smartin#include <errno.h> 361.1Smartin#include <stdio.h> 371.1Smartin#include <stdlib.h> 381.1Smartin#include <signal.h> 391.1Smartin#include <unistd.h> 401.1Smartin 411.1Smartin/* 421.1Smartin * Helper to test the hardcoded assumptions from t_spawnattr.c 431.2Sandvar * Exit with appropriate exit status and print diagnostics to 441.1Smartin * stderr explaining what is wrong. 451.1Smartin */ 461.1Smartinint 471.1Smartinmain(int argc, char **argv) 481.1Smartin{ 491.1Smartin int parent_pipe, res = EXIT_SUCCESS; 501.1Smartin sigset_t sig; 511.1Smartin struct sigaction act; 521.1Smartin ssize_t rd; 531.1Smartin char tmp; 541.1Smartin 551.1Smartin sigemptyset(&sig); 561.1Smartin if (sigprocmask(0, NULL, &sig) < 0) { 571.1Smartin fprintf(stderr, "%s: sigprocmask error\n", getprogname()); 581.1Smartin res = EXIT_FAILURE; 591.1Smartin } 601.1Smartin if (!sigismember(&sig, SIGUSR1)) { 611.1Smartin fprintf(stderr, "%s: SIGUSR not in procmask\n", getprogname()); 621.1Smartin res = EXIT_FAILURE; 631.1Smartin } 641.1Smartin if (sigaction(SIGUSR1, NULL, &act) < 0) { 651.1Smartin fprintf(stderr, "%s: sigaction error\n", getprogname()); 661.1Smartin res = EXIT_FAILURE; 671.1Smartin } 681.1Smartin if (act.sa_sigaction != (void *)SIG_DFL) { 691.1Smartin fprintf(stderr, "%s: SIGUSR1 action != SIG_DFL\n", 701.1Smartin getprogname()); 711.1Smartin res = EXIT_FAILURE; 721.1Smartin } 731.1Smartin 741.1Smartin if (argc >= 2) { 751.1Smartin parent_pipe = atoi(argv[1]); 761.1Smartin if (parent_pipe > 2) { 771.1Smartin printf("%s: waiting for command from parent on pipe " 781.1Smartin "%d\n", getprogname(), parent_pipe); 791.1Smartin rd = read(parent_pipe, &tmp, 1); 801.1Smartin if (rd == 1) { 811.1Smartin printf("%s: got command %c from parent\n", 821.1Smartin getprogname(), tmp); 831.1Smartin } else if (rd == -1) { 841.1Smartin printf("%s: %d is no pipe, errno %d\n", 851.1Smartin getprogname(), parent_pipe, errno); 861.1Smartin res = EXIT_FAILURE; 871.1Smartin } 881.1Smartin } 891.1Smartin } 901.1Smartin 911.1Smartin return res; 921.1Smartin} 93