On linux, report version of kernel headers seen by compiler.
[kopensolaris-gnu/glibc.git] / glibcbug.in
1 #! /bin/sh
2 #
3 # glibcbug - create a bug report and mail it to the bug address.
4 #
5 # configuration section:
6 #       these variables are filled in by configure
7 #
8 VERSION="@VERSION@"
9 BUGGLIBC="bugs@gnu.org"
10 ADDONS="@subdirs@"
11 HOST="@host@"
12 CC='@CC@'
13 CFLAGS="@CFLAGS@"
14 VERSIONING="@VERSIONING@"
15 BUILD_STATIC="@static@"
16 BUILD_SHARED="@shared@"
17 BUILD_PIC_DEFAULT="@pic_default@"
18 BUILD_PROFILE="@profile@"
19 BUILD_OMITFP="@omitfp@"
20 BUILD_BOUNDED="@bounded@"
21 BUILD_STATIC_NSS="@static_nss@"
22 STDIO="@stdio@"
23
24 PATH=/bin:/usr/bin:/usr/local/bin:$PATH
25 export PATH
26
27 TEMP=`mktemp -q /tmp/glibcbugXXXXXX 2>/dev/null`
28 if test $? -ne 0; then
29   TEMP=/tmp/glibcbug.$$
30   echo > $TEMP
31   chmod 600 $TEMP
32 fi
33 TEMPx=`mktemp -q /tmp/glibcbugXXXXXX 2>/dev/null`
34 if test $? -ne 0; then
35   TEMPx=/tmp/glibcbug.$$.x
36   echo > $TEMPx
37   chmod 600 $TEMPx
38 fi
39
40 BUGADDR=${1-$BUGGLIBC}
41
42 : ${EDITOR=emacs}
43
44 : ${USER=${LOGNAME-`whoami`}}
45
46 trap 'rm -f $TEMP $TEMPx; exit 1' 1 2 3 13 15
47 trap 'rm -f $TEMP $TEMPx' 0
48
49
50 # How to read the passwd database.
51 PASSWD="cat /etc/passwd"
52
53 if [ -f /usr/lib/sendmail ] ; then
54         MAIL_AGENT="/usr/lib/sendmail -oi -t"
55 elif [ -f /usr/sbin/sendmail ] ; then
56         MAIL_AGENT="/usr/sbin/sendmail -oi -t"
57 else
58         MAIL_AGENT=rmail
59 fi
60
61 # Figure out how to echo a string without a trailing newline
62 N=`echo 'hi there\c'`
63 case "$N" in
64 *c)     ECHON1='echo -n' ECHON2= ;;
65 *)      ECHON1=echo ECHON2='\c' ;;
66 esac
67
68 # Find out the name of the originator of this PR.
69 if [ -n "$NAME" ]; then
70   ORIGINATOR="$NAME"
71 elif [ -f $HOME/.fullname ]; then
72   ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
73 else
74   # Must use temp file due to incompatibilities in quoting behavior
75   # and to protect shell metacharacters in the expansion of $LOGNAME
76   $PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP
77   ORIGINATOR="`cat $TEMP`"
78 fi
79
80 if [ -n "$ORGANIZATION" ]; then
81   if [ -f "$ORGANIZATION" ]; then
82     ORGANIZATION="`cat $ORGANIZATION`"
83   fi
84 else
85   if [ -f $HOME/.organization ]; then
86     ORGANIZATION="`cat $HOME/.organization`"
87   elif [ -f $HOME/.signature ]; then
88     ORGANIZATION=`sed -e "s/^/  /" $HOME/.signature; echo ">"`
89   fi
90 fi
91
92 # If they don't have a preferred editor set, then use
93 if [ -z "$VISUAL" ]; then
94   if [ -z "$EDITOR" ]; then
95     EDIT=vi
96   else
97     EDIT="$EDITOR"
98   fi
99 else
100   EDIT="$VISUAL"
101 fi
102
103 # Find out some information.
104 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
105         ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
106 ARCH=`[ -f /bin/arch ] && /bin/arch`
107 MACHINE=`[ -f /bin/machine ] && /bin/machine`
108 CCVERSION=`$CC -v 2>&1 | sed -n 's/gcc version //p'`
109
110 case $HOST in *linux*)
111   KHDRS=`(echo '#include <linux/version.h>
112           echo '! UTS_RELEASE' ) |
113          $CC -E - | sed -n '/!/s/[! "]//gp'`;;
114 esac
115
116 ORGANIZATION_C='<organization of PR author (multiple lines)>'
117 SYNOPSIS_C='<synopsis of the problem (one line)>'
118 SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
119 PRIORITY_C='<[ low | medium | high ] (one line)>'
120 CLASS_C='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
121 RELEASE_C='<release number or tag (one line)>'
122 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
123 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
124 HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
125 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
126
127
128 cat > $TEMP <<EOF
129 SEND-PR: -*- send-pr -*-
130 SEND-PR: Lines starting with \`SEND-PR' will be removed automatically, as
131 SEND-PR: will all comments (text enclosed in \`<' and \`>').
132 SEND-PR:
133 From: ${USER}
134 To: ${BUGADDR}
135 Subject: [50 character or so descriptive subject here (for reference)]
136
137 >Submitter-Id:  net
138 >Originator:    ${ORIGINATOR}
139 >Organization:
140 ${ORGANIZATION- $ORGANIZATION_C}
141 >Confidential:  no
142 >Synopsis:      $SYNOPSIS_C
143 >Severity:      $SEVERITY_C
144 >Priority:      $PRIORITY_C
145 >Category:      libc
146 >Class:         $CLASS_C
147 >Release:       libc-${VERSION}
148 >Environment:
149         $ENVIRONMENT_C
150 `[ -n "$HOST" ] && echo Host type: $HOST`
151 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
152 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
153 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
154 `[ -n "$ADDONS" ] && echo Addons: $ADDONS`
155 `[ -n "$CFLAGS" ] && echo Build CFLAGS: $CFLAGS`
156 `[ -n "$CC" ] && echo Build CC: $CC`
157 `[ -n "$CCVERSION" ] && echo Compiler version: $CCVERSION`
158 `[ -n "$KHDRS" ] && echo Kernel headers: $KHDRS`
159 `[ -n "$VERSIONING" ] && echo Symbol versioning: $VERSIONING`
160 `[ -n "$BUILD_STATIC" ] && echo Build static: $BUILD_STATIC`
161 `[ -n "$BUILD_SHARED" ] && echo Build shared: $BUILD_SHARED`
162 `[ -n "$BUILD_PIC_DEFAULT" ] && echo Build pic-default: $BUILD_PIC_DEFAULT`
163 `[ -n "$BUILD_PROFILE" ] && echo Build profile: $BUILD_PROFILE`
164 `[ -n "$BUILD_OMITFP" ] && echo Build omitfp: $BUILD_OMITFP`
165 `[ -n "$BUILD_BOUNDED" ] && echo Build bounded: $BUILD_BOUNDED`
166 `[ -n "$BUILD_STATIC_NSS" ] && echo Build static-nss: $BUILD_STATIC_NSS`
167 `[ -n "$STDIO" ] && echo Stdio: $STDIO`
168
169 >Description:
170         $DESCRIPTION_C
171 >How-To-Repeat:
172         $HOW_TO_REPEAT_C
173 >Fix:
174         $FIX_C
175 EOF
176
177 chmod u+w $TEMP
178 cp $TEMP $TEMPx
179
180 eval $EDIT $TEMP
181
182 if cmp -s $TEMP $TEMPx; then
183         echo "File not changed, no bug report submitted."
184         exit 1
185 fi
186
187 #\f
188 #       Check the enumeration fields
189
190 # This is a "sed-subroutine" with one keyword parameter
191 # (with workaround for Sun sed bug)
192 #
193 SED_CMD='
194 /$PATTERN/{
195 s|||
196 s|<.*>||
197 s|^[    ]*||
198 s|[     ]*$||
199 p
200 q
201 }'
202
203
204 while :; do
205   CNT=0
206
207   #
208   # 1) Severity
209   #
210   PATTERN=">Severity:"
211   SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
212   case "$SEVERITY" in
213     ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
214     *)  echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
215   esac
216   #
217   # 2) Priority
218   #
219   PATTERN=">Priority:"
220   PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
221   case "$PRIORITY" in
222     ""|low|medium|high) CNT=`expr $CNT + 1` ;;
223     *)  echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
224   esac
225   #
226   # 3) Class
227   #
228   PATTERN=">Class:"
229   CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
230   case "$CLASS" in
231     ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
232     *)  echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
233   esac
234
235   [ $CNT -lt 3 ] &&
236     echo "Errors were found with the problem report."
237
238   while :; do
239     $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
240     read input
241     case "$input" in
242       a*)
243         echo "$COMMAND: problem report saved in $HOME/dead.glibcbug."
244         cat $TEMP >> $HOME/dead.glibcbug
245         xs=1; exit
246         ;;
247       e*)
248         eval $EDIT $TEMP
249         continue 2
250         ;;
251       s*)
252         break 2
253         ;;
254     esac
255   done
256 done
257 #
258 #       Remove comments and send the problem report
259 #       (we have to use patterns, where the comment contains regex chars)
260 #
261 # /^>Originator:/s;$ORIGINATOR;;
262 sed  -e "
263 /^SEND-PR:/d
264 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
265 /^>Confidential:/s;<.*>;;
266 /^>Synopsis:/s;$SYNOPSIS_C;;
267 /^>Severity:/s;<.*>;;
268 /^>Priority:/s;<.*>;;
269 /^>Class:/s;<.*>;;
270 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
271 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
272 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
273 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
274 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
275 " $TEMP > $TEMPx
276
277 if $MAIL_AGENT < $TEMPx; then
278   echo "$COMMAND: problem report sent"
279   xs=0; exit
280 else
281   echo "$COMMAND: mysterious mail failure, report not sent."
282   echo "$COMMAND: problem report saved in $HOME/dead.glibcbug."
283   cat $TEMP >> $HOME/dead.glibcbug
284 fi
285
286 exit 0