diff --git a/services/init/standard/init.c b/services/init/standard/init.c index 0e14cdc4650584bbf9fd421f86fbc422f9da340b..2c2ae7c17aabbaaa30d8405392aa7884500391fb 100755 --- a/services/init/standard/init.c +++ b/services/init/standard/init.c @@ -93,6 +93,7 @@ static int FdHolderSockInit(void) void SystemInit(void) { + CloseStdio(); #ifndef STARTUP_INIT_TEST // Set up a session keyring that all processes will have access to. KeyCtrlGetKeyringId(KEY_SPEC_SESSION_KEYRING, 1); diff --git a/services/utils/init_utils.c b/services/utils/init_utils.c index 97bf1ffd8e7324ed920c027dbb168431b1e4edb5..b90e75fd045083f6b06c7569f79db1865d5372f3 100644 --- a/services/utils/init_utils.c +++ b/services/utils/init_utils.c @@ -167,14 +167,16 @@ void CloseStdio(void) { #ifndef STARTUP_INIT_TEST #ifndef __LITEOS_M__ - int fd = open("/dev/null", O_RDWR | O_CLOEXEC); + int fd = open("/dev/null", O_RDWR); if (fd < 0) { return; } dup2(fd, 0); dup2(fd, 1); dup2(fd, STDERR_HANDLE); - close(fd); + if (fd > STDERR_HANDLE) { + close(fd); + } #endif #endif }