Home | History | Annotate | Line # | Download | only in at
panic.c revision 1.8
      1  1.8       mjl /*	$NetBSD: panic.c,v 1.8 2000/10/04 19:24:59 mjl 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.1       cgd #include <stdio.h>
     33  1.1       cgd #include <stdlib.h>
     34  1.1       cgd #include <unistd.h>
     35  1.1       cgd 
     36  1.1       cgd /* Local headers */
     37  1.1       cgd 
     38  1.1       cgd #include "panic.h"
     39  1.1       cgd #include "at.h"
     40  1.5  christos #include "privs.h"
     41  1.1       cgd 
     42  1.1       cgd /* File scope variables */
     43  1.1       cgd 
     44  1.2     glass #ifndef lint
     45  1.5  christos #if 0
     46  1.5  christos static char rcsid[] = "$OpenBSD: panic.c,v 1.4 1997/03/01 23:40:09 millert Exp $";
     47  1.5  christos #else
     48  1.8       mjl __RCSID("$NetBSD: panic.c,v 1.8 2000/10/04 19:24:59 mjl Exp $");
     49  1.2     glass #endif
     50  1.5  christos #endif
     51  1.1       cgd 
     52  1.1       cgd /* External variables */
     53  1.1       cgd 
     54  1.1       cgd /* Global functions */
     55  1.1       cgd 
     56  1.1       cgd void
     57  1.8       mjl panic(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.5  christos 		PRIV_START
     65  1.5  christos 		(void)unlink(atfile);
     66  1.5  christos 		PRIV_END
     67  1.5  christos 	}
     68  1.1       cgd 
     69  1.7       mjl 	errx(EXIT_FAILURE, "%s: %s", namep, a);
     70  1.1       cgd }
     71  1.1       cgd 
     72  1.1       cgd void
     73  1.8       mjl perr(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.5  christos 		PRIV_START
     82  1.5  christos 		(void)unlink(atfile);
     83  1.5  christos 		PRIV_END
     84  1.5  christos 	}
     85  1.1       cgd 
     86  1.1       cgd 	exit(EXIT_FAILURE);
     87  1.1       cgd }
     88  1.1       cgd 
     89  1.1       cgd void
     90  1.8       mjl perr2(char *a, char *b)
     91  1.1       cgd {
     92  1.6       mrg 
     93  1.5  christos 	(void)fputs(a, stderr);
     94  1.1       cgd 	perr(b);
     95  1.1       cgd }
     96  1.1       cgd 
     97  1.1       cgd void
     98  1.8       mjl usage(void)
     99  1.1       cgd {
    100  1.6       mrg 
    101  1.5  christos 	/* Print usage and exit.  */
    102  1.5  christos 	(void)fprintf(stderr,   "Usage: at [-V] [-q x] [-f file] [-m] time\n"
    103  1.5  christos 				"       at [-V] -c job [job ...]\n"
    104  1.5  christos 				"       atq [-V] [-q x] [-v]\n"
    105  1.5  christos 				"       atrm [-V] job [job ...]\n"
    106  1.5  christos 				"       batch [-V] [-f file] [-m]\n");
    107  1.1       cgd 	exit(EXIT_FAILURE);
    108  1.1       cgd }
    109