]> git.corax.cc Git - corax/commitdiff
Call soclose() from sys_close()
authorMatthias Kruk <m@m10k.eu>
Fri, 4 Oct 2019 06:40:10 +0000 (15:40 +0900)
committerMatthias Kruk <m@m10k.eu>
Fri, 4 Oct 2019 06:40:10 +0000 (15:40 +0900)
kernel/core/cxnet.c

index 4dca679290c3078ad58ce7819541a67e077a5b5a..c369d58f5ee3d670bba267d5df837be4d96671ec 100644 (file)
@@ -9,6 +9,7 @@
 #include <poll.h>
 #include <debug.h>
 #include "socket.h"
+#include <process.h>
 
 int sys_socket(int domain, int type, int protocol)
 {
@@ -25,9 +26,34 @@ int sys_socket(int domain, int type, int protocol)
        return(ret_val);
 }
 
-int sys_close(int sockfd)
+int sys_close(int procfd)
 {
-       return(-ENOSYS);
+       process_t *cproc;
+       int ret_val;
+
+       /*
+        * The fd that was passed is a per-process "procfd", but soclose() needs
+        * the global "sockfd" - so we have to look it up first.
+        */
+
+       cproc = process_get_current();
+       ret_val = -EFAULT;
+
+       if(cproc) {
+               ret_val = process_flookup(cproc, procfd);
+
+               /*
+                * If ret_val is not negative, it holds the sockfd to be
+                * closed. Otherwise it holds an error number that we're
+                * going to return to the caller.
+                */
+               if(ret_val >= 0) {
+                       dbg_printf("soclose(0x%08x)\n", ret_val);
+                       ret_val = soclose(ret_val);
+               }
+       }
+
+       return(ret_val);
 }
 
 int sys_sendto(int sockfd, const void *buf, size_t len, int flags,