[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: dboostrap segfault with no CDROM drive



#include <hallo.h>
Eduard Bloch wrote on Thu Feb 21, 2002 um 08:35:57AM:
> > FWIW I couldn't reproduce the segfault.  I used the same
> > "/proc/sys/dev/cdrom/info" as in the bug report and got fine behavior.
> 
> Oh, I tried. Detach your cdrom drives and boot bf2.4. You get the
> flashing screen syndrome. Reattached the driver - works. So I rebuilt
> BFs, hacked root to remove duplicated libs and fit on the floppy.
> Rebootet - same game. Works with an attached CD drive, crashes without
> it. Looks like my patch would net help to solve the real problem,
> whatever it is.

The patch was not working correctly, I looked for spaces rather for
tabs. This should work - untested for now.


-- 
Du hast recht, und er hat auch recht. Dein Argument ist, als ob Du
sagst, Krankenhäuser werden abgeschafft, die Apotheken sind doch voller
Medikamente und jeder kann sich für ein paar Mark bedienen;-).
                     (Hannes Birnbacher in de.comm.software.newsreader)
diff -u -r1.132 choose_medium.c
--- choose_medium.c	2002/02/07 04:00:25	1.132
+++ choose_medium.c	2002/02/21 08:36:09
@@ -664,44 +664,6 @@
 }
 
 
-/*
- * "/proc/sys/dev/cdrom/info", on bittersweet, contains:
- * 8<------------------------------------------------->8
- * CD-ROM information, Id: cdrom.c 2.56 1999/09/09
- *
- * drive name:             sr0     hdd
- * drive speed:            6       4
- * drive # of slots:       1       0
- * Can close tray:         1       1
- * Can open tray:          1       1
- * Can lock tray:          1       1
- * Can change speed:       1       1
- * Can select disk:        0       0
- * Can read multisession:  1       1
- * Can read MCN:           1       1
- * Reports media changed:  1       1
- * Can play audio:         1       1
- *
- *
- * 8<------------------------------------------------->8
- *
- * Note that there are actually tab characters in the file; I've
- * untabified so it stays lined up in this comment.  I have verified
- * that this file does not exist on a machine with no CDROM attached.
- * - karlheg 2000.03.20
- * Linux bittersweet 2.2.14 #9 Fri Mar 17 00:50:19 PST 2000 i586 unknown
- */
-
-int
-have_cdrom ()
-{
-    struct stat statbuf;
-    int status;
-    if ((status = stat("/proc/sys/dev/cdrom/info", &statbuf)) == 0)
-	return 1;
-    return 0;
-}
-
 static
 char *
 get_cd_type_description (const char *dev)
@@ -755,7 +717,7 @@
     
     /* Should be guaranteed on entry that the cd_info file exists - use have_cdrom() */
     /* #### I get a warning here about assignment makes pointer from integer without a cast.  Why?? */
-    if ((cd_info = fopen ("/proc/sys/dev/cdrom/info", "r")) == NULL) {
+    if (have_cdrom() && (cd_info = fopen ("/proc/sys/dev/cdrom/info", "r")) == NULL) {
 	return;		/* ¿ Shouldn't happen if I can stat it, right ? */
     }
 
Index: reboot_system.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/reboot_system.c,v
retrieving revision 1.24
diff -u -r1.24 reboot_system.c
--- reboot_system.c	2001/12/21 07:54:45	1.24
+++ reboot_system.c	2002/02/21 08:36:09
@@ -33,7 +33,7 @@
   char *p_line,*line = NULL;
   size_t line_size = 0;
   char bootmagic='\0';
-  if ((cd_info = fopen ("/proc/sys/dev/cdrom/info", "r")) != NULL)
+  if (have_cdrom() && (cd_info = fopen ("/proc/sys/dev/cdrom/info", "r")) != NULL)
   {
     /* successfull, continuing */
 
Index: util.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/util.c,v
retrieving revision 1.69
diff -u -r1.69 util.c
--- util.c	2002/02/10 19:30:14	1.69
+++ util.c	2002/02/21 08:36:09
@@ -1115,5 +1115,52 @@
 }
 
 
+/*
+ * "/proc/sys/dev/cdrom/info", on bittersweet, contains:
+ * 8<------------------------------------------------->8
+ * CD-ROM information, Id: cdrom.c 2.56 1999/09/09
+ *
+ * drive name:             sr0     hdd
+ * drive speed:            6       4
+ * drive # of slots:       1       0
+ * Can close tray:         1       1
+ * Can open tray:          1       1
+ * Can lock tray:          1       1
+ * Can change speed:       1       1
+ * Can select disk:        0       0
+ * Can read multisession:  1       1
+ * Can read MCN:           1       1
+ * Reports media changed:  1       1
+ * Can play audio:         1       1
+ *
+ *
+ * 8<------------------------------------------------->8
+ *
+ * Note that there are actually tab characters in the file; I've
+ * untabified so it stays lined up in this comment.  I have verified
+ * that this file does not exist on a machine with no CDROM attached.
+ * - karlheg 2000.03.20
+ * Linux bittersweet 2.2.14 #9 Fri Mar 17 00:50:19 PST 2000 i586 unknown
+ */
 
+int
+have_cdrom ()
+{
+    FILE *cd_info;
+    char *line = NULL;
+    size_t line_size = 0;
+    if ((cd_info = fopen ("/proc/sys/dev/cdrom/info", "r")) != NULL) {
+       /* Read the file and build a list of available CD devices. */
+       getline (&line, &line_size, cd_info);
+       getline (&line, &line_size, cd_info);
+       getline (&line, &line_size, cd_info);
+       if(strstr(line, "\t\t") != NULL) {
+          /* leading tabs exist so the device names must follow in the line */
+          fclose(cd_info);
+          return 1;
+       }
+       fclose(cd_info);
+    }
+    return 0;
+}
 
Index: util.h
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/util.h,v
retrieving revision 1.26
diff -u -r1.26 util.h
--- util.h	2001/12/20 07:36:17	1.26
+++ util.h	2002/02/21 08:36:09
@@ -173,6 +173,9 @@
  */
 extern int is_cdrom_image(void);
 
+/* Looks in the procfs whetever a cdrom drive does exist (1) or not (0) */
+extern int have_cdrom(void);
+
 /* Is the partition on an NFS mountpoint? */
 int is_nfs_partition(const char *);
 

Reply to: