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