What happens if a linux kernel argument is passed twice with different values?

As the question states, what if I pass

kernel /vmlinuz audit=1 audit=0

Will auditing enabled or disabled? Or will the kernel just freak out? Or is it undefined and will depend on the build of the kernel/argument being passed?


Solution 1:

Well, looking at the Vanilla code in linux/kernel/params.c and the parse_one function (for v3.2.6) I would assume that audit=0 would be the version used by the kernel as its the last one in the list.

static int parse_one(char *param,
                   char *val,
                   const struct kernel_param *params,
                   unsigned num_params,
                   int (*handle_unknown)(char *param, char *val))   {
     unsigned int i;
     int err;

     /* Find parameter */
     for (i = 0; i < num_params; i++) {
             if (parameq(param, params[i].name)) {
                     /* No one handled NULL, so do it here. */
                     if (!val && params[i].ops->set != param_set_bool)
                             return -EINVAL;
                     DEBUGP("They are equal!  Calling %p\n",
                            params[i].ops->set);
                     mutex_lock(&param_lock);
                     err = params[i].ops->set(val, &params[i]);
                     mutex_unlock(&param_lock);
                     return err;
             }
     }

     if (handle_unknown) {
             DEBUGP("Unknown argument: calling %p\n", handle_unknown);
             return handle_unknown(param, val);
     }

     DEBUGP("Unknown argument `%s'\n", param);
     return -ENOENT;  }

I am not near a GNU/Linux machine to verify this right now, and it would also depend on patches done by the distributor of your kernel.