summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Schnelle <svens@linux.ibm.com>2021-12-16 12:43:55 +0100
committerSimon Horman <horms@verge.net.au>2022-01-14 16:02:15 +0100
commitd6516ba4c88f217fe14455db92c60cd0e9af18f8 (patch)
tree1483881e2576da7e1325089b16b9782cfa4cb7d4
parent193e51deccc62544f6423eb5e5eefc8a23aad679 (diff)
downloadkexec-tools-d6516ba4c88f217fe14455db92c60cd0e9af18f8.tar.gz
use slurp_proc_file() in get_command_line()
This way the size of the command line that get_command_line() can handle is no longer fixed. Signed-off-by: Sven Schnelle <svens@linux.ibm.com> Signed-off-by: Simon Horman <horms@verge.net.au>
-rw-r--r--kexec/kexec.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/kexec/kexec.c b/kexec/kexec.c
index f3adac5..7e4787b 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -1172,25 +1172,19 @@ static char *slurp_proc_file(const char *filename, size_t *len)
*/
char *get_command_line(void)
{
- FILE *fp;
- char *line;
- const int sizeof_line = 2048;
-
- line = malloc(sizeof_line);
- if (line == NULL)
- die("Could not allocate memory to read /proc/cmdline.");
-
- fp = fopen("/proc/cmdline", "r");
- if (!fp)
- die("Could not open /proc/cmdline.");
-
- if (fgets(line, sizeof_line, fp) == NULL)
- die("Can't read /proc/cmdline.");
+ char *p, *line;
+ size_t size;
- fclose(fp);
+ line = slurp_proc_file("/proc/cmdline", &size);
+ if (!line || !size)
+ die("Failed to read /proc/cmdline\n");
/* strip newline */
- line[strlen(line) - 1] = '\0';
+ line[size-1] = '\0';
+
+ p = strpbrk(line, "\r\n");
+ if (p)
+ *p = '\0';
remove_parameter(line, "BOOT_IMAGE");
if (kexec_flags & KEXEC_ON_CRASH)