--- scsiinfo-1.7/Makefile
+++ scsiinfo-1.7/Makefile
@@ -1,28 +1,34 @@
-CFLAGS=-O2 -fomit-frame-pointer -Wall -fno-strength-reduce
+CFLAGS=-O2 -Wall -D_GNU_SOURCE
 #CFLAGS=-g -Wall -fno-strength-reduce
-LDFLAGS=-s
+LDFLAGS=
 
 #do not modify this without changing the tcl/tk scripts
 
 BINDIR=/usr/lib/scsi
-MANDIR=/usr/man
+MANDIR=/usr/share/man
+DESTDIR=
 WISHEXECS=tk/cache tk/control tk/disconnect tk/error tk/format\
 	tk/inquiry tk/notch tk/peripheral tk/rigid tk/save-changes tk/verify\
 	tk/save-file tk/overview
 TARGETS=scsiinfo scsiformat tworands
+DOC = 0-CHANGES 0-README.first 0-TODO
 
 .PHONY: all install dist clean
 
 all: $(TARGETS)
 
 install: $(TARGETS) $(WISHEXECS) scsi-config tk_scsiformat
-	cp scsiinfo scsiformat /usr/bin
-	if [ ! -d $(BINDIR) ]; then mkdir -p $(BINDIR); fi
-	cp tworands $(BINDIR)
-	install-wish $(BINDIR) $(WISHEXECS)
-	install-wish /usr/bin scsi-config tk_scsiformat
-	cp tk/generic $(BINDIR)
-	cp man8/* $(MANDIR)/man8
+	install -d $(DESTDIR)/usr/bin
+	install -m 755 scsiinfo scsiformat $(DESTDIR)/usr/bin
+	install -d $(DESTDIR)$(BINDIR)
+	install -m 755 tworands $(DESTDIR)$(BINDIR)
+	./install-wish $(DESTDIR)$(BINDIR) $(WISHEXECS)
+	./install-wish $(DESTDIR)/usr/bin scsi-config tk_scsiformat
+	install -m 644 tk/generic $(DESTDIR)$(BINDIR)
+	install -d $(DESTDIR)$(MANDIR)/man8
+	install -m 644 man8/* $(DESTDIR)$(MANDIR)/man8
+	install -d $(DESTDIR)/usr/sbin
+	install -m 755 sgcheck $(DESTDIR)/usr/sbin/
 
 clean:
 	rm -f core *~ *.o $(TARGETS)
--- scsiinfo-1.7/scsi-config
+++ scsiinfo-1.7/scsi-config
@@ -16,7 +16,7 @@
 	 configuration options for a scsi device}
     pack .warn.h.l .warn.h.m -side left -padx 10
     frame .warn.f
-    button .warn.f.quit -text "Quit" -command exit \
+    button .warn.f.quit -text "Quit" -command {[exec rm -fr $tmpdir ;exit]} \
 	-activeforeground white -activebackground red
     button .warn.f.continue -text "Continue anyway" -activebackground green \
 	-command {destroy .warn}
@@ -26,6 +26,17 @@
     tkwait window .warn
 }
 
+# security counter measures
+set tmpdir "/tmp/.scsi-config"
+
+
+exec rm -rf $tmpdir
+if {![file exists $tmpdir]} {exec mkdir $tmpdir }
+
+#exec rm -rf $tmpdir
+#if { [exec mkdir $tmpdir] != 0 } exit;
+
+
 set sdevice $argv
 while { [string compare [lindex $sdevice 0] ""] == 0 } {
     frame .select
@@ -34,7 +45,7 @@
     message .select.h.m -aspect 200 -background pink -text \
 	{Select a scsi device}
     frame .select.f
-    button .select.f.quit -text "Quit" -command exit \
+    button .select.f.quit -text "Quit" -command {[exec rm -fr $tmpdir ;exit]} \
 	-activeforeground white -activebackground red
     button .select.f.continue -text "Continue" -activebackground green \
 	-command {destroy .select}
@@ -42,11 +53,11 @@
     pack .select.h.l .select.h.m -side left -padx 10
     pack .select.h .select.f -pady 10
     pack .select
-    exec /usr/bin/scsiinfo -l > /tmp/devices
-    if {[catch {set file [open /tmp/devices r]}] == 1} return;
+    exec /usr/bin/scsiinfo -l > $tmpdir/devices
+    if {[catch {set file [open $tmpdir/devices r]}] == 1} return;
     gets $file line
     close $file
-    exec rm /tmp/devices
+    exec rm $tmpdir/devices
     set n 0
     foreach x $line { 
        radiobutton .select.$n -text "$x" -width 10   -variable sdevice -value $x -anchor w
@@ -59,6 +70,7 @@
 	.select.0 select
     }
     tkwait window .select
+#    exec rm -rf $tmpdir
 }
 
 proc showdef {flag} {
@@ -117,14 +129,14 @@
 frame .f_top
 
 set line {}
-exec /usr/bin/scsiinfo -X -L $sdevice > /tmp/cachepage
-if {[catch {set file [open /tmp/cachepage r]}] == 1} return;
+exec /usr/bin/scsiinfo -X -L $sdevice > $tmpdir/cachepage
+if {[catch {set file [open $tmpdir/cachepage r]}] == 1} return;
 gets $file line
 set pages_sup [lindex $line 0]
 set pages_notch [lindex $line 1]
 set curr_not [lindex $line 2]
 close $file
-exec rm /tmp/cachepage
+exec rm $tmpdir/cachepage
 
 button .f_top.info -text "Device Info" -command "exec /usr/lib/scsi/inquiry $sdevice" \
 	-activebackground green
@@ -142,7 +154,7 @@
 
 pack .f_top.filesave -side left -padx 12 -ipadx 2 -ipady 2
 
-button .f_top.quit -text "Quit" -command { exit } \
+button .f_top.quit -text "Quit" -command {[exec rm -fr $tmpdir ;exit]} \
 	-activebackground red -activeforeground white
 
 pack .f_top.quit -side left -padx 12 -ipadx 2 -ipady 2
@@ -202,12 +214,12 @@
 
   exec /usr/lib/scsi/notch $sdevice
   set line {}
-  exec /usr/bin/scsiinfo -X -L $sdevice > /tmp/cachepage
-  if {[catch {set file [open /tmp/cachepage r]}] == 1} return;
+  exec /usr/bin/scsiinfo -X -L $sdevice > $tmpdir/cachepage
+  if {[catch {set file [open $tmpdir/cachepage r]}] == 1} return;
   gets $file line
   set curr_not [lindex $line 2]
   close $file
-  exec rm /tmp/cachepage
+  exec rm $tmpdir/cachepage
   .notchinfo.notchnum configure -text $curr_not
 }
 
--- scsiinfo-1.7/scsiformat.c
+++ scsiinfo-1.7/scsiformat.c
@@ -45,10 +45,29 @@
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
+#if defined __GLIBC__ && __GLIBC__ >= 2
+#include <sys/user.h>
+#include <sys/mount.h>
+#include <sys/swap.h>
+#else
 #include <linux/swap.h>
 #include <linux/fs.h>
+#endif
 #include <linux/hdreg.h>
-#include <linux/genhd.h>
+/* #include <linux/genhd.h> */
+
+struct partition {
+        unsigned char boot_ind;         /* 0x80 - active */
+        unsigned char head;             /* starting head */
+        unsigned char sector;           /* starting sector */
+        unsigned char cyl;              /* starting cylinder */
+        unsigned char sys_ind;          /* What partition type */
+        unsigned char end_head;         /* end head */
+        unsigned char end_sector;       /* end sector */
+        unsigned char end_cyl;          /* end cylinder */
+        unsigned int start_sect;        /* starting sector counting from 0 */
+        unsigned int nr_sects;          /* nr of sectors in partition */
+} __attribute__((packed));
 
 #define TEST_UNIT_READY	(0x00)
 #define FORMAT_UNIT	(0x04)
