Coverage Report

Created: 2023-06-07 06:09

/src/varnish-cache/lib/libvarnish/vas.c
Line
Count
Source (jump to first uncovered line)
1
/*-
2
 * Copyright (c) 2006 Verdens Gang AS
3
 * Copyright (c) 2006-2016 Varnish Software AS
4
 * All rights reserved.
5
 *
6
 * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
7
 *
8
 * SPDX-License-Identifier: BSD-2-Clause
9
 *
10
 * Redistribution and use in source and binary forms, with or without
11
 * modification, are permitted provided that the following conditions
12
 * are met:
13
 * 1. Redistributions of source code must retain the above copyright
14
 *    notice, this list of conditions and the following disclaimer.
15
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in the
17
 *    documentation and/or other materials provided with the distribution.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
23
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29
 * SUCH DAMAGE.
30
 *
31
 * This is the default backend function for libvarnish' assert facilities.
32
 */
33
34
#include "config.h"
35
36
#include <stdio.h>
37
#include <stdlib.h>
38
#include <string.h>
39
40
#include "vdef.h"
41
42
#include "vas.h"
43
44
const char *
45
VAS_errtxt(int e)
46
0
{
47
0
  const char *p;
48
0
  int oerrno = errno;
49
50
0
  p = strerror(e);
51
0
  if (p != NULL)
52
0
    return (p);
53
54
0
  errno = oerrno;
55
0
  return ("strerror(3) returned NULL");
56
0
}
57
58
vas_f *VAS_Fail_Func v_noreturn_;
59
60
void v_noreturn_
61
VAS_Fail(const char *func, const char *file, int line,
62
    const char *cond, enum vas_e kind)
63
0
{
64
0
  int err = errno;
65
66
0
  if (VAS_Fail_Func != NULL) {
67
0
    VAS_Fail_Func(func, file, line, cond, kind);
68
0
  } else {
69
0
    if (kind == VAS_MISSING) {
70
0
      fprintf(stderr,
71
0
          "Missing error handling code in %s(), %s line %d:\n"
72
0
          "  Condition(%s) not true.\n",
73
0
          func, file, line, cond);
74
0
    } else if (kind == VAS_INCOMPLETE) {
75
0
      fprintf(stderr,
76
0
          "Incomplete code in %s(), %s line %d:\n",
77
0
          func, file, line);
78
0
    } else if (kind == VAS_WRONG) {
79
0
      fprintf(stderr,
80
0
          "Wrong turn in %s(), %s line %d: %s\n",
81
0
          func, file, line, cond);
82
0
    } else {
83
0
      fprintf(stderr,
84
0
          "Assert error in %s(), %s line %d:\n"
85
0
          "  Condition(%s) not true.\n",
86
0
          func, file, line, cond);
87
0
    }
88
0
    if (err)
89
0
      fprintf(stderr,
90
0
          "  errno = %d (%s)\n", err, strerror(err));
91
0
  }
92
0
  abort();
93
0
}