Skip to content

umask seems to be ignored on file creation #26707

@hly2019

Description

@hly2019

Version of emscripten/emsdk:

5.0.6

A process-wide umask(0077) seems to be ignored by open(..., O_CREAT, 0666) and mkdir(). The created file keeps the raw mode instead of mode & ~umask.

Failing command line in full:

$ emcc -O0 -Wall umask.c -o a.out.js
$ node a.out.js
mode: 666 (expect 600)

The same program on native Linux prints mode: 600 (expect 600).

Example code snippet:

#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>

int main(void) {
    mkdir("/tmp/xsv_test", 0755);
    umask(0077);
    int fd = open("/tmp/xsv_test/f.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    write(fd, "x", 1);
    close(fd);

    struct stat st;
    stat("/tmp/xsv_test/f.txt", &st);
    printf("mode: %o (expect 600)\n", st.st_mode & 0777);
    return ((st.st_mode & 0777) == 0600) ? 0 : 1;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions