diff options
author | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2015-10-14 16:42:52 +0000 |
---|---|---|
committer | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2015-10-14 16:42:52 +0000 |
commit | aa554f11ab0443579d18a5c343412f85a308c385 (patch) | |
tree | b23cbdc63a55c4e3739008eac2e6c186a11aace6 /usr.bin/sort | |
parent | 98ffe4fdc52ed9eb4a64f15ec4f296ac6e757f84 (diff) |
Copy permissions AND ownership when -o will override an input file.
with input by and ok deraadt@, millert@, tim@
Diffstat (limited to 'usr.bin/sort')
-rw-r--r-- | usr.bin/sort/sort.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c index c0305db5d9c..4827f72e7fe 100644 --- a/usr.bin/sort/sort.c +++ b/usr.bin/sort/sort.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sort.c,v 1.81 2015/10/13 16:55:03 tim Exp $ */ +/* $OpenBSD: sort.c,v 1.82 2015/10/14 16:42:51 tobias Exp $ */ /*- * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org> @@ -1132,9 +1132,13 @@ main(int argc, char *argv[]) real_outfile = outfile; sort_asprintf(&outfile, "%s.XXXXXXXXXX", real_outfile); - if ((fd = mkstemp(outfile)) == -1 || - fchmod(fd, sb.st_mode & ACCESSPERMS) == -1) - err(2, "%s", outfile); + if ((fd = mkstemp(outfile)) == -1) + err(2, "mkstemp: %s", outfile); + if (fchown(fd, sb.st_uid, sb.st_gid) == -1) + warn("unable to set ownership of %s", + outfile); + if (fchmod(fd, sb.st_mode & ACCESSPERMS) == -1) + err(2, "fchmod: %s", outfile); close(fd); tmp_file_atexit(outfile); break; |