Re: eject from halt

2008-06-05 Thread Jeremy Katz
On Wed, 2008-06-04 at 22:26 +0100, Scott James Remnant wrote:
 On Wed, 2008-06-04 at 16:50 -0400, Jeremy Katz wrote:
  On Wed, 2008-06-04 at 17:18 +0100, Scott James Remnant wrote:
   On Wed, 2008-06-04 at 11:23 -0400, Jeremy Katz wrote:
Not without doing some sort of hack to precache binaries.  Because you
want to eject and then halt.  If you have to do eject separately in the
script, then you need to be sure that halt exists in the buffer cache so
that you don't need to go to the (now ejected) CD to read the halt
binary

   There's no guarantee that all of halt will be in the cache either, you
   may well eject inside halt and be unable to page in the rest of the
   binary to actually do the syscall.
  
  There's never a guarantee, but you can at least reduce your likelihood
  of failure.  And seriously, having support to call an ioctl() in halt vs
  ldd across a static list of binaries and then cat'ing all of those files
  to /dev/null before running eject(1)?  One of these feels like a hack,
  one of them feels like an incredibly gross hack ;)
  
 How do you handle it right now?

We don't.  Which sucks if you have a slot-loading CD drive for the
obvious reasons

But the answer done by pretty much everyone else who tries (Ubuntu,
Knoppix being the two I looked at) is the cat files + their library deps
per ldd to /dev/null crud.

Jeremy


-- 
upstart-devel mailing list
upstart-devel@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/upstart-devel


Re: eject from halt

2008-06-05 Thread Jeremy Katz
On Wed, 2008-06-04 at 16:13 +0100, Scott James Remnant wrote:
 On Tue, 2008-06-03 at 22:59 -0400, Jeremy Katz wrote:
  Attached is a simple patch to add support to upstart's halt command for
  ejecting a given device.  This is really nice to make it so that you can
  eject a livecd on shutdown without having to do some of the contortions
  that are currently done on the shutdown of the Ubuntu livecd ;)
  
  And while a little ugly, it's not any worse than having -h and -i there.
  And it makes the rest of the shutdown process substantially cleaner.
  Patch is  against current bzr trunk, although I've only tested atm with
  it applied to 0.3.19.  There's nothing to speak of changed, though, so
  should be fine.
  
 I'd actually planned to remove both -h and -i from reboot, since they're
 poorly duplicating functionality that's better off handled elsewhere.
 
 Could this not be better handled by a call to eject in the shutdown
 scripts?

Not without doing some sort of hack to precache binaries.  Because you
want to eject and then halt.  If you have to do eject separately in the
script, then you need to be sure that halt exists in the buffer cache so
that you don't need to go to the (now ejected) CD to read the halt
binary

Jeremy


-- 
upstart-devel mailing list
upstart-devel@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/upstart-devel


eject from halt

2008-06-04 Thread Jeremy Katz
Attached is a simple patch to add support to upstart's halt command for
ejecting a given device.  This is really nice to make it so that you can
eject a livecd on shutdown without having to do some of the contortions
that are currently done on the shutdown of the Ubuntu livecd ;)

And while a little ugly, it's not any worse than having -h and -i there.
And it makes the rest of the shutdown process substantially cleaner.
Patch is  against current bzr trunk, although I've only tested atm with
it applied to 0.3.19.  There's nothing to speak of changed, though, so
should be fine.

Thoughts?

Jeremy
=== modified file 'compat/sysv/reboot.c'
--- compat/sysv/reboot.c	2008-02-29 16:17:17 +
+++ compat/sysv/reboot.c	2008-05-29 20:05:10 +
@@ -39,6 +39,7 @@
 
 #include linux/if.h
 #include linux/hdreg.h
+#include linux/cdrom.h
 
 #include nih/macros.h
 #include nih/main.h
@@ -95,6 +96,7 @@
 /* Prototypes for static functions */
 static void down_drives (void);
 static void down_interfaces (void);
+static void eject_drive (void);
 
 
 /**
@@ -139,6 +141,8 @@
  **/
 static int exit_only = FALSE;
 
+static char *eject_device = NULL;
+
 
 /**
  * options:
@@ -156,6 +160,8 @@
 	  NULL, NULL, disk_standby, NULL },
 	{ 'i', NULL, N_(bring down network interfaces),
 	  NULL, NULL, interface_down, NULL },
+	{ 'e', NULL, N_(eject the given device),
+	  NULL, DEVICE, eject_device, NULL },
 
 	/* Compatibility option, just causes us to exit */
 	{ 'w', NULL, NULL, NULL, NULL, exit_only, NULL },
@@ -275,6 +281,10 @@
 	if (disk_standby)
 		down_drives ();
 
+	/* If we need to eject a device, do it now */
+	if (eject_device)
+		eject_drive ();
+
 	/* Do the syscall */
 	switch (mode) {
 	case REBOOT:
@@ -298,6 +308,28 @@
 	return 0;
 }
 
+/**
+ * eject_drive:
+ *
+ * Eject the drive given on the command line
+ **/
+static void
+eject_drive (void)
+{
+	int fd;
+	
+	fd = open(eject_device, O_RDONLY | O_NONBLOCK);
+	if (fd  0) {
+		nih_warn (_(Unable to open device %s to eject: %s), eject_device,
+			  strerror(errno));
+		return;
+	}
+	
+	if (ioctl(fd, CDROMEJECT, 1)) {
+		nih_warn (_(Unable to eject device %s: %s), eject_device,
+			  strerror(errno));
+	}
+}
 
 /**
  * down_drives:

-- 
upstart-devel mailing list
upstart-devel@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/upstart-devel


Re: eject from halt

2008-06-04 Thread Bill Nottingham
Jeremy Katz ([EMAIL PROTECTED]) said: 
 Thoughts?

Is the ioctl the same for CD and non-CD devices?

Bill

-- 
upstart-devel mailing list
upstart-devel@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/upstart-devel


Re: eject from halt

2008-06-04 Thread Scott James Remnant
On Wed, 2008-06-04 at 16:50 -0400, Jeremy Katz wrote:

 On Wed, 2008-06-04 at 17:18 +0100, Scott James Remnant wrote:
  On Wed, 2008-06-04 at 11:23 -0400, Jeremy Katz wrote:
   Not without doing some sort of hack to precache binaries.  Because you
   want to eject and then halt.  If you have to do eject separately in the
   script, then you need to be sure that halt exists in the buffer cache so
   that you don't need to go to the (now ejected) CD to read the halt
   binary
   
  There's no guarantee that all of halt will be in the cache either, you
  may well eject inside halt and be unable to page in the rest of the
  binary to actually do the syscall.
 
 There's never a guarantee, but you can at least reduce your likelihood
 of failure.  And seriously, having support to call an ioctl() in halt vs
 ldd across a static list of binaries and then cat'ing all of those files
 to /dev/null before running eject(1)?  One of these feels like a hack,
 one of them feels like an incredibly gross hack ;)
 
How do you handle it right now?

Scott
-- 
Have you ever, ever felt like this?
Had strange things happen?  Are you going round the twist?


signature.asc
Description: This is a digitally signed message part
-- 
upstart-devel mailing list
upstart-devel@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/upstart-devel