@@ -736,7 +755,7 @@
 	if (!par_deflistform) {
 	    fprintf(fh, "\nUser supplied defect logical blocks:\n");
 	    for (i = off = 0; off < par_defectlen; i++, off += 4) {
-		fprintf(fh, " %9lu", ntohl(par_defects[i]));
+		fprintf(fh, " %9u", ntohl(par_defects[i]));
 		if ((i & 7) == 7) {
 		    fprintf(fh, "\n");
 		    flag = 1;
@@ -747,8 +766,10 @@
 	    fprintf(fh, "\nUser supplied defects in Cylinder:Head:%s format:\n",
 	     par_deflistform == 5 ? "PhysicalSector" : "BytesFromIndex");
 	    for (i = off = 0; off < par_defectlen; i += 2, off += 8) {
-		sprintf(buffer, " %lu:%lu:%ld", ntohl(par_defects[i]) >> 8,
-			ntohl(par_defects[i]) & 255, (long) ntohl(par_defects[i + 1]));
+		sprintf(buffer, " %u:%u:%ld",
+			(unsigned int)(ntohl(par_defects[i]) >> 8),
+			(unsigned int)(ntohl(par_defects[i]) & 255),
+			(long) ntohl(par_defects[i + 1]));
 		fprintf(fh, "%20s", buffer);
 		if ((i & 3) == 3) {
 		    fprintf(fh, "\n");
@@ -905,8 +926,11 @@
     unsigned char sig2catch[] =
     {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE,
      SIGSEGV, SIGPIPE, SIGALRM, SIGTERM, SIGUSR1, SIGUSR2, SIGTRAP,
-     SIGIOT, SIGBUS, SIGSTKFLT, SIGIO, SIGXCPU, SIGXFSZ, SIGVTALRM,
-     SIGPROF, SIGPWR};
+     SIGIOT, SIGBUS,
+#ifdef SIGSTKFLT
+     SIGSTKFLT,
+#endif
+     SIGIO, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF, SIGPWR};
 
     siga.sa_handler = term_handler;
     siga.sa_flags = SA_ONESHOT | SA_NOMASK;
@@ -1333,7 +1357,7 @@
 
 int main(int argc, char *argv[])
 {
-    char c;
+    int c;
     int flag, par;
     FILE *mntfd;
     struct mntent *mnt;
--- scsiinfo-1.7/scsiinfo.c
+++ scsiinfo-1.7/scsiinfo.c
@@ -62,6 +62,7 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <getopt.h>
 #include <unistd.h>
@@ -1284,7 +1285,7 @@
 
 int main(int argc, char *argv[])
 {
-    char c;
+    int c;
     int page_code;
     int status = 0;
     char all = 0;
--- scsiinfo-1.7/sgcheck
+++ scsiinfo-1.7/sgcheck
@@ -0,0 +1,47 @@
+#! /usr/bin/perl
+#
+# checks the attached SCSI devices and gives you the generic
+# SCSI device attached to it
+#
+
+if ( $ARGV[0] eq "" ) {
+  $scsiprocfile = "/proc/scsi/scsi";
+}
+else {
+  $scsiprocfile = $ARGV[0];
+}
+
+sub cut_trailing_blanks {
+  local ($s) = @_;
+  local ($x);
+  $s =~ /(\s*)$/;
+  return substr($s, 0, length($s) - length($1));
+}
+
+open(FIN, "<$scsiprocfile") || die "Can't open $scsiprocfile";
+
+$sgminor = -1;
+
+print "\nAssignment of generic SCSI devices,\n";
+print "device host/channel/ID/LUN type(numeric type) vendor model:\n\n";
+
+LINE: while (<FIN>) {
+  if ( /^Attached devices:/ ) {next LINE;}
+  if ( /^Host:\s+scsi(\d)\s+Channel:\s+(\d+)\s+Id:\s(\d+)\s+Lun:\s+(\d+)/ ) {
+    $sgminor++;
+    $host = $1;
+    $channel = $2 * 1;
+    $id = $3 * 1;
+    $lun = $4 * 1;
+  }
+  if ( /^\s+Vendor:\s+(.+)\s+Model:\s+(.+)\s+Rev:\s+(.+)/ ) {
+    $vendor = cut_trailing_blanks($1);
+    $model = cut_trailing_blanks($2);
+    $rev = cut_trailing_blanks($3);
+  }
+  if ( /^\s+Type:\s+(.+)\s+ANSI SCSI revision:/ ) {
+    $type = cut_trailing_blanks($1);
+    print "/dev/sg$sgminor $host/$channel/$id/$lun $type $vendor $model\n";
+  }
+}
+close(FIN)
--- scsiinfo-1.7/tk/inquiry
+++ scsiinfo-1.7/tk/inquiry
@@ -14,7 +14,7 @@
 
 frame .buttons
 button .buttons.quit -text Quit \
-	-activeforeground white -activebackground red -command exit
+	-activeforeground white -activebackground red -command {[exec rm -fr /tmp/.inquiry ;exit]} 
 
 pack  .buttons.quit  -side left -padx 10 -pady 3
 pack .buttons
@@ -154,8 +154,21 @@
     global text_list
     global switch
     set line {}
-    exec /usr/bin/scsiinfo -X $switch $option $device > /tmp/cachepage
-    if {[catch {set file [open /tmp/cachepage r]}] == 1} return;
+
+
+#    exec rm -rf $inqdir
+    set inqdir "/tmp/.inquiry"
+    if {![file exists $inqdir]} {exec mkdir $inqdir }
+
+
+#    set make_dir [ catch {eval {exec mkdir /tmp/.inquiry} } ]
+#    if { $make_dir != 0 } {
+#	puts "Error: Can't create /tmp/.inquiry"
+#	exit
+#    }
+
+    exec /usr/bin/scsiinfo -X $switch $option $device > /tmp/.inquiry/cachepage
+    if {[catch {set file [open /tmp/.inquiry/cachepage r]}] == 1} return;
     gets $file line
     set first [lindex $line 0]
     set second [lindex $line 1]
@@ -185,7 +198,7 @@
     .revision.text insert end $line
     .revision.text configure -state disabled
     close $file
-    exec rm /tmp/cachepage
+    exec rm -rf /tmp/.inquire
 }
 
 read_page $argv "-X"
--- scsiinfo-1.7/tk/overview
+++ scsiinfo-1.7/tk/overview
@@ -30,7 +30,10 @@
      set line [ exec scsiinfo -nX $sdevice ]
      set line [ lreplace $line 3 3 $notch ]
 # Use /bin/sh to cut $line in multiple pieces
-     set line [ exec sh -c "scsiinfo -nXR $sdevice $line" ]
+	exec sh -c "scsiinfo -nXR $sdevice $line"
+
+#     set line [ exec sh -c "scsiinfo -nXR $sdevice $line" ]
+
 #    exec scsiinfo -nX $sdevice >/dev/tty
   }
 }
--- scsiinfo-1.7/tk/peripheral
+++ scsiinfo-1.7/tk/peripheral
@@ -29,12 +29,12 @@
     global text_list
     global switch
     set line {}
-    exec /usr/bin/scsiinfo -X $switch $option $device > /tmp/cachepage 2> /dev/null
-    if {[catch {set file [open /tmp/cachepage r]}] == 1} return;
+    exec /usr/bin/scsiinfo -X $switch $option $device > /tmp/.peripheral/cachepage 2> /dev/null
+    if {[catch {set file [open /tmp/.peripheral/cachepage r]}] == 1} return;
     gets $file line
     gets $file asciidesc
     close $file
-    exec rm /tmp/cachepage
+    exec rm /tmp/.peripheral/cachepage
 
     .ident.text delete 1.0 end
     .ident.text insert end [lindex $line 0]
@@ -51,11 +51,11 @@
     global text_list
     global switch
     set line {}
-    exec /usr/bin/scsiinfo -X -m $switch $device > /tmp/cachepage
-    if {[catch {set file [open /tmp/cachepage r]}] == 1} return;
+    exec /usr/bin/scsiinfo -X -m $switch $device > /tmp/.peripheral/cachepage
+    if {[catch {set file [open /tmp/.peripheral/cachepage r]}] == 1} return;
     gets $file line
     close $file
-    exec rm /tmp/cachepage
+    exec rm /tmp/.peripheral/cachepage
 
     if { [ string compare [lindex $line 0] "0" ] == 0} \
       then { .ident.text configure -state disabled } \
@@ -82,11 +82,11 @@
     set r3 [concat $r3 @[.vendor.text get 1.0 end]]
 
 
-    set file [open /tmp/wrscsi w]
+    set file [open /tmp/.peripheral/wrscsi w]
     puts $file "/usr/bin/scsiinfo $r3"
     close $file
-    exec sh < /tmp/wrscsi
-    exec rm /tmp/wrscsi
+    exec sh < /tmp/.peripheral/wrscsi
+    exec rm /tmp/.peripheral/wrscsi
 }
 
 
@@ -103,6 +103,14 @@
 
 frame .f1
 
+exec rm -rf /tmp/.peripheral
+set make_dir [ catch {eval {exec mkdir /tmp/.peripheral} } ]
+if { $make_mkdir != 0 } {
+     puts "Error: Can't create /tmp/.peripheral"
+     exit
+}
+
+
 generate_textboxes
 
 pack .ident .identasc .vendor -in .f1 -pady 10 -anchor w
@@ -110,3 +118,5 @@
 
 read_page $argv "-X"
 read_modifiable $argv
+
+exec rm -rf /tmp/.peripheral
--- scsiinfo-1.7/tk_scsiformat
+++ scsiinfo-1.7/tk_scsiformat
@@ -128,7 +128,7 @@
     } else {
 	set label "Other ($par_mkfs)"
     }
-    .f_def.part.menu.mkfs entryconfigure [expr [llength $par_mkfscmds] + 1] -label "$label"
+    .f_def.part.menu.mkfs entryconfigure [expr [llength $par_mkfscmds] + 1] -label "$label" 
 }
 
 proc bind_eedit {w} {
@@ -872,9 +872,9 @@
    global check_cmd format_initiator
 
    set security "-F'Ene Mene Meck, und Du bist weg!'"
-   append fcmd " $security -t0 -X $sdevice"
+   append fcmd " $security -t0 -X $sdevice >& /tmp/scsiformat.$$"
    
-   if { [catch {exec sh -c "$fcmd" >& /tmp/scsiformat.[pid] } err] != 0 } then {
+   if { [catch {exec sh -C -c "$fcmd" } err] != 0 } then {
         set fd [open /tmp/scsiformat.[pid] r]
 	set err "$err\x0a[read $fd]"
 	close $fd
--- scsiinfo-1.7/tworands.c
+++ scsiinfo-1.7/tworands.c
@@ -6,7 +6,7 @@
 #include <sys/time.h>
 #include <unistd.h>
 
-int main(int argc) {
+int main(int argc, char *argv[]) {
     struct timeval tv;
 
     if (argc != 1) {
