-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[Fix](build) Restore Doris glibc-compatibility interposition with lance-c #67312
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
Draft
linrrzqqq
wants to merge
1
commit into
apache:branch-4.1
Choose a base branch
from
linrrzqqq:restore-doris-glibc-compatibility-4.1
base: branch-4.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| #include <errno.h> | ||
| #include <limits.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <unistd.h> | ||
|
|
||
| static char* strchrnul_compat(const char* str, int ch) { | ||
| const char* found = strchr(str, ch); | ||
| return (char*)(found ? found : str + strlen(str)); | ||
| } | ||
|
|
||
| int __execvpe(const char* file, char* const argv[], char* const envp[]) { | ||
| const char* path = getenv("PATH"); | ||
| int seen_eacces = 0; | ||
|
|
||
| errno = ENOENT; | ||
| if (!*file) return -1; | ||
| if (strchr(file, '/')) return execve(file, argv, envp); | ||
| if (!path) path = "/usr/local/bin:/bin:/usr/bin"; | ||
|
|
||
| size_t file_len = strnlen(file, NAME_MAX + 1); | ||
| if (file_len > NAME_MAX) { | ||
| errno = ENAMETOOLONG; | ||
| return -1; | ||
| } | ||
| size_t path_len = strnlen(path, PATH_MAX - 1) + 1; | ||
|
|
||
| const char* cursor; | ||
| const char* end; | ||
| for (cursor = path;; cursor = end) { | ||
| char candidate[path_len + file_len + 1]; | ||
| end = strchrnul_compat(cursor, ':'); | ||
| if (end - cursor >= path_len) { | ||
| if (!*end++) break; | ||
| continue; | ||
| } | ||
| memcpy(candidate, cursor, end - cursor); | ||
| candidate[end - cursor] = '/'; | ||
| memcpy(candidate + (end - cursor) + (end > cursor), file, file_len + 1); | ||
| execve(candidate, argv, envp); | ||
| switch (errno) { | ||
| case EACCES: | ||
| seen_eacces = 1; | ||
| // Fall through. | ||
| case ENOENT: | ||
| case ENOTDIR: | ||
| break; | ||
| default: | ||
| return -1; | ||
| } | ||
| if (!*end++) break; | ||
| } | ||
| if (seen_eacces) errno = EACCES; | ||
| return -1; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #pragma once | ||
|
|
||
| #include <sys/types.h> | ||
|
|
||
| #define FDOP_CLOSE 1 | ||
| #define FDOP_DUP2 2 | ||
| #define FDOP_OPEN 3 | ||
| #define FDOP_CHDIR 4 | ||
| #define FDOP_FCHDIR 5 | ||
|
|
||
| struct fdop { | ||
| struct fdop* next; | ||
| struct fdop* prev; | ||
| int cmd; | ||
| int fd; | ||
| int srcfd; | ||
| int oflag; | ||
| mode_t mode; | ||
| char path[]; | ||
| }; |
95 changes: 95 additions & 0 deletions
95
be/src/glibc-compatibility/musl/posix_spawn_file_actions.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| #define _GNU_SOURCE | ||
| #include <errno.h> | ||
| #include <spawn.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
|
|
||
| #include "fdop.h" | ||
|
|
||
| static struct fdop* first_action(const posix_spawn_file_actions_t* file_actions) { | ||
| return (struct fdop*)file_actions->__actions; | ||
| } | ||
|
|
||
| static void prepend_action(posix_spawn_file_actions_t* file_actions, struct fdop* action) { | ||
| action->next = first_action(file_actions); | ||
| if (action->next) action->next->prev = action; | ||
| action->prev = NULL; | ||
| file_actions->__actions = (struct __spawn_action*)action; | ||
| } | ||
|
|
||
| int posix_spawn_file_actions_init(posix_spawn_file_actions_t* file_actions) { | ||
| file_actions->__allocated = 0; | ||
| file_actions->__used = 0; | ||
| file_actions->__actions = NULL; | ||
| return 0; | ||
| } | ||
|
|
||
| int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t* restrict file_actions, | ||
| const char* restrict path) { | ||
| struct fdop* action = malloc(sizeof(*action) + strlen(path) + 1); | ||
| if (!action) return ENOMEM; | ||
| action->cmd = FDOP_CHDIR; | ||
| action->fd = -1; | ||
| strcpy(action->path, path); | ||
| prepend_action(file_actions, action); | ||
| return 0; | ||
| } | ||
|
|
||
| int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t* file_actions, int fd) { | ||
| if (fd < 0) return EBADF; | ||
| struct fdop* action = malloc(sizeof(*action)); | ||
| if (!action) return ENOMEM; | ||
| action->cmd = FDOP_CLOSE; | ||
| action->fd = fd; | ||
| prepend_action(file_actions, action); | ||
| return 0; | ||
| } | ||
|
|
||
| int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t* file_actions, int source_fd, | ||
| int target_fd) { | ||
| if (source_fd < 0 || target_fd < 0) return EBADF; | ||
| struct fdop* action = malloc(sizeof(*action)); | ||
| if (!action) return ENOMEM; | ||
| action->cmd = FDOP_DUP2; | ||
| action->srcfd = source_fd; | ||
| action->fd = target_fd; | ||
| prepend_action(file_actions, action); | ||
| return 0; | ||
| } | ||
|
|
||
| int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t* file_actions, int fd) { | ||
| if (fd < 0) return EBADF; | ||
| struct fdop* action = malloc(sizeof(*action)); | ||
| if (!action) return ENOMEM; | ||
| action->cmd = FDOP_FCHDIR; | ||
| action->fd = fd; | ||
| prepend_action(file_actions, action); | ||
| return 0; | ||
| } | ||
|
|
||
| int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t* restrict file_actions, int fd, | ||
| const char* restrict path, int flags, mode_t mode) { | ||
| if (fd < 0) return EBADF; | ||
| struct fdop* action = malloc(sizeof(*action) + strlen(path) + 1); | ||
| if (!action) return ENOMEM; | ||
| action->cmd = FDOP_OPEN; | ||
| action->fd = fd; | ||
| action->oflag = flags; | ||
| action->mode = mode; | ||
| strcpy(action->path, path); | ||
| prepend_action(file_actions, action); | ||
| return 0; | ||
| } | ||
|
|
||
| int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t* file_actions) { | ||
| struct fdop* action = first_action(file_actions); | ||
| while (action) { | ||
| struct fdop* next = action->next; | ||
| free(action); | ||
| action = next; | ||
| } | ||
| file_actions->__allocated = 0; | ||
| file_actions->__used = 0; | ||
| file_actions->__actions = NULL; | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #include <spawn.h> | ||
|
|
||
| int __execvpe(const char* file, char* const argv[], char* const envp[]); | ||
|
|
||
| int __posix_spawnx(pid_t* restrict result, const char* restrict path, | ||
| int (*exec)(const char*, char* const*, char* const*), | ||
| const posix_spawn_file_actions_t* file_actions, | ||
| const posix_spawnattr_t* restrict attr, char* const argv[restrict], | ||
| char* const envp[restrict]); | ||
|
|
||
| int posix_spawnp(pid_t* restrict result, const char* restrict file, | ||
| const posix_spawn_file_actions_t* file_actions, | ||
| const posix_spawnattr_t* restrict attr, char* const argv[restrict], | ||
| char* const envp[restrict]) { | ||
| return __posix_spawnx(result, file, __execvpe, file_actions, attr, argv, envp); | ||
|
linrrzqqq marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #define _DEFAULT_SOURCE | ||
| #include <sys/uio.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include "syscall.h" | ||
|
|
||
| ssize_t preadv(int fd, const struct iovec* iov, int count, off_t offset) { | ||
| return syscall(SYS_preadv, fd, iov, count, (long)(offset), (long)(offset >> 32)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #define _GNU_SOURCE | ||
| #include <fcntl.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include "syscall.h" | ||
|
|
||
| ssize_t splice(int fd_in, off_t* off_in, int fd_out, off_t* off_out, size_t len, | ||
| unsigned int flags) { | ||
| return syscall(SYS_splice, fd_in, off_in, fd_out, off_out, len, flags); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.