* [LTP] [PATCH] containers: added pidns/pidns03.c
@ 2014-07-21 10:41 Matus Marhefka
2014-07-21 13:22 ` Jan Stancek
0 siblings, 1 reply; 9+ messages in thread
From: Matus Marhefka @ 2014-07-21 10:41 UTC (permalink / raw)
To: ltp-list
* Clones a new child process with CLONE_NEWPID flag - the new child
* process mounts procfs to a "/proc2" directory and checks if it belongs
* to a new pid namespace by:
* 1. reading value of a symbolic link "/proc2/self"
* 2. comparing read value (PID) with "1"
Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
Signed-off-by: Jiri Jaburek <jjaburek@redhat.com>
---
testcases/kernel/containers/pidns/pidns03.c | 111 ++++++++++++++++++++++++++++
1 file changed, 111 insertions(+)
create mode 100644 testcases/kernel/containers/pidns/pidns03.c
diff --git a/testcases/kernel/containers/pidns/pidns03.c b/testcases/kernel/containers/pidns/pidns03.c
new file mode 100644
index 0000000..203b67b
--- /dev/null
+++ b/testcases/kernel/containers/pidns/pidns03.c
@@ -0,0 +1,111 @@
+/* Copyright (c) 2014 Red Hat, Inc. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of version 2 the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ * File: pidns03.c
+ *
+ * Description:
+ * Clones a new child process with CLONE_NEWPID flag - the new child
+ * process mounts procfs to a "/proc2" directory and checks if it belongs
+ * to a new pid namespace by:
+ * 1. reading value of a symbolic link "/proc2/self"
+ * 2. comparing read value (PID) with "1"
+ */
+
+#define _GNU_SOURCE
+#include <sys/wait.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include "usctest.h"
+#include "test.h"
+#include "safe_macros.h"
+#include "libclone.h"
+
+
+char *TCID = "pidns03";
+int TST_TOTAL = 1;
+
+
+static void cleanup(void)
+{
+ umount("/proc2");
+ rmdir("/proc2");
+}
+
+static void setup(void)
+{
+ tst_require_root(NULL);
+}
+
+int childFunc(void *arg)
+{
+ char buf[10];
+ int result = 1;
+
+ SAFE_MKDIR(cleanup, "/proc2", 0555);
+
+ if (mount("none", "/proc2", "proc", MS_RDONLY, NULL) == -1)
+ tst_brkm(TFAIL | TERRNO, cleanup, "mount");
+
+ if (readlink("/proc2/self", buf, sizeof(buf)) == -1)
+ tst_brkm(TFAIL | TERRNO, cleanup, "readlink");
+
+ /* child should have PID 1 in a new pid namespace - if true
+ * procfs belongs to the new pid namespace */
+ if (!strcmp(buf, "1"))
+ result = 0;
+
+ return result;
+}
+
+static void test(void)
+{
+ int status;
+ int ret;
+
+ ret = do_clone_tests(CLONE_NEWPID, childFunc, NULL, NULL, NULL);
+
+ if (ret == -1) {
+ tst_brkm(TFAIL | TTERRNO, cleanup, "clone failed");
+ } else if ((wait(&status)) == -1) {
+ tst_brkm(TWARN | TERRNO, cleanup, "wait failed");
+ }
+
+ if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
+ tst_resm(TFAIL, "mounting procfs in a new namespace");
+ } else if (WIFSIGNALED(status)) {
+ tst_resm(TFAIL, "child was killed with signal = %d",
+ WTERMSIG(status));
+ } else {
+ tst_resm(TPASS, "mounting procfs in a new namespace");
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ const char *msg;
+ if ((msg = parse_opts(argc, argv, NULL, NULL)))
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+
+ test();
+
+ cleanup();
+ tst_exit();
+}
--
1.8.3.1
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH] containers: added pidns/pidns03.c
2014-07-21 10:41 [LTP] [PATCH] containers: added pidns/pidns03.c Matus Marhefka
@ 2014-07-21 13:22 ` Jan Stancek
2014-07-21 15:19 ` [LTP] [PATCH v2] " Matus Marhefka
0 siblings, 1 reply; 9+ messages in thread
From: Jan Stancek @ 2014-07-21 13:22 UTC (permalink / raw)
To: Matus Marhefka; +Cc: ltp-list
----- Original Message -----
> From: "Matus Marhefka" <mmarhefk@redhat.com>
> To: ltp-list@lists.sourceforge.net
> Sent: Monday, 21 July, 2014 12:41:38 PM
> Subject: [LTP] [PATCH] containers: added pidns/pidns03.c
>
> * Clones a new child process with CLONE_NEWPID flag - the new child
> * process mounts procfs to a "/proc2" directory and checks if it belongs
> * to a new pid namespace by:
> * 1. reading value of a symbolic link "/proc2/self"
> * 2. comparing read value (PID) with "1"
>
> Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
> Signed-off-by: Jiri Jaburek <jjaburek@redhat.com>
> ---
> testcases/kernel/containers/pidns/pidns03.c | 111
> ++++++++++++++++++++++++++++
> 1 file changed, 111 insertions(+)
> create mode 100644 testcases/kernel/containers/pidns/pidns03.c
>
> diff --git a/testcases/kernel/containers/pidns/pidns03.c
> b/testcases/kernel/containers/pidns/pidns03.c
> new file mode 100644
> index 0000000..203b67b
> --- /dev/null
> +++ b/testcases/kernel/containers/pidns/pidns03.c
> @@ -0,0 +1,111 @@
> +/* Copyright (c) 2014 Red Hat, Inc. All rights reserved.
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of version 2 the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + ***********************************************************************
> + * File: pidns03.c
> + *
> + * Description:
> + * Clones a new child process with CLONE_NEWPID flag - the new child
> + * process mounts procfs to a "/proc2" directory and checks if it belongs
> + * to a new pid namespace by:
> + * 1. reading value of a symbolic link "/proc2/self"
> + * 2. comparing read value (PID) with "1"
> + */
> +
> +#define _GNU_SOURCE
> +#include <sys/wait.h>
> +#include <sys/mount.h>
> +#include <sys/stat.h>
Hi,
Is header sys/stat.h used for anything?
> +#include <sys/types.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <errno.h>
> +#include "usctest.h"
> +#include "test.h"
> +#include "safe_macros.h"
> +#include "libclone.h"
> +
> +
> +char *TCID = "pidns03";
> +int TST_TOTAL = 1;
> +
> +
> +static void cleanup(void)
> +{
> + umount("/proc2");
> + rmdir("/proc2");
I'd prefer this to be just "proc2" inside temporary directory created by
"tst_tmpdir()" in setup() and cleaned up by "tst_rmdir()" in cleanup().
> +}
> +
> +static void setup(void)
> +{
> + tst_require_root(NULL);
> +}
> +
> +int childFunc(void *arg)
> +{
> + char buf[10];
> + int result = 1;
> +
> + SAFE_MKDIR(cleanup, "/proc2", 0555);
You shouldn't use tst_ and SAFE macros in child process.
See "2.2.7" in doc/test-writing-guidelines.txt about possible consequences.
One option is to move SAFE_MKDIR to setup() and keep rmdir in cleanup().
> +
> + if (mount("none", "/proc2", "proc", MS_RDONLY, NULL) == -1)
> + tst_brkm(TFAIL | TERRNO, cleanup, "mount");
> +
^^^^^^^^ There is some unnecessary whitespace here.
> + if (readlink("/proc2/self", buf, sizeof(buf)) == -1)
> + tst_brkm(TFAIL | TERRNO, cleanup, "readlink");
I'd move umount() here.
> +
> + /* child should have PID 1 in a new pid namespace - if true
> + * procfs belongs to the new pid namespace */
> + if (!strcmp(buf, "1"))
> + result = 0;
It would be useful to print buf value if this check fails.
> +
> + return result;
> +}
> +
> +static void test(void)
> +{
> + int status;
> + int ret;
> +
> + ret = do_clone_tests(CLONE_NEWPID, childFunc, NULL, NULL, NULL);
> +
> + if (ret == -1) {
> + tst_brkm(TFAIL | TTERRNO, cleanup, "clone failed");
I'd expect "TBROK | TERRNO" here. TTERRNO is using TEST_ERRNO, which I can't see
being set anywhere in libclone.c or lib/cloner.c.
Braces {} are not necessary for single line statements.
> + } else if ((wait(&status)) == -1) {
> + tst_brkm(TWARN | TERRNO, cleanup, "wait failed");
same as above, TBROK | TERRNO
> + }
> +
> + if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
> + tst_resm(TFAIL, "mounting procfs in a new namespace");
> + } else if (WIFSIGNALED(status)) {
> + tst_resm(TFAIL, "child was killed with signal = %d",
> + WTERMSIG(status));
> + } else {
> + tst_resm(TPASS, "mounting procfs in a new namespace");
> + }
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + const char *msg;
> + if ((msg = parse_opts(argc, argv, NULL, NULL)))
> + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> + setup();
> +
You are missing TEST_LOOPING here:
for (lc = 0; TEST_LOOPING(lc); lc++)
test();
Regards,
Jan
> + test();
> +
> + cleanup();
> + tst_exit();
> +}
> --
> 1.8.3.1
>
>
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 9+ messages in thread
* [LTP] [PATCH v2] containers: added pidns/pidns03.c
2014-07-21 13:22 ` Jan Stancek
@ 2014-07-21 15:19 ` Matus Marhefka
2014-07-22 16:54 ` chrubis
0 siblings, 1 reply; 9+ messages in thread
From: Matus Marhefka @ 2014-07-21 15:19 UTC (permalink / raw)
To: ltp-list
* Clones a new child process with CLONE_NEWPID flag - the new child
* process mounts procfs to a "proc2" directory and checks if it belongs
* to a new pid namespace by:
* 1. reading value of a symbolic link "proc2/self"
* 2. comparing read value (PID) with "1"
Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
Signed-off-by: Jiri Jaburek <jjaburek@redhat.com>
---
testcases/kernel/containers/pidns/pidns03.c | 120 ++++++++++++++++++++++++++++
1 file changed, 120 insertions(+)
create mode 100644 testcases/kernel/containers/pidns/pidns03.c
diff --git a/testcases/kernel/containers/pidns/pidns03.c b/testcases/kernel/containers/pidns/pidns03.c
new file mode 100644
index 0000000..ad2a683
--- /dev/null
+++ b/testcases/kernel/containers/pidns/pidns03.c
@@ -0,0 +1,120 @@
+/* Copyright (c) 2014 Red Hat, Inc. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of version 2 the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ * File: pidns03.c
+ *
+ * Description:
+ * Clones a new child process with CLONE_NEWPID flag - the new child
+ * process mounts procfs to a "proc2" directory and checks if it belongs
+ * to a new pid namespace by:
+ * 1. reading value of a symbolic link "proc2/self"
+ * 2. comparing read value (PID) with "1"
+ */
+
+#define _GNU_SOURCE
+#include <sys/wait.h>
+#include <sys/mount.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include "usctest.h"
+#include "test.h"
+#include "safe_macros.h"
+#include "libclone.h"
+
+
+#define PROCDIR "proc2"
+char *TCID = "pidns03";
+int TST_TOTAL = 1;
+
+
+static void cleanup(void)
+{
+ umount(PROCDIR);
+ rmdir(PROCDIR);
+ tst_rmdir();
+}
+
+static void setup(void)
+{
+ tst_require_root(NULL);
+ tst_tmpdir();
+ SAFE_MKDIR(cleanup, PROCDIR, 0555);
+}
+
+int childFunc(void *arg)
+{
+ char buf[10];
+ int result = 1;
+
+ if (mount("none", PROCDIR, "proc", MS_RDONLY, NULL) == -1) {
+ perror("mount");
+ return 1;
+ }
+
+ if (readlink(PROCDIR"/self", buf, sizeof(buf)) == -1) {
+ perror("readlink");
+ return 1;
+ }
+
+
+ /* child should have PID 1 in a new pid namespace - if true
+ * procfs belongs to the new pid namespace */
+ if (!strcmp(buf, "1"))
+ result = 0;
+ else
+ fprintf(stderr, "%s contains: %s\n", PROCDIR"/self", buf);
+
+ return result;
+}
+
+static void test(void)
+{
+ int status;
+ int ret;
+
+ ret = do_clone_tests(CLONE_NEWPID, childFunc, NULL, NULL, NULL);
+
+ if (ret == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+ else if ((wait(&status)) == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "wait failed");
+
+ if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
+ tst_resm(TFAIL, "mounting procfs in a new namespace");
+ else if (WIFSIGNALED(status))
+ tst_resm(TFAIL, "child was killed with signal = %d",
+ WTERMSIG(status));
+ else
+ tst_resm(TPASS, "mounting procfs in a new namespace");
+}
+
+int main(int argc, char *argv[])
+{
+ const char *msg;
+ int lc;
+
+ if ((msg = parse_opts(argc, argv, NULL, NULL)))
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++)
+ test();
+
+ cleanup();
+ tst_exit();
+}
--
1.8.3.1
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH v2] containers: added pidns/pidns03.c
2014-07-21 15:19 ` [LTP] [PATCH v2] " Matus Marhefka
@ 2014-07-22 16:54 ` chrubis
2014-07-23 9:28 ` [LTP] [PATCH v3] " Matus Marhefka
0 siblings, 1 reply; 9+ messages in thread
From: chrubis @ 2014-07-22 16:54 UTC (permalink / raw)
To: Matus Marhefka; +Cc: ltp-list
Hi!
> +#define _GNU_SOURCE
> +#include <sys/wait.h>
> +#include <sys/mount.h>
> +#include <sys/types.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <errno.h>
> +#include "usctest.h"
> +#include "test.h"
> +#include "safe_macros.h"
> +#include "libclone.h"
> +
> +
> +#define PROCDIR "proc2"
This is very minor, but we don't have to name it "proc2" now because we
create it in the newly created test temporary directory, so why not just
"proc" now?
> +char *TCID = "pidns03";
> +int TST_TOTAL = 1;
> +
> +
> +static void cleanup(void)
> +{
> + umount(PROCDIR);
> + rmdir(PROCDIR);
You don't have to remove any files/directories under the test temporary
directory, these are deleted automatically in tst_rmdir().
> + tst_rmdir();
> +}
> +
> +static void setup(void)
> +{
> + tst_require_root(NULL);
> + tst_tmpdir();
> + SAFE_MKDIR(cleanup, PROCDIR, 0555);
> +}
> +
> +int childFunc(void *arg)
In LKML coding style (which LTP follows), mixed case is frowned upon.
You can use checkpatch.pl (from scripts from linux kernel sources) to
check you patch before sending it to the ML.
> +{
> + char buf[10];
> + int result = 1;
> +
> + if (mount("none", PROCDIR, "proc", MS_RDONLY, NULL) == -1) {
> + perror("mount");
> + return 1;
> + }
> +
> + if (readlink(PROCDIR"/self", buf, sizeof(buf)) == -1) {
> + perror("readlink");
> + return 1;
> + }
> +
> +
> + /* child should have PID 1 in a new pid namespace - if true
> + * procfs belongs to the new pid namespace */
> + if (!strcmp(buf, "1"))
> + result = 0;
> + else
> + fprintf(stderr, "%s contains: %s\n", PROCDIR"/self", buf);
> +
> + return result;
> +}
> +
> +static void test(void)
> +{
> + int status;
> + int ret;
> +
> + ret = do_clone_tests(CLONE_NEWPID, childFunc, NULL, NULL, NULL);
> +
> + if (ret == -1)
> + tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
> + else if ((wait(&status)) == -1)
> + tst_brkm(TBROK | TERRNO, cleanup, "wait failed");
> +
> + if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
> + tst_resm(TFAIL, "mounting procfs in a new namespace");
> + else if (WIFSIGNALED(status))
> + tst_resm(TFAIL, "child was killed with signal = %d",
> + WTERMSIG(status));
^
We have tst_strsig() so that you can print
human readable signal name instead of the
number.
> + else
> + tst_resm(TPASS, "mounting procfs in a new namespace");
I would do:
if (foo) {
tst_resm(...);
return;
}
if (bar) {
tst_resm(...);
return;
}
tst_resm(...);
rather than the if else if ... maze.
Also the tst_brkm() exits the test execution (does not return) so the
first else is redundand.
And we also have SAFE_WAIT() in include/safe_macros.h so you can do
just:
SAFE_WAIT(cleanup, &status);
instead of the two if (...) tst_brkm(...);
(Safe macros and library functions are documented in Test Writing Guidelines at
https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines)
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 9+ messages in thread
* [LTP] [PATCH v3] containers: added pidns/pidns03.c
2014-07-22 16:54 ` chrubis
@ 2014-07-23 9:28 ` Matus Marhefka
2014-07-24 7:20 ` Jan Stancek
0 siblings, 1 reply; 9+ messages in thread
From: Matus Marhefka @ 2014-07-23 9:28 UTC (permalink / raw)
To: ltp-list; +Cc: metan
* Clones a new child process with CLONE_NEWPID flag - the new child
* process mounts procfs to a "proc" directory and checks if it belongs
* to a new pid namespace by:
* 1. reading value of a symbolic link "proc/self"
* 2. comparing read value (PID) with "1"
Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
Signed-off-by: Jiri Jaburek <jjaburek@redhat.com>
---
testcases/kernel/containers/pidns/pidns03.c | 121 ++++++++++++++++++++++++++++
1 file changed, 121 insertions(+)
create mode 100644 testcases/kernel/containers/pidns/pidns03.c
diff --git a/testcases/kernel/containers/pidns/pidns03.c b/testcases/kernel/containers/pidns/pidns03.c
new file mode 100644
index 0000000..ac0dcbf
--- /dev/null
+++ b/testcases/kernel/containers/pidns/pidns03.c
@@ -0,0 +1,121 @@
+/* Copyright (c) 2014 Red Hat, Inc. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of version 2 the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ * File: pidns03.c
+ *
+ * Description:
+ * Clones a new child process with CLONE_NEWPID flag - the new child
+ * process mounts procfs to a "proc" directory and checks if it belongs
+ * to a new pid namespace by:
+ * 1. reading value of a symbolic link "proc/self"
+ * 2. comparing read value (PID) with "1"
+ */
+
+#define _GNU_SOURCE
+#include <sys/wait.h>
+#include <sys/mount.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include "usctest.h"
+#include "test.h"
+#include "safe_macros.h"
+#include "libclone.h"
+
+
+#define PROCDIR "proc"
+char *TCID = "pidns03";
+int TST_TOTAL = 1;
+
+
+static void cleanup(void)
+{
+ tst_rmdir();
+}
+
+static void setup(void)
+{
+ tst_require_root(NULL);
+ tst_tmpdir();
+ SAFE_MKDIR(cleanup, PROCDIR, 0555);
+}
+
+int child_func(void *arg)
+{
+ char buf[10];
+
+ if (mount("none", PROCDIR, "proc", MS_RDONLY, NULL) == -1) {
+ perror("mount");
+ return 1;
+ }
+
+ if (readlink(PROCDIR"/self", buf, sizeof(buf)) == -1) {
+ perror("readlink");
+ return 1;
+ }
+
+ umount(PROCDIR);
+
+ /* child should have PID 1 in a new pid namespace - if true
+ * procfs belongs to the new pid namespace */
+ if (strcmp(buf, "1")) {
+ fprintf(stderr, "%s contains: %s\n", PROCDIR"/self", buf);
+ return 1;
+ }
+
+ return 0;
+}
+
+static void test(void)
+{
+ int status;
+
+ if (do_clone_tests(CLONE_NEWPID, child_func, NULL, NULL, NULL) == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+
+ SAFE_WAIT(cleanup, &status);
+
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
+ tst_resm(TPASS, "mounting procfs in a new namespace");
+ return;
+ }
+
+ if (WIFSIGNALED(status)) {
+ tst_resm(TFAIL, "child was killed with signal %s",
+ tst_strsig(WTERMSIG(status)));
+ return;
+ }
+
+ tst_resm(TFAIL, "mounting procfs in a new namespace");
+}
+
+int main(int argc, char *argv[])
+{
+ const char *msg;
+ int lc;
+
+ msg = parse_opts(argc, argv, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++)
+ test();
+
+ cleanup();
+ tst_exit();
+}
--
1.8.3.1
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH v3] containers: added pidns/pidns03.c
2014-07-23 9:28 ` [LTP] [PATCH v3] " Matus Marhefka
@ 2014-07-24 7:20 ` Jan Stancek
2014-07-25 10:30 ` [LTP] [PATCH v4] " Matus Marhefka
2014-07-28 14:08 ` [LTP] [PATCH v3] " chrubis
0 siblings, 2 replies; 9+ messages in thread
From: Jan Stancek @ 2014-07-24 7:20 UTC (permalink / raw)
To: Matus Marhefka; +Cc: ltp-list, metan
----- Original Message -----
> From: "Matus Marhefka" <mmarhefk@redhat.com>
> To: ltp-list@lists.sourceforge.net
> Cc: metan@suse.de, jstancek@redhat.com
> Sent: Wednesday, 23 July, 2014 11:28:49 AM
> Subject: [PATCH v3] containers: added pidns/pidns03.c
>
> * Clones a new child process with CLONE_NEWPID flag - the new child
> * process mounts procfs to a "proc" directory and checks if it belongs
> * to a new pid namespace by:
> * 1. reading value of a symbolic link "proc/self"
> * 2. comparing read value (PID) with "1"
>
> Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
> Signed-off-by: Jiri Jaburek <jjaburek@redhat.com>
> ---
> testcases/kernel/containers/pidns/pidns03.c | 121
> ++++++++++++++++++++++++++++
> 1 file changed, 121 insertions(+)
> create mode 100644 testcases/kernel/containers/pidns/pidns03.c
>
> diff --git a/testcases/kernel/containers/pidns/pidns03.c
> b/testcases/kernel/containers/pidns/pidns03.c
> new file mode 100644
> index 0000000..ac0dcbf
> --- /dev/null
> +++ b/testcases/kernel/containers/pidns/pidns03.c
> @@ -0,0 +1,121 @@
> +/* Copyright (c) 2014 Red Hat, Inc. All rights reserved.
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of version 2 the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + ***********************************************************************
> + * File: pidns03.c
> + *
> + * Description:
> + * Clones a new child process with CLONE_NEWPID flag - the new child
> + * process mounts procfs to a "proc" directory and checks if it belongs
> + * to a new pid namespace by:
> + * 1. reading value of a symbolic link "proc/self"
> + * 2. comparing read value (PID) with "1"
> + */
> +
> +#define _GNU_SOURCE
> +#include <sys/wait.h>
> +#include <sys/mount.h>
> +#include <sys/types.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <errno.h>
> +#include "usctest.h"
> +#include "test.h"
> +#include "safe_macros.h"
> +#include "libclone.h"
> +
> +
> +#define PROCDIR "proc"
> +char *TCID = "pidns03";
> +int TST_TOTAL = 1;
> +
> +
> +static void cleanup(void)
> +{
> + tst_rmdir();
> +}
> +
> +static void setup(void)
> +{
> + tst_require_root(NULL);
> + tst_tmpdir();
> + SAFE_MKDIR(cleanup, PROCDIR, 0555);
> +}
> +
> +int child_func(void *arg)
> +{
> + char buf[10];
> +
> + if (mount("none", PROCDIR, "proc", MS_RDONLY, NULL) == -1) {
> + perror("mount");
> + return 1;
> + }
> +
> + if (readlink(PROCDIR"/self", buf, sizeof(buf)) == -1) {
> + perror("readlink");
Hi,
looks good to me, with small note to make umount also in readlink() error path.
If there'll be no other objections from Cyril, I can add that during commit (no need to resubmit).
Regards,
Jan
> + return 1;
> + }
> +
> + umount(PROCDIR);
> +
> + /* child should have PID 1 in a new pid namespace - if true
> + * procfs belongs to the new pid namespace */
> + if (strcmp(buf, "1")) {
> + fprintf(stderr, "%s contains: %s\n", PROCDIR"/self", buf);
> + return 1;
> + }
> +
> + return 0;
> +}
> +
> +static void test(void)
> +{
> + int status;
> +
> + if (do_clone_tests(CLONE_NEWPID, child_func, NULL, NULL, NULL) == -1)
> + tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
> +
> + SAFE_WAIT(cleanup, &status);
> +
> + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
> + tst_resm(TPASS, "mounting procfs in a new namespace");
> + return;
> + }
> +
> + if (WIFSIGNALED(status)) {
> + tst_resm(TFAIL, "child was killed with signal %s",
> + tst_strsig(WTERMSIG(status)));
> + return;
> + }
> +
> + tst_resm(TFAIL, "mounting procfs in a new namespace");
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + const char *msg;
> + int lc;
> +
> + msg = parse_opts(argc, argv, NULL, NULL);
> + if (msg != NULL)
> + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> + setup();
> +
> + for (lc = 0; TEST_LOOPING(lc); lc++)
> + test();
> +
> + cleanup();
> + tst_exit();
> +}
> --
> 1.8.3.1
>
>
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 9+ messages in thread
* [LTP] [PATCH v4] containers: added pidns/pidns03.c
2014-07-24 7:20 ` Jan Stancek
@ 2014-07-25 10:30 ` Matus Marhefka
2014-07-28 14:08 ` [LTP] [PATCH v3] " chrubis
1 sibling, 0 replies; 9+ messages in thread
From: Matus Marhefka @ 2014-07-25 10:30 UTC (permalink / raw)
To: ltp-list
* Clones a new child process with CLONE_NEWPID flag - the new child
* process mounts procfs to a "proc" directory and checks if it belongs
* to a new pid namespace by:
* 1. reading value of a symbolic link "proc/self"
* 2. comparing read value (PID) with "1"
Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
Signed-off-by: Jiri Jaburek <jjaburek@redhat.com>
---
testcases/kernel/containers/pidns/pidns03.c | 122 ++++++++++++++++++++++++++++
1 file changed, 122 insertions(+)
create mode 100644 testcases/kernel/containers/pidns/pidns03.c
diff --git a/testcases/kernel/containers/pidns/pidns03.c b/testcases/kernel/containers/pidns/pidns03.c
new file mode 100644
index 0000000..600683d
--- /dev/null
+++ b/testcases/kernel/containers/pidns/pidns03.c
@@ -0,0 +1,122 @@
+/* Copyright (c) 2014 Red Hat, Inc. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of version 2 the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ * File: pidns03.c
+ *
+ * Description:
+ * Clones a new child process with CLONE_NEWPID flag - the new child
+ * process mounts procfs to a "proc" directory and checks if it belongs
+ * to a new pid namespace by:
+ * 1. reading value of a symbolic link "proc/self"
+ * 2. comparing read value (PID) with "1"
+ */
+
+#define _GNU_SOURCE
+#include <sys/wait.h>
+#include <sys/mount.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include "usctest.h"
+#include "test.h"
+#include "safe_macros.h"
+#include "libclone.h"
+
+
+#define PROCDIR "proc"
+char *TCID = "pidns03";
+int TST_TOTAL = 1;
+
+
+static void cleanup(void)
+{
+ tst_rmdir();
+}
+
+static void setup(void)
+{
+ tst_require_root(NULL);
+ tst_tmpdir();
+ SAFE_MKDIR(cleanup, PROCDIR, 0555);
+}
+
+int child_func(void *arg)
+{
+ char buf[10];
+
+ if (mount("none", PROCDIR, "proc", MS_RDONLY, NULL) == -1) {
+ perror("mount");
+ return 1;
+ }
+
+ if (readlink(PROCDIR"/self", buf, sizeof(buf)) == -1) {
+ perror("readlink");
+ umount(PROCDIR);
+ return 1;
+ }
+
+ umount(PROCDIR);
+
+ /* child should have PID 1 in a new pid namespace - if true
+ * procfs belongs to the new pid namespace */
+ if (strcmp(buf, "1")) {
+ fprintf(stderr, "%s contains: %s\n", PROCDIR"/self", buf);
+ return 1;
+ }
+
+ return 0;
+}
+
+static void test(void)
+{
+ int status;
+
+ if (do_clone_tests(CLONE_NEWPID, child_func, NULL, NULL, NULL) == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+
+ SAFE_WAIT(cleanup, &status);
+
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
+ tst_resm(TPASS, "mounting procfs in a new namespace");
+ return;
+ }
+
+ if (WIFSIGNALED(status)) {
+ tst_resm(TFAIL, "child was killed with signal %s",
+ tst_strsig(WTERMSIG(status)));
+ return;
+ }
+
+ tst_resm(TFAIL, "mounting procfs in a new namespace");
+}
+
+int main(int argc, char *argv[])
+{
+ const char *msg;
+ int lc;
+
+ msg = parse_opts(argc, argv, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++)
+ test();
+
+ cleanup();
+ tst_exit();
+}
--
1.8.3.1
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH v3] containers: added pidns/pidns03.c
2014-07-24 7:20 ` Jan Stancek
2014-07-25 10:30 ` [LTP] [PATCH v4] " Matus Marhefka
@ 2014-07-28 14:08 ` chrubis
[not found] ` <2081581613.15959281.1406557594456.JavaMail.zimbra@redhat.com>
1 sibling, 1 reply; 9+ messages in thread
From: chrubis @ 2014-07-28 14:08 UTC (permalink / raw)
To: Jan Stancek; +Cc: metan, ltp-list
Hi!
> looks good to me, with small note to make umount also in readlink() error path.
> If there'll be no other objections from Cyril, I can add that during commit (no need to resubmit).
The latest version looks good to me as well.
Maybe we can add a comment that would explain that /proc/self points to
directory named with the process pid so that it's clear why readlink
returns the process pid there.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls.
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH v3] containers: added pidns/pidns03.c
[not found] ` <2081581613.15959281.1406557594456.JavaMail.zimbra@redhat.com>
@ 2014-07-28 14:34 ` chrubis
0 siblings, 0 replies; 9+ messages in thread
From: chrubis @ 2014-07-28 14:34 UTC (permalink / raw)
To: Jan Stancek; +Cc: metan, ltp-list
Hi!
> > > looks good to me, with small note to make umount also in readlink() error
> > > path.
> > > If there'll be no other objections from Cyril, I can add that during commit
> > > (no need to resubmit).
> >
> > The latest version looks good to me as well.
> >
> > Maybe we can add a comment that would explain that /proc/self points to
> > directory named with the process pid so that it's clear why readlink
> > returns the process pid there.
>
> Pushed with extra comment about proc/self symlink.
Looking at the commit we miss runtest record.
Even more the testcases are currently executed by the runpidnstest.sh.
Can we get that converted to a runtest file and have the pidns03 added?
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls.
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-07-28 14:35 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-21 10:41 [LTP] [PATCH] containers: added pidns/pidns03.c Matus Marhefka
2014-07-21 13:22 ` Jan Stancek
2014-07-21 15:19 ` [LTP] [PATCH v2] " Matus Marhefka
2014-07-22 16:54 ` chrubis
2014-07-23 9:28 ` [LTP] [PATCH v3] " Matus Marhefka
2014-07-24 7:20 ` Jan Stancek
2014-07-25 10:30 ` [LTP] [PATCH v4] " Matus Marhefka
2014-07-28 14:08 ` [LTP] [PATCH v3] " chrubis
[not found] ` <2081581613.15959281.1406557594456.JavaMail.zimbra@redhat.com>
2014-07-28 14:34 ` chrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox