Because we are dependent of the system mount/umount utilities to
ensure correct mtab locking, we should not suppress their error
output. During a successful mount/umount they will be silent,
but during a failure the error message they print is the only sure
way to know why a mount failed. This is because the (u)mount(8)
return code does not contain the result of the system call issued.
The only way to clearly idenify why thing failed is to rely on
the error message printed by the tool.
Longer term once libmount is available we can issue the mount/umount
system calls within the tool and still be ensured correct mtab locking.
Closed #107
/*
* Utility functions to run an external process.
*/
/*
* Utility functions to run an external process.
*/
-int libzfs_run_process(const char *, char **);
+#define STDOUT_VERBOSE 0x01
+#define STDERR_VERBOSE 0x02
+
+int libzfs_run_process(const char *, char **, int flags);
int libzfs_load_module(const char *);
/*
int libzfs_load_module(const char *);
/*
int rc;
/* Return only the most critical mount error */
int rc;
/* Return only the most critical mount error */
- rc = libzfs_run_process(argv[0], argv);
+ rc = libzfs_run_process(argv[0], argv, STDOUT_VERBOSE|STDERR_VERBOSE);
if (rc) {
if (rc & MOUNT_FILEIO)
return EIO;
if (rc) {
if (rc & MOUNT_FILEIO)
return EIO;
}
argv[count] = (char *)mntpt;
}
argv[count] = (char *)mntpt;
- rc = libzfs_run_process(argv[0], argv);
+ rc = libzfs_run_process(argv[0], argv, STDOUT_VERBOSE|STDERR_VERBOSE);
return (rc ? EINVAL : 0);
}
return (rc ? EINVAL : 0);
}
static int
unmount_one(libzfs_handle_t *hdl, const char *mountpoint, int flags)
{
static int
unmount_one(libzfs_handle_t *hdl, const char *mountpoint, int flags)
{
- if (do_unmount(mountpoint, flags) != 0) {
- zfs_error_aux(hdl, strerror(errno));
+ int error;
+
+ error = do_unmount(mountpoint, flags);
+ if (error != 0) {
return (zfs_error_fmt(hdl, EZFS_UMOUNTFAILED,
dgettext(TEXT_DOMAIN, "cannot unmount '%s'"),
mountpoint));
return (zfs_error_fmt(hdl, EZFS_UMOUNTFAILED,
dgettext(TEXT_DOMAIN, "cannot unmount '%s'"),
mountpoint));
-libzfs_run_process(const char *path, char *argv[])
+libzfs_run_process(const char *path, char *argv[], int flags)
{
pid_t pid;
int rc;
pid = vfork();
if (pid == 0) {
{
pid_t pid;
int rc;
pid = vfork();
if (pid == 0) {
+ if (!(flags & STDOUT_VERBOSE))
+ close(STDOUT_FILENO);
+
+ if (!(flags & STDERR_VERBOSE))
+ close(STDERR_FILENO);
+
(void) execvp(path, argv);
_exit(-1);
} else if (pid > 0) {
(void) execvp(path, argv);
_exit(-1);
} else if (pid > 0) {
if (libzfs_module_loaded(module))
return 0;
if (libzfs_module_loaded(module))
return 0;
- return libzfs_run_process("/sbin/modprobe", argv);
+ return libzfs_run_process("/sbin/modprobe", argv, 0);