All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: lufei <lufei@uniontech.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2] syscalls/unshare: New test: CLONE_NEWNS unshares fs info
Date: Fri, 25 Apr 2025 11:07:11 +0200	[thread overview]
Message-ID: <aAtQvzjrXc49XoHH@yuki.lan> (raw)
In-Reply-To: <20250423120516.10680-1-lufei@uniontech.com>

Hi!
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2025 lufei <lufei@uniontech.com>
> + */
> +
> +/*\
> + * This test case is to verify unshare(CLONE_NEWNS) also unshares filesystem
> + * information.
> + *
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include "tst_test.h"
> +#include "lapi/sched.h"
> +
> +#define TMP "/tmp1"
> +
> +static char *cwd;
> +static char *tmpdir;
> +static char *c_cwd;
> +static char *p_cwd;
> +static size_t size = 1024;
> +
> +static void setup(void)
> +{
> +	cwd = SAFE_MALLOC(size);
> +	SAFE_GETCWD(cwd, size);
> +
> +	tmpdir = tst_tmpdir_genpath(TMP);
> +	SAFE_MKDIR(tmpdir, 0700);

There no need for absolute paths, the test starts with CWD pointing to
the newly created temporary directory. So all that we need to do is to
use relative paths with:

#define TESTDIR "test_dir"

	SAFE_MKDIR(TESTDIR, 0700);

And then later do SAFE_CHDIR(TESTDIR) in the child.

> +	c_cwd = SAFE_MALLOC(size);
> +	p_cwd = SAFE_MALLOC(size);

We do not need two of these, we can use the same buffer both in child
and parent.

> +}
> +
> +static void cleanup(void)
> +{
> +	free(c_cwd);
> +	free(p_cwd);
> +	free(cwd);
> +}
> +
> +
> +static void run(void)
> +{
> +	struct tst_clone_args args = {
> +		.flags = CLONE_FS,
> +		.exit_signal = SIGCHLD,
> +	};
> +
> +	if (!SAFE_CLONE(&args)) {
> +
> +		TST_EXP_PASS(unshare(CLONE_NEWNS));
> +
> +		SAFE_CHDIR(tmpdir);
> +		SAFE_GETCWD(c_cwd, size);
> +
> +		if (strcmp(cwd, c_cwd) == 0)
> +			tst_res(TFAIL, "current dir not changed");
> +		else
> +			tst_res(TPASS, "current dir changed to %s", c_cwd);
> +	} else {
> +		SAFE_WAIT(NULL);
> +
> +		SAFE_GETCWD(p_cwd, size);
> +
> +		if (strcmp(cwd, p_cwd) == 0)
> +			tst_res(TPASS, "cwd unshared");
> +		else
> +			tst_res(TFAIL, "cwd not unshare as expected");
                                                  ^
						unshared
> +	}
> +}
> +
> +static struct tst_test test = {
> +	.forks_child = 1,
> +	.needs_root = 1,
> +	.needs_tmpdir = 1,
> +	.test_all = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +};
> -- 
> 2.39.3
> 

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2025-04-25  9:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-23  4:46 [LTP] [PATCH] syscalls/unshare: New test: CLONE_NEWNS unshares fs info lufei
2025-04-23  9:10 ` Cyril Hrubis
2025-04-23 12:05 ` [LTP] [PATCH v2] " lufei
2025-04-25  9:07   ` Cyril Hrubis [this message]
2025-04-25  9:33   ` [LTP] [PATCH v3] " lufei
2025-04-25 12:10     ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aAtQvzjrXc49XoHH@yuki.lan \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=lufei@uniontech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.