diff options
author | David Cantrell <dcantrell@redhat.com> | 2009-04-07 14:31:50 -1000 |
---|---|---|
committer | David Cantrell <dcantrell@redhat.com> | 2009-04-08 09:11:42 -1000 |
commit | d108c723a3bef2a6d2b3714a645e8829f8df8f29 (patch) | |
tree | a00fbb7ddb0e6d7330c1477eaf5879b73de79347 /isys/imount.c | |
parent | cd333fa45091c36629f05f75233cdbcf44e26bf7 (diff) | |
download | anaconda-d108c723a3bef2a6d2b3714a645e8829f8df8f29.tar.gz anaconda-d108c723a3bef2a6d2b3714a645e8829f8df8f29.tar.xz anaconda-d108c723a3bef2a6d2b3714a645e8829f8df8f29.zip |
Add doPwUmount() and mountCommandWrapper() to isys (#493333)
Turn doPwMount() in to a mount command wrapper. We're already calling
mount(8) and capturing error messages so we can pass them back up to our
Python code, so the same for unmounting filesystems.
Diffstat (limited to 'isys/imount.c')
-rw-r--r-- | isys/imount.c | 127 |
1 files changed, 83 insertions, 44 deletions
diff --git a/isys/imount.c b/isys/imount.c index fd51fdefa..30b63029f 100644 --- a/isys/imount.c +++ b/isys/imount.c @@ -1,7 +1,7 @@ /* * imount.c * - * Copyright (C) 2007, 2008 Red Hat, Inc. All rights reserved. + * Copyright (C) 2007, 2008, 2009 Red Hat, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -68,44 +68,58 @@ static int readFD(int fd, char **buf) { return filesize; } -int doPwMount(char *dev, char *where, char *fs, char *options, char **err) { +int mountCommandWrapper(int mode, char *dev, char *where, char *fs, + char *options, char **err) { int rc, child, status, pipefd[2]; - char *opts = NULL, *device; + char *opts = NULL, *device = NULL, *cmd = NULL; int programLogFD; - if (mkdirChain(where)) - return IMOUNT_ERR_ERRNO; + if (mode == IMOUNT_MODE_MOUNT) { + cmd = "/bin/mount"; + } else if (mode == IMOUNT_MODE_UMOUNT) { + cmd = "/bin/umount"; + } else { + return IMOUNT_ERR_MODE; + } - if (strstr(fs, "nfs")) { - if (options) { - if (asprintf(&opts, "%s,nolock", options) == -1) { - fprintf(stderr, "%s: %d: %s\n", __func__, __LINE__, - strerror(errno)); - fflush(stderr); - abort(); + if (mode == IMOUNT_MODE_MOUNT) { + if (mkdirChain(where)) + return IMOUNT_ERR_ERRNO; + + if (strstr(fs, "nfs")) { + if (options) { + if (asprintf(&opts, "%s,nolock", options) == -1) { + fprintf(stderr, "%s: %d: %s\n", __func__, __LINE__, + strerror(errno)); + fflush(stderr); + abort(); + } + } else { + opts = strdup("nolock"); } + + device = strdup(dev); } else { - opts = strdup("nolock"); - } - device = strdup(dev); - } else { - if ((options && strstr(options, "bind") == NULL) && - strncmp(dev, "LABEL=", 6) && strncmp(dev, "UUID=", 5) && - *dev != '/') { - if (asprintf(&device, "/dev/%s", dev) == -1) { - fprintf(stderr, "%s: %d: %s\n", __func__, __LINE__, - strerror(errno)); - fflush(stderr); - abort(); - } - } else { - device = strdup(dev); + if ((options && strstr(options, "bind") == NULL) && + strncmp(dev, "LABEL=", 6) && strncmp(dev, "UUID=", 5) && + *dev != '/') { + if (asprintf(&device, "/dev/%s", dev) == -1) { + fprintf(stderr, "%s: %d: %s\n", __func__, __LINE__, + strerror(errno)); + fflush(stderr); + abort(); + } + } else { + device = strdup(dev); + } + + if (options) + opts = strdup(options); } - if (options) - opts = strdup(options); } - programLogFD = open("/tmp/program.log", O_APPEND|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); + programLogFD = open("/tmp/program.log", + O_APPEND|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); if (pipe(pipefd)) return IMOUNT_ERR_ERRNO; @@ -116,8 +130,9 @@ int doPwMount(char *dev, char *where, char *fs, char *options, char **err) { close(pipefd[0]); /* Close stdin entirely, redirect stdout to /tmp/program.log, and - * redirect stderr to a pipe so we can put error messages into exceptions. - * We'll only use these messages should mount also return an error code. + * redirect stderr to a pipe so we can put error messages into + * exceptions. We'll only use these messages should mount also + * return an error code. */ fd = open("/dev/tty5", O_RDONLY); close(STDIN_FILENO); @@ -129,17 +144,25 @@ int doPwMount(char *dev, char *where, char *fs, char *options, char **err) { dup2(pipefd[1], STDERR_FILENO); - if (opts) { - fprintf(stdout, "Running... /bin/mount -n -t %s -o %s %s %s\n", - fs, opts, device, where); - rc = execl("/bin/mount", - "/bin/mount", "-n", "-t", fs, "-o", opts, device, where, NULL); + if (mode == IMOUNT_MODE_MOUNT) { + if (opts) { + fprintf(stdout, "Running... %s -n -t %s -o %s %s %s\n", + cmd, fs, opts, device, where); + rc = execl(cmd, cmd, + "-n", "-t", fs, "-o", opts, device, where, NULL); + exit(1); + } else { + fprintf(stdout, "Running... %s -n -t %s %s %s\n", + cmd, fs, device, where); + rc = execl(cmd, cmd, "-n", "-t", fs, device, where, NULL); + exit(1); + } + } else if (mode == IMOUNT_MODE_UMOUNT) { + fprintf(stdout, "Running... %s %s\n", cmd, where); + rc = execl(cmd, cmd, where, NULL); exit(1); - } - else { - fprintf(stdout, "Running... /bin/mount -n -t %s %s %s\n", - fs, device, where); - rc = execl("/bin/mount", "/bin/mount", "-n", "-t", fs, device, where, NULL); + } else { + fprintf(stdout, "Running... Unknown imount mode: %d\n", mode); exit(1); } } @@ -158,14 +181,30 @@ int doPwMount(char *dev, char *where, char *fs, char *options, char **err) { close(programLogFD); - free(opts); - free(device); + if (opts) { + free(opts); + } + + if (device) { + free(device); + } + if (!WIFEXITED(status) || (WIFEXITED(status) && WEXITSTATUS(status))) return IMOUNT_ERR_OTHER; return 0; } +int doPwMount(char *dev, char *where, char *fs, char *options, char **err) { + return mountCommandWrapper(IMOUNT_MODE_MOUNT, + dev, where, fs, options, err); +} + +int doPwUmount(char *where, char **err) { + return mountCommandWrapper(IMOUNT_MODE_UMOUNT, + NULL, where, NULL, NULL, err); +} + int mkdirChain(char * origChain) { char * chain; char * chptr; |