diff -Naur sysvinit-2.86.orig/src/halt.c sysvinit-2.86/src/halt.c --- sysvinit-2.86.orig/src/halt.c 2004-07-30 14:16:18.000000000 +0200 +++ sysvinit-2.86/src/halt.c 2006-04-22 01:10:31.000000000 +0200 @@ -37,24 +38,28 @@ #include #include #include +#include +#include +#include #include #include #include #include #include -#include -#include #include -#include -#include +#include #include "reboot.h" -char *Version = "@(#)halt 2.86 31-Jul-2004 miquels@cistron.nl"; char *progname; #define KERNEL_MONITOR 1 /* If halt() puts you into the kernel monitor. */ #define RUNLVL_PICKY 0 /* Be picky about the runlevel */ +#ifndef MNT_DETACH +#define MNT_DETACH 0x00000002 +#endif +#define UMOUNT(x) umount2(x,MNT_DETACH) + extern int ifdown(void); extern int hddown(void); extern void write_wtmp(char *user, char *id, int pid, int type, char *line); @@ -262,6 +270,50 @@ if (do_nothing) exit(0); + /* KNOPPIX: Umount /KNOPPIX, unload/eject CD-Rom */ + /* All these are really syscalls */ + + /* check the environment variable NOEJECT */ + { + char *noeject=getenv("NOEJECT") ; + /* if it is not defined or not equal to "yes" then we eject */ + if ( (!noeject) || !(!strcmp(noeject,"yes")||!strcmp(noeject,"true")) ) { + + for(c=1;c<=3;c++) /* Attempt to umount this many times */ + { + if(UMOUNT("/KNOPPIX")==0) + { + char *msg1="Please remove CD, close cdrom drive and hit return."; + char *msg2="\rShutdown complete."; + /* missing in linux/module.h */ + extern int delete_module(const char *); + usleep(250000); delete_module("cloop"); usleep(250000); + if(UMOUNT("/cdrom")!=EBUSY) + { + char *noprompt=getenv("NOPROMPT"); + /* if it is not defined or not equal to "yes" then we eject */ + if ( (!noprompt) || !(!strcmp(noprompt,"yes")||!strcmp(noprompt,"true")) ) { + write(2,msg1,strlen(msg1)); tcflush(1,TCIFLUSH); getchar(); + write(2,msg2,strlen(msg2)); + usleep(250000); + } + } + break; + } + else + { + if(errno==EBUSY) + { + char *msg=c<3?"Can't unmount CD yet...\n": + "Can't unmount CD, please reset.\n"; + write(2,msg,strlen(msg)); + } + sleep(3); + } + } + } + } + if (do_reboot) { init_reboot(BMAGIC_REBOOT); } else {