got commit can't use unveil with an editor Theo says unveil(2) is supposed to traverse exec(2) (though this seems to be broken or not implemented at present). In which case the commmit message editor would find itself without access to files it needs (startup config files, shared libs, user's home dir, etc.) Apply unveil after the log message has been written.
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
diff --git a/got/got.c b/got/got.c
index 23370a0..3ef3e75 100644
--- a/got/got.c
+++ b/got/got.c
@@ -223,7 +223,7 @@ get_editor(char **abspath)
static const struct got_error *
apply_unveil(const char *repo_path, int repo_read_only,
- const char *worktree_path, int create_worktree, char **editor)
+ const char *worktree_path, int create_worktree)
{
const struct got_error *err;
static char err_msg[MAXPATHLEN + 36];
@@ -249,18 +249,6 @@ apply_unveil(const char *repo_path, int repo_read_only,
return err;
}
- if (editor) {
- err = get_editor(editor);
- if (err)
- return err;
- if (unveil(*editor, "x") != 0) {
- err = got_error_from_errno2("unveil", *editor);
- free(*editor);
- *editor = NULL;
- return err;
- }
- }
-
if (repo_path && unveil(repo_path, repo_read_only ? "r" : "rwc") != 0)
return got_error_from_errno2("unveil", repo_path);
@@ -442,8 +430,7 @@ cmd_checkout(int argc, char *argv[])
if (error != NULL)
goto done;
- error = apply_unveil(got_repo_get_path(repo), 0, worktree_path, 1,
- NULL);
+ error = apply_unveil(got_repo_get_path(repo), 0, worktree_path, 1);
if (error)
goto done;
@@ -581,7 +568,7 @@ cmd_update(int argc, char *argv[])
goto done;
error = apply_unveil(got_repo_get_path(repo), 0,
- got_worktree_get_root_path(worktree), 0, NULL);
+ got_worktree_get_root_path(worktree), 0);
if (error)
goto done;
@@ -953,7 +940,7 @@ cmd_log(int argc, char *argv[])
goto done;
error = apply_unveil(got_repo_get_path(repo), 1,
- worktree ? got_worktree_get_root_path(worktree) : NULL, 0, NULL);
+ worktree ? got_worktree_get_root_path(worktree) : NULL, 0);
if (error)
goto done;
@@ -1215,7 +1202,7 @@ cmd_diff(int argc, char *argv[])
goto done;
error = apply_unveil(got_repo_get_path(repo), 1,
- worktree ? got_worktree_get_root_path(worktree) : NULL, 0, NULL);
+ worktree ? got_worktree_get_root_path(worktree) : NULL, 0);
if (error)
goto done;
@@ -1375,7 +1362,7 @@ cmd_blame(int argc, char *argv[])
if (error != NULL)
goto done;
- error = apply_unveil(got_repo_get_path(repo), 1, NULL, 0, NULL);
+ error = apply_unveil(got_repo_get_path(repo), 1, NULL, 0);
if (error)
goto done;
@@ -1603,7 +1590,7 @@ cmd_tree(int argc, char *argv[])
if (error != NULL)
goto done;
- error = apply_unveil(got_repo_get_path(repo), 1, NULL, 0, NULL);
+ error = apply_unveil(got_repo_get_path(repo), 1, NULL, 0);
if (error)
goto done;
@@ -1732,7 +1719,7 @@ cmd_status(int argc, char *argv[])
goto done;
error = apply_unveil(got_repo_get_path(repo), 1,
- got_worktree_get_root_path(worktree), 0, NULL);
+ got_worktree_get_root_path(worktree), 0);
if (error)
goto done;
@@ -1903,7 +1890,7 @@ cmd_ref(int argc, char *argv[])
goto done;
error = apply_unveil(got_repo_get_path(repo), do_list,
- worktree ? got_worktree_get_root_path(worktree) : NULL, 0, NULL);
+ worktree ? got_worktree_get_root_path(worktree) : NULL, 0);
if (error)
goto done;
@@ -1982,7 +1969,7 @@ cmd_add(int argc, char *argv[])
goto done;
error = apply_unveil(got_repo_get_path(repo), 1,
- got_worktree_get_root_path(worktree), 0, NULL);
+ got_worktree_get_root_path(worktree), 0);
if (error)
goto done;
@@ -2068,7 +2055,7 @@ cmd_rm(int argc, char *argv[])
goto done;
error = apply_unveil(got_repo_get_path(repo), 1,
- got_worktree_get_root_path(worktree), 0, NULL);
+ got_worktree_get_root_path(worktree), 0);
if (error)
goto done;
@@ -2145,7 +2132,7 @@ cmd_revert(int argc, char *argv[])
goto done;
error = apply_unveil(got_repo_get_path(repo), 1,
- got_worktree_get_root_path(worktree), 0, NULL);
+ got_worktree_get_root_path(worktree), 0);
if (error)
goto done;
@@ -2210,6 +2197,7 @@ struct collect_commit_logmsg_arg {
const char *cmdline_log;
const char *editor;
const char *worktree_path;
+ const char *repo_path;
char *logmsg_path;
};
@@ -2311,6 +2299,10 @@ collect_commit_logmsg(struct got_pathlist_head *commitable_paths, char **logmsg,
}
done:
free(template);
+
+ /* Editor is done; we can now apply unveil(2) */
+ if (err == NULL)
+ err = apply_unveil(a->repo_path, 0, a->worktree_path, 0);
return err;
}
@@ -2371,14 +2363,22 @@ cmd_commit(int argc, char *argv[])
if (error != NULL)
goto done;
- error = apply_unveil(got_repo_get_path(repo), 0,
- got_worktree_get_root_path(worktree), 0, &editor);
+ /*
+ * unveil(2) traverses exec(2); if an editor is used we have
+ * to apply unveil after the log message has been written.
+ */
+ if (logmsg == NULL || strlen(logmsg) == 0)
+ error = get_editor(&editor);
+ else
+ error = apply_unveil(got_repo_get_path(repo), 0,
+ got_worktree_get_root_path(worktree), 0);
if (error)
goto done;
cl_arg.editor = editor;
cl_arg.cmdline_log = logmsg;
cl_arg.worktree_path = got_worktree_get_root_path(worktree);
+ cl_arg.repo_path = got_repo_get_path(repo);
cl_arg.logmsg_path = NULL;
error = got_worktree_commit(&id, worktree, path, got_author, NULL,
collect_commit_logmsg, &cl_arg, print_status, NULL, repo);