mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add umask(2).
This commit is contained in:
parent
a91af78c1f
commit
3c6ecd6512
6 changed files with 33 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||||
|
|
||||||
This file is part of the Sortix C Library.
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
@ -24,12 +24,10 @@
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
// TODO: Implement this in the kernel.
|
DEFN_SYSCALL1(mode_t, sys_umask, SYSCALL_UMASK, mode_t);
|
||||||
|
|
||||||
extern "C" mode_t umask(mode_t mask)
|
extern "C" mode_t umask(mode_t mask)
|
||||||
{
|
{
|
||||||
(void) mask;
|
return sys_umask(mask);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,6 +356,11 @@ static bool IsLastPathElement(const char* elem)
|
||||||
Ref<Descriptor> Descriptor::open(ioctx_t* ctx, const char* filename, int flags,
|
Ref<Descriptor> Descriptor::open(ioctx_t* ctx, const char* filename, int flags,
|
||||||
mode_t mode)
|
mode_t mode)
|
||||||
{
|
{
|
||||||
|
Process* process = CurrentProcess();
|
||||||
|
kthread_mutex_lock(&process->idlock);
|
||||||
|
mode &= ~process->umask;
|
||||||
|
kthread_mutex_unlock(&process->idlock);
|
||||||
|
|
||||||
// Unlike early Unix systems, the empty path does not mean the current
|
// Unlike early Unix systems, the empty path does not mean the current
|
||||||
// directory on Sortix, so reject it.
|
// directory on Sortix, so reject it.
|
||||||
if ( !filename[0] )
|
if ( !filename[0] )
|
||||||
|
@ -444,6 +449,11 @@ Ref<Descriptor> Descriptor::open_elem(ioctx_t* ctx, const char* filename,
|
||||||
|
|
||||||
int Descriptor::mkdir(ioctx_t* ctx, const char* filename, mode_t mode)
|
int Descriptor::mkdir(ioctx_t* ctx, const char* filename, mode_t mode)
|
||||||
{
|
{
|
||||||
|
Process* process = CurrentProcess();
|
||||||
|
kthread_mutex_lock(&process->idlock);
|
||||||
|
mode &= ~process->umask;
|
||||||
|
kthread_mutex_unlock(&process->idlock);
|
||||||
|
|
||||||
char* final;
|
char* final;
|
||||||
Ref<Descriptor> dir = OpenDirContainingPath(ctx, Ref<Descriptor>(this),
|
Ref<Descriptor> dir = OpenDirContainingPath(ctx, Ref<Descriptor>(this),
|
||||||
filename, &final);
|
filename, &final);
|
||||||
|
|
|
@ -96,6 +96,7 @@ public:
|
||||||
kthread_mutex_t idlock;
|
kthread_mutex_t idlock;
|
||||||
uid_t uid, euid;
|
uid_t uid, euid;
|
||||||
gid_t gid, egid;
|
gid_t gid, egid;
|
||||||
|
mode_t umask;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
kthread_mutex_t ptrlock;
|
kthread_mutex_t ptrlock;
|
||||||
|
|
|
@ -128,6 +128,7 @@
|
||||||
#define SYSCALL_CLOCK_SETTIMERES 104
|
#define SYSCALL_CLOCK_SETTIMERES 104
|
||||||
#define SYSCALL_CLOCK_NANOSLEEP 105
|
#define SYSCALL_CLOCK_NANOSLEEP 105
|
||||||
#define SYSCALL_TIMENS 106
|
#define SYSCALL_TIMENS 106
|
||||||
#define SYSCALL_MAX_NUM 107 /* index of highest constant + 1 */
|
#define SYSCALL_UMASK 107
|
||||||
|
#define SYSCALL_MAX_NUM 108 /* index of highest constant + 1 */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -131,6 +131,7 @@ namespace Sortix
|
||||||
pid = AllocatePID();
|
pid = AllocatePID();
|
||||||
uid = euid = 0;
|
uid = euid = 0;
|
||||||
gid = egid = 0;
|
gid = egid = 0;
|
||||||
|
umask = 0022;
|
||||||
Time::InitializeProcessClocks(this);
|
Time::InitializeProcessClocks(this);
|
||||||
alarm_timer.Attach(Time::GetClock(CLOCK_MONOTONIC));
|
alarm_timer.Attach(Time::GetClock(CLOCK_MONOTONIC));
|
||||||
Put(this);
|
Put(this);
|
||||||
|
@ -611,6 +612,7 @@ namespace Sortix
|
||||||
clone->gid = gid;
|
clone->gid = gid;
|
||||||
clone->euid = euid;
|
clone->euid = euid;
|
||||||
clone->egid = egid;
|
clone->egid = egid;
|
||||||
|
clone->umask = umask;
|
||||||
kthread_mutex_unlock(&idlock);
|
kthread_mutex_unlock(&idlock);
|
||||||
|
|
||||||
if ( !(clone->program_image_path = String::Clone(program_image_path)) )
|
if ( !(clone->program_image_path = String::Clone(program_image_path)) )
|
||||||
|
@ -978,6 +980,15 @@ namespace Sortix
|
||||||
return Page::Size();
|
return Page::Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mode_t sys_umask(mode_t newmask)
|
||||||
|
{
|
||||||
|
Process* process = CurrentProcess();
|
||||||
|
ScopedLock lock(&process->idlock);
|
||||||
|
mode_t oldmask = process->umask;
|
||||||
|
process->umask = newmask & 0666;
|
||||||
|
return oldmask;
|
||||||
|
}
|
||||||
|
|
||||||
void Process::Init()
|
void Process::Init()
|
||||||
{
|
{
|
||||||
Syscall::Register(SYSCALL_EXEC, (void*) SysExecVE);
|
Syscall::Register(SYSCALL_EXEC, (void*) SysExecVE);
|
||||||
|
@ -985,6 +996,7 @@ namespace Sortix
|
||||||
Syscall::Register(SYSCALL_GETPID, (void*) SysGetPID);
|
Syscall::Register(SYSCALL_GETPID, (void*) SysGetPID);
|
||||||
Syscall::Register(SYSCALL_GETPPID, (void*) SysGetParentPID);
|
Syscall::Register(SYSCALL_GETPPID, (void*) SysGetParentPID);
|
||||||
Syscall::Register(SYSCALL_EXIT, (void*) SysExit);
|
Syscall::Register(SYSCALL_EXIT, (void*) SysExit);
|
||||||
|
Syscall::Register(SYSCALL_UMASK, (void*) sys_umask);
|
||||||
Syscall::Register(SYSCALL_WAIT, (void*) SysWait);
|
Syscall::Register(SYSCALL_WAIT, (void*) SysWait);
|
||||||
Syscall::Register(SYSCALL_SBRK, (void*) SysSbrk);
|
Syscall::Register(SYSCALL_SBRK, (void*) SysSbrk);
|
||||||
Syscall::Register(SYSCALL_GET_PAGE_SIZE, (void*) SysGetPageSize);
|
Syscall::Register(SYSCALL_GET_PAGE_SIZE, (void*) SysGetPageSize);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
under the terms of the GNU General Public License as published by the Free
|
under the terms of the GNU General Public License as published by the Free
|
||||||
|
@ -75,6 +75,9 @@ int main(int /*argc*/, char* /*argv*/[])
|
||||||
printf("\r\e[m\e[J");
|
printf("\r\e[m\e[J");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
|
// Set the default file creation mask.
|
||||||
|
umask(022);
|
||||||
|
|
||||||
// By default, compile to the same architecture that the kernel told us that
|
// By default, compile to the same architecture that the kernel told us that
|
||||||
// we are running.
|
// we are running.
|
||||||
setenv("objtype", getenv("cputype"), 0);
|
setenv("objtype", getenv("cputype"), 0);
|
||||||
|
|
Loading…
Reference in a new issue