Skip to content

visionipc: add HANDLE_EINTR Macro for connect, sendmsg, and recvmsg system calls #639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions msgq/visionipc/handle_eintr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

// keep trying if x gets interrupted by a signal
#define HANDLE_EINTR(x) \
({ \
decltype(x) ret; \
int try_cnt = 0; \
do { \
ret = (x); \
} while (ret == -1 && errno == EINTR && try_cnt++ < 100); \
ret; \
})
12 changes: 1 addition & 11 deletions msgq/visionipc/visionbuf_ion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@
#include <msm_ion.h>

#include "msgq/visionipc/visionbuf.h"

// keep trying if x gets interrupted by a signal
#define HANDLE_EINTR(x) \
({ \
decltype(x) ret; \
int try_cnt = 0; \
do { \
ret = (x); \
} while (ret == -1 && errno == EINTR && try_cnt++ < 100); \
ret; \
})
#include "msgq/visionipc/handle_eintr.h"

// just hard-code these for convenience
// size_t device_page_size = 0;
Expand Down
7 changes: 4 additions & 3 deletions msgq/visionipc/visionipc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define getsocket() socket(AF_UNIX, SOCK_SEQPACKET, 0)
#endif

#include "msgq/visionipc/handle_eintr.h"
#include "msgq/visionipc/visionipc.h"

int ipc_connect(const char* socket_path) {
Expand All @@ -27,7 +28,7 @@ int ipc_connect(const char* socket_path) {
.sun_family = AF_UNIX,
};
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socket_path);
err = connect(sock, (struct sockaddr*)&addr, sizeof(addr));
err = HANDLE_EINTR(connect(sock, (struct sockaddr*)&addr, sizeof(addr)));
if (err != 0) {
close(sock);
return -1;
Expand Down Expand Up @@ -87,9 +88,9 @@ int ipc_sendrecv_with_fds(bool send, int fd, void *buf, size_t buf_size, int* fd
cmsg->cmsg_len = CMSG_LEN(sizeof(int) * num_fds);
memcpy(CMSG_DATA(cmsg), fds, sizeof(int) * num_fds);
}
return sendmsg(fd, &msg, 0);
return HANDLE_EINTR(sendmsg(fd, &msg, 0));
} else {
int r = recvmsg(fd, &msg, 0);
int r = HANDLE_EINTR(recvmsg(fd, &msg, 0));
if (r < 0) return r;

int recv_fds = 0;
Expand Down
Loading