Пример #1
0
int lstat(const char *path, struct stat *sb)
{
    int ret;

    init_syms();

    if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) {
        init_sysfs();
        char *newpath;
        if (asprintf(&newpath, "%s/%s",
                     fakesysfscgroupdir,
                     path + strlen(SYSFS_CGROUP_PREFIX)) < 0) {
            errno = ENOMEM;
            return -1;
        }
        ret = real_lstat(newpath, sb);
        free(newpath);
    } else if (STRPREFIX(path, fakedevicedir0)) {
        sb->st_mode = S_IFBLK;
        sb->st_rdev = makedev(8, 0);
        return 0;
    } else if (STRPREFIX(path, fakedevicedir1)) {
        sb->st_mode = S_IFBLK;
        sb->st_rdev = makedev(9, 0);
        return 0;
    } else {
        ret = real_lstat(path, sb);
    }
    return ret;
}
Пример #2
0
int lstat(const char *pathname, struct stat *buf) {
    static int (*real_lstat)(const char *pathname, struct stat *buf) = NULL;
    const char *p;
    int ret;

    GET_PATH(lstat);
    if (p) {
	ret = real_lstat(p, buf);
	PUT_PATH(-1);
    }
    return real_lstat(pathname, buf);
}
Пример #3
0
/* Contributed by Philipp Hachtmann in version 0.6 */
int __lxstat64 (int ver, const char *path, struct stat64 *buf){
  static int (*real_lstat) (int, const char *, struct stat64 *);
  static int has_real_lstat = 0;

  SINGLE_IF(has_real_lstat==0)
    real_lstat = NULL;
    real_lstat = dlsym(RTLD_NEXT, "__lxstat64");
    if (dlerror() == NULL) {
      has_real_lstat = 1;
    }
  END_SINGLE_IF
  if (!has_real_lstat) {  /* dlsym() failed */
#ifdef DEBUG
    (void) fprintf(stderr, "faketime problem: original lstat() not found.\n");
#endif
    return -1; /* propagate error to caller */
  }

  int result = real_lstat(ver, path, buf);
  if (result == -1){
    return -1;
  }

  if (buf != NULL){
    if (!fake_stat_disabled) {
      buf->st_ctime = fake_time(&(buf->st_ctime));
      buf->st_atime = fake_time(&(buf->st_atime));
      buf->st_mtime = fake_time(&(buf->st_mtime));
    }
  }
  return result;
}
Пример #4
0
void stat_cache_update(struct hash *hash, const char *path, const struct hash *path_hash, int do_hash)
{
    initialize();

    // lstat the file
    struct stat st;
    if (real_lstat(path, &st) < 0) {
        int errno_ = errno;
        if (errno_ == ENOENT || errno_ == ENOTDIR) {
            // Set hash to zero to represent nonexistent file
            memset(hash, 0, sizeof(struct hash));
            return;
        }
        die("lstat(\"%s\") failed: %s", path, strerror(errno_));
    }

    // TODO: We currently ignore the S_ISLNK flag, which assumes that traced
    // processes never detect symlinks via lstat and never create them.

    // For now we go the simple route and hold the stat_cache lock for the
    // entire duration of the hash computation.  In future we may want to drop
    // the lock while we compute the hash.  Alternatively, switching to a finer
    // grain locking discipline might avoid the problem.
    shared_map_lock(&stat_cache);

    // Lookup entry, creating it if necessary, and check if it's up to date
    struct stat_cache_entry *entry;
    if (!shared_map_lookup(&stat_cache, path_hash, (void**)&entry, 1)
        || entry->st_mtimespec.tv_nsec != st.st_mtimespec.tv_nsec
        || entry->st_mtimespec.tv_sec != st.st_mtimespec.tv_sec
        || entry->st_size != st.st_size
        || entry->st_ino != st.st_ino
        || (do_hash && hash_is_all_one(&entry->contents_hash)))
    {
        // Entry is new or out of date.  In either case, compute hash and
        // record new stat details.
        entry->st_ino = st.st_ino;
        entry->st_mtimespec = st.st_mtimespec;
        entry->st_size = st.st_size;

        if (do_hash) {
            // Hash the file
            int fd = real_open(path, O_RDONLY, 0);
            if (fd < 0)
                die("can't open '%s' to compute hash", path);
            hash_fd(&entry->contents_hash, fd);
            real_close(fd);
        }
        else
            memset(&entry->contents_hash, -1, sizeof(struct hash));
    }
    shared_map_unlock(&stat_cache);
    if (do_hash)
        *hash = entry->contents_hash;
    else
        memset(hash, -1, sizeof(struct hash));
}
Пример #5
0
int lstat(char *name, void *st)
{
#if HAVE___LXSTAT
    return __lxstat(0, name, st);
#else
    if (smbw_path(name)) {
        return smbw_stat(name, st);
    }
    return real_lstat(name, st);
#endif
}
Пример #6
0
int lstat(const char *path, struct stat *buf)
{
    die("not implemented: lstat(\"%s\", ...)", path);

    if (!inside_libc && !action_lstat(path)) {
        errno = ENOENT;
        return -1;
    }
    // TODO: Coalesce this lstat with the one in action_read
    return real_lstat(path, buf);
}
Пример #7
0
int __lxstat(int vers, char *name, void *st)
{
    double xx[32];
    int ret;

    if (smbw_path(name)) {
        return smbw_stat(name, st);
    }

    ret = real_lstat(name, xx);
    xstat_convert(vers, st, xx);
    return ret;
}
Пример #8
0
/*
 * Copyright (c) 2011 Wind River Systems; see
 * guts/COPYRIGHT for information.
 *
 * int lstat(const char *path, struct stat *buf)
 *	int rc = -1;
 */

	pseudo_msg_t *msg;

	rc = real_lstat(path, buf);
	if (rc == -1) {
		return rc;
	}

	/* query database
	 * note that symlink canonicalizing is now automatic, so we
	 * don't need to check for a symlink on this end
	 */
	msg = pseudo_client_op(OP_STAT, 0, -1, -1, path, buf);
	if (msg && msg->result == RESULT_SUCCEED) {
		pseudo_stat_msg(buf, msg);
	}

/*	return rc;
 * }
 */