Before SSH terminates, it waits for the PTYs that it creates for use as
stdin, stdout, and stderr to be closed. When any of the Open vSwitch
daemons were started in the background over an SSH session, they held
those file descriptors open and thus the SSH session hung. This commit
fixes the problem by closing those file descriptors, allowing SSH to
terminate.
- * Copyright (c) 2008, 2009 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
if (detach) {
size_t bytes_written;
{
if (detach) {
size_t bytes_written;
int error;
error = write_fully(daemonize_fds[1], "", 1, &bytes_written);
int error;
error = write_fully(daemonize_fds[1], "", 1, &bytes_written);
if (chdir_) {
ignore(chdir("/"));
}
if (chdir_) {
ignore(chdir("/"));
}
+
+ /* Close stdin, stdout, stderr. Otherwise if we're started from
+ * e.g. an SSH session then we tend to hold that session open
+ * artificially. */
+ null_fd = get_null_fd();
+ if (null_fd >= 0) {
+ dup2(null_fd, STDIN_FILENO);
+ dup2(null_fd, STDOUT_FILENO);
+ dup2(null_fd, STDERR_FILENO);
+ }