From ff88223ea6024e1396a23947f3c2ada6bd017a6c Mon Sep 17 00:00:00 2001 From: officeyutong Date: Wed, 21 Aug 2024 21:17:31 +0800 Subject: [PATCH] update --- runtime/src/bpftime_shm.cpp | 79 ++++++++++++++----------------------- 1 file changed, 30 insertions(+), 49 deletions(-) diff --git a/runtime/src/bpftime_shm.cpp b/runtime/src/bpftime_shm.cpp index df7903d3..91075019 100644 --- a/runtime/src/bpftime_shm.cpp +++ b/runtime/src/bpftime_shm.cpp @@ -26,32 +26,35 @@ #ifdef __APPLE__ // Custom implementation for sigtimedwait -int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout) { - struct timespec start, now; - clock_gettime(CLOCK_REALTIME, &start); - int sig; - - while (true) { - // Try to wait for a signal - if (sigwait(set, &sig) == 0) { - if (info != nullptr) { - memset(info, 0, sizeof(*info)); - info->si_signo = sig; - } - return sig; - } - - // Check if the timeout has expired - clock_gettime(CLOCK_REALTIME, &now); - if ((now.tv_sec - start.tv_sec) > timeout->tv_sec || - ((now.tv_sec - start.tv_sec) == timeout->tv_sec && (now.tv_nsec - start.tv_nsec) > timeout->tv_nsec)) { - errno = EAGAIN; - return -1; - } - - // Sleep for a short time before retrying - usleep(1000); // Sleep for 1ms before retrying - } +int sigtimedwait(const sigset_t *set, siginfo_t *info, + const struct timespec *timeout) +{ + struct timespec start, now; + clock_gettime(CLOCK_REALTIME, &start); + int sig; + + while (true) { + // Try to wait for a signal + if (sigwait(set, &sig) == 0) { + if (info != nullptr) { + memset(info, 0, sizeof(*info)); + info->si_signo = sig; + } + return sig; + } + + // Check if the timeout has expired + clock_gettime(CLOCK_REALTIME, &now); + if ((now.tv_sec - start.tv_sec) > timeout->tv_sec || + ((now.tv_sec - start.tv_sec) == timeout->tv_sec && + (now.tv_nsec - start.tv_nsec) > timeout->tv_nsec)) { + errno = EAGAIN; + return -1; + } + + // Sleep for a short time before retrying + usleep(1000); // Sleep for 1ms before retrying + } } #endif @@ -210,28 +213,6 @@ void bpftime_close(int fd) shm_holder.global_shared_memory.close_fd(fd); } -const char * expand_filename(const char *filename) -{ - const char *home_dir = getenv("HOME"); - if (home_dir == NULL) { - SPDLOG_INFO("Error: HOME environment variable is not set"); - return NULL; - } - - size_t size = strlen(home_dir) + strlen(filename) + 1; - char *absolute_path = (char *)malloc(size); - if (absolute_path == NULL) { - SPDLOG_INFO("Error: Memory allocation failed"); - return NULL; - } - - sprintf(absolute_path, "%s/%s", home_dir, filename); - const char *result = strdup(absolute_path); - free(absolute_path); - - return result; -} - int bpftime_map_get_info(int fd, bpftime::bpf_map_attr *out_attr, const char **out_name, bpftime::bpf_map_type *type) { @@ -566,7 +547,7 @@ int bpftime_shared_perf_event_output(int map_fd, const void *buf, size_t sz) return -1; } } -#endif +#endif int bpftime_is_prog_array(int fd) {