Changeset 3105f50


Ignore:
Timestamp:
05/28/15 21:36:03 (9 years ago)
Author:
Hal Finkel <hfinkel@…>
Branches:
master
Children:
081a0fa
Parents:
430548b
git-author:
Hal Finkel <hfinkel@…> (05/28/15 21:36:03)
git-committer:
Hal Finkel <hfinkel@…> (05/28/15 21:36:03)
Message:

use the self link for no file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • memlog.c

    r430548b r3105f50  
    2929// sure this does not cause an infinite loop. 
    3030static __thread int in_malloc = 0; 
     31static char self_path[PATH_MAX+1] = { '\0' }; 
    3132 
    3233__attribute__((__constructor__)) 
     
    3536  uname(&u); 
    3637 
    37   char log_name[PATH_MAX]; 
    38   snprintf(log_name, PATH_MAX, "%s.%d.memlog", u.nodename, getpid()); 
     38  char log_name[PATH_MAX+1]; 
     39  snprintf(log_name, PATH_MAX+1, "%s.%d.memlog", u.nodename, getpid()); 
    3940  log_file = fopen(log_name, "w"); 
    4041  if (!log_file) 
    4142    fprintf(stderr, "fopen failed for '%s': %m\n", log_name); 
     43 
     44  const char *link_name = "/proc/self/exe"; 
     45  readlink(link_name, self_path, PATH_MAX); 
    4246} 
    4347 
     
    110114      file_name = dlinfo.dli_fname; 
    111115    } else { 
    112       off = pc; 
    113       relpc = pc; 
     116      // We don't know these... 
     117      off = 0; 
     118      relpc = 0; 
    114119      proc_name = "?"; 
    115       file_name = "?"; 
     120 
     121      // If we can't determine the file, assume it is the base executable 
     122      // (which does the right thing for statically-linked binaries). 
     123      file_name = self_path; 
    116124    } 
    117125 
Note: See TracChangeset for help on using the changeset viewer.