[LTP] [PATCH v4 1/4] shell: Add tst_runas.c helper

Li Wang liwang@redhat.com
Mon Dec 15 07:57:25 CET 2025


Hi Petr,

Petr Vorel <pvorel@suse.cz> wrote:


> +++ b/testcases/lib/tst_runas.c
> @@ -0,0 +1,50 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2025 Petr Vorel <pvorel@suse.cz>
> + */
> +
> +#define LTP_USR_UID 65534
> +#define LTP_USR_GID 65534
> +
> +#define TST_NO_DEFAULT_MAIN
> +#include "tst_test.h"
> +
> +static void print_help(void)
> +{
> +       fprintf(stderr, "Usage: %s cmd [args] ...\n", __FILE__);
> +       fprintf(stderr, "Usage: %s cmd [-h] print help\n\n", __FILE__);
> +
> +       fprintf(stderr, "Environment Variables\n");
> +       fprintf(stderr, "LTP_USR_UID: UID of 'nobody' user, defaults %d\n",
> +                       LTP_USR_UID);
> +       fprintf(stderr, "LTP_USR_GID: GID of 'nobody' user, defaults %d\n",
> +                       LTP_USR_GID);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +       if (argc < 2 || !strcmp(argv[1], "-h")) {
> +               print_help();
> +               return 1;
> +       }
> +
> +       unsigned uid = LTP_USR_UID, gid = LTP_USR_GID;
> +
>



> +       char *uid_env = getenv(TST_TO_STR_(LTP_USR_UID));
> +       char *gid_env = getenv(TST_TO_STR_(LTP_USR_GID));
>


So far this format is correct.

But as I pointed in the last thread, here using TST_TO_STR_ might be a
potential
issue if someday we make changes on that to become two-level macro.
It likely to interpreted as  getenv("65534");

So on the safe side, I’d still recommend writing it explicitly:

    char *uid_env = getenv("LTP_USR_UID");
    char *gid_env = getenv("LTP_USR_GID");


The rest whole patch set looks good:

Reviewed-by: Li Wang <liwang@redhat.com>


-- 
Regards,
Li Wang


More information about the ltp mailing list