-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explicitly use fork() & execl() to avoid the file descriptor shenanigans, and move & rename the function to util.[ch]. Also, when at it, add a unit test for the function as well.
- Loading branch information
Showing
8 changed files
with
132 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
tests += [ | ||
[files('test-rand.c')], | ||
[files('test-util.c')], | ||
] | ||
|
||
# vi: sw=8 ts=8 et: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <gio/gio.h> | ||
#include <glib.h> | ||
#include <stdio.h> | ||
|
||
#include "util.h" | ||
#include "log.h" | ||
|
||
static void test_df_execute_external_command(void) | ||
{ | ||
for (guint8 i = 0; i < 2; i++) { | ||
gboolean show_output = i == 0 ? FALSE : TRUE; | ||
g_test_message("show_output: %s", show_output ? "TRUE" : "FALSE"); | ||
|
||
g_assert_true(df_execute_external_command("true", show_output) == 0); | ||
g_assert_true(df_execute_external_command("true; echo hello world; cat /proc/$$/stat", show_output) == 0); | ||
g_assert_true(df_execute_external_command("true; echo hello world; false /proc/$$/stat", show_output) > 0); | ||
g_assert_true(df_execute_external_command("exit 66", show_output) == 66); | ||
g_assert_true(df_execute_external_command("this-should-not-exist", show_output) > 0); | ||
g_assert_true(df_execute_external_command("kill -SEGV $$", show_output) > 0); | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
g_test_init(&argc, &argv, NULL); | ||
|
||
g_test_add_func("/df_util/df_execute_external_command", test_df_execute_external_command); | ||
|
||
return g_test_run(); | ||
} |