start_stop_daemon: fix bug where any program name was "matching"
processes for which readlink(/proc/N/exe) fails
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user