mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-26 19:19:32 +03:00
Use libzfs_run_process() in libshare.
This should simplify the code a bit by re-using existing code to fork and exec a process. Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Issue #190
This commit is contained in:
parent
3132cb397a
commit
ddd0fd9ef6
@ -210,30 +210,10 @@ static int
|
|||||||
nfs_enable_share_one(const char *sharepath, const char *host,
|
nfs_enable_share_one(const char *sharepath, const char *host,
|
||||||
const char *security, const char *access, void *pcookie)
|
const char *security, const char *access, void *pcookie)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
int rc;
|
||||||
int rc, status;
|
|
||||||
char *linuxhost, *hostpath, *opts;
|
char *linuxhost, *hostpath, *opts;
|
||||||
const char *linux_opts = (const char *)pcookie;
|
const char *linux_opts = (const char *)pcookie;
|
||||||
|
char *argv[6];
|
||||||
pid = fork();
|
|
||||||
|
|
||||||
if (pid < 0)
|
|
||||||
return SA_SYSTEM_ERR;
|
|
||||||
|
|
||||||
if (pid > 0) {
|
|
||||||
while ((rc = waitpid(pid, &status, 0)) <= 0 && errno == EINTR)
|
|
||||||
; /* empty loop body */
|
|
||||||
|
|
||||||
if (rc <= 0)
|
|
||||||
return SA_SYSTEM_ERR;
|
|
||||||
|
|
||||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
|
||||||
return SA_CONFIG_ERR;
|
|
||||||
|
|
||||||
return SA_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* child */
|
|
||||||
|
|
||||||
/* exportfs -i -o sec=XX,rX,<opts> <host>:<sharepath> */
|
/* exportfs -i -o sec=XX,rX,<opts> <host>:<sharepath> */
|
||||||
|
|
||||||
@ -268,16 +248,22 @@ nfs_enable_share_one(const char *sharepath, const char *host,
|
|||||||
fprintf(stderr, "sharing %s with opts %s\n", hostpath, opts);
|
fprintf(stderr, "sharing %s with opts %s\n", hostpath, opts);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rc = execlp("/usr/sbin/exportfs", "exportfs", "-i", \
|
argv[0] = "/usr/sbin/exportfs";
|
||||||
"-o", opts, hostpath, NULL);
|
argv[1] = "-i";
|
||||||
|
argv[2] = "-o";
|
||||||
|
argv[3] = opts;
|
||||||
|
argv[4] = hostpath;
|
||||||
|
argv[5] = NULL;
|
||||||
|
|
||||||
if (rc < 0) {
|
rc = libzfs_run_process(argv[0], argv, 0);
|
||||||
free(hostpath);
|
|
||||||
free(opts);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
exit(0);
|
free(hostpath);
|
||||||
|
free(opts);
|
||||||
|
|
||||||
|
if (rc < 0)
|
||||||
|
return SA_SYSTEM_ERR;
|
||||||
|
else
|
||||||
|
return SA_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -414,29 +400,9 @@ static int
|
|||||||
nfs_disable_share_one(const char *sharepath, const char *host,
|
nfs_disable_share_one(const char *sharepath, const char *host,
|
||||||
const char *security, const char *access, void *cookie)
|
const char *security, const char *access, void *cookie)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
int rc;
|
||||||
int rc, status;
|
|
||||||
char *linuxhost, *hostpath;
|
char *linuxhost, *hostpath;
|
||||||
|
char *argv[4];
|
||||||
pid = fork();
|
|
||||||
|
|
||||||
if (pid < 0)
|
|
||||||
return SA_SYSTEM_ERR;
|
|
||||||
|
|
||||||
if (pid > 0) {
|
|
||||||
while ((rc = waitpid(pid, &status, 0)) <= 0 && errno == EINTR)
|
|
||||||
; /* empty loop body */
|
|
||||||
|
|
||||||
if (rc <= 0)
|
|
||||||
return SA_SYSTEM_ERR;
|
|
||||||
|
|
||||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
|
||||||
return SA_CONFIG_ERR;
|
|
||||||
|
|
||||||
return SA_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* child */
|
|
||||||
|
|
||||||
rc = get_linux_hostspec(host, &linuxhost);
|
rc = get_linux_hostspec(host, &linuxhost);
|
||||||
|
|
||||||
@ -458,15 +424,19 @@ nfs_disable_share_one(const char *sharepath, const char *host,
|
|||||||
fprintf(stderr, "unsharing %s\n", hostpath);
|
fprintf(stderr, "unsharing %s\n", hostpath);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rc = execlp("/usr/sbin/exportfs", "exportfs", "-u", \
|
argv[0] = "/usr/sbin/exportfs";
|
||||||
hostpath, NULL);
|
argv[1] = "-u";
|
||||||
|
argv[2] = hostpath;
|
||||||
|
argv[3] = NULL;
|
||||||
|
|
||||||
if (rc < 0) {
|
rc = libzfs_run_process(argv[0], argv, 0);
|
||||||
free(hostpath);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
exit(0);
|
free(hostpath);
|
||||||
|
|
||||||
|
if (rc < 0)
|
||||||
|
return SA_SYSTEM_ERR;
|
||||||
|
else
|
||||||
|
return SA_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Loading…
Reference in New Issue
Block a user