Skip to content

Commit

Permalink
SystemServer: Explicitly open /dev/null for services without StdIO
Browse files Browse the repository at this point in the history
Spawning services with nothing open at all on the standard I/O fds is
way too harsh. We now open /dev/null for them instead.
  • Loading branch information
awesomekling committed Jan 4, 2020
1 parent c2b7c43 commit 9bd4bf4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Base/usr/share/man/man5/SystemServer.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describing how to launch and manage this service.

* `Executable` - an executable to spawn. If no explicit executable is specified, SystemServer assumes `/bin/{service name}` (for example, `/bin/WindowServer` for a service named `WindowServer`).
* `Arguments` - a space-separated list of arguments to pass to the service as `argv` (excluding `argv[0]`). By default, SystemServer does not pass any arguments other than `argv[0]`.
* `StdIO` - a path to a file to be passed as standard I/O streams to the service. By default, services inherit SystemServer's own standard I/O streams, which are normally set to `/dev/tty0`.
* `StdIO` - a path to a file to be passed as standard I/O streams to the service. By default, services run with `/dev/null` for standard I/O.
* `Priority` - the scheduling priority to set for the service, either "low", "normal", or "high". The default is "normal".
* `KeepAlive` - whether the service should be restarted if it exits or crashes. For lazy services, this means the service will get respawned once a new connection is attempted on their socket after they exit or crash.
* `Lazy` - whether the service should only get spawned once a client attempts to connect to their socket.
Expand Down
5 changes: 5 additions & 0 deletions Servers/SystemServer/Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ void Service::spawn()
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);

int fd = open("/dev/null", O_RDWR);
ASSERT(fd == STDIN_FILENO);
dup2(STDIN_FILENO, STDOUT_FILENO);
dup2(STDIN_FILENO, STDERR_FILENO);
}

if (!m_socket_path.is_null()) {
Expand Down

0 comments on commit 9bd4bf4

Please sign in to comment.