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.
|
||||
|
||||
|
@ -24,12 +24,10 @@
|
|||
|
||||
#include <sys/stat.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)
|
||||
{
|
||||
(void) mask;
|
||||
return 0;
|
||||
return sys_umask(mask);
|
||||
}
|
||||
|
|
|
@ -356,6 +356,11 @@ static bool IsLastPathElement(const char* elem)
|
|||
Ref<Descriptor> Descriptor::open(ioctx_t* ctx, const char* filename, int flags,
|
||||
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
|
||||
// directory on Sortix, so reject it.
|
||||
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)
|
||||
{
|
||||
Process* process = CurrentProcess();
|
||||
kthread_mutex_lock(&process->idlock);
|
||||
mode &= ~process->umask;
|
||||
kthread_mutex_unlock(&process->idlock);
|
||||
|
||||
char* final;
|
||||
Ref<Descriptor> dir = OpenDirContainingPath(ctx, Ref<Descriptor>(this),
|
||||
filename, &final);
|
||||
|
|
|
@ -96,6 +96,7 @@ public:
|
|||
kthread_mutex_t idlock;
|
||||
uid_t uid, euid;
|
||||
gid_t gid, egid;
|
||||
mode_t umask;
|
||||
|
||||
private:
|
||||
kthread_mutex_t ptrlock;
|
||||
|
|
|
@ -128,6 +128,7 @@
|
|||
#define SYSCALL_CLOCK_SETTIMERES 104
|
||||
#define SYSCALL_CLOCK_NANOSLEEP 105
|
||||
#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
|
||||
|
|
|
@ -131,6 +131,7 @@ namespace Sortix
|
|||
pid = AllocatePID();
|
||||
uid = euid = 0;
|
||||
gid = egid = 0;
|
||||
umask = 0022;
|
||||
Time::InitializeProcessClocks(this);
|
||||
alarm_timer.Attach(Time::GetClock(CLOCK_MONOTONIC));
|
||||
Put(this);
|
||||
|
@ -611,6 +612,7 @@ namespace Sortix
|
|||
clone->gid = gid;
|
||||
clone->euid = euid;
|
||||
clone->egid = egid;
|
||||
clone->umask = umask;
|
||||
kthread_mutex_unlock(&idlock);
|
||||
|
||||
if ( !(clone->program_image_path = String::Clone(program_image_path)) )
|
||||
|
@ -978,6 +980,15 @@ namespace Sortix
|
|||
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()
|
||||
{
|
||||
Syscall::Register(SYSCALL_EXEC, (void*) SysExecVE);
|
||||
|
@ -985,6 +996,7 @@ namespace Sortix
|
|||
Syscall::Register(SYSCALL_GETPID, (void*) SysGetPID);
|
||||
Syscall::Register(SYSCALL_GETPPID, (void*) SysGetParentPID);
|
||||
Syscall::Register(SYSCALL_EXIT, (void*) SysExit);
|
||||
Syscall::Register(SYSCALL_UMASK, (void*) sys_umask);
|
||||
Syscall::Register(SYSCALL_WAIT, (void*) SysWait);
|
||||
Syscall::Register(SYSCALL_SBRK, (void*) SysSbrk);
|
||||
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
|
||||
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");
|
||||
fflush(stdout);
|
||||
|
||||
// Set the default file creation mask.
|
||||
umask(022);
|
||||
|
||||
// By default, compile to the same architecture that the kernel told us that
|
||||
// we are running.
|
||||
setenv("objtype", getenv("cputype"), 0);
|
||||
|
|
Loading…
Reference in a new issue