From 7f3968298058b7d298a0ac7fdc365d559192fe27 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Tue, 30 May 2017 23:30:39 +0100 Subject: [PATCH] exe: add a helper for exe waiting --- src/lib/Edi.h | 1 + src/lib/Makefile.am | 2 ++ src/lib/edi.c | 4 ++++ src/lib/edi_exe.c | 33 ++++++++++++++++++++++++++++++++ src/lib/edi_exe.h | 41 ++++++++++++++++++++++++++++++++++++++++ src/tests/Makefile.am | 1 + src/tests/edi_suite.c | 3 ++- src/tests/edi_suite.h | 1 + src/tests/edi_test_exe.c | 22 +++++++++++++++++++++ 9 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/lib/edi_exe.c create mode 100644 src/lib/edi_exe.h create mode 100644 src/tests/edi_test_exe.c diff --git a/src/lib/Edi.h b/src/lib/Edi.h index 4dd956b..04772a7 100644 --- a/src/lib/Edi.h +++ b/src/lib/Edi.h @@ -37,6 +37,7 @@ extern "C" { #include #include #include +#include /** * @file diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index b3e142a..a4a011c 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -16,6 +16,7 @@ edi_build_provider.h \ edi_builder.h \ edi_create.h \ edi_path.h \ +edi_exe.h \ Edi.h includesdir = $(includedir)/edi-@VMAJ@ @@ -28,6 +29,7 @@ edi_build_provider.c \ edi_builder.c \ edi_create.c \ edi_path.c \ +edi_exe.c \ edi.c libedi_la_LIBADD = @EFL_LIBS@ -lm libedi_la_LDFLAGS = -no-undefined @EFL_LTLIBRARY_FLAGS@ diff --git a/src/lib/edi.c b/src/lib/edi.c index 0573262..47a0171 100644 --- a/src/lib/edi.c +++ b/src/lib/edi.c @@ -7,6 +7,8 @@ #include #include +#include +#include #include #include "Edi.h" @@ -24,6 +26,7 @@ edi_init(void) if (_edi_init > 1) return _edi_init; eina_init(); + ecore_init(); _edi_lib_log_dom = eina_log_domain_register("edi-lib", EINA_COLOR_CYAN); if (_edi_lib_log_dom < 0) @@ -40,6 +43,7 @@ edi_init(void) return _edi_init; shutdown_eina: + ecore_shutdown(); eina_shutdown(); _edi_init--; diff --git a/src/lib/edi_exe.c b/src/lib/edi_exe.c new file mode 100644 index 0000000..2866500 --- /dev/null +++ b/src/lib/edi_exe.c @@ -0,0 +1,33 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include + +#include "Edi.h" +#include "edi_private.h" + +EAPI int +edi_exe_wait(const char *command) +{ + pid_t pid; + Ecore_Exe *exe; + int exit; + + ecore_thread_main_loop_begin(); + exe = ecore_exe_pipe_run(command, ECORE_EXE_USE_SH | + ECORE_EXE_PIPE_WRITE, NULL); + pid = ecore_exe_pid_get(exe); + ecore_thread_main_loop_end(); + + waitpid(pid, &exit, 0); + + ecore_thread_main_loop_begin(); + ecore_exe_free(exe); + ecore_thread_main_loop_end(); + + return exit; +} + diff --git a/src/lib/edi_exe.h b/src/lib/edi_exe.h new file mode 100644 index 0000000..ae0bbe4 --- /dev/null +++ b/src/lib/edi_exe.h @@ -0,0 +1,41 @@ +#ifndef EDI_EXE_H_ +# define EDI_EXE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * @brief These routines are used for Edi executable management. + */ + +/** + * @brief Executable helpers + * @defgroup Exe + * + * @{ + * + * Functions of executable management. + * + */ + +/** + * Run an executable command and wait for it to return. + * + * @param command The command to execute in a child process. + * @return The return code of the executable. + * + * @ingroup Exe + */ +EAPI int edi_exe_wait(const char *command); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* EDI_EXE_H_ */ diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 19c2ab1..23aefb8 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -9,6 +9,7 @@ clang_include = '$(CLANG_INCLUDE)' edi_suite_SOURCES = \ edi_test_path.c \ +edi_test_exe.c \ edi_test_content_provider.c \ edi_test_language_provider.c \ edi_test_language_provider_c.c \ diff --git a/src/tests/edi_suite.c b/src/tests/edi_suite.c index 0caa1be..118f590 100644 --- a/src/tests/edi_suite.c +++ b/src/tests/edi_suite.c @@ -7,7 +7,7 @@ #include "Edi.h" #include "edi_suite.h" -#define COPYRIGHT "Copyright © 2014 Andy Williams and various contributors (see AUTHORS)." +#define COPYRIGHT "Copyright © 2014-2017 Andy Williams and various contributors (see AUTHORS)." static const struct { const char *name; @@ -15,6 +15,7 @@ static const struct { } tests[] = { { "basic", edi_test_basic }, { "path", edi_test_path }, + { "exe", edi_test_exe }, { "content_provider", edi_test_content_provider }, { "language_provider", edi_test_language_provider }, { "language_provider_c", edi_test_language_provider_c } diff --git a/src/tests/edi_suite.h b/src/tests/edi_suite.h index 22e70da..3b235d7 100644 --- a/src/tests/edi_suite.h +++ b/src/tests/edi_suite.h @@ -8,6 +8,7 @@ void edi_test_basic(TCase *tc); void edi_test_console(TCase *tc); void edi_test_path(TCase *tc); +void edi_test_exe(TCase *tc); void edi_test_content_provider(TCase *tc); void edi_test_language_provider(TCase *tc); void edi_test_language_provider_c(TCase *tc); diff --git a/src/tests/edi_test_exe.c b/src/tests/edi_test_exe.c new file mode 100644 index 0000000..ff18cf5 --- /dev/null +++ b/src/tests/edi_test_exe.c @@ -0,0 +1,22 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "edi_suite.h" + +START_TEST (edi_exe_test_wait) +{ + edi_init(); + + ck_assert(1 != edi_exe_wait("false")); + ck_assert_int_eq(0, edi_exe_wait("true")); + + edi_shutdown(); +} +END_TEST + +void edi_test_exe(TCase *tc) +{ + tcase_add_test(tc, edi_exe_test_wait); +} +