diff mbox series

[2/2] fsidd: provide better default socket name.

Message ID 168352675194.17279.12797722278244839616.stgit@noble.brown (mailing list archive)
State New, archived
Headers show
Series Minor improvements for fsidd in nfs-utils | expand

Commit Message

NeilBrown May 8, 2023, 6:19 a.m. UTC
Having the default socket name be in the current directory is a poor
choice for a daemon that is expected to run as root.

It is also likely better to use an "abstract" socket name.  abstract
names do not exist in the filesystem namespace and are local to a
network namespace.  Using an abstract name ensures that the nfsd,
mountd, and fsidd are all in the same network namespace.

This patch:
 - uses a single #define for the default socket name, rather than 2;
 - allows the socket name to start with '@' which is interpreted to
   be a request to use the abstract name space (systemd uses the same
   convention).
 - changes the default to "@/run/fsid.sock".  I don't know of a formal
   standard for choosing names in the abstract name space, the defacto
   standard (seen in "ss -xa|grep @") is to use a name similar to what
   might be used in the filesystem.

Signed-off-by: NeilBrown <neilb@suse.de>
---
 support/reexport/fsidd.c    |   10 ++++++----
 support/reexport/reexport.c |    3 +++
 support/reexport/reexport.h |    2 +-
 3 files changed, 10 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/support/reexport/fsidd.c b/support/reexport/fsidd.c
index 3fef1ef3512b..37649d065ce6 100644
--- a/support/reexport/fsidd.c
+++ b/support/reexport/fsidd.c
@@ -18,11 +18,10 @@ 
 
 #include "conffile.h"
 #include "reexport_backend.h"
+#include "reexport.h"
 #include "xcommon.h"
 #include "xlog.h"
 
-#define FSID_SOCKET_NAME "fsid.sock"
-
 static struct event_base *evbase;
 static struct reexpdb_backend_plugin *dbbackend = &sqlite_plug_ops;
 
@@ -167,11 +166,14 @@  int main(void)
 
 	sock_file = conf_get_str_with_def("reexport", "fsidd_socket", FSID_SOCKET_NAME);
 
-	unlink(sock_file);
-
 	memset(&addr, 0, sizeof(struct sockaddr_un));
 	addr.sun_family = AF_UNIX;
 	strncpy(addr.sun_path, sock_file, sizeof(addr.sun_path) - 1);
+	if (addr.sun_path[0] == '@')
+		/* "abstract" socket namespace */
+		addr.sun_path[0] = 0;
+	else
+		unlink(sock_file);
 
 	srv = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK, 0);
 	if (srv == -1) {
diff --git a/support/reexport/reexport.c b/support/reexport/reexport.c
index eddc9bf413f6..d597a2f73c93 100644
--- a/support/reexport/reexport.c
+++ b/support/reexport/reexport.c
@@ -38,6 +38,9 @@  static bool connect_fsid_service(void)
 	memset(&addr, 0, sizeof(struct sockaddr_un));
 	addr.sun_family = AF_UNIX;
 	strncpy(addr.sun_path, sock_file, sizeof(addr.sun_path) - 1);
+	if (addr.sun_path[0] == '@')
+		/* "abstract" socket namespace */
+		addr.sun_path[0] = 0;
 
 	s = socket(AF_UNIX, SOCK_SEQPACKET, 0);
 	if (s == -1) {
diff --git a/support/reexport/reexport.h b/support/reexport/reexport.h
index 3bed03a9a0bb..856c3085a1dd 100644
--- a/support/reexport/reexport.h
+++ b/support/reexport/reexport.h
@@ -13,6 +13,6 @@  int reexpdb_fsidnum_by_path(char *path, uint32_t *fsidnum, int may_create);
 int reexpdb_apply_reexport_settings(struct exportent *ep, char *flname, int flline);
 void reexpdb_uncover_subvolume(uint32_t fsidnum);
 
-#define FSID_SOCKET_NAME "fsid.sock"
+#define FSID_SOCKET_NAME "@/run/fsid.sock"
 
 #endif /* REEXPORT_H */