11de7b4b8SPedro F. Giffuni /*-
2d78e98d2SNate Williams * panic.c - terminate fast in case of error
31de7b4b8SPedro F. Giffuni *
4*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
51de7b4b8SPedro F. Giffuni *
6b89321a5SAndrey A. Chernov * Copyright (C) 1993 Thomas Koenig
7d78e98d2SNate Williams *
8d78e98d2SNate Williams * Redistribution and use in source and binary forms, with or without
9d78e98d2SNate Williams * modification, are permitted provided that the following conditions
10d78e98d2SNate Williams * are met:
11d78e98d2SNate Williams * 1. Redistributions of source code must retain the above copyright
12d78e98d2SNate Williams * notice, this list of conditions and the following disclaimer.
13d78e98d2SNate Williams * 2. The name of the author(s) may not be used to endorse or promote
14d78e98d2SNate Williams * products derived from this software without specific prior written
15d78e98d2SNate Williams * permission.
16d78e98d2SNate Williams *
17d78e98d2SNate Williams * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
18d78e98d2SNate Williams * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19d78e98d2SNate Williams * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20ddcf8022SAndrey A. Chernov * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
21d78e98d2SNate Williams * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22d78e98d2SNate Williams * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23d78e98d2SNate Williams * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24d78e98d2SNate Williams * THEORY OF LIABILITY, WETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25d78e98d2SNate Williams * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26d78e98d2SNate Williams * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27d78e98d2SNate Williams */
28d78e98d2SNate Williams
2951e2220cSMark Murray #include <sys/cdefs.h>
30d78e98d2SNate Williams /* System Headers */
31d78e98d2SNate Williams
3281c8c7a4SPhilippe Charnier #include <err.h>
33d78e98d2SNate Williams #include <errno.h>
34d78e98d2SNate Williams #include <stdio.h>
35d78e98d2SNate Williams #include <stdlib.h>
36d78e98d2SNate Williams #include <unistd.h>
37d78e98d2SNate Williams
38d78e98d2SNate Williams /* Local headers */
39d78e98d2SNate Williams
40d78e98d2SNate Williams #include "panic.h"
419dd887f1SRuslan Ermilov #include "privs.h"
42d78e98d2SNate Williams #include "at.h"
43d78e98d2SNate Williams
44d78e98d2SNate Williams /* External variables */
45d78e98d2SNate Williams
46d78e98d2SNate Williams /* Global functions */
47d78e98d2SNate Williams
48d78e98d2SNate Williams void
panic(const char * a)493ce6c357SMark Murray panic(const char *a)
50d78e98d2SNate Williams {
51d78e98d2SNate Williams /* Something fatal has happened, print error message and exit.
52d78e98d2SNate Williams */
539dd887f1SRuslan Ermilov if (fcreated) {
549dd887f1SRuslan Ermilov PRIV_START
55d78e98d2SNate Williams unlink(atfile);
569dd887f1SRuslan Ermilov PRIV_END
579dd887f1SRuslan Ermilov }
58d78e98d2SNate Williams
5981c8c7a4SPhilippe Charnier errx(EXIT_FAILURE, "%s", a);
60d78e98d2SNate Williams }
61d78e98d2SNate Williams
62d78e98d2SNate Williams void
perr(const char * a)633ce6c357SMark Murray perr(const char *a)
64d78e98d2SNate Williams {
65d78e98d2SNate Williams /* Some operating system error; print error message and exit.
66d78e98d2SNate Williams */
6781c8c7a4SPhilippe Charnier int serrno = errno;
6881c8c7a4SPhilippe Charnier
699dd887f1SRuslan Ermilov if (fcreated) {
709dd887f1SRuslan Ermilov PRIV_START
71d78e98d2SNate Williams unlink(atfile);
729dd887f1SRuslan Ermilov PRIV_END
739dd887f1SRuslan Ermilov }
74d78e98d2SNate Williams
7581c8c7a4SPhilippe Charnier errno = serrno;
7681c8c7a4SPhilippe Charnier err(EXIT_FAILURE, "%s", a);
77d78e98d2SNate Williams }
78d78e98d2SNate Williams
79d78e98d2SNate Williams void
usage(void)80d78e98d2SNate Williams usage(void)
81d78e98d2SNate Williams {
8212d20ef9SPhilippe Charnier /* Print usage and exit. */
83e1bc822eSMike Barcroft fprintf(stderr, "usage: at [-q x] [-f file] [-m] time\n"
84e1bc822eSMike Barcroft " at -c job [job ...]\n"
85e1bc822eSMike Barcroft " at [-f file] -t [[CC]YY]MMDDhhmm[.SS]\n"
86e1bc822eSMike Barcroft " at -r job [job ...]\n"
87dfd339a0STim J. Robbins " at -l -q queuename\n"
88dfd339a0STim J. Robbins " at -l [job ...]\n"
89e1bc822eSMike Barcroft " atq [-q x] [-v]\n"
90e1bc822eSMike Barcroft " atrm job [job ...]\n"
91e1bc822eSMike Barcroft " batch [-f file] [-m]\n");
92d78e98d2SNate Williams exit(EXIT_FAILURE);
93d78e98d2SNate Williams }
94