add slurp_proc_file()
Resolves: bz2060824 Upstream: git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git Conflicts: None commit 193e51deccc62544f6423eb5e5eefc8a23aad679 Author: Sven Schnelle <svens@linux.ibm.com> Date: Thu Dec 16 12:43:54 2021 +0100 add slurp_proc_file() slurp_file() cannot be used to read proc files, as they are returning a size of zero in stat(). Add a function slurp_proc_file() which is similar to slurp_file(), but doesn't require the size of the file to be known. Signed-off-by: Sven Schnelle <svens@linux.ibm.com> Signed-off-by: Simon Horman <horms@verge.net.au> Signed-off-by: Philipp Rudo <prudo@redhat.com>
This commit is contained in:
parent
f8e3f42ec1
commit
9e3d3bc043
76
kexec-tools-2.0.23-03-add_slurp_proc_file_.patch
Normal file
76
kexec-tools-2.0.23-03-add_slurp_proc_file_.patch
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
commit 193e51deccc62544f6423eb5e5eefc8a23aad679
|
||||||
|
Author: Sven Schnelle <svens@linux.ibm.com>
|
||||||
|
Date: Thu Dec 16 12:43:54 2021 +0100
|
||||||
|
|
||||||
|
add slurp_proc_file()
|
||||||
|
|
||||||
|
slurp_file() cannot be used to read proc files, as they are returning
|
||||||
|
a size of zero in stat(). Add a function slurp_proc_file() which is
|
||||||
|
similar to slurp_file(), but doesn't require the size of the file to
|
||||||
|
be known.
|
||||||
|
|
||||||
|
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
|
||||||
|
Signed-off-by: Simon Horman <horms@verge.net.au>
|
||||||
|
|
||||||
|
diff --git a/kexec/kexec.c b/kexec/kexec.c
|
||||||
|
index f63b36b771eb95a93f07a7c286c4974a558aec8d..f3adac517161d448552a16fd79488c1df100d356 100644
|
||||||
|
--- a/kexec/kexec.c
|
||||||
|
+++ b/kexec/kexec.c
|
||||||
|
@@ -1106,6 +1106,57 @@ static void remove_parameter(char *line, const char *param_name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+static ssize_t _read(int fd, void *buf, size_t count)
|
||||||
|
+{
|
||||||
|
+ ssize_t ret, offset = 0;
|
||||||
|
+
|
||||||
|
+ do {
|
||||||
|
+ ret = read(fd, buf + offset, count - offset);
|
||||||
|
+ if (ret < 0) {
|
||||||
|
+ if ((errno == EINTR) || (errno == EAGAIN))
|
||||||
|
+ continue;
|
||||||
|
+ return ret;
|
||||||
|
+ }
|
||||||
|
+ offset += ret;
|
||||||
|
+ } while (ret && offset < count);
|
||||||
|
+
|
||||||
|
+ return offset;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static char *slurp_proc_file(const char *filename, size_t *len)
|
||||||
|
+{
|
||||||
|
+ ssize_t ret, startpos = 0;
|
||||||
|
+ unsigned int size = 64;
|
||||||
|
+ char *buf = NULL, *tmp;
|
||||||
|
+ int fd;
|
||||||
|
+
|
||||||
|
+ fd = open(filename, O_RDONLY);
|
||||||
|
+ if (fd == -1)
|
||||||
|
+ return NULL;
|
||||||
|
+
|
||||||
|
+ do {
|
||||||
|
+ size *= 2;
|
||||||
|
+ tmp = realloc(buf, size);
|
||||||
|
+ if (!tmp) {
|
||||||
|
+ free(buf);
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
+ buf = tmp;
|
||||||
|
+
|
||||||
|
+ ret = _read(fd, buf + startpos, size - startpos);
|
||||||
|
+ if (ret < 0) {
|
||||||
|
+ free(buf);
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ startpos += ret;
|
||||||
|
+
|
||||||
|
+ } while(ret);
|
||||||
|
+
|
||||||
|
+ *len = startpos;
|
||||||
|
+ return buf;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
/*
|
||||||
|
* Returns the contents of the current command line to be used with
|
||||||
|
* --reuse-cmdline option. The function gets called from architecture specific
|
@ -106,6 +106,7 @@ Requires: systemd-udev%{?_isa}
|
|||||||
#
|
#
|
||||||
Patch401: ./kexec-tools-2.0.23-01-s390_add_variable_command_line_size.patch
|
Patch401: ./kexec-tools-2.0.23-01-s390_add_variable_command_line_size.patch
|
||||||
Patch402: ./kexec-tools-2.0.23-02-s390_use_KEXEC_ALL_OPTIONS.patch
|
Patch402: ./kexec-tools-2.0.23-02-s390_use_KEXEC_ALL_OPTIONS.patch
|
||||||
|
Patch403: ./kexec-tools-2.0.23-03-add_slurp_proc_file_.patch
|
||||||
|
|
||||||
#
|
#
|
||||||
# Patches 501 through 600 are meant for ARM kexec-tools enablement
|
# Patches 501 through 600 are meant for ARM kexec-tools enablement
|
||||||
@ -138,6 +139,7 @@ tar -z -x -v -f %{SOURCE19}
|
|||||||
|
|
||||||
%patch401 -p1
|
%patch401 -p1
|
||||||
%patch402 -p1
|
%patch402 -p1
|
||||||
|
%patch403 -p1
|
||||||
%patch601 -p1
|
%patch601 -p1
|
||||||
%patch602 -p1
|
%patch602 -p1
|
||||||
%patch603 -p1
|
%patch603 -p1
|
||||||
|
Loading…
Reference in New Issue
Block a user