Add automatic umount support to eject command. Patch from Tito,
authorRob Landley <rob@landley.net>
Sat, 14 May 2005 00:46:18 +0000 (00:46 -0000)
committerRob Landley <rob@landley.net>
Sat, 14 May 2005 00:46:18 +0000 (00:46 -0000)
with tweaks from Mike Frysinger and Rob Landley.

Note: this will still fail to umount a path that contains an ' or \ character.
Is it worth the extra size to filter for that?

include/usage.h
miscutils/Config.in
miscutils/eject.c

index f1ae923160b8815b758c310ec0aec647cc7822fa..d634985537fb8430ea40843565f401e35096984f 100644 (file)
        "$ echo \"Erik\\nis\\ncool\"\n" \
        "Erik\\nis\\ncool\n")
 
-#ifdef CONFIG_FEATURE_EJECT_LONG_OPTIONS
-# define USAGE_EJECT_TRAYCLOSE ",trayclose"
-#else
-# define USAGE_EJECT_TRAYCLOSE ""
-#endif
-
 #define eject_trivial_usage \
        "[-t] [DEVICE]"
 #define eject_full_usage \
        "Eject specified DEVICE (or default /dev/cdrom).\n\n" \
        "Options:\n" \
-       "\t-t" USAGE_EJECT_TRAYCLOSE "\tclose tray"
+       "\t-t\tclose tray"
 
 #define env_trivial_usage \
        "[-iu] [-] [name=value]... [command]"
index 710639aba464bac8184fa4e8c13e3bd86a9d4b61..afa70a59725c3c7fcf4c927c36bdfff405093cf6 100644 (file)
@@ -89,13 +89,6 @@ config CONFIG_EJECT
        help
          Used to eject cdroms.  (defaults to /dev/cdrom)
 
-config CONFIG_FEATURE_EJECT_LONG_OPTIONS
-       bool "  Enable support for --trayclose long option (-t)"
-       default n
-       depends on CONFIG_EJECT
-       help
-         Enable use of long options (like --trayclose for -t).
-
 config CONFIG_LAST
        bool "last"
        default n
index cbfd115f7c366dce2caee2f3f87129f0da76980d..df275d74bb1502f9d22d3ba5e747e2b11b7b1fdf 100644 (file)
  * Most of the dirty work blatantly ripped off from cat.c =)
  */
 
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include <getopt.h>
+#include <stdlib.h>
+#include <unistd.h>
 #include "busybox.h"
 
 /* various defines swiped from linux/cdrom.h */
 #define CDROMCLOSETRAY            0x5319  /* pendant of CDROMEJECT  */
 #define CDROMEJECT                0x5309  /* Ejects the cdrom media */
 #define DEFAULT_CDROM             "/dev/cdrom"
-/*#define CLOSE_TRAY              1*/
+
+#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;
        
-#ifdef CONFIG_FEATURE_EJECT_LONG_OPTIONS
-       static const struct option eject_long_options[] = {
-               { "trayclose", 0, 0, 't' },
-               { 0,           0, 0, 0 }
-       };
-       bb_applet_long_options = eject_long_options;
-#endif
-
        flags = bb_getopt_ulflags(argc, argv, "t");
-
-       if (ioctl(bb_xopen((argv[optind] ? argv[optind] : DEFAULT_CDROM), 
+       bb_xasprintf(&command, "umount '%s'", device);
+       
+       /* validate input before calling system */
+       if(find_mount_point(device, MTAB))
+               system(command);
+       
+       if (ioctl(bb_xopen( device, 
                           (O_RDONLY | O_NONBLOCK)), 
-                 ( flags /*& CLOSE_TRAY*/ ? CDROMCLOSETRAY : CDROMEJECT)))
+                 ( flags ? CDROMCLOSETRAY : CDROMEJECT)))
        {
-               bb_perror_msg_and_die(bb_msg_unknown);
+               bb_perror_msg_and_die(device);
        }
-
-       return EXIT_SUCCESS;
+#ifdef CONFIG_FEATURE_CLEAN_UP 
+       free(command);
+#endif
+       return(EXIT_SUCCESS);
 }