diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs index e095345382e85308a22d8e67c9dcb7816e8ed917..daff60cb5760fde81bd0776f39f94af6f3fd73ea 100644 --- a/src/platform/src/linux/mod.rs +++ b/src/platform/src/linux/mod.rs @@ -116,7 +116,7 @@ pub fn getuid() -> uid_t { } pub fn link(path1: *const c_char, path2: *const c_char) -> c_int { - e(unsafe { syscall!(LINKAT, AT_FDCWD, path1, path2) }) as c_int + e(unsafe { syscall!(LINKAT, AT_FDCWD, path1, AT_FDCWD, path2, 0) }) as c_int } pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int { diff --git a/src/unistd/src/lib.rs b/src/unistd/src/lib.rs index 62912097a14b43e7ce11c158bf5ba029340dfbfb..8a1d149f887b8aad5ab05f60d54d8c3607a60f31 100644 --- a/src/unistd/src/lib.rs +++ b/src/unistd/src/lib.rs @@ -225,7 +225,7 @@ pub extern "C" fn getpgid(pid: pid_t) -> pid_t { #[no_mangle] pub extern "C" fn getpgrp() -> pid_t { - unimplemented!(); + platform::getpgid(platform::getpid()) } #[no_mangle] diff --git a/tests/.gitignore b/tests/.gitignore index 7b70bccffc40d658e29d3a82098cafef75130ba3..473a19d76d51f5e52f496acc3bd5c2eb34d404f4 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -23,4 +23,6 @@ /pipe /printf /rmdir +/setid +/unlink /write diff --git a/tests/Makefile b/tests/Makefile index 6c2a838d878c6e7498fa8909e987439c5cb6615e..be24852d81ec6f4eacd4c9948df9fb2f39863788 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -16,9 +16,11 @@ BINS=\ getid \ link \ math \ - rmdir \ pipe \ printf \ + rmdir \ + setid \ + unlink \ write all: $(BINS) @@ -28,7 +30,7 @@ clean: run: $(BINS) for bin in $(BINS); \ - do + do \ echo "# $${bin} #"; \ "./$${bin}" test args; \ done diff --git a/tests/link.c b/tests/link.c index 3e36df81fbfd72fb472c5245aad3db84c05c5c6d..383575e8ce60e3a7d7fd57b71e2cb9b7d41f7c8e 100644 --- a/tests/link.c +++ b/tests/link.c @@ -1,5 +1,6 @@ #include <unistd.h> int main(int argc, char** argv) { - int status = link("link.c", "link.out"); + link("./link.c", "./link.out"); + perror("link"); } diff --git a/tests/setid.c b/tests/setid.c new file mode 100644 index 0000000000000000000000000000000000000000..ce2b42ea93e4ba464faaf9341ea38fd2da171f11 --- /dev/null +++ b/tests/setid.c @@ -0,0 +1,26 @@ +/* + * The process joins process group 0. + */ +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <stdlib.h> + +int main( void ) + { + if( setpgid( getpid(), 0 ) == -1 ) { + perror( "setpgid" ); + } + printf( "%d belongs to process group %d\n", + getpid(), getpgrp() ); + + if( setregid(-1, -1) == -1 ) { + perror( "setregid" ); + } + printf("%d has egid %d and gid %d\n", getpid(), getegid(), getgid()); + + if( setreuid(-1, -1) == -1 ) { + perror( "setreuid" ); + } + printf("%d has euid %d and uid %d\n", getpid(), geteuid(), getuid()); + } diff --git a/tests/unlink.c b/tests/unlink.c new file mode 100644 index 0000000000000000000000000000000000000000..0eceae0ac2891215ab2f531157476b6188952444 --- /dev/null +++ b/tests/unlink.c @@ -0,0 +1,7 @@ +#include <unistd.h> +#include <stdio.h> + +int main(int argc, char** argv) { + link("./unlink.c", "./unlink.out"); + perror("unlink"); +}