Kernel/LibC: remove PATH resoltion from kernel

I have no idea why I had made PATH environment variable parsing
to be part of the kernel. Now the shell does the parsing and
environment syscall is no longer needed.
This commit is contained in:
Bananymous
2023-09-23 02:43:02 +03:00
parent 7a7c5e433e
commit 3ba15b41a3
8 changed files with 73 additions and 71 deletions

View File

@@ -21,7 +21,6 @@ __BEGIN_DECLS
#define SYS_SLEEP 17
#define SYS_WAIT 18
#define SYS_FSTAT 19
#define SYS_SETENVP 20
#define SYS_READ_DIR_ENTRIES 21
#define SYS_SET_UID 22
#define SYS_SET_GID 23

View File

@@ -124,6 +124,16 @@ int putenv(char* string)
return -1;
}
if (!environ)
{
environ = (char**)malloc(sizeof(char*) * 2);
if (!environ)
return -1;
environ[0] = string;
environ[1] = nullptr;
return 0;
}
int cnt = 0;
for (int i = 0; string[i]; i++)
if (string[i] == '=')
@@ -151,10 +161,7 @@ int putenv(char* string)
char** new_envp = (char**)malloc(sizeof(char*) * (env_count + 2));
if (new_envp == nullptr)
{
errno = ENOMEM;
return -1;
}
for (int i = 0; i < env_count; i++)
new_envp[i] = environ[i];
@@ -164,8 +171,6 @@ int putenv(char* string)
free(environ);
environ = new_envp;
if (syscall(SYS_SETENVP, environ) == -1)
return -1;
return 0;
}

View File

@@ -14,8 +14,23 @@ char** environ;
extern void init_malloc();
extern "C" void _init_libc(char** _environ)
{
environ = _environ;
init_malloc();
if (!_environ)
return;
size_t env_count = 0;
while (_environ[env_count])
env_count++;
environ = (char**)malloc(sizeof(char*) * env_count + 1);
for (size_t i = 0; i < env_count; i++)
{
size_t bytes = strlen(_environ[i]) + 1;
environ[i] = (char*)malloc(bytes);
memcpy(environ[i], _environ[i], bytes);
}
environ[env_count] = nullptr;
}
void _exit(int status)