-
Notifications
You must be signed in to change notification settings - Fork 0
/
syslog-redirect.in
executable file
·148 lines (132 loc) · 3.29 KB
/
syslog-redirect.in
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/sh
prefix="@prefix@"
exec_prefix="@exec_prefix@"
libdir="@libdir@"
syslog_redirect_so="$libdir/syslog-redirect.@SHARED_LIB_EXT@"
## ======================================================================
case ":$@LD_PRELOAD@:" in
*":$syslog_redirect_so:"*)
;;
*)
@LD_PRELOAD@="${@LD_PRELOAD@:+$@LD_PRELOAD@:}$syslog_redirect_so"
;;
esac
## ======================================================================
pdie() { echo "$0: ERROR: ${1-}" 1>&2; exit "${2-1}"; }
getopts_want_arg()
{
if [[ $# -lt 2 ]]; then
pdie "Option requires an argument: $1"
fi
if [[ -n ${3:+set} ]]; then
if [[ $2 =~ $3 ]]; then
: OK
else
pdie "Invalid value for option: $1: $2"
fi
fi
if [[ -n ${4:+set} ]]; then
if [[ $2 =~ $4 ]]; then
pdie "Invalid value for option: $1: $2"
fi
fi
}
help_p=
while [[ $# -gt 0 ]]; do
opt="$1"; shift
if [[ -z "${opt##-[!-]?*}" ]]; then
set -- "-${opt#??}" ${1+"$@"}
opt="${opt%${1#-}}"
fi
if [[ -z "${opt##--*=*}" ]]; then
set -- "${opt#--*=}" ${1+"$@"}
opt="${opt%%=*}"
fi
case "$opt" in
--help)
help_p='set'
;;
--sh-init)
echo "@LD_PRELOAD@='$@LD_PRELOAD@'"
echo "export @LD_PRELOAD@"
if [ -n "@DYLD_FORCE_FLAT_NAMESPACE@" ]; then
echo "@DYLD_FORCE_FLAT_NAMESPACE@=1"
echo "export @DYLD_FORCE_FLAT_NAMESPACE@"
fi
exit 0
;;
--log-level)
getopts_want_arg "$opt" ${1+"$1"} '^[0-7]$'
SYSLOG_REDIRECT_LOG_LEVEL="$1"; shift
export SYSLOG_REDIRECT_LOG_LEVEL
;;
-t|--print-timestamp)
## FIXME: Not implemented yet
SYSLOG_REDIRECT_PRINT_TIMESTAMP='set'
export SYSLOG_REDIRECT_PRINT_TIMESTAMP
;;
-i|--print-identity)
SYSLOG_REDIRECT_PRINT_IDENTITY='set'
export SYSLOG_REDIRECT_PRINT_IDENTITY
;;
-f|--print-facility)
SYSLOG_REDIRECT_PRINT_FACILITY='set'
export SYSLOG_REDIRECT_PRINT_FACILITY
;;
-l|--print-level)
SYSLOG_REDIRECT_PRINT_LEVEL='set'
export SYSLOG_REDIRECT_PRINT_LEVEL
;;
-a|--print-all)
SYSLOG_REDIRECT_PRINT_IDENTITY='set'
export SYSLOG_REDIRECT_PRINT_IDENTITY
SYSLOG_REDIRECT_PRINT_FACILITY='set'
export SYSLOG_REDIRECT_PRINT_FACILITY
SYSLOG_REDIRECT_PRINT_LEVEL='set'
export SYSLOG_REDIRECT_PRINT_LEVEL
;;
-a|--append-lf)
SYSLOG_REDIRECT_APPEND_LF='set'
export SYSLOG_REDIRECT_APPEND_LF
;;
--)
break
;;
-*)
pdie "Invalid option: $opt"
;;
*)
set -- "$opt" ${1+"$@"}
break
;;
esac
done
if [ $# -lt 1 ] || [ -n "$help_p" ]; then
echo "Usage: $0 [OPTIONS] COMMAND [ARGUMENT ...]" 1>&2
echo
echo "Options:"
echo " --log-level LEVEL"
echo " Specify log level"
echo " Default: 4 (LOG_WARNING)"
echo " -i, --print-identity"
echo " Print identity string to log"
echo " -f, --print-facility"
echo " Print facility string to log"
echo " -l, --print-level"
echo " Print log level string to log"
echo " -a, --print-all"
echo " Print identity, facility and log level string to log"
exit 1
fi
if [ $# -lt 1 ]; then
echo "Usage: $0 COMMAND [ARGUMENT ...]" 1>&2
exit 1
fi
## ======================================================================
export @LD_PRELOAD@
if [ -n "@DYLD_FORCE_FLAT_NAMESPACE@" ]; then
@DYLD_FORCE_FLAT_NAMESPACE@=1
export @DYLD_FORCE_FLAT_NAMESPACE@
fi
exec "$@"
exit $?