X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fguicast%2Fbcsignals.C;h=ed50cfb15d9e8ac38c630c3096c9ab2b77fce477;hp=e1e5aa38104a588cc42a56d5555fb103dded0bcd;hb=7e5a0760f40ff787cc3d93cb7768a901ebe52809;hpb=5a1b2bb96f2bd6b7ef4f8031763683726c02219d diff --git a/cinelerra-5.1/guicast/bcsignals.C b/cinelerra-5.1/guicast/bcsignals.C index e1e5aa38..ed50cfb1 100644 --- a/cinelerra-5.1/guicast/bcsignals.C +++ b/cinelerra-5.1/guicast/bcsignals.C @@ -88,14 +88,14 @@ void BC_Signals::set_catch_segv(bool v) { if( v == trap_sigsegv ) return; if( v ) catch_segv(); else uncatch_segv(); - v = trap_sigsegv; + trap_sigsegv = v; } void BC_Signals::set_catch_intr(bool v) { if( v == trap_sigintr ) return; if( v ) catch_intr(); else uncatch_intr(); - v = trap_sigintr; + trap_sigintr = v; } static void bc_copy_textfile(int lines, FILE *ofp, const char *fmt,...) @@ -109,6 +109,53 @@ static void bc_copy_textfile(int lines, FILE *ofp, const char *fmt,...) fclose(ifp); } +static void bc_list_openfiles(int lines, FILE *ofp, const char *fmt,...) +{ + va_list ap; va_start(ap, fmt); + char bfr[BCTEXTLEN]; vsnprintf(bfr, sizeof(bfr), fmt, ap); + va_end(ap); + DIR *dir = opendir(bfr); + if( !dir ) return; + struct dirent64 *dent; + while( --lines >= 0 && (dent = readdir64(dir)) ) { + const char *fn = dent->d_name; + fprintf(ofp, "%s", fn); + char path[BCTEXTLEN], link[BCTEXTLEN]; + struct stat st; + snprintf(path, sizeof(path), "%s/%s", bfr, fn); + if( !stat(path,&st) ) { + int typ = 0; + if( S_ISREG(st.st_mode) ) typ = ' '; + else if( S_ISDIR(st.st_mode) ) typ = 'd'; + else if( S_ISBLK(st.st_mode) ) typ = 'b'; + else if( S_ISCHR(st.st_mode) ) typ = 'c'; + else if( S_ISFIFO(st.st_mode) ) typ = 'f'; + else if( S_ISLNK(st.st_mode) ) typ = 'l'; + else if( S_ISSOCK(st.st_mode) ) typ = 's'; + if( typ ) fprintf(ofp, "\t%c", typ); + fprintf(ofp, "\tsize %jd", st.st_size); + int len = readlink(path, link, sizeof(link)-1); + if( len > 0 ) { + link[len] = 0; + fprintf(ofp, "\t-> %s", link); + } + } + snprintf(path, sizeof(path), "%sinfo/%s", bfr, fn); + FILE *fp = fopen(path,"r"); int64_t pos; + if( fp ) { + while( fgets(link, sizeof(link), fp) ) { + if( sscanf(link, "pos:%jd", &pos) == 1 ) { + fprintf(ofp, "\tpos: %jd", pos); + break; + } + } + fclose(fp); + } + fprintf(ofp, "\n"); + } + closedir(dir); +} + // Can't use Mutex because it would be recursive static pthread_mutex_t *handler_lock = 0; @@ -175,7 +222,7 @@ void BC_Signals::kill_subs() if( fgetc(fd) == ' ' ) --sp; // Read in parent process for( ptr=string; !feof(fd) && (*ptr=fgetc(fd))!=' '; ++ptr ); - if( (*ptr=fgetc(fd)) == ' ' ) break; + if( (*ptr=fgetc(fd)) == ' ' ) break; *ptr = 0; // printf("kill_subs %d process=%d getpid=%d parent_process=%d\n", @@ -266,10 +313,11 @@ int BC_Signals::x_error_handler(Display *display, XErrorEvent *event) } -void BC_Signals::initialize() +void BC_Signals::initialize(const char *trap_path) { BC_Signals::global_signals = this; BC_Trace::global_trace = this; + set_trap_path(trap_path); handler_lock = (pthread_mutex_t*)calloc(1, sizeof(pthread_mutex_t)); pthread_mutex_init(handler_lock, 0); old_err_handler = XSetErrorHandler(x_error_handler); @@ -353,7 +401,9 @@ static void handle_dump(int n, siginfo_t * info, void *sc) signal(SIGINT, SIG_DFL); // gotta be root, or the dump is worthless int uid = getuid(); - if( uid != 0 ) return; +// it is not necessary to be root if ptrace is allowed via: +// echo 0 > /proc/sys/kernel/yama/ptrace_scope (usually set to 1) +// if( uid != 0 ) return; ucontext_t *uc = (ucontext_t *)sc; int pid = getpid(), tid = gettid(); struct sigcontext *c = (struct sigcontext *)&uc->uc_mcontext; @@ -390,12 +440,15 @@ static void handle_dump(int n, siginfo_t * info, void *sc) fprintf(fp,"\nTRACES:\n"); BC_Trace::dump_traces(fp); fprintf(fp,"\nLOCKS:\n"); BC_Trace::dump_locks(fp); fprintf(fp,"\nBUFFERS:\n"); BC_Trace::dump_buffers(fp); + fprintf(fp,"\nSHMMEM:\n"); BC_Trace::dump_shm_stats(fp); if( BC_Signals::trap_hook ) { fprintf(fp,"\nMAIN HOOK:\n"); BC_Signals::trap_hook(fp, BC_Signals::trap_data); } fprintf(fp,"\nVERSION:\n"); bc_copy_textfile(INT_MAX, fp,"/proc/version"); fprintf(fp,"\nMEMINFO:\n"); bc_copy_textfile(INT_MAX, fp,"/proc/meminfo"); + fprintf(fp,"\nSTATUS:\n"); bc_copy_textfile(INT_MAX, fp,"/proc/%d/status",pid); + fprintf(fp,"\nFD:\n"); bc_list_openfiles(INT_MAX, fp,"/proc/%d/fd", pid); fprintf(fp,"\nMAPS:\n"); bc_copy_textfile(INT_MAX, fp,"/proc/%d/maps",pid); char proc_mem[64]; if( tid > 0 && tid != pid )