diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2012-04-02 17:26:05 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2012-04-20 10:55:14 -0400 |
commit | 9d7d4458d94d0aac0a7edf999368eb18f89cb76a (patch) | |
tree | b443c2ed560bc5f61cae78e94ceeb795fa1f83b4 /src/sss_client | |
parent | 9959c512ac3ba36f7a0db7614f0357ce0bae748f (diff) | |
download | sssd-9d7d4458d94d0aac0a7edf999368eb18f89cb76a.tar.gz sssd-9d7d4458d94d0aac0a7edf999368eb18f89cb76a.tar.bz2 sssd-9d7d4458d94d0aac0a7edf999368eb18f89cb76a.zip |
Convert read and write operations to sss_atomic_read
https://fedorahosted.org/sssd/ticket/1209
Diffstat (limited to 'src/sss_client')
-rw-r--r-- | src/sss_client/pam_sss.c | 50 | ||||
-rw-r--r-- | src/sss_client/ssh/sss_ssh_knownhostsproxy.c | 4 |
2 files changed, 27 insertions, 27 deletions
diff --git a/src/sss_client/pam_sss.c b/src/sss_client/pam_sss.c index 8778fe19..3de810c5 100644 --- a/src/sss_client/pam_sss.c +++ b/src/sss_client/pam_sss.c @@ -47,6 +47,7 @@ #include "sss_pam_macros.h" #include "sss_cli.h" +#include "util/atomic_io.h" #include <libintl.h> #define _(STRING) dgettext (PACKAGE, STRING) @@ -499,17 +500,12 @@ static errno_t display_pw_reset_message(pam_handle_t *pamh, goto done; } - - total_len = 0; - while (total_len < stat_buf.st_size) { - ret = read(fd, msg_buf + total_len, stat_buf.st_size - total_len); - if (ret == -1) { - if (errno == EINTR || errno == EAGAIN) continue; - ret = errno; - D(("read failed [%d][%s].", ret, strerror(ret))); - goto done; - } - total_len += ret; + errno = 0; + total_len = sss_atomic_read_s(fd, msg_buf, stat_buf.st_size); + if (ret == -1) { + ret = errno; + D(("read failed [%d][%s].", ret, strerror(ret))); + goto done; } ret = close(fd); @@ -1088,7 +1084,8 @@ static int send_and_receive(pam_handle_t *pamh, struct pam_items *pi, #ifdef HAVE_SELINUX char *path = NULL; char *tmp_path = NULL; - int pos, len; + ssize_t written; + int len; int fd; mode_t oldmask; #endif /* HAVE_SELINUX */ @@ -1206,21 +1203,24 @@ static int send_and_receive(pam_handle_t *pamh, struct pam_items *pi, goto done; } - pos = 0; len = strlen(pi->selinux_user); - while (pos < len) { - ret = write(fd, pi->selinux_user + pos, len-pos); - if (ret < 0) { - if (errno != EINTR) { - logger(pamh, LOG_ERR, "writing to SELinux data file " - "failed. %s", tmp_path); - pam_status = PAM_SYSTEM_ERR; - goto done; - } - continue; - } - pos += ret; + + errno = 0; + written = sss_atomic_write_s(fd, pi->selinux_user, len); + if (written == -1) { + ret = errno; + logger(pamh, LOG_ERR, "writing to SELinux data file " + "failed. %s", tmp_path); + pam_status = PAM_SYSTEM_ERR; + goto done; } + + if (written != len) { + logger(pamh, LOG_ERR, "Expected to write %d bytes, wrote %d", + written, len); + goto done; + } + close(fd); rename(tmp_path, path); diff --git a/src/sss_client/ssh/sss_ssh_knownhostsproxy.c b/src/sss_client/ssh/sss_ssh_knownhostsproxy.c index 6424d7b7..e45ef45f 100644 --- a/src/sss_client/ssh/sss_ssh_knownhostsproxy.c +++ b/src/sss_client/ssh/sss_ssh_knownhostsproxy.c @@ -140,11 +140,11 @@ connect_socket(int family, struct sockaddr *addr, size_t addr_len) } errno = 0; - res = sss_atomic_write(i == 0 ? sock : 1, buffer, res); + res = sss_atomic_write_s(i == 0 ? sock : 1, buffer, res); ret = errno; if (res == -1) { DEBUG(SSSDBG_OP_FAILURE, - ("sss_atomic_write() failed (%d): %s\n", + ("sss_atomic_write_s() failed (%d): %s\n", ret, strerror(ret))); goto done; } else if (ret == EPIPE) { |