Added s_open(), s_close() etc. with EINTR wrappers.
* safeio.c, safeio.h: Added s_open(), s_close() etc. with EINTR wrappers. * procdata.c, procmap.c, proclist.c: Use them.
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
1999-05-08 Drazen Kacar <dave@srce.hr>
|
||||
|
||||
* safeio.c, safeio.h: Added s_open(), s_close() etc. with EINTR
|
||||
wrappers.
|
||||
|
||||
* procdata.c, procmap.c, proclist.c: Use them.
|
||||
|
||||
1999-05-08 Drazen Kacar <dave@srce.hr>
|
||||
|
||||
* procmem.c: Use bytes as units for memory consumption.
|
||||
|
@@ -4,11 +4,12 @@ INCLUDES = @INCLUDES@
|
||||
|
||||
lib_LTLIBRARIES = libgtop_sysdeps.la libgtop_sysdeps_suid.la
|
||||
|
||||
libgtop_sysdeps_la_SOURCES = open.c close.c siglist.c cpu.c mem.c swap.c \
|
||||
uptime.c loadavg.c proclist.c procstate.c procuid.c \
|
||||
proctime.c procmem.c procsignal.c prockernel.c \
|
||||
procsegment.c procargs.c procmap.c netload.c \
|
||||
ppp.c procdata.c
|
||||
libgtop_sysdeps_la_SOURCES = open.c close.c siglist.c cpu.c mem.c \
|
||||
safeio.c swap.c uptime.c loadavg.c \
|
||||
proclist.c procstate.c procuid.c \
|
||||
proctime.c procmem.c procsignal.c \
|
||||
prockernel.c procsegment.c procargs.c \
|
||||
procmap.c netload.c ppp.c procdata.c
|
||||
|
||||
libgtop_sysdeps_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
|
||||
@@ -19,5 +20,5 @@ libgtop_sysdeps_suid_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
|
||||
|
||||
include_HEADERS = glibtop_server.h glibtop_machine.h
|
||||
noinst_HEADERS = glibtop_private.h
|
||||
noinst_HEADERS = glibtop_private.h safeio.h
|
||||
|
||||
|
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "safeio.h"
|
||||
|
||||
/* Read /proc/<pid>/psinfo. */
|
||||
|
||||
int
|
||||
@@ -36,19 +38,21 @@ glibtop_get_proc_data_psinfo_s (glibtop *server, struct psinfo *psinfo, pid_t pi
|
||||
char buffer [BUFSIZ];
|
||||
|
||||
sprintf (buffer, "/proc/%d/psinfo", (int) pid);
|
||||
fd = open (buffer, O_RDONLY);
|
||||
fd = s_open (buffer, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
glibtop_warn_io_r (server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pread (fd, psinfo, sizeof (struct psinfo), 0) != sizeof (struct psinfo)) {
|
||||
close (fd);
|
||||
if (s_pread (fd, psinfo, sizeof (struct psinfo), 0) !=
|
||||
sizeof (struct psinfo))
|
||||
{
|
||||
s_close (fd);
|
||||
glibtop_warn_io_r (server, "pread (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
s_close (fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -59,19 +63,21 @@ glibtop_get_proc_data_usage_s (glibtop *server, struct prusage *prusage, pid_t p
|
||||
char buffer [BUFSIZ];
|
||||
|
||||
sprintf (buffer, "/proc/%d/usage", (int) pid);
|
||||
fd = open (buffer, O_RDONLY);
|
||||
fd = s_open (buffer, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
glibtop_warn_io_r (server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pread (fd, prusage, sizeof (struct prusage), 0) != sizeof (struct prusage)) {
|
||||
close (fd);
|
||||
if (s_pread (fd, prusage, sizeof (struct prusage), 0) !=
|
||||
sizeof (struct prusage))
|
||||
{
|
||||
s_close (fd);
|
||||
glibtop_warn_io_r (server, "pread (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
s_close (fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -86,15 +92,16 @@ glibtop_get_proc_credentials_s(glibtop *server,
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
sprintf(buffer, "/proc/%d/cred", (int)pid);
|
||||
if((fd = open(buffer, O_RDONLY)) < 0)
|
||||
if((fd = s_open(buffer, O_RDONLY)) < 0)
|
||||
{
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r(server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
if(pread(fd, prcred, sizeof(struct prcred), 0) != sizeof(struct prcred))
|
||||
if(s_pread(fd, prcred, sizeof(struct prcred), 0) !=
|
||||
sizeof(struct prcred))
|
||||
{
|
||||
close(fd);
|
||||
s_close(fd);
|
||||
glibtop_warn_io_r(server, "pread (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
@@ -104,11 +111,11 @@ glibtop_get_proc_credentials_s(glibtop *server,
|
||||
toread = prcred->pr_ngroups * sizeof(gid_t);
|
||||
else
|
||||
toread = GLIBTOP_MAX_GROUPS * sizeof(gid_t);
|
||||
if(pread(fd, groups, toread,
|
||||
&(((struct prcred *)0)->pr_groups[0])) != toread)
|
||||
prcred->pr_ngroups = 0;
|
||||
if(s_pread(fd, groups, toread,
|
||||
&(((struct prcred *)0)->pr_groups[0])) != toread)
|
||||
prcred->pr_ngroups = 0;
|
||||
}
|
||||
close(fd);
|
||||
s_close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -119,18 +126,19 @@ glibtop_get_proc_status_s(glibtop *server, struct pstatus *pstatus, pid_t pid)
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
sprintf(buffer, "/proc/%d/status", (int)pid);
|
||||
if((fd = open(buffer, O_RDONLY)) < 0)
|
||||
if((fd = s_open(buffer, O_RDONLY)) < 0)
|
||||
{
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r(server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
if(pread(fd, pstatus, sizeof(struct pstatus), 0) != sizeof(struct pstatus))
|
||||
if(s_pread(fd, pstatus, sizeof(struct pstatus), 0) !=
|
||||
sizeof(struct pstatus))
|
||||
{
|
||||
close(fd);
|
||||
glibtop_warn_io_r(server, "pread (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
s_close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
@@ -92,7 +92,7 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
|
||||
|
||||
sprintf (buffer, "/proc/%d", pid);
|
||||
|
||||
if (stat (buffer, &statb)) continue;
|
||||
if (s_stat (buffer, &statb)) continue;
|
||||
|
||||
if (!S_ISDIR (statb.st_mode)) continue;
|
||||
|
||||
@@ -126,7 +126,7 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
|
||||
total++;
|
||||
}
|
||||
|
||||
closedir (proc);
|
||||
s_closedir (proc);
|
||||
|
||||
/* count is only zero if an error occured (one a running Linux system,
|
||||
* we have at least one single process). */
|
||||
|
@@ -30,6 +30,8 @@
|
||||
#include <errno.h>
|
||||
#include <alloca.h>
|
||||
|
||||
#include "safeio.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_map =
|
||||
(1L << GLIBTOP_PROC_MAP_NUMBER) + (1L << GLIBTOP_PROC_MAP_TOTAL) +
|
||||
(1L << GLIBTOP_PROC_MAP_SIZE);
|
||||
@@ -60,7 +62,7 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
memset (buf, 0, sizeof (glibtop_proc_map));
|
||||
|
||||
sprintf(buffer, "/proc/%d/map", (int)pid);
|
||||
if((fd = open(buffer, O_RDONLY)) < 0)
|
||||
if((fd = s_open(buffer, O_RDONLY)) < 0)
|
||||
{
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r(server, "open (%s)", buffer);
|
||||
@@ -76,7 +78,7 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
}
|
||||
maps = alloca(inode.st_size);
|
||||
nmaps = inode.st_size / sizeof(prmap_t);
|
||||
if(pread(fd, maps, inode.st_size, 0) != inode.st_size)
|
||||
if(s_pread(fd, maps, inode.st_size, 0) != inode.st_size)
|
||||
{
|
||||
glibtop_warn_io_r(server, "pread (%s)", buffer);
|
||||
close(fd);
|
||||
|
84
sysdeps/solaris/safeio.c
Normal file
84
sysdeps/solaris/safeio.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/* Copyright (C) 1999 Drazen Kacar
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Drazen Kacar <dave@srce.hr>, May 1999.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
int
|
||||
s_open(const char *file, int mode)
|
||||
{
|
||||
int fd;
|
||||
|
||||
do {
|
||||
fd = open(file, mode);
|
||||
} while(fd < 0 && errno == EINTR);
|
||||
return fd;
|
||||
}
|
||||
|
||||
int
|
||||
s_stat(const char *path, struct stat *buf)
|
||||
{
|
||||
int status;
|
||||
|
||||
do {
|
||||
status = stat(path, buf);
|
||||
} while(status < 0 && errno == EINTR);
|
||||
return status;
|
||||
}
|
||||
|
||||
int
|
||||
s_close(int fd)
|
||||
{
|
||||
int status;
|
||||
|
||||
do {
|
||||
status = close(fd);
|
||||
} while(status < 0 && errno == EINTR);
|
||||
return status;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
s_pread(int fd, void *buf, size_t nbytes, off_t offset)
|
||||
{
|
||||
ssize_t len;
|
||||
|
||||
/* Now, why doesn't the pread(2) man page say anything about pread()
|
||||
return values? Can it read less bytes than requested? */
|
||||
|
||||
do {
|
||||
len = pread(fd, buf, nbytes, offset);
|
||||
} while(len < 0 && errno == EINTR);
|
||||
return len;
|
||||
}
|
||||
|
||||
int s_closedir(DIR *dirp)
|
||||
{
|
||||
int status;
|
||||
|
||||
do {
|
||||
status = closedir(dirp);
|
||||
} while(status < 0 && errno == EINTR);
|
||||
return status;
|
||||
}
|
48
sysdeps/solaris/safeio.h
Normal file
48
sysdeps/solaris/safeio.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* Copyright (C) 1999 Drazen Kacar
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Drazen Kacar <dave@srce.hr>, May 1999.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_SAFEIO_H__
|
||||
#define __GLIBTOP_SAFEIO_H__
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
int
|
||||
s_open(const char *, int);
|
||||
|
||||
int
|
||||
s_stat(const char *, struct stat *);
|
||||
|
||||
int
|
||||
s_close(int);
|
||||
|
||||
ssize_t
|
||||
s_pread(int, void *, size_t, off_t);
|
||||
|
||||
int
|
||||
s_closedir(DIR *);
|
||||
|
||||
END_LIBGTOP_DECLS
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user