Просмотр исходного кода

s-s-d: Check for error on open an ioctl calls

Guillem Jover лет назад: 16
Родитель
Сommit
2e2cab1228
1 измененных файлов с 6 добавлено и 1 удалено
  1. 6 1
      utils/start-stop-daemon.c

+ 6 - 1
utils/start-stop-daemon.c

@@ -1556,8 +1556,12 @@ main(int argc, char **argv)
 
 
 #ifdef HAVE_TIOCNOTTY
 #ifdef HAVE_TIOCNOTTY
 		tty_fd = open("/dev/tty", O_RDWR);
 		tty_fd = open("/dev/tty", O_RDWR);
+		if (tty_fd < 0)
+			fatal("unable to open '%s'", "/dev/tty");
 #endif
 #endif
 		devnull_fd = open("/dev/null", O_RDWR);
 		devnull_fd = open("/dev/null", O_RDWR);
+		if (devnull_fd < 0)
+			fatal("unable to open '%s'", "/dev/null");
 	}
 	}
 	if (nicelevel) {
 	if (nicelevel) {
 		errno = 0;
 		errno = 0;
@@ -1619,7 +1623,8 @@ main(int argc, char **argv)
 		int i;
 		int i;
 #ifdef HAVE_TIOCNOTTY
 #ifdef HAVE_TIOCNOTTY
 		 /* Change tty. */
 		 /* Change tty. */
-		ioctl(tty_fd, TIOCNOTTY, 0);
+		if (ioctl(tty_fd, TIOCNOTTY, 0) != 0)
+			fatal("unable to change tty");
 		close(tty_fd);
 		close(tty_fd);
 #endif
 #endif
 		if (umask_value < 0)
 		if (umask_value < 0)