home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
- #
- # bug
- #
- # replacement for contact, which is just too annoying to live
-
- eval "exec perl -S $0 $*"
- if $running_under_some_shell_and_would_really_prefer_perl;
-
-
- if (!@ARGV || @ARGV > 2) {
- die <<EOF;
- usage: $0 program [priority]
-
- $0 is a replacement for the contact program.
- Besides figuring out paths and versions for you, and using MH if you
- do, its principal feature is that it plops you right into your editor
- instead of asking you annoying questions.
-
- --tchrist
-
- EOF
- }
-
-
- @SIG{'INT', 'QUIT', 'HUP', 'TERM'} = (
- 'INTR', 'INTR', 'CLEANUP', 'CLEANUP');
-
-
- $editor = $ENV{'EDITOR'} || 'vi';
- $pager = $ENV{'PAGER'} || 'less';
-
-
- $user = getlogin
- || $ENV{'USER'}
- || (getpwuid($<))[0]
- || "an unknown uid";
-
- $home = $ENV{'HOME'}
- || (getpwuid($<))[7]
- || '/';
-
-
- if (&get_cpuid) {
- &get_hostname || die "will not continue without hostname\n";
- } else {
- $alien++;
- $cpuid = 147; # default to sushi, like rb
- $hostname = 'sushi';
- }
- &get_userinfo;
-
- if ( $ENV{'PATH'} =~ m#/mh/bin# && -e "$home/.mh_profile" ) {
- $usemh++;
- $ccline = "Fcc: +bug_reports";
- } else {
- $ccline = "Cc: $user";
- }
-
-
- @PATH = ( '/usr/ucb',
- '/usr/convex',
- '/usr/bin',
- '/bin',
- '/etc',
- '/usr/etc',
- '/usr/toolbox',
- '/usr/bin/X11',
- '/usr/lib',
- '/usr/adm',
- );
-
- @PRIORITY = split(/\n/, <<EOP);
-
- Critical - work cannot proceed until the problem is resolved.
- Serious - work can proceed around the problem, with difficulty.
- Necessary - problem has to be fixed.
- Annoying - problem is bothersome.
- Enhancement - requested enhancement.
- Informative - for informational purposes only.
- EOP
-
- ($product, $priority) = @ARGV;
- $priority = 3 unless $priority;
-
- if ($product !~ m#^/#) {
- for (@PATH) {
- next unless -x "$_/$product";
- $product = "$_/$product";
- last;
- }
- }
- $version = (!$alien && (`vers $product 2>/dev/null` =~ /:\s*(\S+)/)[0])
- || "<unknown version>";
-
- $TMP = "/tmp/bug.$$";
-
- open (TMP, ">$TMP") || die "can't create $TMP: $!";
- $tmpmade++;
- select(TMP);
-
- print <<EOM;
- To: contact
- Subject: CPU-$cpuid ($hostname)
- $ccline
-
- User-Information:
- $userinfo
-
- Product: $product
-
- Version: $version
-
- Summary: <put one line summary here>
-
- Description:
- <put multi-line description here>
-
- Priority: $priority ($PRIORITY[$priority])
-
- Repeat-By:
- <put multi-line how-to-repro desc here>
-
- Comments:
- <put any multi-line comments here>
-
- EOM
-
- close(TMP) || die "can't close $TMP: $!";
-
- select (STDOUT);
-
- if ($usemh) {
- system 'whatnow', $TMP;
- exit unless $?;
- warn "whatnow failed -- reverting to $editor\n";
- }
-
- # otherwise go the hard way
-
- system $editor, $TMP;
-
- $| = 1;
-
-
- for (;;) {
- print 'Send, abort, edit, or list? ';
- chop ($action = <STDIN>);
- redo unless $action;
-
- $action =~ s/(\W)/\\$1/g;
-
- last if 'send' =~ /^$action/i;
-
- if ('abort' =~ /^$action/i) {
- do CLEANUP();
- } elsif ('edit' =~ /^$action/i) {
- system $editor, $TMP;
- } elsif ('list' =~ /^$action/i) {
- system $pager, $TMP;
- } else {
- $action =~ s/\\//g;
- print "Unknown action: \"$action\"\n";
- }
- }
-
- if (system "/usr/lib/sendmail -oi -t < $TMP") {
- warn "couldn't mail contact report\n";
- &CLEANUP;
- }
-
- print "Problem report submitted.\n";
-
- exit 0;
-
- #--------------------------------------------------------
-
- sub get_hostname {
- $hostname = "\0" x 100; # pre-nulled buffer for hostname
- $SYS_gethostname = 87;
- $SIG{'SYS'} = 'NOSYS';
- $syscall = 'gethostname';
-
- if (syscall($SYS_gethostname, $hostname, length($hostname)) < 0) {
- warn "couldn't get hostname cheaply";
- chop($hostname = `hostname`);
- } else {
- $hostname =~ s/[\0\s]*$//; # get rid of nasty nulls
- }
- $SIG{'SYS'} = 'NOSYS';
- $syscall = '';
- $hostname;
- }
-
- sub get_cpuid {
- $SYS_getsysinfo = 203;
- $SYSINFO_SIZE = 12;
- $sysinfo = "\0" x $SYSINFO_SIZE;
- $SIG{'SYS'} = 'NOSYS';
- $syscall = 'getsysinfo';
- if (syscall($SYS_getsysinfo, $SYSINFO_SIZE, $sysinfo) < 0) {
- warn "odd, couldn't get cpuid cheaply";
- chop($cpuid = `cpuid`);
- &NOSYS if $? || !$cpuid;
- } else {
- ( $cpuid, $cpu_type, $cpu_count, $cpu_flags0, $cpu_flags1 )
- = unpack('SCCLL', $sysinfo);
- }
- $SIG{'SYS'} = 'DEFAULT';
- $syscall = '';
-
- $cpuid; # retval
- }
-
- sub get_userinfo {
- $FILE = $home . "/.contact";
- if (-e $FILE) {
- open FILE || die "can't open $FILE: $!";
- undef $/;
- chop($userinfo = <FILE>);
- $/ = "\n";
- } else {
- $gcos = (getpwnam($user))[6];
- ($name, $office, $ophone, $hphone) = split(/,/, $gcos);
- $userinfo = "$name (CONVEX employee)\nOffice: $office\nExtension: x$ophone";
- }
- }
-
-
- sub INTR {
- local($more);
- print STDERR "\nInterrupted\007 -- continue? ";
- chop($more = <STDIN>);
- &CLEANUP() if $more && ('quit' =~ /^$more/i || 'no' =~ /^$more/i);
- print STDERR "(continuing)\n";
- }
-
-
- sub CLEANUP {
- if ($tmpmade) {
- $DEAD = "$home/dead.report";
- close TMP;
- open TMP || die "can't reopen $TMP: $!";
- open(DEAD,">$DEAD") || die "can't open $DEAD: $!";
- print DEAD <TMP>;
- close TMP;
- close DEAD;
- print STDERR "Your squished bug report has been saved in $DEAD\n";
- unlink $TMP;
- }
- exit 1;
- }
-
- sub NOSYS {
- warn <<EOF;
- $0: You don't have a $syscall syscall?!
-
- *** WARNING WARNING WARNING ***
- This doesn't seem like a Convex box to me. I'm going to lie and
- pretend you're on sushi, like rb does. Make sure you get the version
- and path right. They're almost surely wrong right now.
-
- EOF
- sleep 3;
- }
-