Philipp Rudo 9e3d3b
 commit 193e51deccc62544f6423eb5e5eefc8a23aad679
Philipp Rudo 9e3d3b
 Author: Sven Schnelle <svens@linux.ibm.com>
Philipp Rudo 9e3d3b
 Date:   Thu Dec 16 12:43:54 2021 +0100
Philipp Rudo 9e3d3b
 
Philipp Rudo 9e3d3b
     add slurp_proc_file()
Philipp Rudo 9e3d3b
     
Philipp Rudo 9e3d3b
     slurp_file() cannot be used to read proc files, as they are returning
Philipp Rudo 9e3d3b
     a size of zero in stat(). Add a function slurp_proc_file() which is
Philipp Rudo 9e3d3b
     similar to slurp_file(), but doesn't require the size of the file to
Philipp Rudo 9e3d3b
     be known.
Philipp Rudo 9e3d3b
     
Philipp Rudo 9e3d3b
     Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Philipp Rudo 9e3d3b
     Signed-off-by: Simon Horman <horms@verge.net.au>
Philipp Rudo 9e3d3b
 
Philipp Rudo 9e3d3b
 diff --git a/kexec/kexec.c b/kexec/kexec.c
Philipp Rudo 9e3d3b
 index f63b36b771eb95a93f07a7c286c4974a558aec8d..f3adac517161d448552a16fd79488c1df100d356 100644
Philipp Rudo 9e3d3b
 --- a/kexec/kexec.c
Philipp Rudo 9e3d3b
 +++ b/kexec/kexec.c
Philipp Rudo 9e3d3b
 @@ -1106,6 +1106,57 @@ static void remove_parameter(char *line, const char *param_name)
Philipp Rudo 9e3d3b
  	}
Philipp Rudo 9e3d3b
  }
Philipp Rudo 9e3d3b
  
Philipp Rudo 9e3d3b
 +static ssize_t _read(int fd, void *buf, size_t count)
Philipp Rudo 9e3d3b
 +{
Philipp Rudo 9e3d3b
 +	ssize_t ret, offset = 0;
Philipp Rudo 9e3d3b
 +
Philipp Rudo 9e3d3b
 +	do {
Philipp Rudo 9e3d3b
 +		ret = read(fd, buf + offset, count - offset);
Philipp Rudo 9e3d3b
 +		if (ret < 0) {
Philipp Rudo 9e3d3b
 +			if ((errno == EINTR) ||	(errno == EAGAIN))
Philipp Rudo 9e3d3b
 +				continue;
Philipp Rudo 9e3d3b
 +			return ret;
Philipp Rudo 9e3d3b
 +		}
Philipp Rudo 9e3d3b
 +		offset += ret;
Philipp Rudo 9e3d3b
 +	} while (ret && offset < count);
Philipp Rudo 9e3d3b
 +
Philipp Rudo 9e3d3b
 +	return offset;
Philipp Rudo 9e3d3b
 +}
Philipp Rudo 9e3d3b
 +
Philipp Rudo 9e3d3b
 +static char *slurp_proc_file(const char *filename, size_t *len)
Philipp Rudo 9e3d3b
 +{
Philipp Rudo 9e3d3b
 +	ssize_t ret, startpos = 0;
Philipp Rudo 9e3d3b
 +	unsigned int size = 64;
Philipp Rudo 9e3d3b
 +	char *buf = NULL, *tmp;
Philipp Rudo 9e3d3b
 +	int fd;
Philipp Rudo 9e3d3b
 +
Philipp Rudo 9e3d3b
 +	fd = open(filename, O_RDONLY);
Philipp Rudo 9e3d3b
 +	if (fd == -1)
Philipp Rudo 9e3d3b
 +		return NULL;
Philipp Rudo 9e3d3b
 +
Philipp Rudo 9e3d3b
 +	do {
Philipp Rudo 9e3d3b
 +		size *= 2;
Philipp Rudo 9e3d3b
 +		tmp = realloc(buf, size);
Philipp Rudo 9e3d3b
 +		if (!tmp) {
Philipp Rudo 9e3d3b
 +			free(buf);
Philipp Rudo 9e3d3b
 +			return NULL;
Philipp Rudo 9e3d3b
 +		}
Philipp Rudo 9e3d3b
 +		buf = tmp;
Philipp Rudo 9e3d3b
 +
Philipp Rudo 9e3d3b
 +		ret = _read(fd, buf + startpos, size - startpos);
Philipp Rudo 9e3d3b
 +		if (ret < 0) {
Philipp Rudo 9e3d3b
 +			free(buf);
Philipp Rudo 9e3d3b
 +			return NULL;
Philipp Rudo 9e3d3b
 +		}
Philipp Rudo 9e3d3b
 +
Philipp Rudo 9e3d3b
 +		startpos += ret;
Philipp Rudo 9e3d3b
 +
Philipp Rudo 9e3d3b
 +	} while(ret);
Philipp Rudo 9e3d3b
 +
Philipp Rudo 9e3d3b
 +	*len = startpos;
Philipp Rudo 9e3d3b
 +	return buf;
Philipp Rudo 9e3d3b
 +}
Philipp Rudo 9e3d3b
 +
Philipp Rudo 9e3d3b
  /*
Philipp Rudo 9e3d3b
   * Returns the contents of the current command line to be used with
Philipp Rudo 9e3d3b
   * --reuse-cmdline option.  The function gets called from architecture specific