Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/pax obey umask as it used to be before the "mkstemp and ...



details:   https://anonhg.NetBSD.org/src/rev/c5adecd5a733
branches:  trunk
changeset: 586896:c5adecd5a733
user:      yamt <yamt%NetBSD.org@localhost>
date:      Wed Jan 04 22:02:11 2006 +0000

description:
obey umask as it used to be before the "mkstemp and then rename" change.

diffstat:

 bin/pax/file_subs.c |  22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

diffs (50 lines):

diff -r 265389403f94 -r c5adecd5a733 bin/pax/file_subs.c
--- a/bin/pax/file_subs.c       Wed Jan 04 22:00:50 2006 +0000
+++ b/bin/pax/file_subs.c       Wed Jan 04 22:02:11 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: file_subs.c,v 1.57 2005/09/18 12:15:41 christos Exp $  */
+/*     $NetBSD: file_subs.c,v 1.58 2006/01/04 22:02:11 yamt Exp $      */
 
 /*-
  * Copyright (c) 1992 Keith Muller.
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)file_subs.c        8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: file_subs.c,v 1.57 2005/09/18 12:15:41 christos Exp $");
+__RCSID("$NetBSD: file_subs.c,v 1.58 2006/01/04 22:02:11 yamt Exp $");
 #endif
 #endif /* not lint */
 
@@ -84,6 +84,21 @@
 #define FILEBITS(dir)          ((dir) ? (FILE_BITS | S_ISVTX) : FILE_BITS)
 #define SETBITS(dir)           ((dir) ? SET_BITS : (SET_BITS | S_ISVTX))
 
+static mode_t
+apply_umask(mode_t mode)
+{
+       static mode_t cached_umask;
+       static int cached_umask_valid;
+
+       if (!cached_umask_valid) {
+               cached_umask = umask(0);
+               umask(cached_umask);
+               cached_umask_valid = 1;
+       }
+
+       return mode & ~cached_umask;
+}
+
 /*
  * file_creat()
  *     Create and open a file.
@@ -206,7 +221,8 @@
        if (pmode)
                set_pmode(tmp_name, arcn->sb.st_mode);
        else
-               set_pmode(tmp_name, arcn->sb.st_mode & FILEBITS(0));
+               set_pmode(tmp_name,
+                   apply_umask((arcn->sb.st_mode & FILEBITS(0))));
        if (patime || pmtime)
                set_ftime(tmp_name, arcn->sb.st_mtime, arcn->sb.st_atime, 0);
 



Home | Main Index | Thread Index | Old Index