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