kolibrios/contrib/kolibri-libc/source/shell_api/shell_init.c
turbocat c1e6562f35 kolibri-libc:
- Added shell_ping
- Added shell_get_pid
- Fixed malloc in stdlib.h
- Added check during SHELL init (uses shell_ping)
- getc is used like fgetc

git-svn-id: svn://kolibrios.org@8635 a494cfbc-eb01-0410-851d-a64ba20cac60
2021-03-04 09:01:18 +00:00

42 lines
937 B
C

#include <ksys.h>
#include <string.h>
#include <stdlib.h>
#include "shell.h"
#include <shell_api.h>
char __shell_shm_name[32];
char*__shell_shm=NULL;
int __shell_is_init=0;
int __shell_shm_init()
{
__shell_is_init=1;
ksys_proc_table_t *proc_info = (ksys_proc_table_t*)malloc(sizeof(ksys_proc_table_t));
if(proc_info == NULL){
return -1;
}
unsigned PID;
_ksys_process_info(proc_info, -1);
PID = proc_info->pid;
free(proc_info);
itoa(PID, __shell_shm_name);
strcat(__shell_shm_name, "-SHELL");
return _ksys_shm_open(__shell_shm_name, KSYS_SHM_OPEN_ALWAYS | KSYS_SHM_WRITE, SHELL_SHM_MAX, &__shell_shm);
}
void __shell_init()
{
if(!__shell_is_init){
if(__shell_shm_init()){
debug_printf("SHELL problems detected!\n");
_ksys_exit();
}
if(!shell_ping()){
debug_printf("No SHELL found!\n");
_ksys_exit();
}
}
}