summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2010-06-09 09:11:48 -0400
committerStephen Gallagher <sgallagh@redhat.com>2010-06-10 10:17:38 -0400
commit9eab847bc1a30ebf4ab27f739d6972402262d045 (patch)
treebe5f0aa594f0c6437845f3fa8f0e7336b6151dbc /src
parent06247775aa9c49ffce72827921eb45e2d04c6aa1 (diff)
downloadsssd-9eab847bc1a30ebf4ab27f739d6972402262d045.tar.gz
sssd-9eab847bc1a30ebf4ab27f739d6972402262d045.tar.bz2
sssd-9eab847bc1a30ebf4ab27f739d6972402262d045.zip
Fix misuse of errno in find_uid.c
Diffstat (limited to 'src')
-rw-r--r--src/util/find_uid.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/util/find_uid.c b/src/util/find_uid.c
index 952aeea4..06c65dbc 100644
--- a/src/util/find_uid.c
+++ b/src/util/find_uid.c
@@ -64,6 +64,7 @@ static errno_t get_uid_from_pid(const pid_t pid, uid_t *uid)
char *e;
char *endptr;
long num=0;
+ errno_t error;
ret = snprintf(path, PATHLEN, "/proc/%d/status", pid);
if (ret < 0) {
@@ -76,13 +77,14 @@ static errno_t get_uid_from_pid(const pid_t pid, uid_t *uid)
ret = lstat(path, &stat_buf);
if (ret == -1) {
- if (errno == ENOENT) {
+ 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", errno, strerror(errno)));
- return errno;
+ DEBUG(1, ("lstat failed [%d][%s].\n", error, strerror(error)));
+ return error;
}
if (!S_ISREG(stat_buf.st_mode)) {
@@ -92,28 +94,31 @@ static errno_t get_uid_from_pid(const pid_t pid, uid_t *uid)
fd = open(path, O_RDONLY);
if (fd == -1) {
- if (errno == ENOENT) {
+ 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", errno, strerror(errno)));
- return errno;
+ DEBUG(1, ("open failed [%d][%s].\n", error, strerror(error)));
+ return error;
}
while ((ret = read(fd, buf, BUFSIZE)) != 0) {
if (ret == -1) {
- if (errno == EINTR || errno == EAGAIN) {
+ error = errno;
+ if (error == EINTR || error == EAGAIN) {
continue;
}
- DEBUG(1, ("read failed [%d][%s].\n", errno, strerror(errno)));
- return errno;
+ DEBUG(1, ("read failed [%d][%s].\n", error, strerror(error)));
+ return error;
}
}
ret = close(fd);
if (ret == -1) {
- DEBUG(1, ("close failed [%d][%s].\n", errno, strerror(errno)));
+ error = errno;
+ DEBUG(1, ("close failed [%d][%s].\n", error, strerror(error)));
}
p = strstr(buf, "\nUid:\t");
@@ -126,10 +131,12 @@ static errno_t get_uid_from_pid(const pid_t pid, uid_t *uid)
} else {
*e = '\0';
}
+ errno = 0;
num = strtol(p, &endptr, 10);
- if(errno == ERANGE) {
- DEBUG(1, ("strtol failed [%s].\n", strerror(errno)));
- return errno;
+ error = errno;
+ if (error == ERANGE) {
+ DEBUG(1, ("strtol failed [%s].\n", strerror(error)));
+ return error;
}
if (*endptr != '\0') {
DEBUG(1, ("uid contains extra characters\n"));
@@ -155,12 +162,14 @@ static errno_t name_to_pid(const char *name, pid_t *pid)
{
long num;
char *endptr;
+ errno_t error;
errno = 0;
num = strtol(name, &endptr, 10);
- if(errno == ERANGE) {
+ error = errno;
+ if (error == ERANGE) {
perror("strtol");
- return errno;
+ return error;
}
if (*endptr != '\0') {
@@ -197,8 +206,8 @@ static errno_t get_active_uid_linux(hash_table_t *table, uid_t search_uid)
proc_dir = opendir("/proc");
if (proc_dir == NULL) {
- DEBUG(1, ("Cannot open proc dir.\n"));
ret = errno;
+ DEBUG(1, ("Cannot open proc dir.\n"));
goto done;
};
@@ -240,8 +249,8 @@ static errno_t get_active_uid_linux(hash_table_t *table, uid_t search_uid)
errno = 0;
}
if (errno != 0 && dirent == NULL) {
- DEBUG(1 ,("readdir failed.\n"));
ret = errno;
+ DEBUG(1 ,("readdir failed.\n"));
goto done;
}