From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 1/4] lib/tst_tmpdir: Normalize user defined TMPDIR
Date: Wed, 7 Feb 2024 17:17:56 +0100 [thread overview]
Message-ID: <20240207161756.GA128563@pevik> (raw)
In-Reply-To: <20240207160628.125908-2-pvorel@suse.cz>
Hi,
> Follow the changes to shell API 273c49793 ("tst_test.sh: Remove possible
> double/trailing slashes from TMPDIR") and remove: 1) trailing slash
> 2) double slashes.
> This is needed, because some tests compare file path of files which are
> in TMPDIR with strcmp() or and extra slashes break it (e.g. chdir01A,
> ioctl_loop0[12], mount0[67]).
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> lib/tst_tmpdir.c | 20 +++++++++++++++++++-
> 1 file changed, 19 insertions(+), 1 deletion(-)
> diff --git a/lib/tst_tmpdir.c b/lib/tst_tmpdir.c
> index b73b5c66f..bc9351251 100644
> --- a/lib/tst_tmpdir.c
> +++ b/lib/tst_tmpdir.c
> @@ -124,7 +124,8 @@ char *tst_get_tmpdir(void)
> const char *tst_get_tmpdir_root(void)
> {
> - const char *env_tmpdir = getenv("TMPDIR");
> + char *p, *env_tmpdir = getenv("TMPDIR");
> + int fixed = 0;
> if (!env_tmpdir)
> env_tmpdir = TEMPDIR;
> @@ -134,6 +135,23 @@ const char *tst_get_tmpdir_root(void)
> "pathname for environment variable TMPDIR");
> return NULL;
> }
> +
> + if (env_tmpdir[strlen(env_tmpdir)-1] == '/') {
> + env_tmpdir[strlen(env_tmpdir)-1] = '\0';
> + fixed = 1;
> + }
Actually, this above supposed to be after removing double slash (in case people
are crazy to put /// or more in the end, see patch bellow.
I'm sorry for the noise.
Kind regards,
Petr
> +
> + while ((p = strstr(env_tmpdir, "//")) != NULL) {
> + memmove(p, p + 1, strlen(env_tmpdir) - (p - env_tmpdir));
> + fixed = 1;
> + }
> +
> + if (fixed) {
> + tst_resm(TINFO, "WARNING: Remove double or trailing slashes from TMPDIR,"
> + " please fix your setup to: TMPDIR='%s'",
> + env_tmpdir);
> + }
> +
> return env_tmpdir;
> }
diff --git lib/newlib_tests/tst_tmpdir.c lib/newlib_tests/tst_tmpdir.c
index 008542808..c34430fa6 100644
--- lib/newlib_tests/tst_tmpdir.c
+++ lib/newlib_tests/tst_tmpdir.c
@@ -18,7 +18,8 @@ static struct tcase {
} tcases[] = {
{NULL, TEMPDIR, "default value"},
{"/tmp/", "/tmp", "removing trailing slash"},
- {"//var///tmp", "/var/tmp", "removing duplicate slashes"},
+ {"/var//tmp", "/var/tmp", "removing duplicate slashes"},
+ {"//var///tmp///", "/var/tmp", "removing too many slashes"},
};
static void do_test(unsigned int nr)
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-02-07 16:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-07 16:06 [LTP] [PATCH 0/4] Remove double or trailing slashes in TMPDIR in C API Petr Vorel
2024-02-07 16:06 ` [LTP] [PATCH 1/4] lib/tst_tmpdir: Normalize user defined TMPDIR Petr Vorel
2024-02-07 16:17 ` Petr Vorel [this message]
2024-02-23 15:39 ` Cyril Hrubis
2024-03-21 7:14 ` Petr Vorel
2024-02-23 15:41 ` Cyril Hrubis
2024-02-07 16:06 ` [LTP] [PATCH 2/4] lib: Add test for tst_tmpdir Petr Vorel
2024-02-07 16:18 ` Petr Vorel
2024-02-07 16:06 ` [LTP] [PATCH 3/4] tst_test.sh: Print warning if slashes in $TMPDIR Petr Vorel
2024-02-07 16:06 ` [LTP] [PATCH 4/4] lib: Improve doc related to $TMPDIR default value Petr Vorel
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=20240207161756.GA128563@pevik \
--to=pvorel@suse.cz \
--cc=ltp@lists.linux.it \
/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.