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