From 946aba311fd280fbd673944c0181063d2600c878 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Fri, 11 Jun 2010 12:47:00 +0200 Subject: get_uid_from_pid should use fstat rather than lstat Fixes: #541 --- src/util/find_uid.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/util/find_uid.c b/src/util/find_uid.c index 06c65dbc0..6f43ac388 100644 --- a/src/util/find_uid.c +++ b/src/util/find_uid.c @@ -75,35 +75,35 @@ static errno_t get_uid_from_pid(const pid_t pid, uid_t *uid) return EINVAL; } - ret = lstat(path, &stat_buf); - if (ret == -1) { + fd = open(path, O_RDONLY); + if (fd == -1) { error = errno; if (error == ENOENT) { DEBUG(7, ("Proc file [%s] is not available anymore, continuing.\n", path)); return EOK; } - DEBUG(1, ("lstat failed [%d][%s].\n", error, strerror(error))); + DEBUG(1, ("open failed [%d][%s].\n", error, strerror(error))); return error; } - if (!S_ISREG(stat_buf.st_mode)) { - DEBUG(1, ("not a regular file\n")); - return EINVAL; - } - - fd = open(path, O_RDONLY); - if (fd == -1) { + ret = fstat(fd, &stat_buf); + if (ret == -1) { error = errno; if (error == ENOENT) { DEBUG(7, ("Proc file [%s] is not available anymore, continuing.\n", path)); return EOK; } - DEBUG(1, ("open failed [%d][%s].\n", error, strerror(error))); + DEBUG(1, ("fstat failed [%d][%s].\n", error, strerror(error))); return error; } + if (!S_ISREG(stat_buf.st_mode)) { + DEBUG(1, ("not a regular file\n")); + return EINVAL; + } + while ((ret = read(fd, buf, BUFSIZE)) != 0) { if (ret == -1) { error = errno; -- cgit