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/monitor | |
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/monitor')
-rw-r--r-- | src/monitor/monitor.c | 41 | ||||
-rw-r--r-- | src/monitor/monitor_netlink.c | 20 |
2 files changed, 29 insertions, 32 deletions
diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c index cadc27fe..041f576e 100644 --- a/src/monitor/monitor.c +++ b/src/monitor/monitor.c @@ -1498,11 +1498,12 @@ static void process_config_file(struct tevent_context *ev, struct inotify_event *in_event; char *buf; char *name; - ssize_t len, total_len; + ssize_t len; ssize_t event_size; struct config_file_ctx *file_ctx; struct config_file_callback *cb; struct rewatch_ctx *rw_ctx; + errno_t ret; event_size = sizeof(struct inotify_event); file_ctx = talloc_get_type(ptr, struct config_file_ctx); @@ -1517,16 +1518,14 @@ static void process_config_file(struct tevent_context *ev, goto done; } - total_len = 0; - while (total_len < event_size) { - len = read(file_ctx->mt_ctx->inotify_fd, buf+total_len, - event_size-total_len); - if (len == -1) { - if (errno == EINTR || errno == EAGAIN) continue; - DEBUG(0, ("Critical error reading inotify file descriptor.\n")); - goto done; - } - total_len += len; + errno = 0; + len = sss_atomic_read_s(file_ctx->mt_ctx->inotify_fd, buf, event_size); + if (len == -1) { + ret = errno; + DEBUG(SSSDBG_CRIT_FAILURE, + ("Critical error reading inotify file descriptor [%d]: %s\n", + ret, strerror(ret))); + goto done; } in_event = (struct inotify_event *)buf; @@ -1535,19 +1534,19 @@ static void process_config_file(struct tevent_context *ev, /* Read in the name, even though we don't use it, * so that read ptr is in the right place */ - name = talloc_size(tmp_ctx, len); + name = talloc_size(tmp_ctx, in_event->len); if (!name) { goto done; } - total_len = 0; - while (total_len < in_event->len) { - len = read(file_ctx->mt_ctx->inotify_fd, &name, in_event->len); - if (len == -1) { - if (errno == EINTR || errno == EAGAIN) continue; - DEBUG(0, ("Critical error reading inotify file descriptor.\n")); - goto done; - } - total_len += len; + + errno = 0; + len = sss_atomic_read_s(file_ctx->mt_ctx->inotify_fd, name, in_event->len); + if (len == -1) { + ret = errno; + DEBUG(SSSDBG_CRIT_FAILURE, + ("Critical error reading inotify file descriptor [%d]: %s\n", + ret, strerror(ret))); + goto done; } } diff --git a/src/monitor/monitor_netlink.c b/src/monitor/monitor_netlink.c index 2fe380ac..3842c4f1 100644 --- a/src/monitor/monitor_netlink.c +++ b/src/monitor/monitor_netlink.c @@ -153,19 +153,17 @@ static bool has_ethernet_encapsulation(const char *sysfs_path) } memset(buf, 0, BUFSIZE); - while ((ret = read(fd, buf, BUFSIZE)) != 0) { - if (ret == -1) { - ret = errno; - if (ret == EINTR || ret == EAGAIN) { - continue; - } - DEBUG(SSSDBG_OP_FAILURE, - ("read failed [%d][%s].\n", ret, strerror(ret))); - close(fd); - return false; - } + errno = 0; + ret = sss_atomic_read_s(fd, buf, BUFSIZE); + if (ret == -1) { + ret = errno; + DEBUG(SSSDBG_OP_FAILURE, + ("read failed [%d][%s].\n", ret, strerror(ret))); + close(fd); + return false; } close(fd); + buf[BUFSIZE-1] = '\0'; return strncmp(buf, "1\n", BUFSIZE) == 0; } |