#include "monotonic.h"
/*
- * sg_io_hdr_t driver_status -- see kernel include/scsi/scsi.h
+ * sg_io_hdr_t driver_status -- see kernel include/scsi/sg.h
*/
#ifndef DRIVER_SENSE
# define DRIVER_SENSE 0x08
out);
fputs(USAGE_SEPARATOR, out);
- printf(USAGE_HELP_OPTIONS(29));
+ fprintf(out, USAGE_HELP_OPTIONS(29));
fputs(_("\nBy default tries -r, -s, -f, and -q in order until success.\n"), out);
- printf(USAGE_MAN_TAIL("eject(1)"));
+ fprintf(out, USAGE_MAN_TAIL("eject(1)"));
exit(EXIT_SUCCESS);
}
/* find line "drive speed" and read the correct speed */
} else {
if (strncmp(line, "drive speed:", 12) == 0) {
- int i;
+ int n;
- str = strtok(&line[12], "\t ");
- for (i = 1; i < drive_number; i++)
- str = strtok(NULL, "\t ");
+ fclose(f);
+
+ str = line + 12;
+ normalize_whitespace((unsigned char *) str);
+
+ if (ul_strtos32(str, &n, 10) == 0)
+ return n;
- if (!str)
- errx(EXIT_FAILURE,
- _("%s: failed to read speed"),
+ errx(EXIT_FAILURE, _("%s: failed to read speed"),
_PATH_PROC_CDROMINFO);
- fclose(f);
- return atoi(str);
}
}
}
switch (fork()) {
case 0: /* child */
- if (setgid(getgid()) < 0)
- err(EXIT_FAILURE, _("cannot set group id"));
-
- if (setuid(getuid()) < 0)
- err(EXIT_FAILURE, _("cannot set user id"));
-
+ if (drop_permissions() != 0)
+ err(EXIT_FAILURE, _("drop permissions failed"));
if (ctl->p_option)
execl("/bin/umount", "/bin/umount", name, "-n", (char *)NULL);
else
return count;
}
-static int is_hotpluggable(const struct eject_control *ctl)
+static int is_ejectable(const struct eject_control *ctl)
{
struct path_cxt *pc = NULL;
dev_t devno;
if (!pc)
return 0;
- rc = sysfs_blkdev_is_hotpluggable(pc);
+ rc = sysfs_blkdev_is_hotpluggable(pc) || sysfs_blkdev_is_removable(pc);
ul_unref_path(pc);
return rc;
}
verbose(&ctl, _("%s: is whole-disk device"), ctl.device);
}
- if (ctl.F_option == 0 && is_hotpluggable(&ctl) == 0)
- errx(EXIT_FAILURE, _("%s: is not hot-pluggable device"), ctl.device);
+ if (ctl.F_option == 0 && is_ejectable(&ctl) == 0)
+ errx(EXIT_FAILURE, _("%s: is not ejectable device"), ctl.device);
/* handle -n option */
if (ctl.n_option) {