All files or device nodes opened here should not be console tty.
Let's open it the flags for safety.
return 1;
}
- fd = open(node, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
+ fd = open(node, O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
if (fd < 0) {
log_error("unable to open '%s'", node);
return 1;
assert(c->fd < 0);
for (int cnt = 0;; cnt++) {
- fd = open(arg_node, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
+ fd = open(arg_node, O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
if (fd >= 0)
break;
if (++cnt >= 20 || errno != EBUSY)
if (!desc_path)
return log_oom();
- fd = open(desc_path, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
+ fd = open(desc_path, O_RDONLY | O_NOFOLLOW | O_CLOEXEC | O_NOCTTY);
if (fd < 0)
return log_device_error_errno(hid_device, errno,
"Failed to open report descriptor at '%s': %m", desc_path);
return EXIT_FAILURE;
}
- mtd_fd = open(argv[1], O_RDONLY|O_CLOEXEC);
+ mtd_fd = open(argv[1], O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (mtd_fd < 0) {
log_error_errno(errno, "Failed to open: %m");
return EXIT_FAILURE;
struct stat statbuf;
int err = 0;
- fd = open(devname, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
+ fd = open(devname, O_RDONLY | O_NONBLOCK | O_CLOEXEC | O_NOCTTY);
if (fd < 0) {
log_debug_errno(errno, "scsi_id: cannot open %s: %m", devname);
return 1;
for (cnt = 20; cnt > 0; cnt--) {
struct timespec duration;
- fd = open(devname, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
+ fd = open(devname, O_RDONLY | O_NONBLOCK | O_CLOEXEC | O_NOCTTY);
if (fd >= 0 || errno != EBUSY)
break;
duration.tv_sec = 0;
if (r < 0)
return log_device_debug_errno(dev, r, "Failed to get device name: %m");
- fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
+ fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0) {
bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
log_device_debug_errno(dev, fd, "Failed to open block device %s%s: %m",
if (argc != 3 || !streq(argv[1], "ready"))
return log_device_error_errno(dev, SYNTHETIC_ERRNO(EINVAL), "Invalid arguments");
- fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC);
+ fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC|O_NOCTTY);
if (fd < 0) {
if (ERRNO_IS_DEVICE_ABSENT(errno)) {
/* Driver not installed? Then we aren't ready. This is useful in initrds that lack
struct input_absinfo xabsinfo = {}, yabsinfo = {};
_cleanup_close_ int fd = -1;
- fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
+ fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0)
return;
return r;
filename = strjoina(syspath, "/descriptors");
- fd = open(filename, O_RDONLY|O_CLOEXEC);
+ fd = open(filename, O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0)
return log_device_debug_errno(dev, errno, "Failed to open \"%s\": %m", filename);
struct stat st;
int r;
- fd = open(path, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
+ fd = open(path, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0)
return log_error_errno(errno, "Failed to open '%s': %m", path);
if (r == 0)
goto nolock;
- fd = sd_device_open(dev_whole_disk, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
+ fd = sd_device_open(dev_whole_disk, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0) {
bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
if (STARTSWITH_SET(val, "dm-", "md", "drbd", "loop", "nbd", "zram"))
return 0;
- fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
+ fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0)
return log_device_debug_errno(dev, fd, "Failed to open '%s', ignoring: %m", val);