Skip to content

Commit

Permalink
config: Deprecate 'cmdline' in favour of 'rc'
Browse files Browse the repository at this point in the history
  • Loading branch information
mato committed Dec 16, 2015
1 parent 5aa54e7 commit 699e081
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 56 deletions.
36 changes: 32 additions & 4 deletions app-tools/rumprun
Expand Up @@ -290,6 +290,34 @@ json_finish ()
json_append_ln -b ""
}

json_array ()
{
local a
local sep
local i
a="["
sep=""
for i in "$@"; do
i=$(printf '%s' "$i" | sed -e 's/"/\\\"/g')
a=$(printf '%s%s"%s"' "$a" "$sep" "$i")
sep=,
done
a="$a]"
echo $a
}

json_store_rc ()
{
local bin
local line
bin=$1
shift
read line <<EOM >>${TMPDIR}/json.cfg
"rc": [ { "bin": "${bin}", "argv": $(json_array "$@") } ],
EOM
json_append_ln $line
}

json_store_netspec ()
{

Expand Down Expand Up @@ -559,7 +587,7 @@ run_xen ()
# kernfs is always present on Xen
json_store_kernfs

json_append_ln "\"cmdline\": \""$@"\""
json_store_rc "$@"
[ -n "${opt_name}" ] && json_append_ln "\"hostname\": \""${opt_name}"\""
json_finalize_block
json_finish
Expand Down Expand Up @@ -706,7 +734,7 @@ run_qemu ()
fi
fi

json_append_ln "\"cmdline\": \""$@"\""
json_store_rc "$@"
[ -n "${opt_name}" ] && json_append_ln "\"hostname\": \""${opt_name}"\""
json_finalize_block
json_finish
Expand Down Expand Up @@ -796,7 +824,7 @@ bake_iso ()

[ ! -f ${opt_name} ] || die target ${opt_name} already exists

json_append_ln "\"cmdline\": \""$@"\""
json_store_rc "$@"
[ -n "${opt_name}" ] && json_append_ln "\"hostname\": \""${opt_name}"\""
json_finalize_block
json_finish
Expand Down Expand Up @@ -875,7 +903,7 @@ make_ec2 ()

[ ! -f ${finaldir} ] || die target ${finaldir} already exists

json_append_ln "\"cmdline\": \""$@"\""
json_store_rc "$@"
[ -n "${opt_name}" ] && json_append_ln "\"hostname\": \""${opt_name}"\""
json_finalize_block
json_finish
Expand Down
15 changes: 1 addition & 14 deletions doc/config.md
Expand Up @@ -30,20 +30,7 @@ When configuration is passed directly on the kernel command line (see
platform-specific methods below), everything up to the first `{` character is
not considered to be part of the configuration.

## cmdline, rc: Program invocation

The `cmdline` key specifies the command line for unikernels containing a single
program:

"cmdline": <string>

* _cmdline_: Whitespace-delimited string of arguments passed to the program as
`argv[]`, including `argv[0]`.

_TODO_: Is `cmdline` deprecated entirely in favour of `rc`?

Unikernels which contain more than one program (using multibake) MUST use
the `rc` key to specify command lines for each baked-in program:
## rc: Program invocation

"rc": [
{
Expand Down
47 changes: 9 additions & 38 deletions lib/librumprun_base/config.c
Expand Up @@ -81,43 +81,13 @@ jexpect(enum jtypes t, jvalue *v, const char *loc)
jtypestr(v->d));
}

static void
makeargv(char *argvstr)
{
struct rumprun_exec *rre;
char **argv;
int nargs;

rumprun_parseargs(argvstr, &nargs, 0);
rre = malloc(sizeof(*rre) + (nargs+1) * sizeof(*argv));
if (rre == NULL)
err(1, "could not allocate rre");

rumprun_parseargs(argvstr, &nargs, rre->rre_argv);
rre->rre_argv[nargs] = NULL;
rre->rre_flags = RUMPRUN_EXEC_CMDLINE;
rre->rre_argc = nargs;

TAILQ_INSERT_TAIL(&rumprun_execs, rre, rre_entries);
}

static void
handle_cmdline(jvalue *v, const char *loc)
{

jexpect(jstring, v, __func__);
makeargv(strdup(v->u.s));
}
static struct rumprun_exec
rre_dummy = {
.rre_flags = RUMPRUN_EXEC_CMDLINE,
.rre_argc = 1,
.rre_argv = { NULL, NULL }
};

/*
* "rc": [
* { "bin" : "binname",
* "argv" : [ "arg1", "arg2", ... ], (optional)
* "runmode" : "& OR |" (optional)
* },
* ....
* ]
*/
static void
addbin(jvalue *v, const char *loc)
{
Expand Down Expand Up @@ -555,7 +525,6 @@ struct {
const char *name;
void (*handler)(jvalue *, const char *);
} parsers[] = {
{ "cmdline", handle_cmdline },
{ "rc", handle_rc },
{ "env", handle_env },
{ "hostname", handle_hostname },
Expand Down Expand Up @@ -661,7 +630,9 @@ rumprun_config(char *cmdline)
while (*cmdline != '{') {
if (*cmdline == '\0') {
warnx("could not find start of json. no config?");
makeargv(strdup("rumprun"));
rre_dummy.rre_argv[0] = strdup("rumprun");
TAILQ_INSERT_TAIL(&rumprun_execs, &rre_dummy,
rre_entries);
return;
}
cmdline++;
Expand Down

0 comments on commit 699e081

Please sign in to comment.