summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2013-10-09 20:04:40 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2013-10-09 20:04:40 +0000
commitafe2f1fed184040ce1e9c9fdc5714d90dec8c91e (patch)
tree5f0fdcc9748f5a708d209044da465980e76c93cb
parent7884dce5d51b889fc93398546431e8667dc9f687 (diff)
Fix parse_args() to ignore device specification and correctly append the
default kernel name if only a boot device is specified. This makes boot paths like "sd()" auto-boot without asking for a kernel name.
-rw-r--r--sys/arch/aviion/stand/libsa/parse_args.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/sys/arch/aviion/stand/libsa/parse_args.c b/sys/arch/aviion/stand/libsa/parse_args.c
index f13086075b5..d004ee7bdc0 100644
--- a/sys/arch/aviion/stand/libsa/parse_args.c
+++ b/sys/arch/aviion/stand/libsa/parse_args.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse_args.c,v 1.3 2013/10/08 21:55:22 miod Exp $ */
+/* $OpenBSD: parse_args.c,v 1.4 2013/10/09 20:04:39 miod Exp $ */
/*-
* Copyright (c) 1995 Theo de Raadt
@@ -54,7 +54,7 @@ stws(const char *p)
int
parse_args(const char *line, char **filep, int first)
{
- const char *p;
+ const char *po, *pc, *p;
char *name;
size_t namelen;
@@ -64,14 +64,40 @@ parse_args(const char *line, char **filep, int first)
return (1);
}
+ /* skip boot device; up to two nested foo(...) constructs */
+ p = line;
+ po = strchr(line, '(');
+ if (po != NULL) {
+ pc = strchr(po + 1, ')');
+ if (pc != NULL) {
+ p = strchr(po + 1, '(');
+ if (p == NULL || pc < p)
+ p = pc + 1;
+ else if (pc != NULL) {
+ p = strchr(pc + 1, ')');
+ if (p != NULL)
+ p = p + 1;
+ else
+ p = line;
+ }
+ }
+ }
+
/* figure out how long the kernel name is */
- for (p = line; *p != '\0' && *p != ' '; p++) ;
- namelen = p - line;
+ pc = strchr(p, ' ');
+ if (pc == NULL)
+ pc = p + strlen(p);
- /* empty, use the default */
- if (namelen == 0)
- name = KERNEL_NAME;
- else {
+ if (p == pc) {
+ /* empty, use the default kernel name */
+ namelen = 1 + (p - line) + strlen(KERNEL_NAME);
+ name = (char *)alloc(namelen);
+ if (name == NULL)
+ panic("out of memory");
+ memcpy(name, line, p - line);
+ memcpy(name + (p - line), KERNEL_NAME, sizeof(KERNEL_NAME));
+ } else {
+ namelen = pc - line;
name = (char *)alloc(1 + namelen);
if (name == NULL)
panic("out of memory");