File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1135,6 +1135,22 @@ int main(int argc, char *argv[]) {
11351135 struct epoll_event ep_worker = { .events = EPOLLIN };
11361136 int r = 0 , one = 1 ;
11371137
1138+ /*
1139+ * Ensure no file descriptor unwillingly falls in the 0..2 range
1140+ * Warning: DO NOT OPEN FILES BEFORE THE 3 OPENS BELOW
1141+ */
1142+ int fd_stdi = open ("/dev/null" , O_RDWR );
1143+ int fd_stdo = open ("/dev/null" , O_RDWR );
1144+ int fd_stde = open ("/dev/null" , O_RDWR );
1145+
1146+ /* Close only the ones that are safe to close */
1147+ if (fd_stdi > STDERR_FILENO )
1148+ close (fd_stdi );
1149+ if (fd_stdo > STDERR_FILENO )
1150+ close (fd_stdo );
1151+ if (fd_stde > STDERR_FILENO )
1152+ close (fd_stde );
1153+
11381154 udev = udev_new ();
11391155 if (!udev ) {
11401156 r = log_error_errno (errno , "could not allocate udev context: %m" );
@@ -1153,9 +1169,9 @@ int main(int argc, char *argv[]) {
11531169 log_warning_errno (r , "failed to parse kernel command line, ignoring: %m" );
11541170
11551171 if (arg_debug ) {
1156- log_set_target (LOG_TARGET_CONSOLE );
1172+ log_set_target (LOG_TARGET_CONSOLE );
11571173 log_set_max_level (LOG_DEBUG );
1158- }
1174+ }
11591175
11601176 if (getuid () != 0 ) {
11611177 r = log_error_errno (EPERM , "root privileges required" );
You can’t perform that action at this time.
0 commit comments