[BACK]Return to panic.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / at

Annotation of src/usr.bin/at/panic.c, Revision 1.10

1.10    ! millert     1: /*     $OpenBSD: panic.c,v 1.9 2002/05/13 16:12:07 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: #include <errno.h>
                     30: #include <stdio.h>
                     31: #include <stdlib.h>
                     32: #include <unistd.h>
                     33:
1.10    ! millert    34: #include "at.h"
1.1       deraadt    35: #include "panic.h"
1.3       millert    36: #include "privs.h"
1.1       deraadt    37:
                     38: #ifndef lint
1.10    ! millert    39: static const char rcsid[] = "$OpenBSD: panic.c,v 1.9 2002/05/13 16:12:07 millert Exp $";
1.1       deraadt    40: #endif
                     41:
1.10    ! millert    42: /*
        !            43:  * Something fatal has happened, print error message and exit.
        !            44:  */
1.7       millert    45: __dead void
1.8       millert    46: panic(const char *a)
1.1       deraadt    47: {
1.7       millert    48:        (void)fprintf(stderr, "%s: %s\n", __progname, a);
1.3       millert    49:        if (fcreated) {
1.8       millert    50:                PRIV_START;
1.1       deraadt    51:                unlink(atfile);
1.8       millert    52:                PRIV_END;
1.3       millert    53:        }
1.1       deraadt    54:
                     55:        exit(EXIT_FAILURE);
                     56: }
                     57:
1.10    ! millert    58: /*
        !            59:  * Some operating system error; print error message and exit.
        !            60:  */
1.7       millert    61: __dead void
1.8       millert    62: perr(const char *a)
1.1       deraadt    63: {
1.10    ! millert    64:        if (!force)
        !            65:                perror(a);
1.3       millert    66:        if (fcreated) {
1.8       millert    67:                PRIV_START;
1.1       deraadt    68:                unlink(atfile);
1.8       millert    69:                PRIV_END;
1.3       millert    70:        }
1.1       deraadt    71:
                     72:        exit(EXIT_FAILURE);
                     73: }
                     74:
1.10    ! millert    75: /*
        !            76:  * Two-parameter version of perr().
        !            77:  */
1.7       millert    78: __dead void
1.8       millert    79: perr2(const char *a, const char *b)
1.1       deraadt    80: {
1.10    ! millert    81:        if (!force)
        !            82:                (void)fputs(a, stderr);
1.1       deraadt    83:        perr(b);
                     84: }
                     85:
1.7       millert    86: __dead void
1.1       deraadt    87: usage(void)
                     88: {
1.4       millert    89:        /* Print usage and exit.  */
1.9       millert    90:        switch (program) {
                     91:        case AT:
                     92:        case CAT:
                     93:                (void)fprintf(stderr,
1.10    ! millert    94:                    "usage: at [-bm] [-f file] [-q queue] -t time_arg\n"
        !            95:                    "       at [-bm] [-f file] [-q queue] timespec\n"
        !            96:                    "       at -c job [job ...]\n"
        !            97:                    "       at -l [-q queue] [job ...]\n"
        !            98:                    "       at -r job [job ...]\n");
1.9       millert    99:                break;
                    100:        case ATQ:
1.10    ! millert   101:                (void)fprintf(stderr,
        !           102:                    "usage: atq [-cnv] [-q queue] [name...]\n");
1.9       millert   103:                break;
                    104:        case ATRM:
1.10    ! millert   105:                (void)fprintf(stderr,
        !           106:                    "usage: atrm [-afi] [[job] [name] ...]\n");
1.9       millert   107:                break;
                    108:        case BATCH:
                    109:                (void)fprintf(stderr,
1.10    ! millert   110:                    "usage: batch [-m] [-f file] [-q queue] [timespec]\n");
1.9       millert   111:                break;
                    112:        }
1.1       deraadt   113:        exit(EXIT_FAILURE);
                    114: }