From: Karol Lewandowski Date: Thu, 25 Apr 2019 10:03:05 +0000 (+0200) Subject: spawn: Introduce helper to open /dev/null on all standard fds X-Git-Tag: submit/tizen/20190523.140943~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=20af7e1ad9b1941d51ea1eba8a03536fc1bfa840;p=platform%2Fcore%2Fsystem%2Fcrash-worker.git spawn: Introduce helper to open /dev/null on all standard fds This will be used in crash-manager to invoke processes in "non-blocking" way. Change-Id: Ic70eda38c7cba8628e635ba206f1fe81edb944eb --- diff --git a/src/shared/spawn.c b/src/shared/spawn.c index 84d2db9..7139f73 100644 --- a/src/shared/spawn.c +++ b/src/shared/spawn.c @@ -48,6 +48,15 @@ int spawn_setstdouterr(spawn_param_u *param) return dup2(param->int_val, STDOUT_FILENO) < 0 || dup2(param->int_val, STDERR_FILENO) < 0 ? -1 : 0; } +int spawn_nullstdfds(spawn_param_u *param) +{ + int fd = open("/dev/null", O_RDWR); + int ret = dup2(fd, STDIN_FILENO) < 0 || dup2(fd, STDOUT_FILENO) < 0 || dup2(fd, STDERR_FILENO) < 0 ? -1 : 0; + if (fd != STDIN_FILENO && fd != STDOUT_FILENO && fd != STDERR_FILENO) + close(fd); + return ret; +} + int spawn_chdir(spawn_param_u *param) { assert(param); diff --git a/src/shared/spawn.h b/src/shared/spawn.h index f553a9f..7177ae8 100644 --- a/src/shared/spawn.h +++ b/src/shared/spawn.h @@ -36,6 +36,7 @@ typedef int (*spawn_prepare_fn)(spawn_param_u *param); int spawn_setstdout(spawn_param_u *param); int spawn_setstdouterr(spawn_param_u *param); +int spawn_nullstdfds(spawn_param_u *param); int spawn_chdir(spawn_param_u *param); int spawn_umask(spawn_param_u *param);