Autrijus,

Run 'man proc' for more info on the following...

At least on linux 2.2 and 2.4 machines the following works for
finding the fullpath to the exe:

/* Returns the full path to exe or NULL on failure */
char *findprog() {
  char exelink[32]; /* Enough to hold fixed characters plus pid */
  int mypid = getpid();
  char *progexe = (char *)malloc(MAX_PATH_LEN+1);
  int len;

  /* Create full path to exe link in proc filesystem */
  snprintf(31, exelink, "/proc/%d/exe", mypid);

  /* Read the /proc/PID/exe link to get path to exe */
  if( (len = readlink(exelink, progexe, (MAX_PATH_LEN)*sizeof(char))) < 0 ) {
    /* readlink failed, try something else */
    free(progexe);
    progexe = NULL;
  }
  else
    /* readlink succeeded, null terminate the value */
    progexe[len] = '\0';
  return progexe;
}

Best regards,

Alan

At 11:05 PM 5/19/2004 +0800, Autrijus Tang wrote:
>On Wed, May 19, 2004 at 10:25:18AM -0400, the.noonings wrote:
>> Bug!  Help needed!
>
>Duplicated here.  Seems to be a very old bug that involves a botched
>par_findprog() on non-Win32 systems.  Will look into it right after I wake up.
>
>Thanks,
>/Autrijus/

Reply via email to