Fix lxc_attach argument parsing

This commit is contained in:
Andre Nathan 2013-12-05 16:36:29 -02:00
parent 1e4f1802bd
commit 2d86d77cd4

120
ext/lxc.c
View file

@ -284,65 +284,89 @@ lxc_attach_parse_options(VALUE rb_opts)
return opts; return opts;
rb_attach_flags = rb_hash_aref(rb_opts, SYMBOL("flags")); rb_attach_flags = rb_hash_aref(rb_opts, SYMBOL("flags"));
if (is_integer(rb_attach_flags)) if (!NIL_P(rb_attach_flags)) {
opts->attach_flags = NUM2INT(rb_attach_flags); if (is_integer(rb_attach_flags))
else opts->attach_flags = NUM2INT(rb_attach_flags);
goto err; else
goto err;
}
rb_namespaces = rb_hash_aref(rb_opts, SYMBOL("namespaces")); rb_namespaces = rb_hash_aref(rb_opts, SYMBOL("namespaces"));
if (is_integer(rb_namespaces)) if (!NIL_P(rb_namespaces)) {
opts->namespaces = NUM2INT(rb_namespaces); if (is_integer(rb_namespaces))
else opts->namespaces = NUM2INT(rb_namespaces);
goto err; else
goto err;
}
rb_personality = rb_hash_aref(rb_opts, SYMBOL("personality")); rb_personality = rb_hash_aref(rb_opts, SYMBOL("personality"));
if (is_integer(rb_personality)) if (!NIL_P(rb_personality)) {
opts->personality = NUM2INT(rb_personality); if (is_integer(rb_personality))
else opts->personality = NUM2INT(rb_personality);
goto err; else
goto err;
}
rb_initial_cwd = rb_hash_aref(rb_opts, SYMBOL("initial_cwd")); rb_initial_cwd = rb_hash_aref(rb_opts, SYMBOL("initial_cwd"));
if (is_string(rb_initial_cwd)) if (!NIL_P(rb_initial_cwd)) {
opts->initial_cwd = StringValuePtr(rb_initial_cwd); if (is_string(rb_initial_cwd))
else opts->initial_cwd = StringValuePtr(rb_initial_cwd);
goto err; else
goto err;
}
rb_uid = rb_hash_aref(rb_opts, SYMBOL("uid")); rb_uid = rb_hash_aref(rb_opts, SYMBOL("uid"));
if (is_integer(rb_uid)) if (!NIL_P(rb_uid)) {
opts->uid = NUM2INT(rb_uid); if (is_integer(rb_uid))
else opts->uid = NUM2INT(rb_uid);
goto err; else
goto err;
}
rb_gid = rb_hash_aref(rb_opts, SYMBOL("gid")); rb_gid = rb_hash_aref(rb_opts, SYMBOL("gid"));
if (is_integer(rb_gid)) if (!NIL_P(rb_gid)) {
opts->gid = NUM2INT(rb_gid); if (is_integer(rb_gid))
else opts->gid = NUM2INT(rb_gid);
goto err; else
goto err;
}
rb_env_policy = rb_hash_aref(rb_opts, SYMBOL("env_policy")); rb_env_policy = rb_hash_aref(rb_opts, SYMBOL("env_policy"));
if (is_integer(rb_env_policy)) if (!NIL_P(rb_env_policy)) {
opts->env_policy = NUM2INT(rb_env_policy); if (is_integer(rb_env_policy))
else opts->env_policy = NUM2INT(rb_env_policy);
goto err; else
goto err;
}
rb_extra_env_vars = rb_hash_aref(rb_opts, SYMBOL("extra_env_vars")); rb_extra_env_vars = rb_hash_aref(rb_opts, SYMBOL("extra_env_vars"));
if (is_string_array(rb_extra_env_vars)) if (!NIL_P(rb_extra_env_vars)) {
opts->extra_env_vars = ruby_to_c_string_array(rb_extra_env_vars); if (is_string_array(rb_extra_env_vars))
else opts->extra_env_vars = ruby_to_c_string_array(rb_extra_env_vars);
goto err; else
goto err;
}
rb_extra_keep_env = rb_hash_aref(rb_opts, SYMBOL("extra_keep_env")); rb_extra_keep_env = rb_hash_aref(rb_opts, SYMBOL("extra_keep_env"));
if (is_string_array(rb_extra_keep_env)) if (!NIL_P(rb_extra_keep_env)) {
opts->extra_keep_env = ruby_to_c_string_array(rb_extra_keep_env); if (is_string_array(rb_extra_keep_env))
else opts->extra_keep_env = ruby_to_c_string_array(rb_extra_keep_env);
goto err; else
goto err;
}
rb_stdin = rb_hash_aref(rb_opts, SYMBOL("stdin")); rb_stdin = rb_hash_aref(rb_opts, SYMBOL("stdin"));
if (is_io(rb_stdin)) if (!NIL_P(rb_stdin)) {
opts->stdin_fd = io_fileno(rb_stdin); if (is_io(rb_stdin))
else opts->stdin_fd = io_fileno(rb_stdin);
goto err; else
goto err;
}
rb_stdout = rb_hash_aref(rb_opts, SYMBOL("stdout")); rb_stdout = rb_hash_aref(rb_opts, SYMBOL("stdout"));
if (is_io(rb_stdout)) if (!NIL_P(rb_stdout)) {
opts->stdout_fd = io_fileno(rb_stdout); if (is_io(rb_stdout))
else opts->stdout_fd = io_fileno(rb_stdout);
goto err; else
goto err;
}
rb_stderr = rb_hash_aref(rb_opts, SYMBOL("stderr")); rb_stderr = rb_hash_aref(rb_opts, SYMBOL("stderr"));
if (is_io(rb_stderr)) if (!NIL_P(rb_stderr)) {
opts->stderr_fd = io_fileno(rb_stderr); if (is_io(rb_stderr))
else opts->stderr_fd = io_fileno(rb_stderr);
goto err; else
goto err;
}
return opts; return opts;