1d78e98d2SNate Williams /* 2d78e98d2SNate Williams * panic.c - terminate fast in case of error 3b89321a5SAndrey A. Chernov * Copyright (C) 1993 Thomas Koenig 4d78e98d2SNate Williams * 5d78e98d2SNate Williams * Redistribution and use in source and binary forms, with or without 6d78e98d2SNate Williams * modification, are permitted provided that the following conditions 7d78e98d2SNate Williams * are met: 8d78e98d2SNate Williams * 1. Redistributions of source code must retain the above copyright 9d78e98d2SNate Williams * notice, this list of conditions and the following disclaimer. 10d78e98d2SNate Williams * 2. The name of the author(s) may not be used to endorse or promote 11d78e98d2SNate Williams * products derived from this software without specific prior written 12d78e98d2SNate Williams * permission. 13d78e98d2SNate Williams * 14d78e98d2SNate Williams * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15d78e98d2SNate Williams * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16d78e98d2SNate Williams * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17ddcf8022SAndrey A. Chernov * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18d78e98d2SNate Williams * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19d78e98d2SNate Williams * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20d78e98d2SNate Williams * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21d78e98d2SNate Williams * THEORY OF LIABILITY, WETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22d78e98d2SNate Williams * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23d78e98d2SNate Williams * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24d78e98d2SNate Williams */ 25d78e98d2SNate Williams 2651e2220cSMark Murray #include <sys/cdefs.h> 2751e2220cSMark Murray __FBSDID("$FreeBSD$"); 2881c8c7a4SPhilippe Charnier 29d78e98d2SNate Williams /* System Headers */ 30d78e98d2SNate Williams 3181c8c7a4SPhilippe Charnier #include <err.h> 32d78e98d2SNate Williams #include <errno.h> 33d78e98d2SNate Williams #include <stdio.h> 34d78e98d2SNate Williams #include <stdlib.h> 35d78e98d2SNate Williams #include <unistd.h> 36d78e98d2SNate Williams 37d78e98d2SNate Williams /* Local headers */ 38d78e98d2SNate Williams 39d78e98d2SNate Williams #include "panic.h" 409dd887f1SRuslan Ermilov #include "privs.h" 41d78e98d2SNate Williams #include "at.h" 42d78e98d2SNate Williams 43d78e98d2SNate Williams /* External variables */ 44d78e98d2SNate Williams 45d78e98d2SNate Williams /* Global functions */ 46d78e98d2SNate Williams 47d78e98d2SNate Williams void 483ce6c357SMark Murray panic(const char *a) 49d78e98d2SNate Williams { 50d78e98d2SNate Williams /* Something fatal has happened, print error message and exit. 51d78e98d2SNate Williams */ 529dd887f1SRuslan Ermilov if (fcreated) { 539dd887f1SRuslan Ermilov PRIV_START 54d78e98d2SNate Williams unlink(atfile); 559dd887f1SRuslan Ermilov PRIV_END 569dd887f1SRuslan Ermilov } 57d78e98d2SNate Williams 5881c8c7a4SPhilippe Charnier errx(EXIT_FAILURE, "%s", a); 59d78e98d2SNate Williams } 60d78e98d2SNate Williams 61d78e98d2SNate Williams void 623ce6c357SMark Murray perr(const char *a) 63d78e98d2SNate Williams { 64d78e98d2SNate Williams /* Some operating system error; print error message and exit. 65d78e98d2SNate Williams */ 6681c8c7a4SPhilippe Charnier int serrno = errno; 6781c8c7a4SPhilippe Charnier 689dd887f1SRuslan Ermilov if (fcreated) { 699dd887f1SRuslan Ermilov PRIV_START 70d78e98d2SNate Williams unlink(atfile); 719dd887f1SRuslan Ermilov PRIV_END 729dd887f1SRuslan Ermilov } 73d78e98d2SNate Williams 7481c8c7a4SPhilippe Charnier errno = serrno; 7581c8c7a4SPhilippe Charnier err(EXIT_FAILURE, "%s", a); 76d78e98d2SNate Williams } 77d78e98d2SNate Williams 78d78e98d2SNate Williams void 79d78e98d2SNate Williams usage(void) 80d78e98d2SNate Williams { 8112d20ef9SPhilippe Charnier /* Print usage and exit. */ 82e1bc822eSMike Barcroft fprintf(stderr, "usage: at [-q x] [-f file] [-m] time\n" 83e1bc822eSMike Barcroft " at -c job [job ...]\n" 84e1bc822eSMike Barcroft " at [-f file] -t [[CC]YY]MMDDhhmm[.SS]\n" 85e1bc822eSMike Barcroft " at -r job [job ...]\n" 86e1bc822eSMike Barcroft " atq [-q x] [-v]\n" 87e1bc822eSMike Barcroft " atrm job [job ...]\n" 88e1bc822eSMike Barcroft " batch [-f file] [-m]\n"); 89d78e98d2SNate Williams exit(EXIT_FAILURE); 90d78e98d2SNate Williams } 91