Skip to content

Instantly share code, notes, and snippets.

@marineam
Created April 7, 2016 05:23
Show Gist options
  • Save marineam/d3111d4f105fcac7516abde3ae9c3558 to your computer and use it in GitHub Desktop.
Save marineam/d3111d4f105fcac7516abde3ae9c3558 to your computer and use it in GitHub Desktop.
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
index 0a9d2bb..e900eac 100644
--- a/src/basic/terminal-util.c
+++ b/src/basic/terminal-util.c
@@ -837,13 +837,39 @@ int make_stdio(int fd) {
}
int make_null_stdio(void) {
- int null_fd;
+ int null_fd, kmsg_fd;
+ int r, s, t;
null_fd = open("/dev/null", O_RDWR|O_NOCTTY);
if (null_fd < 0)
return -errno;
- return make_stdio(null_fd);
+ kmsg_fd = open("/dev/kmsg", O_WRONLY|O_NOCTTY);
+ if (kmsg_fd < 0)
+ kmsg_fd = null_fd;
+
+ r = dup2(null_fd, STDIN_FILENO);
+ s = dup2(kmsg_fd, STDOUT_FILENO);
+ t = dup2(kmsg_fd, STDERR_FILENO);
+
+ if (null_fd >= 3)
+ safe_close(null_fd);
+ if (null_fd != kmsg_fd && kmsg_fd >= 3)
+ safe_close(kmsg_fd);
+
+ if (r < 0 || s < 0 || t < 0)
+ return -errno;
+
+ /* Explicitly unset O_CLOEXEC, since if fd was < 3, then
+ * dup2() was a NOP and the bit hence possibly set. */
+ fd_cloexec(STDIN_FILENO, false);
+ fd_cloexec(STDOUT_FILENO, false);
+ fd_cloexec(STDERR_FILENO, false);
+
+ // LOLOL
+ setenv("LIBMOUNT_DEBUG", "all", 1);
+
+ return 0;
}
int getttyname_malloc(int fd, char **ret) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment