diff options
author | Marcel Hollerbach <mail@marcel-hollerbach.de> | 2020-04-01 14:04:19 +0200 |
---|---|---|
committer | Marcel Hollerbach <mail@marcel-hollerbach.de> | 2020-04-01 19:25:36 +0200 |
commit | b3786aa83a55ec910b65ab86be3e44c59d1c01e3 (patch) | |
tree | b428a4d2e2439bd7a41ccc8b524a9b1796c17b70 | |
parent | 35986549652d3ed1eb9af0baffa064a1ea21adc8 (diff) | |
download | efl-b3786aa83a55ec910b65ab86be3e44c59d1c01e3.tar.gz |
exactness: protect against forked calls
there came up a issue, where a excatness spawned processes were bringing
up a efreetd instance, when the efreetd instance turned off itself, the
files for exactness were written again, which is wrong. This ensures
that forked instances do not take any actions.
Differential Revision: https://phab.enlightenment.org/D11634
-rw-r--r-- | src/bin/exactness/common.c | 25 | ||||
-rw-r--r-- | src/bin/exactness/common.h | 3 | ||||
-rw-r--r-- | src/bin/exactness/player.c | 14 | ||||
-rw-r--r-- | src/bin/exactness/recorder.c | 16 |
4 files changed, 47 insertions, 11 deletions
diff --git a/src/bin/exactness/common.c b/src/bin/exactness/common.c index d1bb1340a5..f957003117 100644 --- a/src/bin/exactness/common.c +++ b/src/bin/exactness/common.c @@ -4,6 +4,31 @@ #include "common.h" +Eina_Bool +ex_is_original_app(void) +{ + const char *original_pid_env = getenv("EXACTNESS_ORIGINAL_PID"); + if (original_pid_env) + { + pid_t original_pid = atoi(original_pid_env); + if (original_pid == getpid()) + return EINA_TRUE; + } + return EINA_FALSE; +} + +void +ex_set_original_envvar(void) +{ + const char *original_pid_env = getenv("EXACTNESS_ORIGINAL_PID"); + if (!original_pid_env) + { + char pid[30]; + snprintf(pid, sizeof(pid), "%d", getpid()); + setenv("EXACTNESS_ORIGINAL_PID", pid, 0); + } +} + void ex_prepare_elm_overloay(void) { diff --git a/src/bin/exactness/common.h b/src/bin/exactness/common.h index d931973b31..acec924598 100644 --- a/src/bin/exactness/common.h +++ b/src/bin/exactness/common.h @@ -260,6 +260,9 @@ typedef struct Evas *(*_evas_new)(void); const char *_exactness_action_type_to_string_get(Exactness_Action_Type type); + +Eina_Bool ex_is_original_app(void); +void ex_set_original_envvar(void); Eina_Bool exactness_image_compare(Exactness_Image *img1, Exactness_Image *img2, Exactness_Image **diff_img); Exactness_Unit *exactness_unit_file_read(const char *filename); Eina_Bool exactness_unit_file_write(Exactness_Unit *unit, const char *filename); diff --git a/src/bin/exactness/player.c b/src/bin/exactness/player.c index 1240070f37..2440657409 100644 --- a/src/bin/exactness/player.c +++ b/src/bin/exactness/player.c @@ -1039,6 +1039,8 @@ eina_init(void) ORIGINAL_CALL("eina_init"); + ex_set_original_envvar(); + if (original_return == 1) { const char *dest = getenv("EXACTNESS_DEST"); @@ -1080,7 +1082,7 @@ ecore_evas_init(void) ORIGINAL_CALL("ecore_evas_init") - if (original_return == 1) + if (ex_is_original_app() && original_return == 1) { _setup_ee_creation(); } @@ -1095,7 +1097,7 @@ elm_init(int argc, char **argv) int original_return; ORIGINAL_CALL("elm_init", argc, argv) - if (original_return == 1) + if (ex_is_original_app() && original_return == 1) ex_prepare_elm_overloay(); return original_return; @@ -1106,7 +1108,8 @@ ecore_main_loop_begin(void) { int original_return; ORIGINAL_CALL("ecore_main_loop_begin") - _write_unit_file(); + if (ex_is_original_app()) + _write_unit_file(); (void)original_return; } @@ -1115,7 +1118,8 @@ efl_loop_begin(Eo *obj) { Eina_Value *original_return; ORIGINAL_CALL_T(Eina_Value*, "efl_loop_begin", obj); - _write_unit_file(); + if (ex_is_original_app()) + _write_unit_file(); return original_return; } @@ -1125,7 +1129,7 @@ eina_shutdown(void) int original_return; static Eina_Bool output_written = EINA_FALSE; ORIGINAL_CALL("eina_shutdown") - if (original_return == 1 && !output_written) + if (ex_is_original_app() &&original_return == 1 && !output_written) { output_written = EINA_TRUE; _write_unit_file(); diff --git a/src/bin/exactness/recorder.c b/src/bin/exactness/recorder.c index 6c881f950f..d7c6e7a1d8 100644 --- a/src/bin/exactness/recorder.c +++ b/src/bin/exactness/recorder.c @@ -314,7 +314,9 @@ eina_init(void) ORIGINAL_CALL("eina_init"); - if (original_return == 1) + ex_set_original_envvar(); + + if (ex_is_original_app() && original_return == 1) { _log_domain = eina_log_domain_register("exactness_recorder", NULL); @@ -336,7 +338,7 @@ ecore_evas_init(void) ORIGINAL_CALL("ecore_evas_init") - if (original_return == 1) + if (ex_is_original_app() && original_return == 1) { _setup_ee_creation(); @@ -352,7 +354,7 @@ elm_init(int argc, char **argv) int original_return; ORIGINAL_CALL("elm_init", argc, argv) - if (original_return == 1) + if (ex_is_original_app() && original_return == 1) ex_prepare_elm_overloay(); return original_return; @@ -363,7 +365,8 @@ ecore_main_loop_begin(void) { int original_return; ORIGINAL_CALL("ecore_main_loop_begin") - _output_write(); + if (ex_is_original_app()) + _output_write(); (void)original_return; } @@ -372,7 +375,8 @@ efl_loop_begin(Eo *obj) { Eina_Value *original_return; ORIGINAL_CALL_T(Eina_Value*, "efl_loop_begin", obj); - _output_write(); + if (ex_is_original_app()) + _output_write(); return original_return; } @@ -382,7 +386,7 @@ eina_shutdown(void) int original_return; static Eina_Bool output_written = EINA_FALSE; ORIGINAL_CALL("eina_shutdown") - if (original_return == 1 && !output_written) + if (ex_is_original_app() && original_return == 1 && !output_written) { output_written = EINA_TRUE; _output_write(); |