diff --git a/sensors/NonUiNotifier.cpp b/sensors/NonUiNotifier.cpp index c91ba29..a829ba7 100644 --- a/sensors/NonUiNotifier.cpp +++ b/sensors/NonUiNotifier.cpp @@ -54,8 +54,15 @@ static bool readBool(int fd) { struct NonUiSensorCallback : IEventQueueCallback { Return onEvent(const Event& e) { + int touchFd = open(TOUCH_DEV_PATH, O_RDWR); + if (touchFd == -1) { + LOG(ERROR) << "failed to open " << TOUCH_DEV_PATH; + return Void(); + } + int buf[MAX_BUF_SIZE] = {0, Touch_Nonui_Mode, static_cast(e.u.scalar)}; - ioctl(open(TOUCH_DEV_PATH, O_RDWR), TOUCH_IOC_SET_CUR_VALUE, &buf); + ioctl(touchFd, TOUCH_IOC_SET_CUR_VALUE, &buf); + close(touchFd); return Void(); }