Skip to content

Commit

Permalink
[#41] process: Implementation of getppid syscall (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalfita authored Nov 3, 2021
1 parent 1b25502 commit b1fc34a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Documentation/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Not supported.
| 107 | geteuid | Partially | `v0.0.1` | |
| 108 | getegid | Unimplemented | | |
| 109 | setpgid | Partially | `v0.0.1` | |
| 110 | getppid | Unimplemented | | |
| 110 | getppid | Partially | `v0.0.3` | PR# ? |
| 111 | getpgrp | Unimplemented | | |
| 112 | setsid | Unimplemented | | |
| 113 | setreuid | Unimplemented | | |
Expand Down
18 changes: 18 additions & 0 deletions kernel/process/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,24 @@ impl Process {
self.pid
}

/// The process parent.
fn parent(&self) -> Option<Arc<SpinLock<Process>>> {
if let Some(parent) = &self.parent.upgrade() {
Some(parent.clone())
} else {
None
}
}

/// The ID of process being parent of this process.
pub fn ppid(&self) -> PId {
if let Some(parent) = self.parent() {
parent.lock().pid()
} else {
PId::new(0)
}
}

/// The argv. Could be truncated if it's too long.
pub fn cmdline(&self) -> &str {
&self.cmdline
Expand Down
13 changes: 13 additions & 0 deletions kernel/syscalls/getppid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::{
prelude::*,
process::process_group::PgId,
process::{current_process, process_group::ProcessGroup, PId, Process},
result::Result,
syscalls::SyscallHandler,
};

impl<'a> SyscallHandler<'a> {
pub fn sys_getppid(&mut self) -> Result<isize> {
Ok(current_process().ppid().as_i32() as isize)
}
}
3 changes: 3 additions & 0 deletions kernel/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub(self) mod getdents64;
pub(self) mod getpeername;
pub(self) mod getpgid;
pub(self) mod getpid;
pub(self) mod getppid;
pub(self) mod getrandom;
pub(self) mod getsockname;
pub(self) mod getsockopt;
Expand Down Expand Up @@ -146,6 +147,7 @@ const SYS_SETUID: usize = 105;
const SYS_SETGID: usize = 106;
const SYS_GETEUID: usize = 107;
const SYS_SETPGID: usize = 109;
const SYS_GETPPID: usize = 110;
const SYS_GETPGID: usize = 121;
const SYS_SETGROUPS: usize = 116;
const SYS_ARCH_PRCTL: usize = 158;
Expand Down Expand Up @@ -289,6 +291,7 @@ impl<'a> SyscallHandler<'a> {
SYS_SETGID => Ok(0), // TODO:
SYS_SETGROUPS => Ok(0), // TODO:
SYS_SETPGID => self.sys_setpgid(PId::new(a1 as i32), PgId::new(a2 as i32)),
SYS_GETPPID => self.sys_getppid(),
SYS_SET_TID_ADDRESS => self.sys_set_tid_address(UserVAddr::new_nonnull(a1)?),
SYS_PIPE => self.sys_pipe(UserVAddr::new_nonnull(a1)?),
SYS_RT_SIGACTION => self.sys_rt_sigaction(a1 as c_int, a2, UserVAddr::new(a3)?),
Expand Down

0 comments on commit b1fc34a

Please sign in to comment.