[LTP] [PATCH v2 5/8] Rewrite userns05.c using new LTP API

Petr Vorel pvorel@suse.cz
Thu Mar 24 22:08:17 CET 2022


Hi Andrea,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

LGTM, just anybody merging this should remove return; at the end of run().

>  testcases/kernel/containers/userns/userns05.c | 148 ++++++++----------
...
> -/*
> - * Verify that:
> - * A process created via fork(2) or clone(2) without the
> - * CLONE_NEWUSER flag is a member of the same user namespace as its
> - * parent.
> - * When unshare an user namespace, the calling process is moved into
> - * a new user namespace which is not shared with any previously
> - * existing process.
> +/*\
> + * [Description]
> + *
> + * Verify that if a process created via fork(2) or clone(2) without the
> + * CLONE_NEWUSER flag is a member of the same user namespace as its parent.

I'd put blank space here to create 2 paragraphs in html/pdf doc.
> + * When unshare an user namespace, the calling process is moved into a new user
> + * namespace which is not shared with any previously existing process.
>   */

...
>  static int child_fn1(void)
>  {
...
> +	SAFE_READLINK(path, userid, BUFSIZ);
> +
> +	if (sscanf(userid, "user:[%u]", &id) < 0)
> +		tst_brk(TBROK | TERRNO, "sscanf failure");
Ah, we still don't have SAFE_SSCANF() (nothing urgent, this is the first test
using new API which would use it).

> +static void run(void)
>  {
...
> +	cpid1 = ltp_clone_quick(SIGCHLD, (void *)child_fn1, NULL);
>  	if (cpid1 < 0)
> +		tst_brk(TBROK | TTERRNO, "clone failed");
Again, once we implement SAFE_LTP_CLONE_QUICK() we should use it here
(as a separate effort).

...
> +	cpid3 = SAFE_FORK();
> +	if (!cpid3) {
> +		SAFE_UNSHARE(CLONE_NEWUSER);
>  		newparentuserns = getusernsidbypid(getpid());

>  		/* When unshare an user namespace, the calling process
> +		 * is moved into a new user namespace which is not shared
> +		 * with any previously existing process
> +		 */
>  		if (parentuserns == newparentuserns)
> +			tst_res(TFAIL, "unshared namespaces with same id");
> +		else
> +			tst_res(TPASS, "unshared namespaces with different id");

> +		return;
Why this empty return?
> +	}
>  }

Kind regards,
Petr


More information about the ltp mailing list