File libedit-ocloexec.patch of Package libedit

Index: src/readline.c
===================================================================
--- src/readline.c.orig	2014-07-28 16:17:56.006585088 +0200
+++ src/readline.c	2014-07-28 16:17:58.431585084 +0200
@@ -1190,15 +1190,15 @@ history_truncate_file (const char *filen
 
 	if (filename == NULL && (filename = _default_history_file()) == NULL)
 		return errno;
-	if ((fp = fopen(filename, "r+")) == NULL)
+	if ((fp = fopen(filename, "r+e")) == NULL)
 		return errno;
 	strcpy(template, _history_tmp_template);
-	if ((fd = mkstemp(template)) == -1) {
+	if ((fd = mkostemp(template, O_CLOEXEC)) == -1) {
 		ret = errno;
 		goto out1;
 	}
 
-	if ((tp = fdopen(fd, "r+")) == NULL) {
+	if ((tp = fdopen(fd, "r+e")) == NULL) {
 		close(fd);
 		ret = errno;
 		goto out2;
Index: src/vi.c
===================================================================
--- src/vi.c.orig	2014-07-28 16:17:56.006585088 +0200
+++ src/vi.c	2014-07-28 16:17:58.432585084 +0200
@@ -37,6 +37,7 @@
 #include <unistd.h>
 #include <limits.h>
 #include <sys/wait.h>
+#include <fcntl.h>
 
 #if !defined(lint) && !defined(SCCSID)
 #if 0
@@ -1007,7 +1008,7 @@ vi_histedit(EditLine *el, Int c __attrib
 			return CC_ERROR;
 	}
 
-	fd = mkstemp(tempfile);
+	fd = mkostemp(tempfile, O_CLOEXEC);
 	if (fd < 0)
 		return CC_ERROR;
 	len = (size_t)(el->el_line.lastchar - el->el_line.buffer);
Index: src/el.c
===================================================================
--- src/el.c.orig	2014-07-28 16:17:56.006585088 +0200
+++ src/el.c	2014-07-28 16:17:58.432585084 +0200
@@ -557,7 +557,7 @@ el_source(EditLine *el, const char *fnam
 		fname = path;
 	}
 	if (fp == NULL)
-		fp = fopen(fname, "r");
+		fp = fopen(fname, "re");
 	if (fp == NULL) {
 		el_free(path);
 		return -1;
Index: src/history.c
===================================================================
--- src/history.c.orig	2014-07-28 16:17:56.007585088 +0200
+++ src/history.c	2014-07-28 16:18:38.101585014 +0200
@@ -743,7 +743,7 @@ history_load(TYPE(History) *h, const cha
 	static ct_buffer_t conv;
 #endif
 
-	if ((fp = fopen(fname, "r")) == NULL)
+	if ((fp = fopen(fname, "re")) == NULL)
 		return i;
 
 	if ((line = fgetln(fp, &sz)) == NULL)
@@ -844,7 +844,7 @@ history_save(TYPE(History) *h, const cha
     FILE *fp;
     int i;
 
-    if ((fp = fopen(fname, "w")) == NULL)
+    if ((fp = fopen(fname, "we")) == NULL)
 	return -1;
 
     i = history_save_fp(h, fp);
openSUSE Build Service is sponsored by