public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Edward Liaw via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: kernel-team@android.com
Subject: [LTP] [PATCH v1] tst_cgroup: use tmpdir
Date: Thu, 27 Oct 2022 18:15:31 +0000	[thread overview]
Message-ID: <20221027181531.3686476-1-edliaw@google.com> (raw)

Use tmpdir instead of hardcoded /tmp path.

Signed-off-by: Edward Liaw <edliaw@google.com>
---
 lib/tst_cgroup.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 6c015e4f8..458b823f2 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -290,7 +290,7 @@ static struct cgroup_ctrl controllers[] = {
 static const char *cgroup_ltp_dir = "ltp";
 static const char *cgroup_ltp_drain_dir = "drain";
 static char cgroup_test_dir[NAME_MAX + 1];
-static const char *cgroup_mount_ltp_prefix = "/tmp/cgroup_";
+static const char *cgroup_mount_ltp_prefix = "cgroup_";
 static const char *cgroup_v2_ltp_mount = "unified";
 
 #define first_root				\
@@ -645,8 +645,12 @@ static void cgroup_mount_v2(void)
 {
 	int ret;
 	char mnt_path[PATH_MAX];
+	const char *tmpdir = getenv("TMPDIR");
+	if (!tmpdir)
+		tmpdir = "/tmp";
 
-	sprintf(mnt_path, "%s%s", cgroup_mount_ltp_prefix, cgroup_v2_ltp_mount);
+	sprintf(mnt_path, "%s/%s%s",
+		tmpdir, cgroup_mount_ltp_prefix, cgroup_v2_ltp_mount);
 
 	if (!mkdir(mnt_path, 0777)) {
 		roots[0].mnt_dir.we_created_it = 1;
@@ -693,6 +697,9 @@ static void cgroup_mount_v1(struct cgroup_ctrl *const ctrl)
 {
 	char mnt_path[PATH_MAX];
 	int made_dir = 0;
+	const char *tmpdir = getenv("TMPDIR");
+	if (!tmpdir)
+		tmpdir = "/tmp";
 
 	if (ctrl->ctrl_indx == CTRL_BLKIO && controllers[CTRL_IO].ctrl_root) {
 		tst_res(TCONF,
@@ -700,7 +707,8 @@ static void cgroup_mount_v1(struct cgroup_ctrl *const ctrl)
 		return;
 	}
 
-	sprintf(mnt_path, "%s%s", cgroup_mount_ltp_prefix, ctrl->ctrl_name);
+	sprintf(mnt_path, "%s/%s%s",
+		tmpdir, cgroup_mount_ltp_prefix, ctrl->ctrl_name);
 
 	if (!mkdir(mnt_path, 0777)) {
 		made_dir = 1;
-- 
2.38.1.273.g43a17bfeac-goog


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

             reply	other threads:[~2022-10-27 18:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-27 18:15 Edward Liaw via ltp [this message]
2022-10-31  9:03 ` [LTP] [PATCH v1] tst_cgroup: use tmpdir Petr Vorel
2022-10-31 15:51   ` Richard Palethorpe

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=20221027181531.3686476-1-edliaw@google.com \
    --to=ltp@lists.linux.it \
    --cc=edliaw@google.com \
    --cc=kernel-team@android.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox