aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/usage.h8
-rw-r--r--miscutils/Config.in7
-rw-r--r--miscutils/eject.c43
3 files changed, 24 insertions, 34 deletions
diff --git a/include/usage.h b/include/usage.h
index f1ae92316..d63498553 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -565,18 +565,12 @@
565 "$ echo \"Erik\\nis\\ncool\"\n" \ 565 "$ echo \"Erik\\nis\\ncool\"\n" \
566 "Erik\\nis\\ncool\n") 566 "Erik\\nis\\ncool\n")
567 567
568#ifdef CONFIG_FEATURE_EJECT_LONG_OPTIONS
569# define USAGE_EJECT_TRAYCLOSE ",trayclose"
570#else
571# define USAGE_EJECT_TRAYCLOSE ""
572#endif
573
574#define eject_trivial_usage \ 568#define eject_trivial_usage \
575 "[-t] [DEVICE]" 569 "[-t] [DEVICE]"
576#define eject_full_usage \ 570#define eject_full_usage \
577 "Eject specified DEVICE (or default /dev/cdrom).\n\n" \ 571 "Eject specified DEVICE (or default /dev/cdrom).\n\n" \
578 "Options:\n" \ 572 "Options:\n" \
579 "\t-t" USAGE_EJECT_TRAYCLOSE "\tclose tray" 573 "\t-t\tclose tray"
580 574
581#define env_trivial_usage \ 575#define env_trivial_usage \
582 "[-iu] [-] [name=value]... [command]" 576 "[-iu] [-] [name=value]... [command]"
diff --git a/miscutils/Config.in b/miscutils/Config.in
index 710639aba..afa70a597 100644
--- a/miscutils/Config.in
+++ b/miscutils/Config.in
@@ -89,13 +89,6 @@ config CONFIG_EJECT
89 help 89 help
90 Used to eject cdroms. (defaults to /dev/cdrom) 90 Used to eject cdroms. (defaults to /dev/cdrom)
91 91
92config CONFIG_FEATURE_EJECT_LONG_OPTIONS
93 bool " Enable support for --trayclose long option (-t)"
94 default n
95 depends on CONFIG_EJECT
96 help
97 Enable use of long options (like --trayclose for -t).
98
99config CONFIG_LAST 92config CONFIG_LAST
100 bool "last" 93 bool "last"
101 default n 94 default n
diff --git a/miscutils/eject.c b/miscutils/eject.c
index cbfd115f7..df275d74b 100644
--- a/miscutils/eject.c
+++ b/miscutils/eject.c
@@ -24,41 +24,44 @@
24 * Most of the dirty work blatantly ripped off from cat.c =) 24 * Most of the dirty work blatantly ripped off from cat.c =)
25 */ 25 */
26 26
27#include <stdio.h>
28#include <string.h>
29#include <sys/types.h>
30#include <sys/stat.h>
31#include <fcntl.h> 27#include <fcntl.h>
32#include <sys/ioctl.h> 28#include <sys/ioctl.h>
33#include <getopt.h> 29#include <stdlib.h>
30#include <unistd.h>
34#include "busybox.h" 31#include "busybox.h"
35 32
36/* various defines swiped from linux/cdrom.h */ 33/* various defines swiped from linux/cdrom.h */
37#define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */ 34#define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */
38#define CDROMEJECT 0x5309 /* Ejects the cdrom media */ 35#define CDROMEJECT 0x5309 /* Ejects the cdrom media */
39#define DEFAULT_CDROM "/dev/cdrom" 36#define DEFAULT_CDROM "/dev/cdrom"
40/*#define CLOSE_TRAY 1*/ 37
38#ifdef CONFIG_FEATURE_MTAB_SUPPORT
39#define MTAB CONFIG_FEATURE_MTAB_FILENAME
40#else
41#define MTAB "/proc/mounts"
42#endif
41 43
42extern int eject_main(int argc, char **argv) 44extern int eject_main(int argc, char **argv)
43{ 45{
44 unsigned long flags; 46 unsigned long flags;
47 char * command;
48 char *device=argv[optind] ? : DEFAULT_CDROM;
45 49
46#ifdef CONFIG_FEATURE_EJECT_LONG_OPTIONS
47 static const struct option eject_long_options[] = {
48 { "trayclose", 0, 0, 't' },
49 { 0, 0, 0, 0 }
50 };
51 bb_applet_long_options = eject_long_options;
52#endif
53
54 flags = bb_getopt_ulflags(argc, argv, "t"); 50 flags = bb_getopt_ulflags(argc, argv, "t");
55 51 bb_xasprintf(&command, "umount '%s'", device);
56 if (ioctl(bb_xopen((argv[optind] ? argv[optind] : DEFAULT_CDROM), 52
53 /* validate input before calling system */
54 if(find_mount_point(device, MTAB))
55 system(command);
56
57 if (ioctl(bb_xopen( device,
57 (O_RDONLY | O_NONBLOCK)), 58 (O_RDONLY | O_NONBLOCK)),
58 ( flags /*& CLOSE_TRAY*/ ? CDROMCLOSETRAY : CDROMEJECT))) 59 ( flags ? CDROMCLOSETRAY : CDROMEJECT)))
59 { 60 {
60 bb_perror_msg_and_die(bb_msg_unknown); 61 bb_perror_msg_and_die(device);
61 } 62 }
62 63#ifdef CONFIG_FEATURE_CLEAN_UP
63 return EXIT_SUCCESS; 64 free(command);
65#endif
66 return(EXIT_SUCCESS);
64} 67}