Code Coverage: vinyl-cache/include/vut.h
 
82217aa4fc7094b3610340078afaf78cd95a8ec9
 
0
/*-
1
 * Copyright (c) 2006 Verdens Gang AS
2
 * Copyright (c) 2006-2015 Varnish Software AS
3
 * All rights reserved.
4
 *
5
 * Author: Martin Blix Grydeland <martin@varnish-software.com>
6
 *
7
 * SPDX-License-Identifier: BSD-2-Clause
8
 *
9
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions
11
 * are met:
12
 * 1. Redistributions of source code must retain the above copyright
13
 *    notice, this list of conditions and the following disclaimer.
14
 * 2. Redistributions in binary form must reproduce the above copyright
15
 *    notice, this list of conditions and the following disclaimer in the
16
 *    documentation and/or other materials provided with the distribution.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
22
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28
 * SUCH DAMAGE.
29
 *
30
 * Common functions for the utilities
31
 */
32
33
struct VUT;
34
struct vopt_spec;
35
36
typedef void VUT_sighandler_f(int);
37
typedef int VUT_cb_f(struct VUT *);
38
typedef void VUT_error_f(struct VUT *, int, const char *, va_list);
39
40
struct VUT {
41
        unsigned        magic;
42
#define VUT_MAGIC       0xdf3b3de8
43
        const char      *progname;
44
45
        /* Options */
46
        int             dryrun_opt;
47
        int             d_opt;
48
        int             D_opt;
49
        int             g_arg;
50
        int             k_arg;
51
        char            *n_arg;
52
        char            *P_arg;
53
        char            *q_arg;
54
        char            *r_arg;
55
        char            *t_arg;
56
57
        /* State */
58
        struct VSL_data *vsl;
59
        struct vsm      *vsm;
60
        struct VSLQ     *vslq;
61
62
        sig_atomic_t    last_sighup;
63
        sig_atomic_t    last_sigusr1;
64
65
        /* Callback functions */
66
        VUT_cb_f        *idle_f;
67
        VUT_cb_f        *sighup_f;
68
        VUT_error_f     *error_f;
69
        VSLQ_dispatch_f *dispatch_f;
70
        void            *dispatch_priv;
71
};
72
73
void VUT_Error(struct VUT *, int status, const char *fmt, ...)
74
    v_noreturn_ v_printflike_(3, 4);
75
76
int VUT_Arg(struct VUT *, int opt, const char *arg);
77
78
//lint -sem(VUT_Usage, r_no)
79
void VUT_Usage(const struct VUT *, const struct vopt_spec *,
80
    int status) v_noreturn_;
81
82 235
#define VUT_InitProg(argc, argv, spec) VUT_Init(argv[0], argc, argv, spec)
83
84
struct VUT * VUT_Init(const char *progname, int argc, char * const *argv,
85
    const struct vopt_spec *);
86
87
void VUT_Signal(VUT_sighandler_f);
88
void VUT_Signaled(struct VUT *, int);
89
90
void VUT_Setup(struct VUT *);
91
int  VUT_Main(struct VUT *);
92
void VUT_Fini(struct VUT **);