summaryrefslogtreecommitdiffstats
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:21 -0400
commit13b72033b575c29f13c325050f61562a578741ec (patch)
treed81de2ed9aa3aac4eb6dbed7dac73c59f7ec8727
parentcedc75748b155f7c1287de8796409dd79ef7aecd (diff)
downloadsssd-13b72033b575c29f13c325050f61562a578741ec.tar.gz
sssd-13b72033b575c29f13c325050f61562a578741ec.tar.xz
sssd-13b72033b575c29f13c325050f61562a578741ec.zip
Fix misuse of errno in find_uid.c
-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 952aeea4a..06c65dbc0 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;
}