summaryrefslogtreecommitdiff
path: root/miscutils/eject.c
diff options
context:
space:
mode:
authorRob Landley2005-05-15 01:32:47 +0000
committerRob Landley2005-05-15 01:32:47 +0000
commit4079b001193acfe8e7ac1e81abc2bb26ab5f3890 (patch)
tree800520f8ae26cb32c4c9739c8c942a17e188fe62 /miscutils/eject.c
parent9ea8836357d0f2b53319cb54c032d307cf2533be (diff)
downloadbusybox-4079b001193acfe8e7ac1e81abc2bb26ab5f3890.zip
busybox-4079b001193acfe8e7ac1e81abc2bb26ab5f3890.tar.gz
Tito pointed out I'd broken -t (argv[optind] can't be before getulflags),
and replaced the use of system() (and resulting security implications).
Diffstat (limited to 'miscutils/eject.c')
-rw-r--r--miscutils/eject.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/miscutils/eject.c b/miscutils/eject.c
index df275d7..8864687 100644
--- a/miscutils/eject.c
+++ b/miscutils/eject.c
@@ -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_error_msg_and_die("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);
}