diff mbox series

[pseudo,3/3] pseudo_client: remove the unused pseudo_prefix_dir_fd

Message ID 20260718043750.7-4-bbnpreetsingh@gmail.com
State New
Headers show
Series closefrom/close_range: protect every pseudo fd, then drop one | expand

Commit Message

Babanpreet Singh July 18, 2026, 4:37 a.m. UTC
pseudo has kept an O_RDONLY descriptor on PSEUDO_PREFIX since its
first commit (33d9386, 2010), where client_connect() fchdir()'d
through it so the server socket could be reached by a path short
enough for sun_path. 551bf567 ("Add new environment values to allow
easy override of default locations") moved that job to
pseudo_localstate_dir_fd. Nothing has read pseudo_prefix_dir_fd back
since then.

Two side effects of opening it go away. Client init created a missing
PSEUDO_PREFIX with mkdir_p(); the default PSEUDO_LOCALSTATEDIR lives
under the prefix and its own setup runs the same mkdir_p(), so the
directory is still created there, while a custom PSEUDO_LOCALSTATEDIR
never needed the prefix directory at client init. An unset or
unopenable PSEUDO_PREFIX was a diagnostic and exit(1), and still is,
from the local state setup directly below.

The sweeps in OP_CLOSEFROM and OP_CLOSE_RANGE no longer need to step
around the descriptor, so the entries the previous commit added for
it go away again.

Discussed in
https://lore.kernel.org/yocto-patches/20260716055633.7-1-bbnpreetsingh@gmail.com/

AI-Generated: Uses Claude (claude-sonnet-5)
Signed-off-by: Babanpreet Singh <bbnpreetsingh@gmail.com>
---
 doc/program_flow |  1 -
 pseudo_client.c  | 66 +++++-------------------------------------------
 pseudo_client.h  |  1 -
 3 files changed, 6 insertions(+), 62 deletions(-)
diff mbox series

Patch

diff --git a/doc/program_flow b/doc/program_flow
index 3a399a7..e987e4a 100644
--- a/doc/program_flow
+++ b/doc/program_flow
@@ -15,7 +15,6 @@  libpseudo execution flow:
 			setup pseudo_logfile
 		pseudo_client.c: pseudo_init_client()
 			setup PSEUDO_DISABLED
-			setup pseudo_prefix_dir_fd
 			setup pseudo_localstate_dir_fd
 			setup PSEUDO_NOSYMLINKEXP
 			setup PSEUDO_UIDS
diff --git a/pseudo_client.c b/pseudo_client.c
index 7f80a3b..46b6a3b 100644
--- a/pseudo_client.c
+++ b/pseudo_client.c
@@ -46,7 +46,6 @@  static char *base_path(int dirfd, const char *path, int leave_last);
 
 static int connect_fd = -1;
 static int server_pid = 0;
-int pseudo_prefix_dir_fd = -1;
 int pseudo_localstate_dir_fd = -1;
 int pseudo_pwd_fd = -1;
 int pseudo_pwd_lck_fd = -1;
@@ -532,7 +531,6 @@  pseudo_init_client(void) {
 	if (!pseudo_inited) {
 		/* Ensure that all of the values are reset */
 		server_pid = 0;
-		pseudo_prefix_dir_fd = -1;
 		pseudo_localstate_dir_fd = -1;
 		pseudo_pwd_fd = -1;
 		pseudo_pwd_lck_fd = -1;
@@ -555,29 +553,6 @@  pseudo_init_client(void) {
 		pseudo_umask = umask(022);
 		umask(pseudo_umask);
 
-		pseudo_path = pseudo_prefix_path(NULL);
-		if (pseudo_prefix_dir_fd == -1) {
-			if (pseudo_path) {
-				pseudo_prefix_dir_fd = open(pseudo_path, O_RDONLY);
-				/* directory is missing? */
-				if (pseudo_prefix_dir_fd == -1 && errno == ENOENT) {
-					pseudo_debug(PDBGF_CLIENT, "prefix directory '%s' doesn't exist, trying to create\n", pseudo_path);
-					mkdir_p(pseudo_path);
-					pseudo_prefix_dir_fd = open(pseudo_path, O_RDONLY);
-				}
-				pseudo_prefix_dir_fd = pseudo_fd(pseudo_prefix_dir_fd, MOVE_FD);
-			} else {
-				pseudo_diag("No prefix available to to find server.\n");
-				exit(1);
-			}
-			if (pseudo_prefix_dir_fd == -1) {
-				pseudo_diag("Can't open prefix path '%s' for server: %s\n",
-					pseudo_path,
-					strerror(errno));
-				exit(1);
-			}
-		}
-		free(pseudo_path);
 		pseudo_path = pseudo_localstatedir_path(NULL);
 		if (pseudo_localstate_dir_fd == -1) {
 			if (pseudo_path) {
@@ -1439,29 +1414,6 @@  pseudo_client_shutdown(int wait_on_socket) {
 	char *pseudo_path;
 
 	pseudo_debug(PDBGF_INVOKE, "attempting to shut down server.\n");
-	pseudo_path = pseudo_prefix_path(NULL);
-	if (pseudo_prefix_dir_fd == -1) {
-		if (pseudo_path) {
-			pseudo_prefix_dir_fd = open(pseudo_path, O_RDONLY);
-			/* directory is missing? */
-			if (pseudo_prefix_dir_fd == -1 && errno == ENOENT) {
-				pseudo_debug(PDBGF_CLIENT, "prefix directory doesn't exist, trying to create\n");
-				mkdir_p(pseudo_path);
-				pseudo_prefix_dir_fd = open(pseudo_path, O_RDONLY);
-			}
-			pseudo_prefix_dir_fd = pseudo_fd(pseudo_prefix_dir_fd, COPY_FD);
-			free(pseudo_path);
-		} else {
-			pseudo_diag("No prefix available to to find server.\n");
-			exit(1);
-		}
-		if (pseudo_prefix_dir_fd == -1) {
-			pseudo_diag("Can't open prefix path (%s) for server. (%s)\n",
-				pseudo_prefix_path(NULL),
-				strerror(errno));
-			exit(1);
-		}
-	}
 	pseudo_path = pseudo_localstatedir_path(NULL);
 	mkdir_p(pseudo_path);
 	if (pseudo_localstate_dir_fd == -1) {
@@ -1970,8 +1922,6 @@  pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path
 			startfd = pseudo_util_debug_fd + 1;
 		if (pseudo_util_evlog_fd >= startfd)
 			startfd = pseudo_util_evlog_fd + 1;
-		if (pseudo_prefix_dir_fd >= startfd)
-			startfd = pseudo_prefix_dir_fd + 1;
 		if (pseudo_localstate_dir_fd >= startfd)
 			startfd = pseudo_localstate_dir_fd + 1;
 		if (pseudo_pwd_fd >= startfd)
@@ -1984,9 +1934,9 @@  pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path
 			startfd = connect_fd + 1;
 		for (i = fd; i < startfd; ++i) {
 			if (i == pseudo_util_debug_fd || i == pseudo_util_evlog_fd ||
-					i == pseudo_prefix_dir_fd || i == pseudo_localstate_dir_fd ||
-					i == pseudo_pwd_fd || i == pseudo_pwd_lck_fd ||
-					i == pseudo_grp_fd || i == connect_fd)
+					i == pseudo_localstate_dir_fd || i == pseudo_pwd_fd ||
+					i == pseudo_pwd_lck_fd || i == pseudo_grp_fd ||
+					i == connect_fd)
 				continue;
 			pseudo_client_close(i);
 			close(i);
@@ -2004,8 +1954,6 @@  pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path
 			startfd = pseudo_util_debug_fd + 1;
 		if (pseudo_util_evlog_fd >= startfd)
 			startfd = pseudo_util_evlog_fd + 1;
-		if (pseudo_prefix_dir_fd >= startfd)
-			startfd = pseudo_prefix_dir_fd + 1;
 		if (pseudo_localstate_dir_fd >= startfd)
 			startfd = pseudo_localstate_dir_fd + 1;
 		if (pseudo_pwd_fd >= startfd)
@@ -2021,9 +1969,9 @@  pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path
 		 */
 		for (i = fd; i < startfd && (unsigned int) i <= close_range_maxfd; ++i) {
 			if (i == pseudo_util_debug_fd || i == pseudo_util_evlog_fd ||
-					i == pseudo_prefix_dir_fd || i == pseudo_localstate_dir_fd ||
-					i == pseudo_pwd_fd || i == pseudo_pwd_lck_fd ||
-					i == pseudo_grp_fd || i == connect_fd)
+					i == pseudo_localstate_dir_fd || i == pseudo_pwd_fd ||
+					i == pseudo_pwd_lck_fd || i == pseudo_grp_fd ||
+					i == connect_fd)
 				continue;
 			pseudo_client_close(i);
 			close(i);
@@ -2045,8 +1993,6 @@  pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path
 				}
 			} else if (fd == pseudo_util_debug_fd) {
 				pseudo_util_debug_fd = pseudo_fd(fd, COPY_FD);
-			} else if (fd == pseudo_prefix_dir_fd) {
-				pseudo_prefix_dir_fd = pseudo_fd(fd, COPY_FD);
 			} else if (fd == pseudo_localstate_dir_fd) {
 				pseudo_localstate_dir_fd = pseudo_fd(fd, COPY_FD);
 			} else if (fd == pseudo_pwd_fd) {
diff --git a/pseudo_client.h b/pseudo_client.h
index a013f88..206f630 100644
--- a/pseudo_client.h
+++ b/pseudo_client.h
@@ -39,7 +39,6 @@  extern gid_t pseudo_egid;
 extern gid_t pseudo_sgid;
 extern gid_t pseudo_rgid;
 extern gid_t pseudo_fgid;
-extern int pseudo_prefix_dir_fd;
 extern int pseudo_localstate_dir_fd;
 extern FILE *pseudo_pwd_open(void);
 extern FILE *pseudo_grp_open(void);