mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2025-01-28 19:04:23 +03:00
freebsd: libshare/nfs: write directly in translate_opts()
This renders it thread-safe Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #13165
This commit is contained in:
parent
5f0c1c4ebd
commit
ee668b8331
@ -55,7 +55,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
static sa_fstype_t *nfs_fstype;
|
static sa_fstype_t *nfs_fstype;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function translate options to a format acceptable by exports(5), eg.
|
* This function translates options to a format acceptable by exports(5), eg.
|
||||||
*
|
*
|
||||||
* -ro -network=192.168.0.0 -mask=255.255.255.0 -maproot=0 \
|
* -ro -network=192.168.0.0 -mask=255.255.255.0 -maproot=0 \
|
||||||
* zfs.freebsd.org 69.147.83.54
|
* zfs.freebsd.org 69.147.83.54
|
||||||
@ -72,17 +72,14 @@ static sa_fstype_t *nfs_fstype;
|
|||||||
*
|
*
|
||||||
* ro, maproot, mapall, mask, network, sec, alldirs, public, webnfs,
|
* ro, maproot, mapall, mask, network, sec, alldirs, public, webnfs,
|
||||||
* index, quiet
|
* index, quiet
|
||||||
*
|
|
||||||
* NOTE: This function returns a static buffer and thus is not thread-safe.
|
|
||||||
*/
|
*/
|
||||||
static char *
|
static int
|
||||||
translate_opts(const char *shareopts)
|
translate_opts(const char *shareopts, FILE *out)
|
||||||
{
|
{
|
||||||
static const char *const known_opts[] = { "ro", "maproot", "mapall",
|
static const char *const known_opts[] = { "ro", "maproot", "mapall",
|
||||||
"mask", "network", "sec", "alldirs", "public", "webnfs", "index",
|
"mask", "network", "sec", "alldirs", "public", "webnfs", "index",
|
||||||
"quiet" };
|
"quiet" };
|
||||||
static char newopts[OPTSSIZE];
|
char oldopts[OPTSSIZE], newopts[OPTSSIZE];
|
||||||
char oldopts[OPTSSIZE];
|
|
||||||
char *o, *s = NULL;
|
char *o, *s = NULL;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
size_t len;
|
size_t len;
|
||||||
@ -104,7 +101,7 @@ translate_opts(const char *shareopts)
|
|||||||
strlcat(newopts, o, sizeof (newopts));
|
strlcat(newopts, o, sizeof (newopts));
|
||||||
strlcat(newopts, " ", sizeof (newopts));
|
strlcat(newopts, " ", sizeof (newopts));
|
||||||
}
|
}
|
||||||
return (newopts);
|
return (fputs(newopts, out));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -114,8 +111,10 @@ nfs_enable_share_impl(sa_share_impl_t impl_share, FILE *tmpfile)
|
|||||||
if (strcmp(shareopts, "on") == 0)
|
if (strcmp(shareopts, "on") == 0)
|
||||||
shareopts = "";
|
shareopts = "";
|
||||||
|
|
||||||
if (fprintf(tmpfile, "%s\t%s\n", impl_share->sa_mountpoint,
|
if (fputs(impl_share->sa_mountpoint, tmpfile) == EOF ||
|
||||||
translate_opts(shareopts)) < 0) {
|
fputc('\t', tmpfile) == EOF ||
|
||||||
|
translate_opts(shareopts, tmpfile) == EOF ||
|
||||||
|
fputc('\n', tmpfile) == EOF) {
|
||||||
fprintf(stderr, "failed to write to temporary file\n");
|
fprintf(stderr, "failed to write to temporary file\n");
|
||||||
return (SA_SYSTEM_ERR);
|
return (SA_SYSTEM_ERR);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user