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