diff --git a/proc/meminfo.c b/proc/meminfo.c index 7ab1cc9e..6cfe808c 100644 --- a/proc/meminfo.c +++ b/proc/meminfo.c @@ -110,9 +110,16 @@ PROCPS_EXPORT int procps_meminfo_read ( if (lseek(info->meminfo_fd, 0L, SEEK_SET) == -1) { return -errno; } - if ((size = read(info->meminfo_fd, buf, sizeof(buf)-1)) < 0) { - return -1; + for (;;) { + if ((size = read(info->meminfo_fd, buf, sizeof(buf)-1)) < 0) { + if (errno == EINTR || errno == EAGAIN) + continue; + return -errno; + } + break; } + if (size == 0) + return 0; buf[size] = '\0'; /* Scan the file */ @@ -219,11 +226,11 @@ PROCPS_EXPORT struct procps_meminfo *procps_meminfo_ref ( PROCPS_EXPORT struct procps_meminfo *procps_meminfo_unref ( struct procps_meminfo *info) { - if (info == NULL) + if (info == NULL || info->refcount == 0) return NULL; info->refcount--; if (info->refcount > 0) - return NULL; + return info; free(info); return NULL; } diff --git a/proc/readstat.c b/proc/readstat.c index c8873e77..16322ad3 100644 --- a/proc/readstat.c +++ b/proc/readstat.c @@ -90,9 +90,16 @@ PROCPS_EXPORT int procps_stat_read ( if (lseek(info->stat_fd, 0L, SEEK_SET) == -1) { return -errno; } - if ((size = read(info->stat_fd, buf, sizeof(buf)-1)) < 0) { - return -1; + for (;;) { + if ((size = read(info->stat_fd, buf, sizeof(buf)-1)) < 0) { + if (errno == EINTR || errno == EAGAIN) + continue; + return -errno; + } + break; } + if (size == 0) + return 0; buf[size] = '\0'; /* Scan the file */ @@ -155,11 +162,11 @@ PROCPS_EXPORT struct procps_statinfo *procps_stat_ref ( PROCPS_EXPORT struct procps_statinfo *procps_stat_unref ( struct procps_statinfo *info) { - if (info == NULL) + if (info == NULL || info->refcount == 0) return NULL; info->refcount--; if (info->refcount > 0) - return NULL; + return info; free(info); return NULL; } diff --git a/proc/vmstat.c b/proc/vmstat.c index 8f9f1f6f..953c8b6a 100644 --- a/proc/vmstat.c +++ b/proc/vmstat.c @@ -83,9 +83,16 @@ PROCPS_EXPORT int procps_vmstat_read ( if (lseek(info->vmstat_fd, 0L, SEEK_SET) == -1) { return -errno; } - if ((size = read(info->vmstat_fd, buf, sizeof(buf)-1)) < 0) { - return -1; + for (;;) { + if ((size = read(info->vmstat_fd, buf, sizeof(buf)-1)) < 0) { + if (errno == EINTR || errno == EAGAIN) + continue; + return -errno; + } + break; } + if (size == 0) + return 0; buf[size] = '\0'; /* Scan the file */ @@ -130,11 +137,11 @@ PROCPS_EXPORT struct procps_vmstat *procps_vmstat_ref ( PROCPS_EXPORT struct procps_vmstat *procps_vmstat_unref ( struct procps_vmstat *info) { - if (info == NULL) + if (info == NULL || info->refcount == 0) return NULL; info->refcount--; if (info->refcount > 0) - return NULL; + return info; free(info); return NULL; }