diff options
author | 2011-09-05 22:10:00 +0000 | |
---|---|---|
committer | 2011-09-05 22:10:00 +0000 | |
commit | 44333dfc32156bb41dc6839121a532950be2b993 (patch) | |
tree | 02e4ecc19e6d4b54d775cf6e2d9c7aa2d5ff0de1 | |
parent | allowing to access to rdepends of system packages (diff) | |
download | autodep-44333dfc32156bb41dc6839121a532950be2b993.tar.gz autodep-44333dfc32156bb41dc6839121a532950be2b993.tar.bz2 autodep-44333dfc32156bb41dc6839121a532950be2b993.zip |
fixed a bug when hook library intercepts a call while not initialized
-rw-r--r-- | src/autodep/logfs/logger_hooklib.py | 1 | ||||
-rw-r--r-- | src/autodep/package_utils/portage_misc_functions.py | 12 | ||||
-rw-r--r-- | src/hook_lib/file_hook.c | 84 |
3 files changed, 60 insertions, 37 deletions
diff --git a/src/autodep/logfs/logger_hooklib.py b/src/autodep/logfs/logger_hooklib.py index c6af4e4..80f0cd4 100644 --- a/src/autodep/logfs/logger_hooklib.py +++ b/src/autodep/logfs/logger_hooklib.py @@ -7,6 +7,7 @@ class logger: socketname='' # we can't use just file_hook.so here # because program may change LD_LIBRARY_PATH + #hooklibpath='/home/bay/gsoc/src/hook_lib/file_hook.so' hooklibpath='/usr/lib/file_hook.so' def __init__(self,socketname): diff --git a/src/autodep/package_utils/portage_misc_functions.py b/src/autodep/package_utils/portage_misc_functions.py index fd00be9..29fcfec 100644 --- a/src/autodep/package_utils/portage_misc_functions.py +++ b/src/autodep/package_utils/portage_misc_functions.py @@ -308,6 +308,18 @@ class portage_api: ret.append(pkg) return ret + def get_system_packages_rdeps(self): + """ + returns runtime dependencies of packages from system set + + :returns: **list** of package names + """ + ret=set() + + for pkg in self.get_system_packages_list(): + ret=ret.union(self.get_deps(pkg,["RDEPEND"])) + return list(ret) + def parse_emerge_args(self,args): """ call emerge arguments parser diff --git a/src/hook_lib/file_hook.c b/src/hook_lib/file_hook.c index 09cc2e8..9e9bddc 100644 --- a/src/hook_lib/file_hook.c +++ b/src/hook_lib/file_hook.c @@ -79,6 +79,8 @@ pid_t (*_fork)(); int (*_setenv)(const char *name, const char *value, int overwrite); int (*_close)(int fd); // we hooking this, because some programs closes our socket +int is_initialized=0; // when init not lauched yet we should no do any actions + int log_socket=-1; char ld_preload_orig[MAXPATHLEN]; @@ -87,44 +89,10 @@ char log_socket_name[MAXSOCKETPATHLEN]; char ld_preload_env[MAXENVITEMSIZE]; // value: LD_PRELOAD=ld_preload_orig char log_socket_env[MAXENVITEMSIZE]; // value: LOG_SOCKET=log_socket_name -void __doconnect(){ - if(strlen(log_socket_name)>=MAXSOCKETPATHLEN) { - fprintf(stderr,"Unable to create a unix-socket %s: socket name is too long,exiting\n", log_socket_name); - exit(1); - } - - log_socket=socket(AF_UNIX, SOCK_SEQPACKET, 0); - if(log_socket==-1) { - fprintf(stderr,"Unable to create a unix-socket %s: %s\n", log_socket_name, strerror(errno)); - exit(1); - } - - struct sockaddr_un serveraddr; - memset(&serveraddr, 0, sizeof(serveraddr)); - serveraddr.sun_family = AF_UNIX; - strcpy(serveraddr.sun_path, log_socket_name); - - - int ret=connect(log_socket, (struct sockaddr *)&serveraddr, SUN_LEN(&serveraddr)); - if(ret==-1) { - fprintf(stderr,"Unable to connect a unix-socket %s: %s\n",log_socket_name, strerror(errno)); - fflush(stderr); - //execlp("/bin/bash","/bin/bash",NULL); - exit(1); - } -} +void __init_hooks() { + if(is_initialized) + return; -void __dodisconnect() { - close(log_socket); -} - -void __doreconnect() { - __doconnect(); - __dodisconnect(); -} - -// this fucnction executes when library is loaded -void _init() { char *log_socket_val=getenv("LOG_SOCKET"); if(log_socket_val==NULL) { @@ -207,8 +175,50 @@ void _init() { snprintf(ld_preload_env,MAXENVITEMSIZE,"LD_PRELOAD=%s",ld_preload_orig); snprintf(log_socket_env,MAXENVITEMSIZE,"LOG_SOCKET=%s",log_socket_name); + + is_initialized=1; +} +void __doconnect(){ + if(! is_initialized) + __init_hooks(); + if(strlen(log_socket_name)>=MAXSOCKETPATHLEN) { + fprintf(stderr,"Unable to create a unix-socket %s: socket name is too long,exiting\n", log_socket_name); + exit(1); + } + + log_socket=socket(AF_UNIX, SOCK_SEQPACKET, 0); + if(log_socket==-1) { + fprintf(stderr,"Unable to create a unix-socket %s: %s\n", log_socket_name, strerror(errno)); + exit(1); + } + struct sockaddr_un serveraddr; + memset(&serveraddr, 0, sizeof(serveraddr)); + serveraddr.sun_family = AF_UNIX; + strcpy(serveraddr.sun_path, log_socket_name); + + + int ret=connect(log_socket, (struct sockaddr *)&serveraddr, SUN_LEN(&serveraddr)); + if(ret==-1) { + fprintf(stderr,"Unable to connect a unix-socket %s: %s\n",log_socket_name, strerror(errno)); + fflush(stderr); + exit(1); + } +} + +void __dodisconnect() { + close(log_socket); +} + +void __doreconnect() { + __doconnect(); + __dodisconnect(); +} + +// this fucnction executes when library is loaded +void _init() { + __init_hooks(); __doconnect(); } |