add "e" (close-on-exec) flag to fopen(3) calls suggested by millert ok thomas_adam
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
diff --git a/got/got.c b/got/got.c
index 9e4617d..3ed755a 100644
--- a/got/got.c
+++ b/got/got.c
@@ -504,7 +504,7 @@ edit_logmsg(char **logmsg, const char *editor, const char *logmsg_path,
return got_error_from_errno("malloc");
(*logmsg)[0] = '\0';
- fp = fopen(logmsg_path, "r");
+ fp = fopen(logmsg_path, "re");
if (fp == NULL) {
err = got_error_from_errno("fopen");
goto done;
@@ -1236,7 +1236,7 @@ create_gotconfig(const char *proto, const char *host, const char *port,
err = got_error_from_errno("got_repo_get_path_gotconfig");
goto done;
}
- gotconfig_file = fopen(gotconfig_path, "a");
+ gotconfig_file = fopen(gotconfig_path, "ae");
if (gotconfig_file == NULL) {
err = got_error_from_errno2("fopen", gotconfig_path);
goto done;
@@ -1296,7 +1296,7 @@ create_gitconfig(const char *git_url, const char *default_branch,
err = got_error_from_errno("got_repo_get_path_gitconfig");
goto done;
}
- gitconfig_file = fopen(gitconfig_path, "a");
+ gitconfig_file = fopen(gitconfig_path, "ae");
if (gitconfig_file == NULL) {
err = got_error_from_errno2("fopen", gitconfig_path);
goto done;
@@ -7296,7 +7296,7 @@ cmd_revert(int argc, char *argv[])
goto done;
if (patch_script_path) {
- patch_script_file = fopen(patch_script_path, "r");
+ patch_script_file = fopen(patch_script_path, "re");
if (patch_script_file == NULL) {
error = got_error_from_errno2("fopen",
patch_script_path);
@@ -7392,7 +7392,7 @@ read_prepared_logmsg(char **logmsg, const char *path)
*logmsg = NULL;
memset(&sb, 0, sizeof(sb));
- f = fopen(path, "r");
+ f = fopen(path, "re");
if (f == NULL)
return got_error_from_errno2("fopen", path);
@@ -9824,7 +9824,7 @@ histedit_run_editor(struct got_histedit_list *histedit_cmds,
goto done;
}
- f = fopen(path, "r");
+ f = fopen(path, "re");
if (f == NULL) {
err = got_error_from_errno("fopen");
goto done;
@@ -9910,7 +9910,7 @@ histedit_save_list(struct got_histedit_list *histedit_cmds,
if (err)
return err;
- f = fopen(path, "w");
+ f = fopen(path, "we");
if (f == NULL) {
err = got_error_from_errno2("fopen", path);
goto done;
@@ -9957,7 +9957,7 @@ histedit_load_list(struct got_histedit_list *histedit_cmds,
const struct got_error *err = NULL;
FILE *f = NULL;
- f = fopen(path, "r");
+ f = fopen(path, "re");
if (f == NULL) {
err = got_error_from_errno2("fopen", path);
goto done;
@@ -11241,7 +11241,7 @@ cmd_stage(int argc, char *argv[])
goto done;
if (patch_script_path) {
- patch_script_file = fopen(patch_script_path, "r");
+ patch_script_file = fopen(patch_script_path, "re");
if (patch_script_file == NULL) {
error = got_error_from_errno2("fopen",
patch_script_path);
@@ -11361,7 +11361,7 @@ cmd_unstage(int argc, char *argv[])
goto done;
if (patch_script_path) {
- patch_script_file = fopen(patch_script_path, "r");
+ patch_script_file = fopen(patch_script_path, "re");
if (patch_script_file == NULL) {
error = got_error_from_errno2("fopen",
patch_script_path);
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index eeaf4cb..6363042 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -2670,7 +2670,7 @@ gw_get_repo_description(char **description, struct gw_trans *gw_trans,
if (asprintf(&d_file, "%s/description", dir) == -1)
return got_error_from_errno("asprintf");
- f = fopen(d_file, "r");
+ f = fopen(d_file, "re");
if (f == NULL) {
if (errno == ENOENT || errno == EACCES)
return NULL;
@@ -2973,7 +2973,7 @@ gw_get_clone_url(char **url, struct gw_trans *gw_trans, char *dir)
if (asprintf(&d_file, "%s/cloneurl", dir) == -1)
return got_error_from_errno("asprintf");
- f = fopen(d_file, "r");
+ f = fopen(d_file, "re");
if (f == NULL) {
if (errno != ENOENT && errno != EACCES)
error = got_error_from_errno2("fopen", d_file);
diff --git a/gotweb/parse.y b/gotweb/parse.y
index 1d91c1f..dac1eae 100644
--- a/gotweb/parse.y
+++ b/gotweb/parse.y
@@ -503,7 +503,7 @@ pushfile(struct file **nfile, const char *name)
free(nfile);
return got_error_from_errno2(__func__, "strdup");
}
- if (((*nfile)->stream = fopen((*nfile)->name, "r")) == NULL) {
+ if (((*nfile)->stream = fopen((*nfile)->name, "re")) == NULL) {
char *msg = NULL;
if (asprintf(&msg, "%s", (*nfile)->name) == -1)
return got_error_from_errno("asprintf");
diff --git a/lib/diff3.c b/lib/diff3.c
index 95fdb07..ec933af 100644
--- a/lib/diff3.c
+++ b/lib/diff3.c
@@ -207,12 +207,12 @@ diffreg(BUF **d, const char *path1, const char *path2,
*d = NULL;
- f1 = fopen(path1, "r");
+ f1 = fopen(path1, "re");
if (f1 == NULL) {
err = got_error_from_errno2("fopen", path1);
goto done;
}
- f2 = fopen(path2, "r");
+ f2 = fopen(path2, "re");
if (f1 == NULL) {
err = got_error_from_errno2("fopen", path2);
goto done;
@@ -460,11 +460,11 @@ diff3_internal(char *dp13, char *dp23, char *path1, char *path2, char *path3,
if (err)
return err;
- if ((d3s->fp[0] = fopen(path1, "r")) == NULL)
+ if ((d3s->fp[0] = fopen(path1, "re")) == NULL)
return got_error_from_errno2("fopen", path1);
- if ((d3s->fp[1] = fopen(path2, "r")) == NULL)
+ if ((d3s->fp[1] = fopen(path2, "re")) == NULL)
return got_error_from_errno2("fopen", path2);
- if ((d3s->fp[2] = fopen(path3, "r")) == NULL)
+ if ((d3s->fp[2] = fopen(path3, "re")) == NULL)
return got_error_from_errno2("fopen", path3);
return merge(m, n, d3s);
@@ -604,7 +604,7 @@ readin(size_t *n, char *name, struct diff **dd, struct diff3_state *d3s)
*n = 0;
- f = fopen(name, "r");
+ f = fopen(name, "re");
if (f == NULL)
return got_error_from_errno2("fopen", name);
err = getchange(&p, f, d3s);
diff --git a/lib/reference.c b/lib/reference.c
index eff4b9a..b7336cf 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -189,7 +189,7 @@ parse_ref_file(struct got_reference **ref, const char *name,
}
}
- f = fopen(abspath, "rb");
+ f = fopen(abspath, "rbe");
if (f == NULL) {
if (errno != ENOTDIR && errno != ENOENT)
err = got_error_from_errno2("fopen", abspath);
@@ -495,7 +495,7 @@ got_ref_open(struct got_reference **ref, struct got_repository *repo,
if (err)
goto done;
}
- f = fopen(packed_refs_path, "rb");
+ f = fopen(packed_refs_path, "rbe");
free(packed_refs_path);
if (f != NULL) {
struct stat sb;
@@ -1088,7 +1088,7 @@ got_ref_list(struct got_reflist_head *refs, struct got_repository *repo,
goto done;
}
- f = fopen(packed_refs_path, "r");
+ f = fopen(packed_refs_path, "re");
free(packed_refs_path);
if (f) {
size_t linesize = 0;
@@ -1342,7 +1342,7 @@ delete_packed_ref(struct got_reference *delref, struct got_repository *repo)
goto done;
}
- f = fopen(packed_refs_path, "r");
+ f = fopen(packed_refs_path, "re");
if (f == NULL) {
err = got_error_from_errno2("fopen", packed_refs_path);
goto done;
diff --git a/lib/worktree.c b/lib/worktree.c
index 08a1d59..5cb71cf 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2342,7 +2342,7 @@ open_fileindex(struct got_fileindex **fileindex, char **fileindex_path,
if (err)
goto done;
- index = fopen(*fileindex_path, "rb");
+ index = fopen(*fileindex_path, "rbe");
if (index == NULL) {
if (errno != ENOENT)
err = got_error_from_errno2("fopen", *fileindex_path);
@@ -3476,7 +3476,7 @@ add_ignores(struct got_pathlist_head *ignores, const char *root_path,
}
}
} else {
- ignoresfile = fopen(ignorespath, "r");
+ ignoresfile = fopen(ignorespath, "re");
if (ignoresfile == NULL) {
if (errno != ENOENT && errno != EACCES)
err = got_error_from_errno2("fopen",
@@ -8286,7 +8286,7 @@ unstage_hunks(struct got_object_id *staged_blob_id,
goto done;
}
- f = fopen(path_unstaged_content, "r");
+ f = fopen(path_unstaged_content, "re");
if (f == NULL) {
err = got_error_from_errno2("fopen",
path_unstaged_content);