[BusyBox] [PATCH] eject umount patch n° 3 - final ( I hope)
Tito
farmatito at tiscali.it
Sat May 14 12:13:05 UTC 2005
Hi Rob, hi to the list
This patch fixes all remaining issues in eject
1) fix for the breakage of -t by last patch;
2) remove the system() call and all problems related (security, paths with ' or \ chars);
3) removes some unneeded #defines i put in.
4) removes some unneeded #includes.
The size is almost the same:
root at localhost:/dev/pts/4:/root/Desktop/busybox# size miscutils/eject.o
text data bss dec hex filename
172 0 0 172 ac miscutils/eject.o.orig
text data bss dec hex filename
175 0 0 175 af miscutils/eject.o.new
Functionality should now be ok in all cases (I hope....).
Please apply.
Ciao and good weekend to all,
Tito
PS.: I would say that after the long stay in development passing to
feature freeze for 1.1 now is a little bit early, we are just
warming up......
BTW & PPS: There is a size optimization patch for strings.c in BTS that was well
tested and that could go in 1.1. If you have some time left could you
take a look at it.
-------------- next part --------------
--- miscutils/eject_orig.c 2005-05-14 08:49:02.000000000 +0200
+++ miscutils/eject.c 2005-05-14 14:07:47.000000000 +0200
@@ -26,8 +26,9 @@
#include <fcntl.h>
#include <sys/ioctl.h>
-#include <stdlib.h>
#include <unistd.h>
+#include <sys/mount.h>
+#include <mntent.h>
#include "busybox.h"
/* various defines swiped from linux/cdrom.h */
@@ -35,33 +36,28 @@
#define CDROMEJECT 0x5309 /* Ejects the cdrom media */
#define DEFAULT_CDROM "/dev/cdrom"
-#ifdef CONFIG_FEATURE_MTAB_SUPPORT
-#define MTAB CONFIG_FEATURE_MTAB_FILENAME
-#else
-#define MTAB "/proc/mounts"
-#endif
-
extern int eject_main(int argc, char **argv)
{
unsigned long flags;
- char * command;
- char *device=argv[optind] ? : DEFAULT_CDROM;
+ char *device;
+ struct mntent *m;
flags = bb_getopt_ulflags(argc, argv, "t");
- bb_xasprintf(&command, "umount '%s'", device);
-
- /* validate input before calling system */
- if(find_mount_point(device, MTAB))
- system(command);
+ device=argv[optind] ? : DEFAULT_CDROM;
+ if((m = find_mount_point(device, bb_path_mtab_file))) {
+ if(umount(m->mnt_dir))
+ bb_perror_msg("Can't umount");
+#ifdef CONFIG_FEATURE_MTAB_SUPPORT
+ else
+ erase_mtab(m->mnt_fsname);
+#endif
+ }
if (ioctl(bb_xopen( device,
(O_RDONLY | O_NONBLOCK)),
( flags ? CDROMCLOSETRAY : CDROMEJECT)))
{
bb_perror_msg_and_die(device);
}
-#ifdef CONFIG_FEATURE_CLEAN_UP
- free(command);
-#endif
return(EXIT_SUCCESS);
}
More information about the busybox
mailing list