File: error.c

package info (click to toggle)
echoping 6.0.2-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 9,296 kB
  • ctags: 515
  • sloc: sh: 8,951; ansic: 3,352; makefile: 170
file content (116 lines) | stat: -rw-r--r-- 2,271 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "echoping.h"

/* $Id: error.c 377 2007-03-12 20:48:05Z bortz $ */

/* Most of error-handling routines stolen from Stevens' books */

void
my_perror()
{
	fprintf(stderr, " %s\n", sys_err_str());
}

/*
 * Recoverable error.  Print a message, and return to caller. 
 *
 * err_ret(str, arg1, arg2, ...) 
 *
 * The string "str" must specify the conversion specification for any args. 
 */

/* VARARGS1 */
void
err_ret(char *str, ...)
{
	va_list         args;

	va_start(args, str);
	vfprintf(stderr, str, args);
	va_end(args);

	my_perror();

	fflush(stdout);
	fflush(stderr);

	return;
}

/*
 * Fatal error.  Print a message and terminate. Don't dump core and don't
 * print the system's errno value. 
 *
 * err_quit(str, arg1, arg2, ...) 
 *
 * The string "str" must specify the conversion specification for any args. 
 */

/* VARARGS1 */
void
err_quit(char *str, ...)
{
	va_list         args;

	va_start(args, str);
	vfprintf(stderr, str, args);
	fputc('\n', stderr);
	va_end(args);

	exit(1);
}

/*
 * Fatal error related to a system call.  Print a message and terminate.
 * Don't dump core, but do print the system's errno value and its associated
 * message. 
 *
 * err_sys(str, arg1, arg2, ...) 
 *
 * The string "str" must specify the conversion specification for any args. 
 */

/* VARARGS1 */
void
err_sys(char *str, ...)
{
	va_list         args;

	va_start(args, str);
	vfprintf(stderr, str, args);
	va_end(args);

	my_perror();

	exit(1);
}

void
usage(poptContext context)
{
	poptPrintUsage(context, stderr, 0);
	fprintf(stderr, " hostname [plugin-options...]\n");
	exit(1);
}

/*
 * Return a string containing some additional operating-system dependent
 * information. Note that different versions of UNIX assign different
 * meanings to the same value of "errno" (compare errno's starting with 35
 * between System V and BSD, for example).  This means that if an error
 * condition is being sent to another UNIX system, we must interpret the
 * errno value on the system that generated the error, and not just send the
 * decimal value of errno to the other system. 
 */

char           *
sys_err_str()
{
	static char     msgstr[200];

	if (errno != 0) {
		sprintf(msgstr, "(%s)", strerror(errno));
	} else {
		msgstr[0] = '\0';
	}
	return (msgstr);
}