start_stop_daemon: fix bug where any program name was "matching"

processes for which readlink(/proc/N/exe) fails
This commit is contained in:
Denis Vlasenko
2006-12-17 17:30:01 +00:00
parent 7cdc54ff59
commit b131b271a0
2 changed files with 39 additions and 29 deletions

View File

@@ -118,16 +118,19 @@ void *xmalloc_open_read_close(const char *filename, size_t *sizep)
char *buf;
size_t size = sizep ? *sizep : INT_MAX;
int fd = xopen(filename, O_RDONLY);
off_t len = xlseek(fd, 0, SEEK_END);
/* /proc/N/stat files report len 0 here */
/* In order to make such files readable, we add small const */
off_t len = xlseek(fd, 0, SEEK_END) + 256;
xlseek(fd, 0, SEEK_SET);
if (len > size)
bb_error_msg_and_die("file '%s' is too big", filename);
size = len;
buf = xmalloc(size+1);
buf = xmalloc(size + 1);
size = read_close(fd, buf, size);
if ((ssize_t)size < 0)
bb_perror_msg_and_die("'%s'", filename);
xrealloc(buf, size + 1);
buf[size] = '\0';
if (sizep) *sizep = size;
return buf;