h_spawnattr.c revision 1.2
11.2Sandvar/* $NetBSD: h_spawnattr.c,v 1.2 2021/08/21 23:00:32 andvar 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.1Smartin 331.1Smartin#include <errno.h> 341.1Smartin#include <stdio.h> 351.1Smartin#include <stdlib.h> 361.1Smartin#include <signal.h> 371.1Smartin#include <unistd.h> 381.1Smartin 391.1Smartin/* 401.1Smartin * Helper to test the hardcoded assumptions from t_spawnattr.c 411.2Sandvar * Exit with appropriate exit status and print diagnostics to 421.1Smartin * stderr explaining what is wrong. 431.1Smartin */ 441.1Smartinint 451.1Smartinmain(int argc, char **argv) 461.1Smartin{ 471.1Smartin int parent_pipe, res = EXIT_SUCCESS; 481.1Smartin sigset_t sig; 491.1Smartin struct sigaction act; 501.1Smartin ssize_t rd; 511.1Smartin char tmp; 521.1Smartin 531.1Smartin sigemptyset(&sig); 541.1Smartin if (sigprocmask(0, NULL, &sig) < 0) { 551.1Smartin fprintf(stderr, "%s: sigprocmask error\n", getprogname()); 561.1Smartin res = EXIT_FAILURE; 571.1Smartin } 581.1Smartin if (!sigismember(&sig, SIGUSR1)) { 591.1Smartin fprintf(stderr, "%s: SIGUSR not in procmask\n", getprogname()); 601.1Smartin res = EXIT_FAILURE; 611.1Smartin } 621.1Smartin if (sigaction(SIGUSR1, NULL, &act) < 0) { 631.1Smartin fprintf(stderr, "%s: sigaction error\n", getprogname()); 641.1Smartin res = EXIT_FAILURE; 651.1Smartin } 661.1Smartin if (act.sa_sigaction != (void *)SIG_DFL) { 671.1Smartin fprintf(stderr, "%s: SIGUSR1 action != SIG_DFL\n", 681.1Smartin getprogname()); 691.1Smartin res = EXIT_FAILURE; 701.1Smartin } 711.1Smartin 721.1Smartin if (argc >= 2) { 731.1Smartin parent_pipe = atoi(argv[1]); 741.1Smartin if (parent_pipe > 2) { 751.1Smartin printf("%s: waiting for command from parent on pipe " 761.1Smartin "%d\n", getprogname(), parent_pipe); 771.1Smartin rd = read(parent_pipe, &tmp, 1); 781.1Smartin if (rd == 1) { 791.1Smartin printf("%s: got command %c from parent\n", 801.1Smartin getprogname(), tmp); 811.1Smartin } else if (rd == -1) { 821.1Smartin printf("%s: %d is no pipe, errno %d\n", 831.1Smartin getprogname(), parent_pipe, errno); 841.1Smartin res = EXIT_FAILURE; 851.1Smartin } 861.1Smartin } 871.1Smartin } 881.1Smartin 891.1Smartin return res; 901.1Smartin} 91