[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Minios-devel] [UNIKRAFT PATCH v2 1/2] lib/posix-process: Add more process creation functions



Reviewed-by: Stefan Teodorescu <stefanl.teodorescu@xxxxxxxxx>

On Thu, Nov 28, 2019 at 4:39 PM Costin Lupu <costin.lupu@xxxxxxxxx> wrote:
>
> ... such as vfork() and other members of exec*() family. We also add the
> declarations for nolibc.
>
> Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
> ---
>  lib/nolibc/include/stdlib.h |   4 ++
>  lib/nolibc/include/unistd.h |  15 +++++
>  lib/posix-process/process.c | 118 ++++++++++++++++++++++++++++--------
>  3 files changed, 113 insertions(+), 24 deletions(-)
>
> diff --git a/lib/nolibc/include/stdlib.h b/lib/nolibc/include/stdlib.h
> index 28718153..02dd8500 100644
> --- a/lib/nolibc/include/stdlib.h
> +++ b/lib/nolibc/include/stdlib.h
> @@ -86,6 +86,10 @@ int posix_memalign(void **memptr, size_t align, size_t 
> size);
>  void *memalign(size_t align, size_t size);
>  #endif /* CONFIG_LIBUKALLOC */
>
> +#if CONFIG_LIBPOSIX_PROCESS
> +int system(const char *command);
> +#endif
> +
>  #ifdef __cplusplus
>  }
>  #endif
> diff --git a/lib/nolibc/include/unistd.h b/lib/nolibc/include/unistd.h
> index 96cce34d..56a472ce 100644
> --- a/lib/nolibc/include/unistd.h
> +++ b/lib/nolibc/include/unistd.h
> @@ -60,6 +60,21 @@ extern "C" {
>  unsigned int sleep(unsigned int seconds);
>  #endif
>
> +#if CONFIG_LIBPOSIX_PROCESS
> +int execl(const char *path, const char *arg, ...
> +               /* (char  *) NULL */);
> +int execlp(const char *file, const char *arg, ...
> +               /* (char  *) NULL */);
> +int execle(const char *path, const char *arg, ...
> +               /*, (char *) NULL, char * const envp[] */);
> +int execv(const char *path, char *const argv[]);
> +int execvp(const char *file, char *const argv[]);
> +int execvpe(const char *file, char *const argv[],
> +               char *const envp[]);
> +int execve(const char *filename, char *const argv[],
> +               char *const envp[]);
> +#endif
> +
>  #if CONFIG_LIBVFSCORE
>  int close(int fd);
>  ssize_t write(int fd, const void *buf, size_t count);
> diff --git a/lib/posix-process/process.c b/lib/posix-process/process.c
> index 78c2f385..81f16659 100644
> --- a/lib/posix-process/process.c
> +++ b/lib/posix-process/process.c
> @@ -33,13 +33,12 @@
>   * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
>   */
>
> -#include "../posix-process/include/uk/process.h"
> -
>  #include <errno.h>
>  #include <stdlib.h>
>  #include <stdio.h>
>  #include <sys/prctl.h>
>  #include <sys/resource.h>
> +#include <uk/process.h>
>  #include <uk/print.h>
>
>
> @@ -50,47 +49,118 @@ int fork(void)
>         return -1;
>  }
>
> -static
> -void exec_warn(const char *func,
> -               const char *path, char *const argv[], char *const envp[])
> +int vfork(void)
> +{
> +       /* vfork() is not supported on this platform */
> +       errno = ENOSYS;
> +       return -1;
> +}
> +
> +static void exec_warn_argv_variadic(const char *arg, va_list args)
>  {
> -       int i;
> +       int i = 1;
> +       char *argi;
>
> -       uk_pr_warn("%s(): path=%s", func, path);
> +       uk_pr_warn(" argv=[%s", arg);
>
> -       /* print arguments */
> -       i = 0;
> -       uk_pr_warn(" argv=[");
> -       while (argv[i]) {
> -               uk_pr_warn("%s%s", (i > 0 ? ", " : ""), argv[i]);
> +       argi = va_arg(args, char *);
> +       while (argi) {
> +               uk_pr_warn("%s%s", (i > 0 ? ", " : ""), argi);
>                 i++;
> +               argi = va_arg(args, char *);
>         }
> -       uk_pr_warn("]");
> -
> -       /* print environment variables */
> -       if (envp) {
> -               i = 0;
> -               uk_pr_warn(" envp=[");
> -               while (envp[i]) {
> -                       uk_pr_warn("%s%s", (i > 0 ? ", " : ""), envp[i]);
> +       uk_pr_warn("]\n");
> +}
> +
> +static void __exec_warn_array(const char *name, char *const argv[])
> +{
> +       int i = 0;
> +
> +       uk_pr_warn(" %s=[", name);
> +
> +       if (argv) {
> +               while (argv[i]) {
> +                       uk_pr_warn("%s%s", (i > 0 ? ", " : ""), argv[i]);
>                         i++;
>                 }
> -               uk_pr_warn("]");
>         }
> +       uk_pr_warn("]\n");
> +}
> +#define exec_warn_argv(values) __exec_warn_array("argv", values)
> +#define exec_warn_envp(values) __exec_warn_array("envp", values)
> +
> +int execl(const char *path, const char *arg, ...
> +               /* (char  *) NULL */)
> +{
> +       va_list args;
> +
> +       uk_pr_warn("%s(): path=%s\n", __func__, path);
> +       va_start(args, arg);
> +       exec_warn_argv_variadic(arg, args);
> +       va_end(args);
> +       errno = ENOSYS;
> +       return -1;
> +}
> +
> +int execlp(const char *file, const char *arg, ...
> +               /* (char  *) NULL */)
> +{
> +       va_list args;
> +
> +       uk_pr_warn("%s(): file=%s\n", __func__, file);
> +       va_start(args, arg);
> +       exec_warn_argv_variadic(arg, args);
> +       va_end(args);
> +       errno = ENOSYS;
> +       return -1;
> +}
>
> -       uk_pr_warn("\n");
> +int execle(const char *path, const char *arg, ...
> +               /*, (char *) NULL, char * const envp[] */)
> +{
> +       va_list args;
> +       char * const *envp;
> +
> +       uk_pr_warn("%s(): path=%s\n", __func__, path);
> +       va_start(args, arg);
> +       exec_warn_argv_variadic(arg, args);
> +       envp = va_arg(args, char * const *);
> +       exec_warn_envp(envp);
> +       va_end(args);
> +       errno = ENOSYS;
> +       return -1;
>  }
>
>  int execve(const char *path, char *const argv[], char *const envp[])
>  {
> -       exec_warn(__func__, path, argv, envp);
> +       uk_pr_warn("%s(): path=%s\n", __func__, path);
> +       exec_warn_argv(argv);
> +       exec_warn_envp(envp);
>         errno = ENOSYS;
>         return -1;
>  }
>
>  int execv(const char *path, char *const argv[])
>  {
> -       exec_warn(__func__, path, argv, NULL);
> +       uk_pr_warn("%s(): path=%s\n", __func__, path);
> +       exec_warn_argv(argv);
> +       errno = ENOSYS;
> +       return -1;
> +}
> +
> +int execvp(const char *file, char *const argv[])
> +{
> +       uk_pr_warn("%s(): file=%s\n", __func__, file);
> +       exec_warn_argv(argv);
> +       errno = ENOSYS;
> +       return -1;
> +}
> +
> +int execvpe(const char *file, char *const argv[], char *const envp[])
> +{
> +       uk_pr_warn("%s(): file=%s\n", __func__, file);
> +       exec_warn_argv(argv);
> +       exec_warn_envp(envp);
>         errno = ENOSYS;
>         return -1;
>  }
> --
> 2.20.1
>

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.