From cfdb8f2928bdd0efb0fdeaec99d604decb6ce687 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Wed, 14 Aug 2019 17:48:13 +0300 Subject: [PATCH] Add get-ID procedures from draft SRFI 170 --- c/builtins.h | 9 ++++++ c/libraries.c | 9 ++++++ c/os_unix.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) diff --git a/c/builtins.h b/c/builtins.h index 55d213d..f833987 100644 --- a/c/builtins.h +++ b/c/builtins.h @@ -1 +1,10 @@ +value_t builtin_pid(value_t *args, uint32_t nargs); +value_t builtin_parent_pid(value_t *args, uint32_t nargs); +value_t builtin_process_group(value_t *args, uint32_t nargs); + +value_t builtin_user_effective_gid(value_t *args, uint32_t nargs); +value_t builtin_user_effective_uid(value_t *args, uint32_t nargs); +value_t builtin_user_real_gid(value_t *args, uint32_t nargs); +value_t builtin_user_real_uid(value_t *args, uint32_t nargs); + value_t builtin_read_ini_file(value_t *args, uint32_t nargs); diff --git a/c/libraries.c b/c/libraries.c index 6992660..896401a 100644 --- a/c/libraries.c +++ b/c/libraries.c @@ -88,6 +88,15 @@ static struct builtin_procedure builtin_procedures[] = { { "read-ini-file", builtin_read_ini_file, UP_2019 }, + { "pid", builtin_pid, SRFI_170 | UP_2019 }, + { "parent-pid", builtin_parent_pid, SRFI_170 | UP_2019 }, + { "process-group", builtin_process_group, SRFI_170 | UP_2019 }, + + { "user-effective-gid", builtin_user_effective_gid, SRFI_170 | UP_2019 }, + { "user-effective-uid", builtin_user_effective_uid, SRFI_170 | UP_2019 }, + { "user-real-gid", builtin_user_real_gid, SRFI_170 | UP_2019 }, + { "user-real-uid", builtin_user_real_uid, SRFI_170 | UP_2019 }, + { 0, 0, 0 }, }; diff --git a/c/os_unix.c b/c/os_unix.c index 7c3d5f4..22a2230 100644 --- a/c/os_unix.c +++ b/c/os_unix.c @@ -1,6 +1,33 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include +#include "dtypes.h" +#include "utils.h" +#include "utf8.h" +#include "ios.h" +#include "socket.h" +#include "timefuncs.h" +#include "hashing.h" +#include "htable.h" +#include "htableh_inc.h" +#include "bitvector.h" +#include "os.h" +#include "random.h" +#include "llt.h" + +#include "flisp.h" + +#include "argcount.h" #include "os.h" void path_to_dirname(char *path) @@ -21,3 +48,52 @@ int set_cwd(char *buf) return 1; return 0; } + +value_t builtin_pid(value_t *args, uint32_t nargs) +{ + (void)args; + argcount("pid", nargs, 0); + return fixnum(getpid()); +} + +value_t builtin_parent_pid(value_t *args, uint32_t nargs) +{ + (void)args; + argcount("parent-pid", nargs, 0); + return fixnum(getppid()); +} + +value_t builtin_process_group(value_t *args, uint32_t nargs) +{ + (void)args; + argcount("process-group", nargs, 0); + return fixnum(getpgid(0)); +} + +value_t builtin_user_effective_gid(value_t *args, uint32_t nargs) +{ + (void)args; + argcount("user-effective-gid", nargs, 0); + return fixnum(getegid()); +} + +value_t builtin_user_effective_uid(value_t *args, uint32_t nargs) +{ + (void)args; + argcount("user-effective-uid", nargs, 0); + return fixnum(geteuid()); +} + +value_t builtin_user_real_gid(value_t *args, uint32_t nargs) +{ + (void)args; + argcount("user-real-gid", nargs, 0); + return fixnum(getgid()); +} + +value_t builtin_user_real_uid(value_t *args, uint32_t nargs) +{ + (void)args; + argcount("user-real-uid", nargs, 0); + return fixnum(getuid()); +}