Bladeren bron

fixes and tests

Paul Sajna 7 jaren geleden
bovenliggende
commit
161d93466c
7 gewijzigde bestanden met toevoegingen van 43 en 5 verwijderingen
  1. 1 1
      src/platform/src/linux/mod.rs
  2. 1 1
      src/unistd/src/lib.rs
  3. 2 0
      tests/.gitignore
  4. 4 2
      tests/Makefile
  5. 2 1
      tests/link.c
  6. 26 0
      tests/setid.c
  7. 7 0
      tests/unlink.c

+ 1 - 1
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 {

+ 1 - 1
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]

+ 2 - 0
tests/.gitignore

@@ -23,4 +23,6 @@
 /pipe
 /printf
 /rmdir
+/setid
+/unlink
 /write

+ 4 - 2
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

+ 2 - 1
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");
 }

+ 26 - 0
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());
+  }

+ 7 - 0
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");
+}