AcessNative - Fixed CLIShell
authorJohn Hodge <[email protected]>
Wed, 3 Oct 2012 14:53:35 +0000 (22:53 +0800)
committerJohn Hodge <[email protected]>
Wed, 3 Oct 2012 14:53:35 +0000 (22:53 +0800)
- NOTE: Bug with log output in worker threads? X crash

AcessNative/acesskernel_src/server.c
AcessNative/acesskernel_src/syscalls.c
AcessNative/ld-acess_src/exports.c
AcessNative/ld-acess_src/request.c

index 2f6b46f..37694bf 100644 (file)
@@ -118,6 +118,7 @@ tClient *Server_GetClient(int ClientID)
                ret->Mutex = SDL_CreateMutex();
                SDL_mutexP( ret->Mutex );
                #endif
+               Log_Debug("Server", "Creating worker for %p", ret);
                ret->WorkerThread = SDL_CreateThread( Server_WorkerThread, ret );
        }
        
@@ -133,7 +134,7 @@ int Server_WorkerThread(void *ClientPtr)
        #if USE_TCP
 
        while( *((volatile typeof(Client->Socket)*)&Client->Socket) == 0 )
-               SDL_Delay(10);
+               ;
        Threads_SetThread( Client->ClientID );
        
        for( ;; )
@@ -194,11 +195,16 @@ int Server_WorkerThread(void *ClientPtr)
                        // Allocate full buffer
                        hdr = malloc(bufsize);
                        memcpy(hdr, lbuf, hdrsize);
-                       len = recv(Client->Socket, hdr->Params + hdr->NParams, bufsize - hdrsize, 0);
-                       Log_Debug("Server", "%i bytes of data", len);
-                       if( len != bufsize - hdrsize ) {
-                               // Oops?
+                       if( bufsize > hdrsize )
+                       {
+                               len = recv(Client->Socket, hdr->Params + hdr->NParams, bufsize - hdrsize, 0);
+                               Log_Debug("Server", "%i bytes of data", len);
+                               if( len != bufsize - hdrsize ) {
+                                       // Oops?
+                               }
                        }
+                       else
+                               Log_Debug("Server", "no data");
 
                         int    retlen;
                        tRequestHeader  *retHeader;
@@ -361,7 +367,7 @@ int Server_ListenThread(void *Unused)
 
                char    addrstr[4*8+8+1];
                inet_ntop(clientaddr.sin_family, &clientaddr.sin_addr, addrstr, sizeof(addrstr));
-               Log_Debug("Server", "Client connection %s:%i\n", addrstr, ntohs(clientaddr.sin_port));
+               Log_Debug("Server", "Client connection %s:%i", addrstr, ntohs(clientaddr.sin_port));
                
                // Perform auth
                size_t  len;
@@ -371,6 +377,7 @@ int Server_ListenThread(void *Unused)
                        // Some form of error?
                        Log_Warning("Server", "Client auth block bad size (%i != exp %i)",
                                len, sizeof(authhdr));
+                       close(clientSock);
                        continue ;
                }
                
@@ -387,10 +394,17 @@ int Server_ListenThread(void *Unused)
                        // Get client structure and make sure it's unused
                        // - Auth token / verifcation?
                        client = Server_GetClient(authhdr.pid);
+                       if( !client ) {
+                               Log_Warning("Server", "Can't allocate a client struct for %s:%i",
+                                       addrstr, clientaddr.sin_port);
+                               close(clientSock);
+                               continue ;
+                       }
                        if( client->Socket != 0 ) {
                                Log_Warning("Server", "Client (%i)%p owned by FD%i but %s:%i tried to use it",
                                        authhdr.pid, client, addrstr, clientaddr.sin_port);
-                               authhdr.pid = 0;
+                               close(clientSock);
+                               continue;
                        }
                        else {
                                client->Socket = clientSock;
index 9b9fda4..b945df8 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Syscall Distribution
  */
-#define DEBUG  0
+#define DEBUG  1
 #include <acess.h>
 #include <threads.h>
 #include <events.h>
index 55606a8..9ee04f1 100644 (file)
@@ -118,8 +118,8 @@ int acess_finfo(int fd, t_sysFInfo *info, int maxacls) {
                );
 }
 
-int acess_readdir(int fd, char *dest) {
-       DEBUG("readdir(%i, %p)", fd, dest);
+int acess_SysReadDir(int fd, char *dest) {
+       DEBUG("SysReadDir(%i, %p)", fd, dest);
        return _Syscall(SYS_READDIR, ">i <d", fd, 256, dest);
 }
 
@@ -186,8 +186,8 @@ int acess_clone(int flags, void *stack)
                if(ret == 0)
                {
                        _CloseSyscalls();
-                       _InitSyscalls();
                        giSyscall_ClientID = newID;
+                       _InitSyscalls();
                        return 0;
                }
                
@@ -320,7 +320,7 @@ const tSym  caBuiltinSymbols[] = {
        DEFSYM(tell),
        DEFSYM(ioctl),
        DEFSYM(finfo),
-       DEFSYM(readdir),
+       DEFSYM(SysReadDir),
        DEFSYM(select),
        DEFSYM(_SysOpenChild),
        DEFSYM(_SysGetACL),
index 670cc3d..12a26d1 100644 (file)
@@ -1,6 +1,6 @@
 /*
  */
-#define DEBUG  1
+#define DEBUG  0
 
 
 #if DEBUG

UCC git Repository :: git.ucc.asn.au