On Wednesday 18 November 2009 16:42:14 Raphael Kubo da Costa wrote:
> On Wednesday 18 November 2009 12:27:27 David Bruce Naylor wrote:
> > Hi,
> >
> > I've managed to get kdm to work nicely with our grub.  See attached for
> > the patch.  This requires a 'special' menu.lst to support selecting next
> > boot OS and the BootManager option in kdmrc to be set to "GRUB".
> >
> > Sample file:
> >
> > # Important line, tells grub to use saved option to boot from
> > default saved
> > timeout 3
> >
> > title FreeBSD 8.0-i386
> >         root (hd1,0,a)
> >         kernel /boot/loader
> >         # Set the default, for next boot, to 1
> >         savedefault 1
> >
> > title FreeBSD 8.0-amd64
> >         root (hd0,0,a)
> >         kernel /boot/loader
> >         # No need to set default as we are it
> >         #savedefault
> >
> > # Windows Vista
> > title Windows Vista
> >         root (hd1,1)
> >         makeactive
> >         chainloader +1
> >         # Set the default, for next boot, to 1
> >         savedefault 1
> >
> > Make sure you run `grub-set-default 1` otherwise grub will bork when it
> >  hits the savedefault line (since it cannot create files and expects one
> > to be there).
> >
> > Most of the linux distributions have a patched version of grub that
> > allows a difference (and easier) setup.  (The patch is called
> > grub-0.97-once.) We could integrate that patch (and eliminate the need
> > for this patch) but I feel this way allows for greater flexibility.
> >
> > Outstanding task: teach kdm to read the defaults file to correctly get
> > the next booting option (vs assuming the first one is the default).
> >
> > For those on amd64 an easy way to get grub to work is to install the i386
> >  grub package (it doesn't have any dependencies beyond the base system).
> >  I'm currently running grub on amd64.
> >
> > Regards,
> >
> > David
> 
> Do you think you can make the patch flexible enough so that it still works
>  on Linux? Could it be pushed upstream?

See attached for the 'flexible' patch.  This *should* handle both the standard 
and patched versions of grub.  There is no way for me to check if the original 
behaviour works.  

Is there anyone on list who can push these patches upstream (including the one 
to use the correct shutdown options)?  If not I'll send an e-mail to kdm's 
maintainer.  

Regards
--- kdm/backend/bootman.c~	2009-02-04 20:19:06.000000000 +0200
+++ kdm/backend/bootman.c	2009-11-19 12:25:38.000000000 +0200
@@ -40,6 +40,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <ctype.h>
 
 static int
@@ -68,20 +69,30 @@
 	return buf;
 }
 
-#define GRUB_MENU "/boot/grub/menu.lst"
+#define GRUB_MENU    "/boot/grub/menu.lst"
+#define GRUB_DEFAULT "/boot/grub/default"
 
-static char *grub;
+#define GRUB_SET_DEFAULT "grub-set-default"
+#define GRUB             "grub"
+
+static char *grub = NULL;
+static int  grub_set_default;
 
 static int
 getGrub( char ***opts, int *def, int *cur )
 {
 	FILE *f;
-	char *ptr, *linp;
-	int len;
+	char *ptr, *endptr, *linp;
+	int len, no_default = 1;
 	char line[1000];
 
-	if (!grub && !(grub = locate( "grub" )))
-		return BO_NOMAN;
+	if (!grub)
+		if (grub = locate( GRUB_SET_DEFAULT ))
+			grub_set_default = 1;
+		else if (grub = locate( GRUB ))
+			grub_set_default = 0;
+		else
+			return BO_NOMAN;
 
 	*def = 0;
 	*cur = -1;
@@ -91,8 +102,11 @@
 		return errno == ENOENT ? BO_NOMAN : BO_IO;
 	while ((len = fGets( line, sizeof(line), f )) != -1) {
 		for (linp = line; isspace( *linp ); linp++, len--);
-		if ((ptr = match( linp, &len, "default", 7 )))
-			*def = atoi( ptr );
+		if ((ptr = match( linp, &len, "default", 7 ))) {
+			*def = strtol( ptr, &endptr, 10 );
+			if (ptr != endptr)
+				no_default = 0;
+		}
 		else if ((ptr = match( linp, &len, "title", 5 ))) {
 			for (; isspace( ptr[len - 1] ); len--);
 			*opts = addStrArr( *opts, ptr, len );
@@ -100,6 +114,17 @@
 	}
 	fclose( f );
 
+	if (no_default && (f = fopen( GRUB_DEFAULT, "r" ))) {
+		if (fGets( line, sizeof(line), f ) != -1) {
+			*def = strtol(line, NULL, 10);
+			no_default = 0;
+		}
+		fclose( f );
+	}
+
+	if ( no_default )
+		*def = -1;
+
 	return BO_OK;
 }
 
@@ -130,18 +155,28 @@
 static void
 commitGrub( void )
 {
-	FILE *f;
-	int pid;
-	static const char *args[] = { 0, "--batch", "--no-floppy", 0 };
-
 	if (sdRec.bmstamp != mTime( GRUB_MENU ) &&
 	    setGrub( sdRec.osname, &sdRec ) != BO_OK)
 		return;
 
-	args[0] = grub;
-	if ((f = pOpen( (char **)args, 'w', &pid ))) {
-		fprintf( f, "savedefault --default=%d --once\n", sdRec.osindex );
-		pClose( f, &pid );
+	if (grub_set_default) {
+		static char idx[3];
+		static char *args[] = { 0, 0, 0 };
+
+		args[0] = grub;
+		args[1] = idx;
+		snprintf( idx, 2, "%i", sdRec.osindex );
+		runAndWait( args, NULL );
+	} else {
+		FILE *f;
+		int pid;
+		static const char *args[] = { 0, "--batch", "--no-floppy", 0 };
+
+		args[0] = grub;
+		if ((f = pOpen( (char **)args, 'w', &pid ))) {
+			fprintf( f, "savedefault --default=%d --once\n", sdRec.osindex );
+			pClose( f, &pid );
+		}
 	}
 }
 

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
kde-freebsd mailing list
kde-freebsd@kde.org
https://mail.kde.org/mailman/listinfo/kde-freebsd
See also http://freebsd.kde.org/ for latest information

Reply via email to