1*86d7f5d3SJohn Marino /*
2*86d7f5d3SJohn Marino * panic.c - terminate fast in case of error
3*86d7f5d3SJohn Marino * Copyright (C) 1993 Thomas Koenig
4*86d7f5d3SJohn Marino *
5*86d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without
6*86d7f5d3SJohn Marino * modification, are permitted provided that the following conditions
7*86d7f5d3SJohn Marino * are met:
8*86d7f5d3SJohn Marino * 1. Redistributions of source code must retain the above copyright
9*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer.
10*86d7f5d3SJohn Marino * 2. The name of the author(s) may not be used to endorse or promote
11*86d7f5d3SJohn Marino * products derived from this software without specific prior written
12*86d7f5d3SJohn Marino * permission.
13*86d7f5d3SJohn Marino *
14*86d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15*86d7f5d3SJohn Marino * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16*86d7f5d3SJohn Marino * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17*86d7f5d3SJohn Marino * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18*86d7f5d3SJohn Marino * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19*86d7f5d3SJohn Marino * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20*86d7f5d3SJohn Marino * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21*86d7f5d3SJohn Marino * THEORY OF LIABILITY, WETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22*86d7f5d3SJohn Marino * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23*86d7f5d3SJohn Marino * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*86d7f5d3SJohn Marino *
25*86d7f5d3SJohn Marino * $FreeBSD: src/usr.bin/at/panic.c,v 1.17 2002/05/16 00:47:14 tjr Exp $
26*86d7f5d3SJohn Marino * $DragonFly: src/usr.bin/at/panic.c,v 1.4 2007/08/26 16:12:27 pavalos Exp $
27*86d7f5d3SJohn Marino */
28*86d7f5d3SJohn Marino
29*86d7f5d3SJohn Marino /* System Headers */
30*86d7f5d3SJohn Marino
31*86d7f5d3SJohn Marino #include <err.h>
32*86d7f5d3SJohn Marino #include <errno.h>
33*86d7f5d3SJohn Marino #include <stdio.h>
34*86d7f5d3SJohn Marino #include <stdlib.h>
35*86d7f5d3SJohn Marino #include <unistd.h>
36*86d7f5d3SJohn Marino
37*86d7f5d3SJohn Marino /* Local headers */
38*86d7f5d3SJohn Marino
39*86d7f5d3SJohn Marino #include "at.h"
40*86d7f5d3SJohn Marino #include "panic.h"
41*86d7f5d3SJohn Marino #include "privs.h"
42*86d7f5d3SJohn Marino
43*86d7f5d3SJohn Marino /* External variables */
44*86d7f5d3SJohn Marino
45*86d7f5d3SJohn Marino /* Global functions */
46*86d7f5d3SJohn Marino
47*86d7f5d3SJohn Marino void
panic(const char * a)48*86d7f5d3SJohn Marino panic(const char *a)
49*86d7f5d3SJohn Marino {
50*86d7f5d3SJohn Marino /* Something fatal has happened, print error message and exit.
51*86d7f5d3SJohn Marino */
52*86d7f5d3SJohn Marino if (fcreated) {
53*86d7f5d3SJohn Marino PRIV_START
54*86d7f5d3SJohn Marino unlink(atfile);
55*86d7f5d3SJohn Marino PRIV_END
56*86d7f5d3SJohn Marino }
57*86d7f5d3SJohn Marino
58*86d7f5d3SJohn Marino errx(EXIT_FAILURE, "%s", a);
59*86d7f5d3SJohn Marino }
60*86d7f5d3SJohn Marino
61*86d7f5d3SJohn Marino void
perr(const char * a)62*86d7f5d3SJohn Marino perr(const char *a)
63*86d7f5d3SJohn Marino {
64*86d7f5d3SJohn Marino /* Some operating system error; print error message and exit.
65*86d7f5d3SJohn Marino */
66*86d7f5d3SJohn Marino int serrno = errno;
67*86d7f5d3SJohn Marino
68*86d7f5d3SJohn Marino if (fcreated) {
69*86d7f5d3SJohn Marino PRIV_START
70*86d7f5d3SJohn Marino unlink(atfile);
71*86d7f5d3SJohn Marino PRIV_END
72*86d7f5d3SJohn Marino }
73*86d7f5d3SJohn Marino
74*86d7f5d3SJohn Marino errno = serrno;
75*86d7f5d3SJohn Marino err(EXIT_FAILURE, "%s", a);
76*86d7f5d3SJohn Marino }
77*86d7f5d3SJohn Marino
78*86d7f5d3SJohn Marino void
usage(void)79*86d7f5d3SJohn Marino usage(void)
80*86d7f5d3SJohn Marino {
81*86d7f5d3SJohn Marino /* Print usage and exit. */
82*86d7f5d3SJohn Marino fprintf(stderr, "usage: at [-q x] [-f file] [-m] time\n"
83*86d7f5d3SJohn Marino " at -c job [job ...]\n"
84*86d7f5d3SJohn Marino " at [-f file] -t [[CC]YY]MMDDhhmm[.SS]\n"
85*86d7f5d3SJohn Marino " at -r job [job ...]\n"
86*86d7f5d3SJohn Marino " at -l -q queuename\n"
87*86d7f5d3SJohn Marino " at -l [job ...]\n"
88*86d7f5d3SJohn Marino " atq [-q x] [-v]\n"
89*86d7f5d3SJohn Marino " atrm job [job ...]\n"
90*86d7f5d3SJohn Marino " batch [-f file] [-m]\n");
91*86d7f5d3SJohn Marino exit(EXIT_FAILURE);
92*86d7f5d3SJohn Marino }
93