agent/src/os/solaris/proc/saproc.cpp

changeset 1327
a94af87c3357
parent 1014
0fbdb4381b99
child 1907
c18cbe5936b8
     1.1 --- a/agent/src/os/solaris/proc/saproc.cpp	Fri Jul 24 09:01:00 2009 -0700
     1.2 +++ b/agent/src/os/solaris/proc/saproc.cpp	Fri Jul 24 12:40:40 2009 -0700
     1.3 @@ -214,49 +214,58 @@
     1.4    }
     1.5  }
     1.6  
     1.7 -static int find_file_hook(const char * name, int elf_checksum) {
     1.8 -  init_alt_root();
     1.9 +// This function is a complete substitute for the open system call
    1.10 +// since it's also used to override open calls from libproc to
    1.11 +// implement as a pathmap style facility for the SA.  If libproc
    1.12 +// starts using other interfaces then this might have to extended to
    1.13 +// cover other calls.
    1.14 +extern "C" int libsaproc_open(const char * name, int oflag, ...) {
    1.15 +  if (oflag == O_RDONLY) {
    1.16 +    init_alt_root();
    1.17  
    1.18 -  if (_libsaproc_debug) {
    1.19 -    printf("libsaproc DEBUG: find_file_hook %s 0x%x\n", name, elf_checksum);
    1.20 -  }
    1.21 -
    1.22 -  if (alt_root_len > 0) {
    1.23 -    int fd = -1;
    1.24 -    char alt_path[PATH_MAX+1];
    1.25 -
    1.26 -    strcpy(alt_path, alt_root);
    1.27 -    strcat(alt_path, name);
    1.28 -    fd = open(alt_path, O_RDONLY);
    1.29 -    if (fd >= 0) {
    1.30 -      if (_libsaproc_debug) {
    1.31 -        printf("libsaproc DEBUG: find_file_hook substituted %s\n", alt_path);
    1.32 -      }
    1.33 -      return fd;
    1.34 +    if (_libsaproc_debug) {
    1.35 +      printf("libsaproc DEBUG: libsaproc_open %s\n", name);
    1.36      }
    1.37  
    1.38 -    if (strrchr(name, '/')) {
    1.39 +    if (alt_root_len > 0) {
    1.40 +      int fd = -1;
    1.41 +      char alt_path[PATH_MAX+1];
    1.42 +
    1.43        strcpy(alt_path, alt_root);
    1.44 -      strcat(alt_path, strrchr(name, '/'));
    1.45 +      strcat(alt_path, name);
    1.46        fd = open(alt_path, O_RDONLY);
    1.47        if (fd >= 0) {
    1.48          if (_libsaproc_debug) {
    1.49 -          printf("libsaproc DEBUG: find_file_hook substituted %s\n", alt_path);
    1.50 +          printf("libsaproc DEBUG: libsaproc_open substituted %s\n", alt_path);
    1.51          }
    1.52          return fd;
    1.53        }
    1.54 +
    1.55 +      if (strrchr(name, '/')) {
    1.56 +        strcpy(alt_path, alt_root);
    1.57 +        strcat(alt_path, strrchr(name, '/'));
    1.58 +        fd = open(alt_path, O_RDONLY);
    1.59 +        if (fd >= 0) {
    1.60 +          if (_libsaproc_debug) {
    1.61 +            printf("libsaproc DEBUG: libsaproc_open substituted %s\n", alt_path);
    1.62 +          }
    1.63 +          return fd;
    1.64 +        }
    1.65 +      }
    1.66      }
    1.67    }
    1.68 -  return -1;
    1.69 +
    1.70 +  {
    1.71 +    mode_t mode;
    1.72 +    va_list ap;
    1.73 +    va_start(ap, oflag);
    1.74 +    mode = va_arg(ap, mode_t);
    1.75 +    va_end(ap);
    1.76 +
    1.77 +    return open(name, oflag, mode);
    1.78 +  }
    1.79  }
    1.80  
    1.81 -static int pathmap_open(const char* name) {
    1.82 -  int fd = open(name, O_RDONLY);
    1.83 -  if (fd < 0) {
    1.84 -    fd = find_file_hook(name, 0);
    1.85 -  }
    1.86 -  return fd;
    1.87 -}
    1.88  
    1.89  static void * pathmap_dlopen(const char * name, int mode) {
    1.90    init_alt_root();
    1.91 @@ -608,7 +617,7 @@
    1.92    print_debug("looking for %s\n", classes_jsa);
    1.93  
    1.94    // open the classes[_g].jsa
    1.95 -  int fd = pathmap_open(classes_jsa);
    1.96 +  int fd = libsaproc_open(classes_jsa, O_RDONLY);
    1.97    if (fd < 0) {
    1.98      char errMsg[ERR_MSG_SIZE];
    1.99      sprintf(errMsg, "can't open shared archive file %s", classes_jsa);
   1.100 @@ -1209,8 +1218,6 @@
   1.101    return res;
   1.102  }
   1.103  
   1.104 -typedef int (*find_file_hook_t)(const char *, int elf_checksum);
   1.105 -
   1.106  /*
   1.107   * Class:       sun_jvm_hotspot_debugger_proc_ProcDebuggerLocal
   1.108   * Method:      initIDs
   1.109 @@ -1230,16 +1237,6 @@
   1.110    if (libproc_handle == 0)
   1.111       THROW_NEW_DEBUGGER_EXCEPTION("can't load libproc.so, if you are using Solaris 5.7 or below, copy libproc.so from 5.8!");
   1.112  
   1.113 -  // If possible, set shared object find file hook.
   1.114 -  void (*set_hook)(find_file_hook_t) = (void(*)(find_file_hook_t))dlsym(libproc_handle, "Pset_find_file_hook");
   1.115 -  if (set_hook) {
   1.116 -    // we found find file hook symbol, set up our hook function.
   1.117 -    set_hook(find_file_hook);
   1.118 -  } else if (getenv(SA_ALTROOT)) {
   1.119 -    printf("libsaproc WARNING: %s set, but can't set file hook. " \
   1.120 -           "Did you use right version of libproc.so?\n", SA_ALTROOT);
   1.121 -  }
   1.122 -
   1.123    p_ps_prochandle_ID = env->GetFieldID(clazz, "p_ps_prochandle", "J");
   1.124    CHECK_EXCEPTION;
   1.125  

mercurial