Handle EINTR for all syscalls that can return it (#21948)
parent
f539cd45c9
commit
f02c8d0e2c
|
@ -193,7 +193,7 @@ void handle_tty_issue(int err, const char func[]) {
|
|||
}
|
||||
|
||||
void TTYPigeon::connect(const char * tty) {
|
||||
pigeon_tty_fd = open(tty, O_RDWR);
|
||||
pigeon_tty_fd = HANDLE_EINTR(open(tty, O_RDWR));
|
||||
if (pigeon_tty_fd < 0) {
|
||||
handle_tty_issue(errno, __func__);
|
||||
assert(pigeon_tty_fd >= 0);
|
||||
|
@ -253,7 +253,7 @@ void TTYPigeon::set_baud(int baud) {
|
|||
}
|
||||
|
||||
void TTYPigeon::send(const std::string &s) {
|
||||
int err = write(pigeon_tty_fd, s.data(), s.length());
|
||||
int err = HANDLE_EINTR(write(pigeon_tty_fd, s.data(), s.length()));
|
||||
|
||||
if(err < 0) { handle_tty_issue(err, __func__); }
|
||||
err = tcdrain(pigeon_tty_fd);
|
||||
|
|
|
@ -399,7 +399,7 @@ static void sensors_init(MultiCameraState *s) {
|
|||
.output_format = MSM_SENSOR_BAYER,
|
||||
}};
|
||||
|
||||
unique_fd sensorinit_fd = open("/dev/v4l-subdev11", O_RDWR | O_NONBLOCK);
|
||||
unique_fd sensorinit_fd = HANDLE_EINTR(open("/dev/v4l-subdev11", O_RDWR | O_NONBLOCK));
|
||||
assert(sensorinit_fd >= 0);
|
||||
for (auto &info : slave_infos) {
|
||||
info.power_setting_array.power_setting = &info.power_setting_array.power_setting_a[0];
|
||||
|
@ -419,29 +419,29 @@ static void camera_open(CameraState *s, bool is_road_cam) {
|
|||
// open devices
|
||||
const char *sensor_dev;
|
||||
if (is_road_cam) {
|
||||
s->csid_fd = open("/dev/v4l-subdev3", O_RDWR | O_NONBLOCK);
|
||||
s->csid_fd = HANDLE_EINTR(open("/dev/v4l-subdev3", O_RDWR | O_NONBLOCK));
|
||||
assert(s->csid_fd >= 0);
|
||||
s->csiphy_fd = open("/dev/v4l-subdev0", O_RDWR | O_NONBLOCK);
|
||||
s->csiphy_fd = HANDLE_EINTR(open("/dev/v4l-subdev0", O_RDWR | O_NONBLOCK));
|
||||
assert(s->csiphy_fd >= 0);
|
||||
sensor_dev = "/dev/v4l-subdev17";
|
||||
s->isp_fd = open("/dev/v4l-subdev13", O_RDWR | O_NONBLOCK);
|
||||
s->isp_fd = HANDLE_EINTR(open("/dev/v4l-subdev13", O_RDWR | O_NONBLOCK));
|
||||
assert(s->isp_fd >= 0);
|
||||
s->actuator_fd = open("/dev/v4l-subdev7", O_RDWR | O_NONBLOCK);
|
||||
s->actuator_fd = HANDLE_EINTR(open("/dev/v4l-subdev7", O_RDWR | O_NONBLOCK));
|
||||
assert(s->actuator_fd >= 0);
|
||||
} else {
|
||||
s->csid_fd = open("/dev/v4l-subdev5", O_RDWR | O_NONBLOCK);
|
||||
s->csid_fd = HANDLE_EINTR(open("/dev/v4l-subdev5", O_RDWR | O_NONBLOCK));
|
||||
assert(s->csid_fd >= 0);
|
||||
s->csiphy_fd = open("/dev/v4l-subdev2", O_RDWR | O_NONBLOCK);
|
||||
s->csiphy_fd = HANDLE_EINTR(open("/dev/v4l-subdev2", O_RDWR | O_NONBLOCK));
|
||||
assert(s->csiphy_fd >= 0);
|
||||
sensor_dev = "/dev/v4l-subdev18";
|
||||
s->isp_fd = open("/dev/v4l-subdev14", O_RDWR | O_NONBLOCK);
|
||||
s->isp_fd = HANDLE_EINTR(open("/dev/v4l-subdev14", O_RDWR | O_NONBLOCK));
|
||||
assert(s->isp_fd >= 0);
|
||||
}
|
||||
|
||||
// wait for sensor device
|
||||
// on first startup, these devices aren't present yet
|
||||
for (int i = 0; i < 10; i++) {
|
||||
s->sensor_fd = open(sensor_dev, O_RDWR | O_NONBLOCK);
|
||||
s->sensor_fd = HANDLE_EINTR(open(sensor_dev, O_RDWR | O_NONBLOCK));
|
||||
if (s->sensor_fd >= 0) break;
|
||||
LOGW("waiting for sensors...");
|
||||
util::sleep_for(1000); // sleep one second
|
||||
|
@ -927,15 +927,15 @@ void cameras_open(MultiCameraState *s) {
|
|||
{.vfe_intf = VFE0, .intftype = RDI2, .num_cids = 1, .cids[0] = CID2, .csid = CSID0},
|
||||
},
|
||||
};
|
||||
s->msmcfg_fd = open("/dev/media0", O_RDWR | O_NONBLOCK);
|
||||
s->msmcfg_fd = HANDLE_EINTR(open("/dev/media0", O_RDWR | O_NONBLOCK));
|
||||
assert(s->msmcfg_fd >= 0);
|
||||
|
||||
sensors_init(s);
|
||||
|
||||
s->v4l_fd = open("/dev/video0", O_RDWR | O_NONBLOCK);
|
||||
s->v4l_fd = HANDLE_EINTR(open("/dev/video0", O_RDWR | O_NONBLOCK));
|
||||
assert(s->v4l_fd >= 0);
|
||||
|
||||
s->ispif_fd = open("/dev/v4l-subdev15", O_RDWR | O_NONBLOCK);
|
||||
s->ispif_fd = HANDLE_EINTR(open("/dev/v4l-subdev15", O_RDWR | O_NONBLOCK));
|
||||
assert(s->ispif_fd >= 0);
|
||||
|
||||
// ISPIF: stop
|
||||
|
|
|
@ -751,17 +751,17 @@ void cameras_open(MultiCameraState *s) {
|
|||
|
||||
LOG("-- Opening devices");
|
||||
// video0 is req_mgr, the target of many ioctls
|
||||
s->video0_fd = open("/dev/v4l/by-path/platform-soc:qcom_cam-req-mgr-video-index0", O_RDWR | O_NONBLOCK);
|
||||
s->video0_fd = HANDLE_EINTR(open("/dev/v4l/by-path/platform-soc:qcom_cam-req-mgr-video-index0", O_RDWR | O_NONBLOCK));
|
||||
assert(s->video0_fd >= 0);
|
||||
LOGD("opened video0");
|
||||
|
||||
// video1 is cam_sync, the target of some ioctls
|
||||
s->video1_fd = open("/dev/v4l/by-path/platform-cam_sync-video-index0", O_RDWR | O_NONBLOCK);
|
||||
s->video1_fd = HANDLE_EINTR(open("/dev/v4l/by-path/platform-cam_sync-video-index0", O_RDWR | O_NONBLOCK));
|
||||
assert(s->video1_fd >= 0);
|
||||
LOGD("opened video1");
|
||||
|
||||
// looks like there's only one of these
|
||||
s->isp_fd = open("/dev/v4l-subdev1", O_RDWR | O_NONBLOCK);
|
||||
s->isp_fd = HANDLE_EINTR(open("/dev/v4l-subdev1", O_RDWR | O_NONBLOCK));
|
||||
assert(s->isp_fd >= 0);
|
||||
LOGD("opened isp");
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <cstdio>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "selfdrive/common/util.h"
|
||||
#include "selfdrive/common/swaglog.h"
|
||||
#include "selfdrive/common/util.h"
|
||||
|
||||
|
@ -24,7 +25,7 @@ I2CBus::I2CBus(uint8_t bus_id) {
|
|||
char bus_name[20];
|
||||
snprintf(bus_name, 20, "/dev/i2c-%d", bus_id);
|
||||
|
||||
i2c_fd = open(bus_name, O_RDWR);
|
||||
i2c_fd = HANDLE_EINTR(open(bus_name, O_RDWR));
|
||||
if(i2c_fd < 0) {
|
||||
throw std::runtime_error("Failed to open I2C bus");
|
||||
}
|
||||
|
|
|
@ -95,11 +95,11 @@ std::map<std::string, std::string> read_files_in_dir(const std::string &path) {
|
|||
}
|
||||
|
||||
int write_file(const char* path, const void* data, size_t size, int flags, mode_t mode) {
|
||||
int fd = open(path, flags, mode);
|
||||
int fd = HANDLE_EINTR(open(path, flags, mode));
|
||||
if (fd == -1) {
|
||||
return -1;
|
||||
}
|
||||
ssize_t n = write(fd, data, size);
|
||||
ssize_t n = HANDLE_EINTR(write(fd, data, size));
|
||||
close(fd);
|
||||
return (n >= 0 && (size_t)n == size) ? 0 : -1;
|
||||
}
|
||||
|
|
|
@ -514,7 +514,7 @@ void OmxEncoder::encoder_open(const char* path) {
|
|||
|
||||
// create camera lock file
|
||||
snprintf(this->lock_path, sizeof(this->lock_path), "%s/%s.lock", path, this->filename);
|
||||
int lock_fd = open(this->lock_path, O_RDWR | O_CREAT, 0664);
|
||||
int lock_fd = HANDLE_EINTR(open(this->lock_path, O_RDWR | O_CREAT, 0664));
|
||||
assert(lock_fd >= 0);
|
||||
close(lock_fd);
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ void RawLogger::encoder_open(const char* path) {
|
|||
|
||||
LOG("open %s\n", lock_path.c_str());
|
||||
|
||||
int lock_fd = open(lock_path.c_str(), O_RDWR | O_CREAT, 0664);
|
||||
int lock_fd = HANDLE_EINTR(open(lock_path.c_str(), O_RDWR | O_CREAT, 0664));
|
||||
assert(lock_fd >= 0);
|
||||
close(lock_fd);
|
||||
|
||||
|
|
Loading…
Reference in New Issue