AcessNative/libacess-native.so - Fixed init code slightly
authorJohn Hodge <[email protected]>
Sun, 14 Jul 2013 15:17:32 +0000 (23:17 +0800)
committerJohn Hodge <[email protected]>
Sun, 14 Jul 2013 15:17:32 +0000 (23:17 +0800)
AcessNative/libacess-native.so_src/exports.c
AcessNative/libacess-native.so_src/main.c

index 0ab6361..f22fe46 100644 (file)
@@ -1,4 +1,5 @@
 
+#define acess__SysSpawn        _disabled_acess__SysSpawn
 #include "../ld-acess_src/exports.c"
 
 void   *_crt0_exit_handler;
@@ -8,4 +9,29 @@ int *libc_geterrno(void)
        return &acess__errno;
 }
 
+#undef acess__SysSpawn
+
+int acess__SysSpawn(const char *binary, const char **argv, const char **envp, int nfd, int fds[], struct s_sys_spawninfo *info)
+{
+        int    argc = 0;
+       while( argv[argc++] );
+
+       Debug("_SysSpawn('%s', %p (%i), %p, %i, %p, %p)",
+               binary, argv, argc, envp, nfd, fds, info);
+
+        int    kernel_tid;
+        int    newID;
+       newID = _Syscall(SYS_AN_SPAWN, "<d >d >d", sizeof(int), &kernel_tid,
+               nfd*sizeof(int), fds,
+               info ? sizeof(*info) : 0, info);
+       
+
+       // TODO: Translate internal path to actual path 
+
+       // TODO: set environment variables for libacess-native
+       // > ACESSNATIVE_KEY=`newID`
+       native_spawn(binary, argv, envp);
+
+       return 0;
+}
 
index f072864..900a14c 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 
 extern int     giSyscall_ClientID;
 extern void    Request_Preinit(void);
@@ -19,13 +20,28 @@ int DllMain(void)
 #endif
 
 #ifdef __linux__
-int __attribute__ ((constructor)) libacessnative_init(void);
+int __attribute__ ((constructor(102))) libacessnative_init(int argc, char *argv[], char **envp);
 
-int libacessnative_init(void)
+const char *getenv_p(char **envp, const char *name)
 {
-       Request_Preinit();
+       size_t  namelen = strlen(name);
+       for(; *envp; envp ++)
+       {
+               if( strncmp(*envp, name, namelen) != 0 )
+                       continue ;
+               if( (*envp)[namelen] != '=' )
+                       continue ;
+               return (*envp)+namelen+1;
+       }
+       return 0;
+}
 
-       const char *preopens = getenv("AN_PREOPEN");
+int libacessnative_init(int argc, char *argv[], char **envp)
+{
+       Request_Preinit();
+       
+       const char *preopens = getenv_p(envp, "AN_PREOPEN");
+       printf("preopens = %s\n", preopens);
        if( preopens )
        {
                while( *preopens )

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