* [gentoo-commits] proj/autodep:master commit in: src/hook_lib/
@ 2011-08-02 20:19 Александр Берсенев
0 siblings, 0 replies; 7+ messages in thread
From: Александр Берсенев @ 2011-08-02 20:19 UTC (permalink / raw
To: gentoo-commits
commit: bd663fa24ca37b2ea697e782f6548e6133f8365f
Author: Alexander Bersenev <bay <AT> hackerdom <DOT> ru>
AuthorDate: Wed Aug 3 02:18:25 2011 +0000
Commit: Александр Берсенев <bay <AT> hackerdom <DOT> ru>
CommitDate: Wed Aug 3 02:18:25 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/autodep.git;a=commit;h=bd663fa2
hooklib: hide blocked files in directories
---
src/hook_lib/file_hook.c | 158 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 156 insertions(+), 2 deletions(-)
diff --git a/src/hook_lib/file_hook.c b/src/hook_lib/file_hook.c
index 555d6dc..9f114ae 100644
--- a/src/hook_lib/file_hook.c
+++ b/src/hook_lib/file_hook.c
@@ -11,6 +11,8 @@
#include <dlfcn.h>
#include <pthread.h>
+#include <dirent.h>
+
#define _FCNTL_H
#include <bits/fcntl.h>
@@ -19,7 +21,7 @@
#include <sys/socket.h>
#include <sys/un.h>
-#define MAXPATHLEN 1024
+#define MAXPATHLEN PATH_MAX
#define MAXSOCKETPATHLEN 108
#define MAXFILEBUFFLEN 2048
@@ -44,6 +46,13 @@ size_t (*_fwrite)(const void *ptr, size_t size, size_t nmemb, FILE *stream);
void *(*_mmap)(void *addr, size_t length, int prot, int flags,
int fd, off_t offset);
+struct dirent * (*_readdir)(DIR *dirp);
+struct dirent64 * (*_readdir64)(DIR *dirp);
+int (*_readdir_r)(DIR *dirp, struct dirent *entry,
+ struct dirent **result);
+int (*_readdir64_r)(DIR *dirp, struct dirent64 *entry,
+ struct dirent64 **result);
+
int (*_execve)(const char *filename, char *const argv[],char *const envp[]);
int (*_execv)(const char *path, char *const argv[]);
@@ -139,6 +148,12 @@ void _init() {
_mmap=(void* (*)(void *addr, size_t length, int prot, int flags,
int fd, off_t offset)) dlsym(RTLD_NEXT, "mmap");
+ _readdir=(struct dirent * (*)(DIR *dirp)) dlsym(RTLD_NEXT, "readdir");
+ _readdir64=(struct dirent64 * (*)(DIR *dirp)) dlsym(RTLD_NEXT, "readdir64");
+ _readdir_r=(int (*)(DIR *dirp, struct dirent *entry,
+ struct dirent **result)) dlsym(RTLD_NEXT, "readdir_r");
+ _readdir64_r=(int (*)(DIR *dirp, struct dirent64 *entry,
+ struct dirent64 **result)) dlsym(RTLD_NEXT, "readdir64_r");
_fork = (pid_t (*)()) dlsym(RTLD_NEXT, "fork");
@@ -159,7 +174,9 @@ void _init() {
if(_open==NULL || _open64==NULL ||
_fopen==NULL || _fopen64==NULL ||
- _read==NULL || _write==NULL || _mmap==NULL ||
+ _read==NULL || _write==NULL || _mmap==NULL ||
+ _readdir==NULL || _readdir64 == NULL || _readdir_r==NULL ||
+ _readdir64_r==NULL ||
_fork==NULL ||
_execve==NULL || _execv==NULL || _execvp==NULL || _execvpe==NULL ||
_fexecve==NULL || _system==NULL || _setenv==NULL || _close==NULL) {
@@ -727,6 +744,143 @@ void *mmap(void *addr, size_t length, int prot, int flags,
return ret;
}
+// directory reading hooks
+// the strategy for all functions is basic: skip the file if it is blocked
+// all function are in two very similar variants: 32bit and 64bit
+struct dirent *readdir(DIR *dirp) {
+ char *stage=__get_stage();
+ struct dirent *ep;
+
+ char dirpath[MAXPATHLEN];
+
+ int fd;
+ fd=dirfd(dirp);
+
+ // get dirname in dirpath
+ if (__get_path_by_fd(fd,dirpath,MAXPATHLEN)==-1)
+ return _readdir(dirp);
+
+ while((ep=_readdir(dirp))!=NULL) { // Hope that readdir is not looping
+ char fullpath[MAXPATHLEN];
+ snprintf(fullpath,MAXPATHLEN,"%s/%s",dirpath,ep->d_name);
+
+ char abspath[MAXPATHLEN];
+ realpath(fullpath,abspath);
+
+ if(! __is_event_allowed("open",abspath,stage)) {
+ __log_event("open",abspath,"DENIED",errno,stage);
+
+ continue;
+ } else
+ break;
+ }
+ return ep;
+}
+
+struct dirent64 *readdir64(DIR *dirp) {
+ char *stage=__get_stage();
+ struct dirent64 *ep;
+
+ char dirpath[MAXPATHLEN];
+
+ int fd;
+ fd=dirfd(dirp);
+
+ // get dirname in dirpath
+ if (__get_path_by_fd(fd,dirpath,MAXPATHLEN)==-1)
+ return _readdir64(dirp);
+
+ while((ep=_readdir64(dirp))!=NULL) { // Hope that readdir is not looping
+ char fullpath[MAXPATHLEN];
+ snprintf(fullpath,MAXPATHLEN,"%s/%s",dirpath,ep->d_name);
+
+ char abspath[MAXPATHLEN];
+ realpath(fullpath,abspath);
+
+ if(! __is_event_allowed("open",abspath,stage)) {
+ __log_event("open",abspath,"DENIED",errno,stage);
+
+ continue;
+ } else
+ break;
+ }
+ return ep;
+}
+
+
+// next two functions are almost equal
+int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result){
+ char *stage=__get_stage();
+ char dirpath[MAXPATHLEN];
+
+ int fd;
+ fd=dirfd(dirp);
+
+ // get dirname in dirpath
+ if (__get_path_by_fd(fd,dirpath,MAXPATHLEN)==-1)
+ return _readdir_r(dirp, entry, result);
+
+ int ret;
+
+ while((ret=_readdir_r(dirp, entry, result))==0) {
+ if(*result==NULL) {
+ break; // end of directory
+ }
+
+ char fullpath[MAXPATHLEN];
+ snprintf(fullpath,MAXPATHLEN,"%s/%s",dirpath,entry->d_name);
+
+ char abspath[MAXPATHLEN];
+ realpath(fullpath,abspath);
+
+ if(! __is_event_allowed("open",abspath,stage)) {
+ __log_event("open",abspath,"DENIED",errno,stage);
+
+ continue;
+ } else
+ break;
+ }
+
+ return ret;
+}
+
+
+int readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result){
+ char *stage=__get_stage();
+ char dirpath[MAXPATHLEN];
+
+ int fd;
+ fd=dirfd(dirp);
+
+ // get dirname in dirpath
+ if (__get_path_by_fd(fd,dirpath,MAXPATHLEN)==-1)
+ return _readdir64_r(dirp, entry, result);
+
+ int ret;
+
+ while((ret=_readdir64_r(dirp, entry, result))==0) {
+ if(*result==NULL) {
+ break; // end of directory
+ }
+
+ char fullpath[MAXPATHLEN];
+ snprintf(fullpath,MAXPATHLEN,"%s/%s",dirpath,entry->d_name);
+
+ char abspath[MAXPATHLEN];
+ realpath(fullpath,abspath);
+
+ if(! __is_event_allowed("open",abspath,stage)) {
+ __log_event("open",abspath,"DENIED",errno,stage);
+
+ continue;
+ } else
+ break;
+ }
+
+ return ret;
+}
+
+
int setenv(const char *name, const char *value, int overwrite) {
//printf (" CHANGING name: %s, value: %s",name,value);
if(strcmp(name,"LD_PRELOAD")==0 ||
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [gentoo-commits] proj/autodep:master commit in: src/hook_lib/
@ 2011-08-16 7:31 Александр Берсенев
0 siblings, 0 replies; 7+ messages in thread
From: Александр Берсенев @ 2011-08-16 7:31 UTC (permalink / raw
To: gentoo-commits
commit: 8f1c0713e3483d55c5ccd8c04f96355b1ed561eb
Author: Alexander Bersenev <bay <AT> hackerdom <DOT> ru>
AuthorDate: Tue Aug 16 13:30:19 2011 +0000
Commit: Александр Берсенев <bay <AT> hackerdom <DOT> ru>
CommitDate: Tue Aug 16 13:30:19 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/autodep.git;a=commit;h=8f1c0713
access calls catching and disable show blocking events on readdir
---
src/hook_lib/file_hook.c | 87 +++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 82 insertions(+), 5 deletions(-)
diff --git a/src/hook_lib/file_hook.c b/src/hook_lib/file_hook.c
index 9f114ae..36e1328 100644
--- a/src/hook_lib/file_hook.c
+++ b/src/hook_lib/file_hook.c
@@ -54,6 +54,14 @@ int (*_readdir64_r)(DIR *dirp, struct dirent64 *entry,
struct dirent64 **result);
+int (*_access)(const char *pathname, int mode);
+int (*_euidaccess)(const char *pathname, int mode);
+
+// these stat functions are only source level standart of glibc
+// we no catch fxstat
+int (*___xstat)(int vers, const char *name, struct stat *buf);
+int (*___lxstat)(int vers, const char *name, struct stat *buf);
+
int (*_execve)(const char *filename, char *const argv[],char *const envp[]);
int (*_execv)(const char *path, char *const argv[]);
int (*_execvp)(const char *file, char *const argv[]);
@@ -155,7 +163,12 @@ void _init() {
_readdir64_r=(int (*)(DIR *dirp, struct dirent64 *entry,
struct dirent64 **result)) dlsym(RTLD_NEXT, "readdir64_r");
-
+ _access=(int (*)(const char *pathname, int mode)) dlsym(RTLD_NEXT, "access");
+ _euidaccess=(int (*)(const char *pathname, int mode)) dlsym(RTLD_NEXT, "euidaccess");
+
+ ___xstat=(int (*)(int vers, const char *name, struct stat *buf)) dlsym(RTLD_NEXT, "__xstat");
+ ___lxstat=(int (*)(int vers, const char *name, struct stat *buf)) dlsym(RTLD_NEXT, "__lxstat");
+
_fork = (pid_t (*)()) dlsym(RTLD_NEXT, "fork");
_execve = (int (*)(const char *filename, char *const argv[],char *const envp[])) dlsym(RTLD_NEXT, "execve");
@@ -177,6 +190,7 @@ void _init() {
_read==NULL || _write==NULL || _mmap==NULL ||
_readdir==NULL || _readdir64 == NULL || _readdir_r==NULL ||
_readdir64_r==NULL ||
+ _access==NULL || _euidaccess==NULL ||
_fork==NULL ||
_execve==NULL || _execv==NULL || _execvp==NULL || _execvpe==NULL ||
_fexecve==NULL || _system==NULL || _setenv==NULL || _close==NULL) {
@@ -768,7 +782,7 @@ struct dirent *readdir(DIR *dirp) {
realpath(fullpath,abspath);
if(! __is_event_allowed("open",abspath,stage)) {
- __log_event("open",abspath,"DENIED",errno,stage);
+ //__log_event("open",abspath,"DENIED",errno,stage);
continue;
} else
@@ -798,7 +812,7 @@ struct dirent64 *readdir64(DIR *dirp) {
realpath(fullpath,abspath);
if(! __is_event_allowed("open",abspath,stage)) {
- __log_event("open",abspath,"DENIED",errno,stage);
+ //__log_event("open",abspath,"DENIED",errno,stage);
continue;
} else
@@ -834,7 +848,7 @@ int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result){
realpath(fullpath,abspath);
if(! __is_event_allowed("open",abspath,stage)) {
- __log_event("open",abspath,"DENIED",errno,stage);
+ //__log_event("open",abspath,"DENIED",errno,stage);
continue;
} else
@@ -870,7 +884,7 @@ int readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result){
realpath(fullpath,abspath);
if(! __is_event_allowed("open",abspath,stage)) {
- __log_event("open",abspath,"DENIED",errno,stage);
+ //__log_event("open",abspath,"DENIED",errno,stage);
continue;
} else
@@ -881,6 +895,69 @@ int readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result){
}
+int __xstat (int vers, const char *name, struct stat *buf) {
+ char *stage=__get_stage();
+
+ char fullpath[MAXPATHLEN];
+ realpath(name,fullpath);
+
+ if(! __is_event_allowed("open",fullpath,stage))
+ return -1;
+
+ if(___xstat==NULL)
+ return -1;
+
+ return ___xstat(vers,name,buf);
+}
+
+int __lxstat (int vers, const char *name, struct stat *buf) {
+ char *stage=__get_stage();
+
+ char fullpath[MAXPATHLEN];
+ realpath(name,fullpath);
+
+
+ if(! __is_event_allowed("open",fullpath,stage)) {
+ errno = 2;
+ return -1;
+ }
+
+ if(___lxstat==NULL)
+ return -1;
+
+ return ___lxstat(vers,name,buf);
+}
+
+int access(const char *pathname, int mode) {
+ char *stage=__get_stage();
+
+ char fullpath[MAXPATHLEN];
+ realpath(pathname,fullpath);
+
+ if(! __is_event_allowed("open",fullpath,stage)) {
+ errno = 2;
+ return -1;
+ }
+
+ return _access(pathname,mode);
+}
+
+int euidaccess(const char *pathname, int mode) {
+ char *stage=__get_stage();
+
+ char fullpath[MAXPATHLEN];
+ realpath(pathname,fullpath);
+
+ if(! __is_event_allowed("open",fullpath,stage)) {
+ errno = 2;
+ return -1;
+ }
+
+ return _euidaccess(pathname,mode);
+}
+
+
+
int setenv(const char *name, const char *value, int overwrite) {
//printf (" CHANGING name: %s, value: %s",name,value);
if(strcmp(name,"LD_PRELOAD")==0 ||
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [gentoo-commits] proj/autodep:master commit in: src/hook_lib/
@ 2011-08-21 18:50 Александр Берсенев
0 siblings, 0 replies; 7+ messages in thread
From: Александр Берсенев @ 2011-08-21 18:50 UTC (permalink / raw
To: gentoo-commits
commit: 0382d3268438a2a587d08efe09c7a534b2b3cf42
Author: Alexander Bersenev <bay <AT> hackerdom <DOT> ru>
AuthorDate: Sun Aug 21 21:06:10 2011 +0000
Commit: Александр Берсенев <bay <AT> hackerdom <DOT> ru>
CommitDate: Sun Aug 21 21:06:10 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/autodep.git;a=commit;h=0382d326
changed include path
---
src/hook_lib/file_hook.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/hook_lib/file_hook.c b/src/hook_lib/file_hook.c
index 7318149..09cc2e8 100644
--- a/src/hook_lib/file_hook.c
+++ b/src/hook_lib/file_hook.c
@@ -16,7 +16,7 @@
#define _FCNTL_H
#include <bits/fcntl.h>
-#include <bits/stat.h>
+#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/un.h>
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [gentoo-commits] proj/autodep:master commit in: src/hook_lib/
@ 2011-09-30 7:21 Александр Берсенев
0 siblings, 0 replies; 7+ messages in thread
From: Александр Берсенев @ 2011-09-30 7:21 UTC (permalink / raw
To: gentoo-commits
commit: b6e44ffc06122453c92801d39d08f3c6ebc3ba14
Author: Alexander Bersenev <bay <AT> hackerdom <DOT> ru>
AuthorDate: Sat Sep 24 01:51:28 2011 +0000
Commit: Александр Берсенев <bay <AT> hackerdom <DOT> ru>
CommitDate: Sat Sep 24 01:51:28 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/autodep.git;a=commit;h=b6e44ffc
fixes bug with pmake. Use libc\'s snprintf
---
src/hook_lib/Makefile | 2 +-
src/hook_lib/file_hook.c | 15 +++++++++++++--
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/src/hook_lib/Makefile b/src/hook_lib/Makefile
index 365ceee..2457fb2 100644
--- a/src/hook_lib/Makefile
+++ b/src/hook_lib/Makefile
@@ -2,7 +2,7 @@ file_hook.so: file_hook.o
ld -shared -o file_hook.so -ldl -lc file_hook.o
file_hook.o: file_hook.c
- cc -Wall -fPIC -o file_hook.o -c file_hook.c
+ cc -Wall -O0 -fPIC -o file_hook.o -c file_hook.c
all: file_hook.so
diff --git a/src/hook_lib/file_hook.c b/src/hook_lib/file_hook.c
index 9e9bddc..5630581 100644
--- a/src/hook_lib/file_hook.c
+++ b/src/hook_lib/file_hook.c
@@ -79,6 +79,12 @@ 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
+// we not hook this functions but we should be sure that these functions
+// are from glibc
+
+int (*_snprintf)(char *str, size_t size, const char *format, ...);
+
+
int is_initialized=0; // when init not lauched yet we should no do any actions
int log_socket=-1;
@@ -159,6 +165,7 @@ void __init_hooks() {
_setenv=(int (*)(const char *name, const char *value, int overwrite)) dlsym(RTLD_NEXT, "setenv");
_close= (int (*)(int fd)) dlsym(RTLD_NEXT, "close");
+ _snprintf=(int (*)(char *str, size_t size, const char *format, ...)) dlsym(RTLD_NEXT, "snprintf");
if(_open==NULL || _open64==NULL ||
_fopen==NULL || _fopen64==NULL ||
@@ -233,16 +240,20 @@ static int __raw_log_event(const char *event_type, const char *filename, char *r
char msg_buff[MAXSOCKETMSGLEN];
int bytes_to_send;
if(strcmp(result,"ERR")==0) {
- bytes_to_send=snprintf(msg_buff,MAXSOCKETMSGLEN,"%lld%c%s%c%s%c%s%c%s/%d",
+ bytes_to_send=_snprintf(msg_buff,MAXSOCKETMSGLEN,"%lld%c%s%c%s%c%s%c%s/%d",
(unsigned long long)time(NULL),0,event_type,0,filename,0,stage,0,result,err);
} else {
- bytes_to_send=snprintf(msg_buff,MAXSOCKETMSGLEN,"%lld%c%s%c%s%c%s%c%s",
+ bytes_to_send=_snprintf(msg_buff,MAXSOCKETMSGLEN,"%lld%c%s%c%s%c%s%c%s",
(unsigned long long)time(NULL),0,event_type,0,filename,0,stage,0,result);
}
if(bytes_to_send>=MAXSOCKETMSGLEN)
return 0;
+ // we need to recount bytes_to_send here because some programs
+ // use hackish snprintf which returns strlen(buf)
+
+
if(send(log_socket,msg_buff,bytes_to_send,0)==-1) {
__doreconnect(); // looks like our socket has been destroyed by logged program
// try to recreate it
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [gentoo-commits] proj/autodep:master commit in: src/hook_lib/
@ 2011-10-21 4:45 Александр Берсенев
0 siblings, 0 replies; 7+ messages in thread
From: Александр Берсенев @ 2011-10-21 4:45 UTC (permalink / raw
To: gentoo-commits
commit: ef3f7139ec86030a64ce4fed4976c0424fbc0637
Author: Alexander Bersenev <bay <AT> hackerdom <DOT> ru>
AuthorDate: Fri Oct 21 10:45:14 2011 +0000
Commit: Александр Берсенев <bay <AT> hackerdom <DOT> ru>
CommitDate: Fri Oct 21 10:45:14 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/autodep.git;a=commit;h=ef3f7139
fixed a bug when some application using hooked functions before hook library is initialized
---
src/hook_lib/file_hook.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/src/hook_lib/file_hook.c b/src/hook_lib/file_hook.c
index 5630581..728ab4e 100644
--- a/src/hook_lib/file_hook.c
+++ b/src/hook_lib/file_hook.c
@@ -237,6 +237,9 @@ void _fini() {
* Format of log string: time event filename stage result/err
*/
static int __raw_log_event(const char *event_type, const char *filename, char *result,int err, char* stage) {
+ if(! is_initialized) // it is essential to initialize hooks because we are
+ __init_hooks(); // using _snprintf here
+
char msg_buff[MAXSOCKETMSGLEN];
int bytes_to_send;
if(strcmp(result,"ERR")==0) {
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [gentoo-commits] proj/autodep:master commit in: src/hook_lib/
@ 2012-01-31 12:30 Александр Берсенев
0 siblings, 0 replies; 7+ messages in thread
From: Александр Берсенев @ 2012-01-31 12:30 UTC (permalink / raw
To: gentoo-commits
commit: f02db3217ea416cabafe2d65e4d03ed372c3bf0c
Author: Alexander Bersenev <bay <AT> hackerdom <DOT> ru>
AuthorDate: Tue Jan 31 12:30:20 2012 +0000
Commit: Александр Берсенев <bay <AT> hackerdom <DOT> ru>
CommitDate: Tue Jan 31 12:30:20 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/autodep.git;a=commit;h=f02db321
fixed crashes in ruby's rb_thread_blocking_region(). Shrink buffer for proc entrys
---
src/hook_lib/file_hook.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/hook_lib/file_hook.c b/src/hook_lib/file_hook.c
index 728ab4e..cd3850a 100644
--- a/src/hook_lib/file_hook.c
+++ b/src/hook_lib/file_hook.c
@@ -22,6 +22,7 @@
#include <sys/un.h>
#define MAXPATHLEN PATH_MAX
+#define MAXPROCPATHLEN 512
#define MAXSOCKETPATHLEN 108
#define MAXFILEBUFFLEN 2048
@@ -292,9 +293,9 @@ static char * __get_stage(){
* Get full path by fd
*/
ssize_t __get_path_by_fd(int fd, char *output, int output_len) {
- char path_to_fd_link[MAXPATHLEN];
+ char path_to_fd_link[MAXPROCPATHLEN];
- snprintf(path_to_fd_link,MAXPATHLEN,"/proc/self/fd/%d",fd);
+ snprintf(path_to_fd_link,MAXPROCPATHLEN,"/proc/self/fd/%d",fd);
ssize_t bytes_num=readlink(path_to_fd_link,output,output_len-1);
output[bytes_num]=0; // because readlink don't do this
if(output[0]!='/') return -1; // some odd string like pipe:
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [gentoo-commits] proj/autodep:master commit in: src/hook_lib/
@ 2012-02-11 20:56 Александр Берсенев
0 siblings, 0 replies; 7+ messages in thread
From: Александр Берсенев @ 2012-02-11 20:56 UTC (permalink / raw
To: gentoo-commits
commit: ee2122ad032c5b8601e6d590df75f2147531aae2
Author: Alexander Bersenev <bay <AT> hackerdom <DOT> ru>
AuthorDate: Sat Feb 11 20:55:09 2012 +0000
Commit: Александр Берсенев <bay <AT> hackerdom <DOT> ru>
CommitDate: Sat Feb 11 20:55:09 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/autodep.git;a=commit;h=ee2122ad
fixed a deadlock
---
src/hook_lib/file_hook.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/src/hook_lib/file_hook.c b/src/hook_lib/file_hook.c
index cd3850a..493c206 100644
--- a/src/hook_lib/file_hook.c
+++ b/src/hook_lib/file_hook.c
@@ -539,9 +539,18 @@ pid_t fork(void) {
__fixenv();
+ // We have to get lock here because we can't be sure that other thread not in
+ // protected code. When we forks, only current thread gets copied, so
+ // child mutex may be always locked without this.
+ pthread_mutex_lock( &socketblock );
+
int ret=_fork();
int saved_errno=errno;
+
// we must to handle fork for reconnect a socket
+
+ pthread_mutex_unlock( &socketblock );
+
if(ret==0) {
__doreconnect(); // reinit connection for children
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-02-11 20:56 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-16 7:31 [gentoo-commits] proj/autodep:master commit in: src/hook_lib/ Александр Берсенев
-- strict thread matches above, loose matches on Subject: below --
2012-02-11 20:56 Александр Берсенев
2012-01-31 12:30 Александр Берсенев
2011-10-21 4:45 Александр Берсенев
2011-09-30 7:21 Александр Берсенев
2011-08-21 18:50 Александр Берсенев
2011-08-02 20:19 Александр Берсенев
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox