- if (b->fd >= 0) {
- close_nointr_nofail(b->fd);
- b->fd = -1;
- }
-
- p = strappend("/dev/input/", b->name);
- if (!p)
- return log_oom();
-
- b->fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
- free(p);
- if (b->fd < 0) {
- log_warning("Failed to open %s: %m", b->name);
- return -errno;
- }
-
- if (ioctl(b->fd, EVIOCGNAME(sizeof(name)), name) < 0) {
- log_error("Failed to get input name: %m");
- r = -errno;
- goto fail;
- }
-
- zero(ev);
- ev.events = EPOLLIN;
- ev.data.u32 = FD_OTHER_BASE + b->fd;
-
- if (epoll_ctl(b->manager->epoll_fd, EPOLL_CTL_ADD, b->fd, &ev) < 0) {
- log_error("Failed to add to epoll: %m");
- r = -errno;
- goto fail;
- }
-
- r = hashmap_put(b->manager->button_fds, INT_TO_PTR(b->fd + 1), b);
- if (r < 0) {
- log_error("Failed to add to hash map: %s", strerror(-r));
- assert_se(epoll_ctl(b->manager->epoll_fd, EPOLL_CTL_DEL, b->fd, NULL) == 0);
- goto fail;
- }
-
- log_info("Watching system buttons on /dev/input/%s (%s)", b->name, name);
-
- return 0;
-
-fail:
- close_nointr_nofail(b->fd);
- b->fd = -1;
- return r;
+ manager_handle_action(b->manager, INHIBIT_HANDLE_LID_SWITCH, b->manager->handle_lid_switch, b->manager->lid_switch_ignore_inhibited, false);
+ return 1;