Ticket #1698: 0001-Use-0666-as-default-file-open-mode.patch

File 0001-Use-0666-as-default-file-open-mode.patch, 3.6 KB (added by evhan, 4 years ago)
  • posixunix.scm

    From 7c66c86724f4c758fd468627ac7f22a207f64c7d Mon Sep 17 00:00:00 2001
    From: Evan Hanson <evhan@foldling.org>
    Date: Wed, 13 May 2020 17:50:39 +1200
    Subject: [PATCH] Use 0666 as default file-open mode
    
    There doesn't seem to be a default mode for open(2) specified anywhere,
    so let's make `file-open' match fopen(3) so the permissions of files
    created using the posix unit match files created with the normal
    `open-output-file' procedure, rather than making them executable by
    default. This closes #1698.
    ---
     posixunix.scm         |  2 +-
     posixwin.scm          |  2 +-
     tests/posix-tests.scm | 40 ++++++++++++++++++++++++++++++++++++++++
     3 files changed, 42 insertions(+), 2 deletions(-)
    
    diff --git a/posixunix.scm b/posixunix.scm
    index 23ff157e..1bddc429 100644
    a b static int set_file_mtime(char *filename, C_word atime, C_word mtime) 
    335335            res ) ) ) ) )
    336336
    337337(set! chicken.file.posix#file-open
    338   (let ((defmode (bitwise-ior _s_irwxu (bitwise-ior _s_irgrp _s_iroth))) )
     338  (let ((defmode (bitwise-ior _s_irusr _s_iwusr _s_irgrp _s_iwgrp _s_iroth _s_iwoth)))
    339339    (lambda (filename flags . mode)
    340340      (let ([mode (if (pair? mode) (car mode) defmode)])
    341341        (##sys#check-string filename 'file-open)
  • posixwin.scm

    diff --git a/posixwin.scm b/posixwin.scm
    index c279c58e..cb31a07b 100644
    a b static int set_file_mtime(char *filename, C_word atime, C_word mtime) 
    517517(set! chicken.file.posix#open/noinherit _o_noinherit)
    518518
    519519(set! chicken.file.posix#file-open
    520   (let ((defmode (bitwise-ior _s_irwxu (fxior _s_irgrp _s_iroth))))
     520  (let ((defmode (bitwise-ior _s_irusr _s_iwusr _s_irgrp _s_iwgrp _s_iroth _s_iwoth)))
    521521    (lambda (filename flags . mode)
    522522      (let ([mode (if (pair? mode) (car mode) defmode)])
    523523        (##sys#check-string filename 'file-open)
  • tests/posix-tests.scm

    diff --git a/tests/posix-tests.scm b/tests/posix-tests.scm
    index 807730e6..361f55c1 100644
    a b  
    8787(assert (equal? (get-environment-variable "FOO") "bar"))
    8888(unset-environment-variable! "FOO")
    8989(assert (not (get-environment-variable "FOO")))
     90
     91;; file creation and umask interaction
     92(letrec-syntax ((test (syntax-rules ()
     93                        ((test umask expected)
     94                         (test umask "expected" expected "given"))
     95                        ((test umask given expected)
     96                         (test umask "expected" expected "given" given))
     97                        ((test umask "expected" expected "given" given ...)
     98                         (let ((mode (file-creation-mode)))
     99                           (set! (file-creation-mode) umask)
     100                           (delete-file* "posix-tests.out")
     101                           (file-open "posix-tests.out" open/creat given ...)
     102                           (assert (equal? (file-permissions "posix-tests.out") expected))
     103                           (set! (file-creation-mode) mode))))))
     104  ;; default file mode
     105  (test #o000 #o666)
     106  (test #o002 #o664)
     107  (test #o020 #o646)
     108  (test #o022 #o644)
     109  (test #o027 #o640)
     110  (test #o072 #o604)
     111  (test #o077 #o600)
     112  (test #o777 #o000)
     113  ;; explicit file mode argument
     114  (test #o000 #o644 #o644)
     115  (test #o002 #o644 #o644)
     116  (test #o020 #o644 #o644)
     117  (test #o022 #o644 #o644)
     118  (test #o027 #o644 #o640)
     119  (test #o072 #o644 #o604)
     120  (test #o077 #o644 #o600)
     121  (test #o777 #o644 #o000)
     122  (test #o000 #o777 #o777)
     123  (test #o002 #o777 #o775)
     124  (test #o020 #o777 #o757)
     125  (test #o022 #o777 #o755)
     126  (test #o027 #o777 #o750)
     127  (test #o072 #o777 #o705)
     128  (test #o077 #o777 #o700)
     129  (test #o777 #o777 #o000))