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;
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",
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;
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 )