pid_t waitpid(pid_t pid, int* status, int options)
{
  pid_t rc;
  uint64_t time;

  VT_MEMHOOKS_OFF();

  if ( DO_TRACE(waitpid) )
  {
    /* mark enter function */
    time = vt_pform_wtime();
    vt_enter(&time, libc_funcs[FUNCIDX(waitpid)].rid);
  }

  /* call (real) function */
  CALL_FUNC(waitpid, rc, (pid, status, options));

  if ( DO_TRACE(waitpid) )
  {
    /* mark leave function */
    time = vt_pform_wtime();
    vt_exit(&time);
  }

  VT_MEMHOOKS_ON();

  return rc;
}
int system(const char* string)
{
  int rc;
  uint64_t time;

  VT_MEMHOOKS_OFF();

  if ( DO_TRACE(system) )
  {
    /* mark enter function */
    time = vt_pform_wtime();
    vt_enter(&time, libc_funcs[FUNCIDX(system)].rid);
  }

  /* call (real) function */
  CALL_FUNC(system, rc, (string));

  if ( DO_TRACE(system) )
  {
    /* mark leave function */
    time = vt_pform_wtime();
    vt_exit(&time);
  }

  VT_MEMHOOKS_ON();

  return rc;
}
pid_t wait(WAIT_STATUS_TYPE status)
{
  pid_t rc;
  uint64_t time;

  VT_MEMHOOKS_OFF();

  if ( DO_TRACE(wait) )
  {
    /* mark enter function */
    time = vt_pform_wtime();
    vt_enter(&time, libc_funcs[FUNCIDX(wait)].rid);
  }

  /* call (real) function */
  CALL_FUNC(wait, rc, (status));

  if ( DO_TRACE(wait) )
  {
    /* mark leave function */
    time = vt_pform_wtime();
    vt_exit(&time);
  }

  VT_MEMHOOKS_ON();

  return rc;
}
pid_t fork(void)
{
  pid_t rc;
  uint64_t time;

  VT_MEMHOOKS_OFF();

  if ( DO_TRACE(fork) )
  {
    /* mark enter function */
    time = vt_pform_wtime();
    vt_enter(&time, libc_funcs[FUNCIDX(fork)].rid);
  }

  /* call (real) function */
  CALL_FUNC(fork, rc, ());

  if ( DO_TRACE(fork) )
  {
    /* handle fork, if succeeded */
    if ( rc != -1 )
      vt_fork(rc);

    if ( rc != 0 )
    {
      /* mark leave function */
      time = vt_pform_wtime();
      vt_exit(&time);
    }
  }
    
  VT_MEMHOOKS_ON();

  return rc;
}
int execvp(const char* path, char* const argv[])
{
  int rc;

  VT_MEMHOOKS_OFF();

  if ( DO_TRACE(execvp) )
  {
    /* mark enter function */
    uint64_t time = vt_pform_wtime();
    vt_enter(&time, libc_funcs[FUNCIDX(execvp)].rid);
  }

  /* close VT for current process */
  vt_close();

  /* call (real) function */
  CALL_FUNC(execvp, rc, (path, argv));

  vt_warning("execvp failed: %s", strerror(errno));
  return rc;
}
int execle(const char* path, const char* arg, ...)
{
  int rc;
  char* argv[100];
  char** envp;
  char* tmp;
  int i;
  va_list ap;

  VT_MEMHOOKS_OFF();

  va_start(ap, arg);

  i = 0;
  argv[i++] = (char*)arg;
  while((tmp = va_arg(ap, char*) ))
    argv[i++] = tmp;
  argv[i] = NULL;
  envp = va_arg(ap, char**);

  va_end(ap);

  if ( DO_TRACE(execle) )
  {
    /* mark enter function */
    uint64_t time = vt_pform_wtime();
    vt_enter(&time, libc_funcs[FUNCIDX(execle)].rid);
  }

  /* close VT for current process */
  vt_close();

  /* call (real) function */
  CALL_FUNC(execve, rc, (path, argv, envp));

  vt_warning("execle failed: %s", strerror(errno));
  return rc;
}
Exemple #7
0
int XP_MakeDirectory(const char* name, XP_FileType type)
{
    int result;
    static XP_Bool madeXoverDir = FALSE;
    mode_t mode;
    switch (type) {
    case xpMailFolder:
        mode = 0700;
        break;
    default:
        mode = 0755;
        break;
    }
    if (type == xpXoverCache) {
        /* Once per session, we'll check that the xovercache directory is
           created before trying to make any subdirectories of it.  Sigh. ###*/
        if (!madeXoverDir) {
            madeXoverDir = TRUE;
            XP_MakeDirectory("", type);
        }
    }
#ifdef __linux
    {
        /* Linux is a chokes if the parent of the
           named directory is a symbolic link. */
        char rp[MAXPATHLEN];
        char *s, *s0 = WH_FileName (name, type);
        if (!s0) return -1;

        /* realpath is advertised to return a char* (rp) on success, and on
           failure, return 0, set errno, and leave a partial path in rp.
           But on Linux 1.2.3, it doesn't -- it returns 0, leaves the result
           in rp, and doesn't set errno.  So, if errno is unset, assume all
           is well.
         */
        rp[0] = 0;
        errno = 0;
        s = realpath (s0, rp);
        XP_FREE(s0);
        /* WTF??? if (errno) return -1; */
        if (!s) s = rp;
        if (!*s) return -1;
        result = mkdir (s, mode);
    }
#elif defined(SUNOS4)
    {
        char rp[MAXPATHLEN];
        char *s = WH_FileName (name, type);
        char *tmp;
        if (!s) return -1;

        /* Take off all trailing slashes, because some systems (SunOS 4.1.2)
           don't think mkdir("/tmp/x/") means mkdir("/tmp/x"), sigh... */
        PR_snprintf (rp, MAXPATHLEN-1, "%s", s);
        XP_FREE(s);
        while ((tmp = XP_STRRCHR(rp, '/')) && tmp[1] == '\0')
            *tmp = '\0';

        result = mkdir (rp, mode);
    }
#else /* !__linux && !SUNOS4 */
    DO_TRACE(("XP_MakeDirectory called: creating: %s", name));
    {
        char* filename = WH_FileName(name, type);
        if (!filename) return -1;
        result = mkdir(filename, mode);
        XP_FREE(filename);
    }
#endif
    return result;
}
Exemple #8
0
char *
xp_TempName (XP_FileType type, const char * prefix, char* buf, char* buf2, unsigned int *count)
{
#define NS_BUFFER_SIZE	1024
    char *value = buf;
    time_t now;

    *buf = 0;
    XP_ASSERT (type != xpTemporaryNewsRC);

    if (type == xpCache || type == xpSARCache)
    {
        /* WH_TempName() must return relative pathnames for the cache files,
         so that relative paths get written into the cacheFAT database,
         making the directory relocatable.
         */
        *buf = 0;
    }
    else  if ( (type == xpURL) && prefix )
    {
        if ( XP_STRRCHR(prefix, '/') )
        {
            XP_StatStruct st;

            XP_SPRINTF (buf, "%.500s", prefix);
            if (XP_Stat (buf, &st, xpURL))
                XP_MakeDirectoryR (buf, xpURL);
            prefix = "su";
        }
    }
    else
    {
        char *tmp = FE_TempDir;
        if (!tmp || !*tmp) tmp = "/tmp";
        XP_SPRINTF (buf, "%.500s", tmp);

        if (!prefix || !*prefix)
            prefix = "tmp";
    }

    XP_ASSERT (!XP_STRCHR (prefix, '/'));
    if (*buf && buf[XP_STRLEN (buf)-1] != '/')
        XP_STRCAT (buf, "/");

    /* It's good to have the cache file names be pretty long, with a bunch of
     inputs; this makes the variant part be 15 chars long, consisting of the
     current time (in seconds) followed by a counter (to differentiate
     documents opened in the same second) followed by the current pid (to
     differentiate simultanious processes.)  This organization of the bits
     has the effect that they are ordered the same lexicographically as by
     creation time.

     If name length was an issue we could cut the character count a lot by
     printing them in base 72 [A-Za-z0-9@%-_=+.,~:].
     */
    now = time ((time_t *) 0);
    sprintf (buf2,
             "%08X%03X%04X",
             (unsigned int) now,
             (unsigned int) *count,
             (unsigned int) (getpid () & 0xFFFF));

    if (++(*count) > 4095) (*count) = 0; /* keep it 3 hex digits */

#ifdef CACHE_SUBDIRS
    if (type == xpCache || type == xpSARCache)
    {
        XP_StatStruct st;
        char *s;
        char *tmp = (type == xpCache) ? FE_CacheDir : FE_SARCacheDir;
        if (!tmp || !*tmp) tmp = "/tmp";
        sprintf (buf, "%.500s", tmp);
        if (buf [XP_STRLEN(buf)-1] != '/')
            XP_STRCAT (buf, "/");

        s = buf + XP_STRLEN (buf);

        value = s;		/* return a relative path! */

        /* The name of the subdirectory is the bottom 5 bits of the time part,
         in hex (giving a total of 32 directories.) */
        sprintf (s, "%02X", (now & 0x1F));

        if (XP_Stat (buf, &st, xpURL))		/* create the dir if necessary */
            XP_MakeDirectory (buf, type);

        s[2] = '/';
        s[3] = 0;
    }
#endif /* !CACHE_SUBDIRS */

    XP_STRNCAT (value, prefix, NS_BUFFER_SIZE - XP_STRLEN(value));
    XP_STRNCAT (value, buf2, NS_BUFFER_SIZE - XP_STRLEN(value));

    /* Tao
     */
    if (type == xpAddrBook) {
        XP_STRNCAT (value, ".nab", NS_BUFFER_SIZE - XP_STRLEN(value));
    }/* if */

    value[NS_BUFFER_SIZE - 1] = '\0'; /* just in case */

    DO_TRACE(("WH_TempName called: returning: %s", value));

    return(value);
}