/*
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011 Gunnar Beutner
+ * Copyright (c) 2012 Cyril Plisko. All rights reserved.
*/
#include <stdio.h>
#include <libshare.h>
#include "libshare_impl.h"
+static boolean_t nfs_available(void);
+
static sa_fstype_t *nfs_fstype;
-static boolean_t nfs_available;
/*
* nfs_exportfs_temp_fd refers to a temporary copy of the output
char *shareopts, *linux_opts;
int rc;
- if (!nfs_available) {
+ if (!nfs_available()) {
return SA_SYSTEM_ERR;
}
static int
nfs_disable_share(sa_share_impl_t impl_share)
{
- if (!nfs_available) {
+ if (!nfs_available()) {
/*
* The share can't possibly be active, so nothing
* needs to be done to disable it.
char *tab, *cur;
FILE *nfs_exportfs_temp_fp;
- if (nfs_exportfs_temp_fd < 0)
+ if (!nfs_available())
return B_FALSE;
nfs_exportfs_temp_fp = fdopen(dup(nfs_exportfs_temp_fd), "r");
pid = fork();
- if (pid < 0)
+ if (pid < 0) {
+ (void) close(nfs_exportfs_temp_fd);
+ nfs_exportfs_temp_fd = -1;
return SA_SYSTEM_ERR;
+ }
if (pid > 0) {
while ((rc = waitpid(pid, &status, 0)) <= 0 && errno == EINTR)
; /* empty loop body */
- if (rc <= 0)
+ if (rc <= 0) {
+ (void) close(nfs_exportfs_temp_fd);
+ nfs_exportfs_temp_fd = -1;
return SA_SYSTEM_ERR;
+ }
- if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+ (void) close(nfs_exportfs_temp_fd);
+ nfs_exportfs_temp_fd = -1;
return SA_CONFIG_ERR;
+ }
return SA_OK;
}
exit(0);
}
+/*
+ * Provides a convenient wrapper for determing nfs availability
+ */
+static boolean_t
+nfs_available(void)
+{
+ if (nfs_exportfs_temp_fd == -1)
+ (void) nfs_check_exportfs();
+
+ return (nfs_exportfs_temp_fd != -1) ? B_TRUE : B_FALSE;
+}
+
/**
* Initializes the NFS functionality of libshare.
*/
void
libshare_nfs_init(void)
{
- nfs_available = (nfs_check_exportfs() == SA_OK);
-
nfs_fstype = register_fstype("nfs", &nfs_shareops);
}