* A set to functions to fill struct image args. * * NOTE: exec_args_add_fname() must be called (possibly with a NULL * fname) before the other functions. All exec_args_add_arg() calls must * be made before any exec_args_add_env() calls. exec_args_adjust_args() * may be called any time after exec_args_add_fname(). * * exec_args_add_fname() - install path to be executed * exec_args_add_arg
| 1435 | * allow new arguments to be prepended |
| 1436 | */ |
| 1437 | int |
| 1438 | exec_args_add_fname(struct image_args *args, const char *fname, |
| 1439 | enum uio_seg segflg) |
| 1440 | { |
| 1441 | int error; |
| 1442 | size_t length; |
| 1443 | |
| 1444 | KASSERT(args->fname == NULL, ("fname already appended")); |
| 1445 | KASSERT(args->endp == NULL, ("already appending to args")); |
| 1446 | |
| 1447 | if (fname != NULL) { |
| 1448 | args->fname = args->buf; |
| 1449 | error = segflg == UIO_SYSSPACE ? |
| 1450 | copystr(fname, args->fname, PATH_MAX, &length) : |
| 1451 | copyinstr(fname, args->fname, PATH_MAX, &length); |
| 1452 | if (error != 0) |
| 1453 | return (error == ENAMETOOLONG ? E2BIG : error); |
| 1454 | } else |
| 1455 | length = 0; |
| 1456 | |
| 1457 | /* Set up for _arg_*()/_env_*() */ |
| 1458 | args->endp = args->buf + length; |
| 1459 | /* begin_argv must be set and kept updated */ |
| 1460 | args->begin_argv = args->endp; |
| 1461 | KASSERT(exec_map_entry_size - length >= ARG_MAX, |
| 1462 | ("too little space remaining for arguments %zu < %zu", |
| 1463 | exec_map_entry_size - length, (size_t)ARG_MAX)); |
| 1464 | args->stringspace = ARG_MAX; |
| 1465 | |
| 1466 | return (0); |
| 1467 | } |
| 1468 | |
| 1469 | static int |
| 1470 | exec_args_add_str(struct image_args *args, const char *str, |
no test coverage detected