Improve ctrl+ management.

This commit is contained in:
Enrico Fraccaroli (Galfurian)
2022-01-25 15:01:53 -05:00
parent f9334b25ed
commit 41990c570f
5 changed files with 86 additions and 66 deletions
+8 -6
View File
@@ -20,7 +20,7 @@ void syscall_handler(pt_regs *f);
/// @brief Returns the current interrupt stack frame.
/// @return Pointer to the stack frame.
pt_regs* get_current_interrupt_stack_frame();
pt_regs *get_current_interrupt_stack_frame();
/// The exit() function causes normal process termination.
/// @param exit_code The exit code.
@@ -88,11 +88,13 @@ int sys_execve(pt_regs *f);
/// @brief Changes the working directory.
/// @param path The new working directory.
void sys_chdir(char const *path);
/// @return On success 0. On error -1, and errno indicates the error.
int sys_chdir(char const *path);
/// @brief Changes the working directory.
/// @param fd File descriptor of the new working directory.
void sys_fchdir(int fd);
/// @return On success 0. On error -1, and errno indicates the error.
int sys_fchdir(int fd);
/// @brief Returns the process ID (PID) of the calling process.
/// @return The process ID.
@@ -103,7 +105,7 @@ pid_t sys_getpid();
/// If pid != 0 return the SID corresponding to the process having identifier == pid
///@param pid process identifier from wich we want the SID
///@return On success return SID of the session
/// Otherwise return -1 with errno set on: EPERM or ESRCH
/// Otherwise return -1 with errno set on: EPERM or ESRCH
pid_t sys_getsid(pid_t pid);
///@brief creates a new session if the calling process is not a
@@ -113,7 +115,7 @@ pid_t sys_getsid(pid_t pid);
/// of a new process group in the session (i.e., its process group ID
/// is made the same as its process ID).
///@return On success return SID of the session just created
/// Otherwise return -1 with errno : EPERM
/// Otherwise return -1 with errno : EPERM
pid_t sys_setsid();
///@brief returns the Process Group ID (PGID) of the process specified by pid.
@@ -134,7 +136,7 @@ int sys_setpgid(pid_t pid, pid_t pgid);
pid_t sys_getgid();
///@brief sets the effective group ID of the calling process.
///@param pid process identifier to
///@param pid process identifier to
///@return On success, zero is returned.
/// Otherwise returns -1 with errno set to :EINVAL or EPERM.
int sys_setgid(pid_t pid);
+8 -4
View File
@@ -113,6 +113,12 @@ int kmain(boot_info_t *boot_informations)
initial_esp = boot_info.stack_base;
// Dump the multiboot structure.
dump_multiboot(boot_info.multiboot_header);
//==========================================================================
// First, disable the keyboard, otherwise the PS/2 initialization does not
// work properly.
keyboard_disable();
//==========================================================================
pr_notice("Initialize the video...\n");
vga_initialize();
@@ -298,9 +304,8 @@ int kmain(boot_info_t *boot_informations)
return 1;
}
print_ok();
//==========================================================================
#if 1
pr_notice("Setting up PS/2 driver...\n");
printf("Setting up PS/2 driver...");
if (ps2_initialize()) {
@@ -309,8 +314,7 @@ int kmain(boot_info_t *boot_informations)
return 1;
}
print_ok();
#endif
//==========================================================================
pr_notice("Setting up keyboard driver...\n");
printf("Setting up keyboard driver...");
+37 -32
View File
@@ -228,7 +228,7 @@ static inline task_struct *__alloc_task(task_struct *source, task_struct *parent
// Initalize real_timer for intervals
proc->real_timer = NULL;
// Set the default terminal options.
proc->termios = (termios_t){
.c_cflag = 0,
@@ -338,47 +338,52 @@ task_struct *process_create_init(const char *path)
char *sys_getcwd(char *buf, size_t size)
{
task_struct *current_process = scheduler_get_current_process();
if ((current_process != NULL) && (buf != NULL)) {
strncpy(buf, current_process->cwd, size);
task_struct *current = scheduler_get_current_process();
if ((current != NULL) && (buf != NULL)) {
strncpy(buf, current->cwd, size);
return buf;
}
return (char *)-EACCES;
}
void sys_chdir(char const *path)
int sys_chdir(char const *path)
{
task_struct *current_process = scheduler_get_current_process();
if ((current_process != NULL) && (path != NULL)) {
char absolute_path[PATH_MAX];
realpath(path, absolute_path);
// Check that the directory exists.
vfs_file_t *dir = vfs_open(absolute_path, O_RDONLY | O_DIRECTORY, S_IXUSR);
if (dir != NULL) {
pr_debug("Success `%s` -> `%s` -> `%s`\n", path, absolute_path, dir->name);
strcpy(current_process->cwd, absolute_path);
vfs_close(dir);
} else {
pr_debug("Failed `%s` -> `%s` -> `NULL`\n", path, absolute_path);
}
task_struct *current = scheduler_get_current_process();
assert(current && "There is no running process.");
if (!path)
return -EFAULT;
char absolute_path[PATH_MAX];
realpath(path, absolute_path);
// Check that the directory exists.
vfs_file_t *dir = vfs_open(absolute_path, O_RDONLY | O_DIRECTORY, S_IXUSR);
if (dir) {
strcpy(current->cwd, absolute_path);
vfs_close(dir);
return 0;
}
// Return the errno value set by either VFS or the filesystem underneath.
return -errno;
}
void sys_fchdir(int fd)
int sys_fchdir(int fd)
{
// Get the current task.
task_struct *task = scheduler_get_current_process();
// Check the current FD.
if (fd >= 0 && fd < task->max_fd) {
// Get the file descriptor.
vfs_file_descriptor_t *vfd = &task->fd_list[fd];
// Check the file.
if (vfd->file_struct != NULL) {
char absolute_path[PATH_MAX];
realpath(vfd->file_struct->name, absolute_path);
strcpy(task->cwd, absolute_path);
}
}
task_struct *current = scheduler_get_current_process();
assert(current && "There is no running process.");
// Check if it is a valid file descriptor.
if ((fd < 0) || (fd >= current->max_fd))
return -EBADF;
// Get the file descriptor.
vfs_file_descriptor_t *vfd = &current->fd_list[fd];
// Check if the file descriptor file is set.
if (vfd->file_struct == NULL)
return -ENOENT;
// Check that the path points to a directory.
if (!bitmask_check(vfd->file_struct->flags, DT_DIR))
return -ENOTDIR;
char absolute_path[PATH_MAX];
realpath(vfd->file_struct->name, absolute_path);
strcpy(current->cwd, absolute_path);
return 0;
}
pid_t sys_fork(pt_regs *f)