forked from enlightenment/edi
exe: add a helper for exe waiting
This commit is contained in:
parent
37759291c5
commit
7f39682980
|
@ -37,6 +37,7 @@ extern "C" {
|
|||
#include <edi_build_provider.h>
|
||||
#include <edi_builder.h>
|
||||
#include <edi_path.h>
|
||||
#include <edi_exe.h>
|
||||
|
||||
/**
|
||||
* @file
|
||||
|
|
|
@ -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@
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include <Eina.h>
|
||||
#include <Ecore.h>
|
||||
#include <Ecore_File.h>
|
||||
|
||||
#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--;
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <Ecore.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
|
@ -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_ */
|
|
@ -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 \
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include "Edi.h"
|
||||
#include "edi_suite.h"
|
||||
|
||||
#define COPYRIGHT "Copyright © 2014 Andy Williams <andy@andyilliams.me> and various contributors (see AUTHORS)."
|
||||
#define COPYRIGHT "Copyright © 2014-2017 Andy Williams <andy@andyilliams.me> 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 }
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue