1*9351ac6dSMark Johnston /*- 2*9351ac6dSMark Johnston * Copyright (c) 2014 Mark Johnston <markj@FreeBSD.org> 3*9351ac6dSMark Johnston * All rights reserved. 4*9351ac6dSMark Johnston * 5*9351ac6dSMark Johnston * Redistribution and use in source and binary forms, with or without 6*9351ac6dSMark Johnston * modification, are permitted provided that the following conditions 7*9351ac6dSMark Johnston * are met: 8*9351ac6dSMark Johnston * 1. Redistributions of source code must retain the above copyright 9*9351ac6dSMark Johnston * notice, this list of conditions and the following disclaimer. 10*9351ac6dSMark Johnston * 2. Redistributions in binary form must reproduce the above copyright 11*9351ac6dSMark Johnston * notice, this list of conditions and the following disclaimer in the 12*9351ac6dSMark Johnston * documentation and/or other materials provided with the distribution. 13*9351ac6dSMark Johnston * 14*9351ac6dSMark Johnston * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*9351ac6dSMark Johnston * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*9351ac6dSMark Johnston * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*9351ac6dSMark Johnston * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*9351ac6dSMark Johnston * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*9351ac6dSMark Johnston * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*9351ac6dSMark Johnston * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*9351ac6dSMark Johnston * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*9351ac6dSMark Johnston * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*9351ac6dSMark Johnston * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*9351ac6dSMark Johnston * SUCH DAMAGE. 25*9351ac6dSMark Johnston */ 26*9351ac6dSMark Johnston 27*9351ac6dSMark Johnston #include <sys/cdefs.h> 28*9351ac6dSMark Johnston __FBSDID("$FreeBSD$"); 29*9351ac6dSMark Johnston 30*9351ac6dSMark Johnston #include <err.h> 31*9351ac6dSMark Johnston #include <signal.h> 32*9351ac6dSMark Johnston #include <stdlib.h> 33*9351ac6dSMark Johnston #include <string.h> 34*9351ac6dSMark Johnston #include <unistd.h> 35*9351ac6dSMark Johnston 36*9351ac6dSMark Johnston static volatile sig_atomic_t saw; 37*9351ac6dSMark Johnston 38*9351ac6dSMark Johnston static void 39*9351ac6dSMark Johnston usr1(int sig __unused) 40*9351ac6dSMark Johnston { 41*9351ac6dSMark Johnston 42*9351ac6dSMark Johnston saw = 1; 43*9351ac6dSMark Johnston } 44*9351ac6dSMark Johnston 45*9351ac6dSMark Johnston int 46*9351ac6dSMark Johnston main(int argc, char **argv) 47*9351ac6dSMark Johnston { 48*9351ac6dSMark Johnston 49*9351ac6dSMark Johnston if (argc == 1) 50*9351ac6dSMark Johnston return (EXIT_SUCCESS); 51*9351ac6dSMark Johnston if (argc == 2 && strcmp(argv[1], "-s") == 0) { 52*9351ac6dSMark Johnston if (signal(SIGUSR1, usr1) == SIG_ERR) 53*9351ac6dSMark Johnston err(1, "signal"); 54*9351ac6dSMark Johnston if (kill(getpid(), SIGUSR1) != 0) 55*9351ac6dSMark Johnston err(1, "kill"); 56*9351ac6dSMark Johnston return (saw == 1 ? EXIT_SUCCESS : EXIT_FAILURE); 57*9351ac6dSMark Johnston } 58*9351ac6dSMark Johnston return (EXIT_FAILURE); 59*9351ac6dSMark Johnston } 60