File: mvrun_c

package info (click to toggle)
metview 5.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 242,296 kB
  • sloc: cpp: 437,117; ansic: 41,433; xml: 19,944; f90: 13,059; sh: 6,562; python: 3,953; yacc: 1,774; lex: 1,121; perl: 701; makefile: 92
file content (281 lines) | stat: -rw-r--r-- 8,571 bytes parent folder | download | duplicates (6)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/bin/bash

# **************************** LICENSE START ***********************************
#
# Copyright 2012 ECMWF and INPE. This software is distributed under the terms
# of the Apache License version 2.0. In applying this license, ECMWF does not
# waive the privileges and immunities granted to it by virtue of its status as
# an Intergovernmental Organization or submit itself to any jurisdiction.
#
# ***************************** LICENSE END ************************************

#                                                (vk Sep-95, rev 020904)
#
# This is a common version of SGI specific script 'mvrun' that
# has been written only for ECMWF and it has not been
# designed to be portable...
#
# Script executes a metview module and reports crashes by mail.
# (within time this script has grown toooo looooooonnnngggggggg!)

set +e
Module=`basename $1`
start_date=`date`
running_bin="`ls -l $1 | cut -c43-`"
send_mail=NO

#-- these ok for sgimips & rs6000:
MV_DBG=dbx
MV_MAIL=/usr/bin/mail

if [ X$ARCH = Xlinux ]
then
  MV_DBG=gdb
  MV_MAIL=mail
fi

#-- execute module, with possible parameters
if [ $METVIEW_LOG = no_log -o "$METVIEW_LOG" = "-" ]
then
  "$@"
  SUCCESS_STATUS=$?
else
  if [ "$OS" = "hpcf" ]
  then
    MVLOGROOT="$TEMP"
  else
    MVLOGROOT="$SCRATCH"
  fi
  
  MYLOG="$MVLOGROOT/$METVIEW_LOG.$Module.log"
  echo "[mvrun_c info] process $$ starting `date` with cmd:" >| $MYLOG
  echo "[mvrun info] $@"                    >> $MYLOG
  echo "[mvrun info] MAG_HOME = $MAG_HOME"  >> $MYLOG
  echo "[mvrun info] mode is $METVIEW_MODE" >> $MYLOG
  echo " " >> $MYLOG

  /usr/bin/time "$@"      2>&1 | tee -a $MYLOG > /dev/null
  SUCCESS_STATUS=$?

  echo " " >> $MYLOG
  echo "[mvrun info] process $$ ended `date`" >> $MYLOG
  echo "[mvrun info] process exit status was $SUCCESS_STATUS" >> $MYLOG

  #-- if development macro log then no mail => exit
  if [ X$METV_DEV = Xyes ]
  then
    exit $SUCCESS_STATUS
  fi
fi

st_sig=`expr $SUCCESS_STATUS / 128`
st_signal=`expr $SUCCESS_STATUS % 128`
#-- (x:y) were used when divided by 16, now [x:y] when div 128
st_text="$SUCCESS_STATUS [$st_sig:$st_signal]"

current_bin="`ls -l $1 | cut -c43-`"
if [ "$running_bin" != "$current_bin" ]
then
  st_text="UPDATED!"
fi

MVUSERID=$USER
[ "$MVUSERID" = "" ] && MVUSERID=$LOGNAME
[ "$MVUSERID" = "" ] && MVUSERID="???"

if [ $st_sig -ne 0 ]
then
  send_mail=YES
  case $st_signal in
    1)
      send_mail=NO
      ;;
    2)
      send_mail=NO
      ;;
    4)
      st_reason="Illegal Instruction"
      ;;
    5)
      st_reason="Trace/Breakpoint Trap"
      ;;
    6)
      st_reason="Abort"
      ;;
    7)
      st_reason="Emulation Trap"
      ;;
    8)
      st_reason="Arithmetic Exception"
      ;;
    10)
      st_reason="Bus Error"
      ;;
    11)
      st_reason="Segmentation Fault"
      ;;
    12)
      st_reason="Bad System Call"
      ;;
    *)
      send_mail=NO
      st_reason="(reason not decoded)"

      MV_CRASH_LOG="/home/graphics/cgx/public/Metview_crashlog_nomail"
      if [ ! -f $MV_CRASH_LOG ]
      then
        touch $MV_CRASH_LOG
        chmod 666 $MV_CRASH_LOG
        #-- give file to cgx (not to decrease users available disk quota) --
        chown cgx $MV_CRASH_LOG
      fi
      #echo "`date -u '+%d.%m.%Y %R'`; $Module; `echo $METVIEW_MODE | cut -c1`; $st_text; $MVUSERID; `hostname`; `cat $METVIEW_DIR_SHARE/app-defaults/MvTitleBarVersionText`" >> $MV_CRASH_LOG
      echo "`date -u '+%d.%m.%Y %R'`; $MVUSERID; `echo $METVIEW_MODE | cut -c1`; $st_text; $Module; `hostname`; $METVIEW_VERSION_TITLE" >> $MV_CRASH_LOG
      ;;
  esac
fi

#-- is this a Graphics Section user id --#
graph_uid=NO
if [ X`echo $MVUSERID | cut -c 1-2` = Xcg ]
then
  graph_uid=YES
fi

#-- do the hard work if really crashed and not Graphics id
if [ $send_mail = YES ]
then
  UserMsg=/tmp/crash_$$.$Module.UserMsg
  MailMsg=/tmp/crash_$$.$Module.MailMsg
  Person=`finger $LOGNAME | grep "name: $LOGNAME" | cut -f3 -d: | head -1`

  #-- log into logfile --
  MV_CRASH_LOG="/home/graphics/cgx/public/Metview_crashlog_`cat $METVIEW_DIR_SHARE/app-defaults/MvVersion`"
  if [ ! -f $MV_CRASH_LOG ]
  then
    touch $MV_CRASH_LOG
    chmod 666 $MV_CRASH_LOG
    #-- give file to cgx (not to decrease users available disk quota) --
    chown cgx $MV_CRASH_LOG
  fi
  #-- new crash file format 25.3.1998, add METVIEW_MODE first letter 6.8.1998 --
  #-- 2000-08-18: make column widths more even i.e. constant width values first --
  echo "`date -u '+%d.%m.%Y %R'`; $MVUSERID; `echo $METVIEW_MODE | cut -c1`; $st_text; $Module; `hostname`; `cat $METVIEW_DIR_SHARE/app-defaults/MvTitleBarVersionText`" >> $MV_CRASH_LOG

  #-- inform user about crash and core --
  echo " " >> $UserMsg
  echo "This is an automatic message to Metview user $Person:"    > $UserMsg
  echo "a module '$Module' just crashed in your Metview session !">>$UserMsg

  if [ "$running_bin" != "$current_bin" ]
  then
    echo " " >> $UserMsg
    echo " " >> $UserMsg
    echo "________THIS CRASH WAS CAUSED BY A METVIEW UPDATE !!!!!" >> $UserMsg
  fi
  echo "________" >> $UserMsg
  echo " " >> $UserMsg

  if [ -s core ]
  then
    echo "You have the following core file in your directory:" >> $UserMsg
    ls -l core >> $UserMsg
    file core >> $UserMsg
    echo "________" >> $UserMsg
    echo " " >> $UserMsg
    #-- ecquota is an ECMWF modification for HP servers --
    ecquota -v >> $UserMsg
  else
    echo "No core file was produced or the core file is empty !" >> $UserMsg
  fi
  echo " " >> $UserMsg

  if [ "$running_bin" = "$current_bin" ]
  then
   echo "    +------------------------------------------------------+">>$UserMsg
   echo "    |      A Metview module has crashed unexpectedly!      |">>$UserMsg
   echo "    |     Sorry for the trouble it may have caused you.    |">>$UserMsg
   echo "    |                                                      |">>$UserMsg
   echo "    | If this happens repeatedly then please contact us.   |">>$UserMsg
   echo "    | We would be very happy to have a look at the problem |">>$UserMsg
   echo "    | in order to fix it as soon as possible.              |">>$UserMsg
   echo "    |                                                      |">>$UserMsg
   echo "    |          Software Applications Team, ECMWF           |">>$UserMsg
   echo "    +------------------------------------------------------+">>$UserMsg
   echo " " >> $UserMsg
  fi

  [ -s core ] && echo "Check your disk quota" >> $UserMsg
  echo "  M e t v i e w" >> $UserMsg

  if [ $graph_uid = YES ]
  then
    echo " " >> $UserMsg
    echo " ($MVUSERID is Graphics User Id => no email will be sent!)" >> $UserMsg
  fi

  if [ $METVIEW_MODE = batch ]
  then
    $MV_MAIL $MVUSERID < $UserMsg
  else
    xterm -title "Metview Crash Info" -bg gray -fg red4 -b 12 -e view $UserMsg &
    #-- try to make sure window appears even when network is slow...
    sleep 15
  fi

  #-- inform Metview group by mail --
  SUBJ="Mv_$METVIEW_RELEASE-$Module-crash"
  cat $METVIEW_DIR_SHARE/app-defaults/MvTitleBarVersionText >> $MailMsg
  echo " " >> $MailMsg
  echo "$Module: $st_reason! (status=$SUCCESS_STATUS: code=$st_sig, signal=$st_signal)" >> $MailMsg
  echo "User is $MVUSERID:$Person on `hostname` (informed)" >> $MailMsg

  #-- phone number is an ECMWF command!!!
  pn "\[$MVUSERID" >> $MailMsg

  echo " " >> $MailMsg
  echo "Started: $start_date" >> $MailMsg
  echo "Crashed: `date`" >> $MailMsg
  echo " " >> $MailMsg
  echo "Crashed binary: $running_bin" >> $MailMsg
  echo "Current binary: $current_bin" >> $MailMsg
  if [ "$running_bin" != "$current_bin" ]
  then
    echo " " >> $MailMsg
    echo "!!!!!! CRASH DUE TO EXECUTABLE UPDATE !!!!!" >> $MailMsg
  fi
  echo " " >> $MailMsg

  if [ -s core ]
  then
    CoreOk=`file core | grep $Module`
    file core >> $MailMsg
    echo "file etc.: `ls -l core | cut -c17-`" >> $MailMsg
    echo "directory: `pwd`" >> $MailMsg
    chmod 777 core

    if [ "$CoreOk" != "" ]
    then
      #-- examine call stack, redirect & tee to catch crash reason
      echo " " >> $MailMsg
      echo "where;quit" | $MV_DBG $1 core 2>&1 | tee -a $MailMsg
    else
      echo " " >> $MailMsg
      echo "Wrong core file !" >> $MailMsg
    fi
  else
    echo "No core file or core file empty !" >> $MailMsg
  fi

  if [ $graph_uid = NO ]
  then
    #-- do not use full address 'name-at-ecmwf-dot-int'
    METVIEW_SUPPORT_MAIL=${METVIEW_SUPPORT_MAIL:=metviewbugs}
    $MV_MAIL -s $SUBJ $METVIEW_SUPPORT_MAIL < $MailMsg
    # $MV_MAIL -s $SUBJ cgh < $MailMsg
  fi

  rm -f $MailMsg
  rm -f $UserMsg
fi
exit $SUCCESS_STATUS