1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00

Test return value from read() and close() for an error.

This commit is contained in:
Zdenek Kabelac 2010-12-20 13:16:30 +00:00
parent 1ea4c6d449
commit b3cb194c03

View File

@ -1191,15 +1191,19 @@ static const char *_get_cmdline(pid_t pid)
{
static char _proc_cmdline[32];
char buf[256];
int fd;
int fd, n = 0;
snprintf(buf, sizeof(buf), DEFAULT_PROC_DIR "/%u/cmdline", pid);
/* FIXME Use generic read code. */
if ((fd = open(buf, O_RDONLY)) > 0) {
read(fd, _proc_cmdline, sizeof(_proc_cmdline) - 1);
_proc_cmdline[sizeof(_proc_cmdline) - 1] = '\0';
close(fd);
} else
_proc_cmdline[0] = '\0';
if ((n = read(fd, _proc_cmdline, sizeof(_proc_cmdline) - 1)) < 0) {
log_sys_error("read", buf);
n = 0;
}
if (close(fd))
log_sys_error("close", buf);
}
_proc_cmdline[n] = '\0';
return _proc_cmdline;
}