Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
7.3 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM <<template_script.cmd>>
  5. REM <<purpose of this script>>
  6. REM
  7. REM Copyright (c) Microsoft Corporation. All rights reserved.
  8. REM
  9. REM ------------------------------------------------------------------
  10. perl -x "%~f0" %*
  11. goto :EOF
  12. #!perl
  13. use strict;
  14. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  15. use lib $ENV{RAZZLETOOLPATH};
  16. use PbuildEnv;
  17. use ParseArgs;
  18. use File::Basename;
  19. require "sendmsg.pl";
  20. # vars,consts
  21. my $MASK="\*\.err\.tmp";
  22. my %known=(); # COLLECT BAD FILES WITH BAD WORDS
  23. my $DEBUG=1;
  24. my $LOOP=10;
  25. my $SLEEP=120;
  26. my $TRUE=1;
  27. my $BASE=undef;
  28. my @BASELIST = ();
  29. my $BASELIST = "";
  30. my $INITBASELIST;
  31. my $DOPRINT=undef;
  32. my $NOMAIL=undef;
  33. my $RECEIVERS;
  34. my $scriptname = basename $0;
  35. sub Usage { print<<USAGE; exit(1) }
  36. Polls the temporary error files in the %TEMP% directory, piping them
  37. through mail to designated user list and/or printing when they appear.
  38. Usage:
  39. $scriptname [-l:<lang>|-p|-d] [-s|-m:alias]
  40. -l:<LANG> Default is "usa".
  41. -m:<ALIAS> Use alias to pipe to mail to. Default alias found
  42. by "TapeLineErrReceiver" keyword in .ini files.
  43. -s (Silent) No mail.
  44. -u:<LIST> To check distributed build logs, provide the list os shares to monitor, e.g
  45. $0 -u:\\\\x86fre00\\bc_build_logs\\usa;\\\\x86fre01\\bc_build_logs\\usa;...;\\\\x86fre04\\bc_build_logs\\usa
  46. using just -u will lead to standard US distributed build machines
  47. to be polled.
  48. -p Print to screen.
  49. -d Include debugging information.
  50. -b:<DIR> Specify the base directory to poll (defaults to \%TEMP\%)
  51. Examples:
  52. $scriptname -l:GER -p -d:\%TEMP\% -s
  53. $scriptname -p -d -b:\lp.temp.ia64\chh
  54. USAGE
  55. parseargs('?' => \&Usage,
  56. 's' => \$NOMAIL,
  57. 'p' => \$DOPRINT,
  58. 'd' => \$DEBUG,
  59. 'u:' => \$BASELIST,
  60. 'u' => \$INITBASELIST,
  61. 'm:' => \$RECEIVERS,
  62. 'b:' => \$BASE
  63. );
  64. $BASE = $ENV{"TEMP"} unless $BASE;
  65. @BASELIST = ();
  66. $DOPRINT= 1;
  67. $BASE =~ s/\%(\w+)\%/$ENV{$1}/ieg;
  68. push @BASELIST, $BASE;
  69. $BASELIST and @BASELIST = split (";", $BASELIST);
  70. &InitBaseList() if $INITBASELIST;
  71. $DEBUG and print STDERR join "\n", @BASELIST , "\n\n";
  72. my $loop=0;
  73. while($TRUE){
  74. $loop=$loop+1;
  75. my %new = map {$_=>&TkPeek($_)} &Tapeline;
  76. $DEBUG and print STDERR join "\n", keys(%new), "\n\n";
  77. $DEBUG and print STDERR "total=", scalar(keys(%new)),"\n";
  78. foreach my $bits (keys(%new)){
  79. delete $new{$bits} and next unless scalar(@{$new{$bits}}) and
  80. (!defined $known{$bits} or
  81. "@{$known{$bits}}" cmp "@{$new{$bits}}");
  82. $DEBUG and print STDERR "new file:", $bits, "\n";
  83. $known{$bits} = $new{$bits};
  84. }
  85. $DEBUG and print STDERR "new=",scalar(keys(%new)),"\n";
  86. map {&NicePrint($_, @{$known{$_}})} keys(%new);
  87. &OutDoor and last;
  88. map {&Gone($_) and delete $known{$_}} keys(%known);
  89. sleep $SLEEP;
  90. last if $DEBUG and $loop > $LOOP;
  91. }
  92. sub InitBaseList{
  93. # should it better parse main.usa.ini ?
  94. my @buildmachines = ();
  95. push @buildmachines , map {"x86fre0$_"} 0..4 ;
  96. push @buildmachines , map {"x86chk0$_"} 0..4 ;
  97. push @buildmachines , map {"ia64fre0$_"} 0..4 ;
  98. push @buildmachines , map {"ia64chk0$_"} 0..4 ;
  99. @BASELIST = map {"\\\\$_\\bc_build_logs\\usa"} @buildmachines ;
  100. }
  101. sub Tapeline{
  102. my @list;
  103. foreach my $BASE (@BASELIST){
  104. $DEBUG and print STDERR "dir /b $BASE\\$MASK 2>NUL\n";
  105. push @list, map {"$BASE\\$_"} grep {/\W/} split("\n", qx("dir /b $BASE\\$MASK 2>NUL"));
  106. }
  107. @list;
  108. }
  109. sub OutDoor{
  110. # Go home:
  111. # !-d $ENV{"_NTPOSTBLD"};
  112. # qx("tlist|findstr -i postbuild.cmd");
  113. 0;
  114. }
  115. sub Gone{
  116. # Forget who gone
  117. !-e shift;
  118. }
  119. sub NicePrint{
  120. local $\="\n";
  121. my $Sender=$ENV{"COMPUTERNAME"};
  122. my $Title="Error files detected in $BASE,".
  123. $ENV{"LANG"}.
  124. " ".
  125. $ENV{"COMPUTERNAME"};
  126. my @MessageLines = @_;
  127. splice @MessageLines, 1, 0, " "x79;
  128. foreach my $MessageLine (@MessageLines){
  129. chomp $MessageLine;
  130. }
  131. $DOPRINT and map {print} @MessageLines;
  132. my @Receivers=split(",", $RECEIVERS);
  133. @Receivers = &Receivers unless $DEBUG or @Receivers;
  134. foreach my $Receiver (@Receivers){
  135. $NOMAIL or
  136. &sendmsg(($DEBUG) ? "-v": "",
  137. $Sender,
  138. $Title,
  139. join($\, @MessageLines),
  140. $Receiver);
  141. }
  142. 1;
  143. }
  144. sub TkPeek{
  145. open WPEEKF, shift;
  146. my @inside= grep {/\S/} <WPEEKF>;close(WPEEKF);
  147. \@inside;
  148. }
  149. sub Receivers{
  150. my @Receivers=qx("perl \%RazzleToolPath\%\\PostBuildScripts\\CmdIniSetting.pl -l:\%LANG\% -f:TapeLineErrReceiver 2>NUL".
  151. ($DOPRINT) ? "2>NUL": "");
  152. @Receivers;
  153. }
  154. __END__
  155. =head1 SEE ALSO
  156. =head1 AUTHOR
  157. <serguei kouzmine >
  158. =head1 DESCRIPTION
  159. tapeline.cmd
  160. Error file polling agent.
  161. The error log ($MASK) files found in %TEMP% reported to the user mail immediately to save from
  162. dead build runs.
  163. The script loops indefinitely during the postbuild, or other build steps
  164. until &OutDoor function gives it TRUE, or until $loop count reaches $LOOP value
  165. (in case you $DEBUG).
  166. Dummy OutDoor function checking %_NTPOSTBLD% no more exists, is provided.
  167. In the current design there
  168. is no way to stop tapeline.cmd from running except for process managed.
  169. Every round, the files of $MASK ("*.err.tmp") are checked in the %TEMP%.
  170. Each of these file names is stored in %new keys. Contents of the file are stored in $new->
  171. Every time %new information is not %known, mail is sent
  172. about all the %new - %known error logs.
  173. When %known file disappears, this is handled silently.
  174. So all the error log files encountered since the start are mailed to the list of users defined in
  175. scope .ini files: once mail per person per each new file.
  176. The mail list identified by the script had the tag "TapeLineErrReceiver"
  177. -----------------------------------------------------------------------------------------
  178. I only see one specific case where that would be a problem.
  179. When a program runs it deletes .err.tmp file if one exists and will create a new one if an error occurs. When the program is done it will open the .err.tmp file for reading and append it to a .err file and then delete the .err.tmp file.
  180. If a program is run twice and the polling program causes the final delete of the first run and the inital delete of the second run to fail then the second run will report the same errors as the first one.
  181. That is the only thing I can come up with right now, I don't think it is a very big risk.
  182. The way I normally look for errors is to do a findstr /c:"error:" %temp%\lang\postbuild.*.int.log. That file is only deleted at the very beginning of postbuild.cmd.
  183. Jeremy
  184. The list of shared directories to lookup the error message files in is recognized.