* [LTP] [PATCH v3] lib: tst_run_cmd: add tst_run_cmd() to exec specified program
@ 2013-06-27 14:52 Alexey Kodanev
2013-06-27 15:02 ` chrubis
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Alexey Kodanev @ 2013-06-27 14:52 UTC (permalink / raw)
To: ltp-list; +Cc: vasily.isaenko, Alexey Kodanev
vfork() + execvp() specified program.
Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
---
include/test.h | 9 +++++++++
lib/tst_run_cmd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 0 deletions(-)
create mode 100644 lib/tst_run_cmd.c
diff --git a/include/test.h b/include/test.h
index e68ae60..ee3efc3 100644
--- a/include/test.h
+++ b/include/test.h
@@ -206,6 +206,15 @@ int tst_get_path(const char *prog_name, char *buf, size_t buf_len);
long tst_ncpus(void);
long tst_ncpus_max(void);
+/* lib/tst_run_cmd.c
+ *
+ * vfork() + execvp() specified program.
+ * @argv: a list of two (at least program name + NULL) or more pointers that
+ * represent the argument list to the new program. The array of pointers
+ * must be terminated by a NULL pointer.
+ */
+void tst_run_cmd(void (cleanup_fn)(void), char *const argv[]);
+
#ifdef TST_USE_COMPAT16_SYSCALL
#define TCID_BIT_SUFFIX "_16"
#elif TST_USE_NEWER64_SYSCALL
diff --git a/lib/tst_run_cmd.c b/lib/tst_run_cmd.c
new file mode 100644
index 0000000..93fe2d6
--- /dev/null
+++ b/lib/tst_run_cmd.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would 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, write the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Alexey Kodanev <alexey.kodanev@oracle.com>
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include "test.h"
+
+void tst_run_cmd(void (cleanup_fn)(void), char *const argv[])
+{
+ if (argv == NULL || argv[0] == NULL) {
+ tst_brkm(TBROK, cleanup_fn,
+ "argument list is empty at %s:%d", __FILE__, __LINE__);
+ }
+
+ pid_t pid = vfork();
+ if (pid == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn, "vfork failed at %s:%d",
+ __FILE__, __LINE__);
+ }
+ if (!pid)
+ _exit(execvp(argv[0], argv));
+
+ int ret = -1;
+ if (waitpid(pid, &ret, 0) != pid) {
+ tst_brkm(TBROK, cleanup_fn, "waitpid failed at %s:%d",
+ __FILE__, __LINE__);
+ }
+
+ if (!WIFEXITED(ret) || WEXITSTATUS(ret) != 0) {
+ tst_brkm(TBROK, cleanup_fn, "failed to exec cmd '%s' at %s:%d",
+ argv[0], __FILE__, __LINE__);
+ }
+}
--
1.7.1
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [LTP] [PATCH v3] lib: tst_run_cmd: add tst_run_cmd() to exec specified program
2013-06-27 14:52 [LTP] [PATCH v3] lib: tst_run_cmd: add tst_run_cmd() to exec specified program Alexey Kodanev
@ 2013-06-27 15:02 ` chrubis
2013-06-28 3:15 ` Caspar Zhang
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: chrubis @ 2013-06-27 15:02 UTC (permalink / raw)
To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list
Hi!
> vfork() + execvp() specified program.
>
> Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
> ---
> include/test.h | 9 +++++++++
> lib/tst_run_cmd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 61 insertions(+), 0 deletions(-)
> create mode 100644 lib/tst_run_cmd.c
This one looks fine to me.
Let's wait a day or two to give other people chance to look at the code.
And if nobody object I will start pushing the patches in the order.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [LTP] [PATCH v3] lib: tst_run_cmd: add tst_run_cmd() to exec specified program
2013-06-27 14:52 [LTP] [PATCH v3] lib: tst_run_cmd: add tst_run_cmd() to exec specified program Alexey Kodanev
2013-06-27 15:02 ` chrubis
@ 2013-06-28 3:15 ` Caspar Zhang
2013-06-28 3:16 ` Wanlong Gao
2013-07-01 8:58 ` Wanlong Gao
3 siblings, 0 replies; 5+ messages in thread
From: Caspar Zhang @ 2013-06-28 3:15 UTC (permalink / raw)
To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list
On 06/27/2013 10:52 PM, Alexey Kodanev wrote:
> vfork() + execvp() specified program.
>
> Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
> ---
> include/test.h | 9 +++++++++
> lib/tst_run_cmd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 61 insertions(+), 0 deletions(-)
> create mode 100644 lib/tst_run_cmd.c
>
> diff --git a/include/test.h b/include/test.h
> index e68ae60..ee3efc3 100644
> --- a/include/test.h
> +++ b/include/test.h
> @@ -206,6 +206,15 @@ int tst_get_path(const char *prog_name, char *buf, size_t buf_len);
> long tst_ncpus(void);
> long tst_ncpus_max(void);
>
> +/* lib/tst_run_cmd.c
> + *
> + * vfork() + execvp() specified program.
> + * @argv: a list of two (at least program name + NULL) or more pointers that
> + * represent the argument list to the new program. The array of pointers
> + * must be terminated by a NULL pointer.
> + */
> +void tst_run_cmd(void (cleanup_fn)(void), char *const argv[]);
> +
> #ifdef TST_USE_COMPAT16_SYSCALL
> #define TCID_BIT_SUFFIX "_16"
> #elif TST_USE_NEWER64_SYSCALL
> diff --git a/lib/tst_run_cmd.c b/lib/tst_run_cmd.c
> new file mode 100644
> index 0000000..93fe2d6
> --- /dev/null
> +++ b/lib/tst_run_cmd.c
> @@ -0,0 +1,52 @@
> +/*
> + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it would 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, write the Free Software Foundation,
> + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> + *
> + * Author: Alexey Kodanev <alexey.kodanev@oracle.com>
> + *
> + */
> +
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <unistd.h>
> +#include "test.h"
> +
> +void tst_run_cmd(void (cleanup_fn)(void), char *const argv[])
> +{
> + if (argv == NULL || argv[0] == NULL) {
> + tst_brkm(TBROK, cleanup_fn,
> + "argument list is empty at %s:%d", __FILE__, __LINE__);
> + }
> +
> + pid_t pid = vfork();
> + if (pid == -1) {
> + tst_brkm(TBROK | TERRNO, cleanup_fn, "vfork failed at %s:%d",
> + __FILE__, __LINE__);
> + }
> + if (!pid)
> + _exit(execvp(argv[0], argv));
> +
> + int ret = -1;
> + if (waitpid(pid, &ret, 0) != pid) {
> + tst_brkm(TBROK, cleanup_fn, "waitpid failed at %s:%d",
> + __FILE__, __LINE__);
> + }
> +
> + if (!WIFEXITED(ret) || WEXITSTATUS(ret) != 0) {
> + tst_brkm(TBROK, cleanup_fn, "failed to exec cmd '%s' at %s:%d",
> + argv[0], __FILE__, __LINE__);
> + }
> +}
>
LGTM
Reviewed-by: Caspar Zhang <caspar@casparzhang.com>
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [LTP] [PATCH v3] lib: tst_run_cmd: add tst_run_cmd() to exec specified program
2013-06-27 14:52 [LTP] [PATCH v3] lib: tst_run_cmd: add tst_run_cmd() to exec specified program Alexey Kodanev
2013-06-27 15:02 ` chrubis
2013-06-28 3:15 ` Caspar Zhang
@ 2013-06-28 3:16 ` Wanlong Gao
2013-07-01 8:58 ` Wanlong Gao
3 siblings, 0 replies; 5+ messages in thread
From: Wanlong Gao @ 2013-06-28 3:16 UTC (permalink / raw)
To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list
On 06/27/2013 10:52 PM, Alexey Kodanev wrote:
> vfork() + execvp() specified program.
>
> Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
LGTM
Reviewed-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
> ---
> include/test.h | 9 +++++++++
> lib/tst_run_cmd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 61 insertions(+), 0 deletions(-)
> create mode 100644 lib/tst_run_cmd.c
>
> diff --git a/include/test.h b/include/test.h
> index e68ae60..ee3efc3 100644
> --- a/include/test.h
> +++ b/include/test.h
> @@ -206,6 +206,15 @@ int tst_get_path(const char *prog_name, char *buf, size_t buf_len);
> long tst_ncpus(void);
> long tst_ncpus_max(void);
>
> +/* lib/tst_run_cmd.c
> + *
> + * vfork() + execvp() specified program.
> + * @argv: a list of two (at least program name + NULL) or more pointers that
> + * represent the argument list to the new program. The array of pointers
> + * must be terminated by a NULL pointer.
> + */
> +void tst_run_cmd(void (cleanup_fn)(void), char *const argv[]);
> +
> #ifdef TST_USE_COMPAT16_SYSCALL
> #define TCID_BIT_SUFFIX "_16"
> #elif TST_USE_NEWER64_SYSCALL
> diff --git a/lib/tst_run_cmd.c b/lib/tst_run_cmd.c
> new file mode 100644
> index 0000000..93fe2d6
> --- /dev/null
> +++ b/lib/tst_run_cmd.c
> @@ -0,0 +1,52 @@
> +/*
> + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it would 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, write the Free Software Foundation,
> + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> + *
> + * Author: Alexey Kodanev <alexey.kodanev@oracle.com>
> + *
> + */
> +
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <unistd.h>
> +#include "test.h"
> +
> +void tst_run_cmd(void (cleanup_fn)(void), char *const argv[])
> +{
> + if (argv == NULL || argv[0] == NULL) {
> + tst_brkm(TBROK, cleanup_fn,
> + "argument list is empty at %s:%d", __FILE__, __LINE__);
> + }
> +
> + pid_t pid = vfork();
> + if (pid == -1) {
> + tst_brkm(TBROK | TERRNO, cleanup_fn, "vfork failed at %s:%d",
> + __FILE__, __LINE__);
> + }
> + if (!pid)
> + _exit(execvp(argv[0], argv));
> +
> + int ret = -1;
> + if (waitpid(pid, &ret, 0) != pid) {
> + tst_brkm(TBROK, cleanup_fn, "waitpid failed at %s:%d",
> + __FILE__, __LINE__);
> + }
> +
> + if (!WIFEXITED(ret) || WEXITSTATUS(ret) != 0) {
> + tst_brkm(TBROK, cleanup_fn, "failed to exec cmd '%s' at %s:%d",
> + argv[0], __FILE__, __LINE__);
> + }
> +}
>
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [LTP] [PATCH v3] lib: tst_run_cmd: add tst_run_cmd() to exec specified program
2013-06-27 14:52 [LTP] [PATCH v3] lib: tst_run_cmd: add tst_run_cmd() to exec specified program Alexey Kodanev
` (2 preceding siblings ...)
2013-06-28 3:16 ` Wanlong Gao
@ 2013-07-01 8:58 ` Wanlong Gao
3 siblings, 0 replies; 5+ messages in thread
From: Wanlong Gao @ 2013-07-01 8:58 UTC (permalink / raw)
To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list
On 06/27/2013 10:52 PM, Alexey Kodanev wrote:
> vfork() + execvp() specified program.
>
> Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
Applied, thank you.
Wanlong Gao
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-07-01 9:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-27 14:52 [LTP] [PATCH v3] lib: tst_run_cmd: add tst_run_cmd() to exec specified program Alexey Kodanev
2013-06-27 15:02 ` chrubis
2013-06-28 3:15 ` Caspar Zhang
2013-06-28 3:16 ` Wanlong Gao
2013-07-01 8:58 ` Wanlong Gao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox