[PATCH:xsm] Close file descriptors on exec.

Thomas Klausner wiz at NetBSD.org
Wed Feb 25 13:24:06 PST 2015


From: Christos Zoulas <christos at NetBSD.org>

Signed-off-by: Thomas Klausner <wiz at NetBSD.org>
---
 auth.c     | 8 ++++----
 choose.c   | 2 ++
 lock.c     | 2 +-
 remote.c   | 2 +-
 restart.c  | 4 ++--
 saveutil.c | 6 +++---
 6 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/auth.c b/auth.c
index 5b3bcac..c380fda 100644
--- a/auth.c
+++ b/auth.c
@@ -154,25 +154,25 @@ SetAuthentication(int count, IceListenObj *listenObjs,
     if ((addAuthFile = unique_filename (path, ".xsm")) == NULL)
 	goto bad;
 
-    if (!(addfp = fopen (addAuthFile, "w")))
+    if (!(addfp = fopen (addAuthFile, "we")))
 	goto bad;
 
     if ((remAuthFile = unique_filename (path, ".xsm")) == NULL)
 	goto bad;
 
-    if (!(removefp = fopen (remAuthFile, "w")))
+    if (!(removefp = fopen (remAuthFile, "we")))
 	goto bad;
 #else
     if ((addAuthFile = unique_filename (path, ".xsm", &fd)) == NULL)
 	goto bad;
     
-    if (!(addfp = fdopen(fd, "wb"))) 
+    if (!(addfp = fdopen(fd, "wbe"))) 
 	goto bad;
 
     if ((remAuthFile = unique_filename (path, ".xsm", &fd)) == NULL)
 	goto bad;
     
-    if (!(removefp = fdopen(fd, "wb"))) 
+    if (!(removefp = fdopen(fd, "wbe"))) 
 	goto bad;
 #endif
 
diff --git a/choose.c b/choose.c
index 6459b61..4ec80c3 100644
--- a/choose.c
+++ b/choose.c
@@ -98,6 +98,8 @@ GetSessionNames(int *count_ret, String **short_names_ret,
     if ((dir = opendir (path)) == NULL)
 	return 0;
 
+    (void)fcntl(dirfd(dir), F_SETFD, FD_CLOEXEC);
+
     count = 0;
 
     while ((entry = readdir (dir)) != NULL)
diff --git a/lock.c b/lock.c
index 84c0ee3..c8a9094 100644
--- a/lock.c
+++ b/lock.c
@@ -117,7 +117,7 @@ GetLockId(const char *session_name)
     snprintf (lock_file, sizeof(lock_file), "%s/.XSMlock-%s",
 	      path, session_name);
 
-    if ((fp = fopen (lock_file, "r")) == NULL)
+    if ((fp = fopen (lock_file, "re")) == NULL)
     {
 	return (NULL);
     }
diff --git a/remote.c b/remote.c
index 54d95ac..c5ea385 100644
--- a/remote.c
+++ b/remote.c
@@ -111,7 +111,7 @@ remote_start(const char *restart_protocol, const char *restart_machine,
 	default:		/* parent */
 
 	    close (pipefd[0]);
-	    fp = (FILE *) fdopen (pipefd[1], "w");
+	    fp = fdopen (pipefd[1], "we");
 
 	    fprintf (fp, "CONTEXT X\n");
 	    fprintf (fp, "DIR %s\n", cwd);
diff --git a/restart.c b/restart.c
index 57663a5..6bbf6e9 100644
--- a/restart.c
+++ b/restart.c
@@ -531,11 +531,11 @@ StartDefaultApps (void)
 	home = ".";
     snprintf (filename, sizeof(filename), "%s/.xsmstartup", home);
 
-    f = fopen (filename, "r");
+    f = fopen (filename, "re");
 
     if (!f)
     {
-	f = fopen (SYSTEM_INIT_FILE, "r");
+	f = fopen (SYSTEM_INIT_FILE, "re");
 	if (!f)
 	{
 	    printf ("Could not find default apps file.  Make sure you did\n");
diff --git a/saveutil.c b/saveutil.c
index 091763a..b0226d1 100644
--- a/saveutil.c
+++ b/saveutil.c
@@ -65,7 +65,7 @@ ReadSave(const char *session_name, char **sm_id)
     int			state, i;
     int			version_number;
 
-    f = fopen(session_save_file, "r");
+    f = fopen(session_save_file, "re");
     if(!f) {
 	if (verbose)
 	    printf("No session save file.\n");
@@ -306,7 +306,7 @@ WriteSave(const char *sm_id)
     char *p, *c;
     int count;
 
-    f = fopen (session_save_file, "w");
+    f = fopen (session_save_file, "we");
 
     if (!f)
     {
@@ -427,7 +427,7 @@ DeleteSession(const char *session_name)
 
     snprintf (filename, sizeof(filename), "%s/.XSM-%s", dir, session_name);
 
-    f = fopen(filename, "r");
+    f = fopen(filename, "re");
     if(!f) {
 	return (0);
     }
-- 
2.3.0



More information about the xorg-devel mailing list