aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2017-02-27 11:14:42 -0800
committerMichael Forney <mforney@mforney.org>2017-02-27 11:19:24 -0800
commit74085e92c095d0bf4b98e262cc07ccf9b7dfff3b (patch)
tree3246525195f82b582f5fdc032165e772f435248b
parent80605f5a6cdcfd1d18d12151b69973b28db8c8eb (diff)
downloadvis-74085e92c095d0bf4b98e262cc07ccf9b7dfff3b.tar.gz
vis-74085e92c095d0bf4b98e262cc07ccf9b7dfff3b.tar.xz
Honor user's umask when saving files
If the user wants new files to be created as 600, they will have set their umask to 077 in their environment. vis shouldn't restrict this further than the user has configured.
-rw-r--r--text.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/text.c b/text.c
index bc599f5..59af7a1 100644
--- a/text.c
+++ b/text.c
@@ -856,7 +856,7 @@ static bool text_save_begin_atomic(TextSave *ctx) {
goto err;
snprintf(ctx->tmpname, namelen, "%s~", ctx->filename);
- if ((ctx->fd = open(ctx->tmpname, O_CREAT|O_WRONLY|O_TRUNC, oldfd == -1 ? S_IRUSR|S_IWUSR : oldmeta.st_mode)) == -1)
+ if ((ctx->fd = open(ctx->tmpname, O_CREAT|O_WRONLY|O_TRUNC, oldfd == -1 ? 0666 : oldmeta.st_mode)) == -1)
goto err;
if (oldfd != -1) {
if (!preserve_acl(oldfd, ctx->fd) || !preserve_selinux_context(oldfd, ctx->fd))
@@ -924,7 +924,7 @@ static bool text_save_begin_inplace(TextSave *ctx) {
Text *txt = ctx->txt;
struct stat meta = { 0 };
int newfd = -1, saved_errno;
- if ((ctx->fd = open(ctx->filename, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR)) == -1)
+ if ((ctx->fd = open(ctx->filename, 0666, S_IRUSR|S_IWUSR)) == -1)
goto err;
if (fstat(ctx->fd, &meta) == -1)
goto err;