-
Notifications
You must be signed in to change notification settings - Fork 650
[WIP] main: oneshot mode, reading source file contents from stdin #4407
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
masatake
wants to merge
13
commits into
universal-ctags:master
Choose a base branch
from
masatake:oneshot
base: master
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
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1bede02
main: (bugfix) don't allow to use --sort if sandbox is enabled
masatake 3dfe9f2
main/sort: (potential bug fix) consider the error occurs in mio_file_…
masatake 7f7f2b0
main: use bit-oriented representation for interative mode
masatake 538ef35
main/writer: add a method to initialize the writer in early stage
masatake 16d6e11
json-writer: (potential bug fix) set alloc funcs before calling any J…
masatake 59f8880
json-writer,refactor: move the part of code preparing sandbox to the …
masatake 90693e1
main,refactor: make the code preparing sandbox reusable
masatake 172c704
main,refactor: simplify the code processing the --_interactive option
masatake 08db055
main: add --_interactive=oneshot:FILENAME option
masatake e4e64ea
main: set the upper limit of input in oneshot mode
masatake c7c9014
main: always compile the internal sort routines
masatake 1a16310
main: make the set of system calls allowed in the sandbox tunable
masatake 214b6af
main: add --oneshot=<filename> option
masatake 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Copyright: 2026 Masatake YAMATO | ||
| # License: GPL-2 | ||
|
|
||
| CTAGS=$1 | ||
|
|
||
| gen() | ||
| { | ||
| cat <<EOF | ||
| int v; | ||
| int f(void) | ||
| { | ||
| return 0; | ||
| } | ||
| EOF | ||
| } | ||
|
|
||
| gen | ${CTAGS} --quiet --options=NONE --oneshot=sort-no.c --sort=no -o - | ||
| gen | ${CTAGS} --quiet --options=NONE --oneshot=sort-yes.c --sort=yes -o - | ||
| gen | ${CTAGS} --quiet --options=NONE --oneshot=x.c -x |
Empty file.
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,6 @@ | ||
| v sort-no.c /^int v;$/;" v typeref:typename:int | ||
| f sort-no.c /^int f(void)$/;" f typeref:typename:int | ||
| f sort-yes.c /^int f(void)$/;" f typeref:typename:int | ||
| v sort-yes.c /^int v;$/;" v typeref:typename:int | ||
| f function 2 x.c int f(void) | ||
| v variable 1 x.c int v; |
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
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 |
|---|---|---|
|
|
@@ -67,8 +67,8 @@ | |
| #include "writer_p.h" | ||
| #include "xtag_p.h" | ||
|
|
||
| #ifdef HAVE_JANSSON | ||
| #include "interactive_p.h" | ||
| #ifdef HAVE_JANSSON | ||
| #include <jansson.h> | ||
| #include <errno.h> | ||
| #endif | ||
|
|
@@ -376,7 +376,7 @@ static void batchMakeTags (cookedArgs *args, void *user CTAGS_ATTR_UNUSED) | |
| timeStamp (1); | ||
|
|
||
| if ((! Option.filter) && (!Option.printLanguage)) | ||
| closeTagFile (resize); | ||
| closeTagFile (resize, false); | ||
|
|
||
| timeStamp (2); | ||
|
|
||
|
|
@@ -391,27 +391,24 @@ static void batchMakeTags (cookedArgs *args, void *user CTAGS_ATTR_UNUSED) | |
| #undef timeStamp | ||
| } | ||
|
|
||
| static void prepareSandbox (unsigned int set) | ||
| { | ||
| if (installSyscallFilter (set)) { | ||
| error (FATAL, "install_syscall_filter failed"); | ||
| /* The explicit exit call is needed because | ||
| "error (FATAL,..." just prints a message in | ||
| interactive mode. */ | ||
| exit (1); | ||
| } | ||
| } | ||
|
|
||
| #ifdef HAVE_JANSSON | ||
| void interactiveLoop (cookedArgs *args CTAGS_ATTR_UNUSED, void *user) | ||
| { | ||
| struct interactiveModeArgs *iargs = user; | ||
|
|
||
| if (iargs->sandbox) { | ||
| /* As of jansson 2.6, the object hashing is seeded off | ||
| of /dev/urandom, so trigger the hash seeding | ||
| before installing the syscall filter. | ||
| */ | ||
| json_t * tmp = json_object (); | ||
| json_decref (tmp); | ||
|
|
||
| if (installSyscallFilter ()) { | ||
| error (FATAL, "install_syscall_filter failed"); | ||
| /* The explicit exit call is needed because | ||
| "error (FATAL,..." just prints a message in | ||
| interactive mode. */ | ||
| exit (1); | ||
| } | ||
| } | ||
| if (iargs->sandbox) | ||
| prepareSandbox (syscall_coreset); | ||
|
|
||
| char buffer[1024]; | ||
| json_t *request; | ||
|
|
@@ -457,7 +454,7 @@ void interactiveLoop (cookedArgs *args CTAGS_ATTR_UNUSED, void *user) | |
| if (iargs->sandbox) { | ||
| error (FATAL, | ||
| "invalid request in sandbox submode: reading file contents from a file is limited"); | ||
| closeTagFile (false); | ||
| closeTagFile (false, false); | ||
| goto next; | ||
| } | ||
|
|
||
|
|
@@ -472,7 +469,7 @@ void interactiveLoop (cookedArgs *args CTAGS_ATTR_UNUSED, void *user) | |
| mio_unref (mio); | ||
| } | ||
|
|
||
| closeTagFile (false); | ||
| closeTagFile (false, false); | ||
| fputs ("{\"_type\": \"completed\", \"command\": \"generate-tags\"}\n", stdout); | ||
| fflush(stdout); | ||
| } | ||
|
|
@@ -488,6 +485,68 @@ void interactiveLoop (cookedArgs *args CTAGS_ATTR_UNUSED, void *user) | |
| } | ||
| #endif | ||
|
|
||
| static void oneshotCommon (const char *fname, size_t limit, bool sandbox, int strictSyscallset) | ||
| { | ||
| openTagFile (); | ||
|
|
||
| if (sandbox && strictSyscallset) | ||
| prepareSandbox (strictSyscallset); | ||
|
|
||
| MIO *mio = mio_new_memory (NULL, 0, eRealloc, eFreeNoNullCheck); | ||
| int c; | ||
| size_t r = 0; | ||
| while ((c = getchar()) != EOF) | ||
| { | ||
| r++; | ||
| if (limit != 0 && r > limit) | ||
| { | ||
| error (WARNING, "input read from stdin exceeds the limit: name: %s, size: %lu", | ||
| fname, | ||
| (unsigned long) limit); | ||
| break; | ||
| } | ||
| mio_putc (mio, c); | ||
| } | ||
|
Comment on lines
+495
to
+509
|
||
|
|
||
| mio_seek (mio, 0, SEEK_SET); | ||
|
|
||
| parseFileWithMio (fname, mio, NULL); | ||
|
|
||
| mio_unref (mio); | ||
|
|
||
| closeTagFile (false, sandbox ? true : false); | ||
| } | ||
|
|
||
| extern void batchOneshot (cookedArgs *args CTAGS_ATTR_UNUSED, void *user) | ||
| { | ||
| struct interactiveModeArgs *iargs = user; | ||
|
|
||
| Assert (iargs->fname); | ||
|
|
||
| unsigned int extra_set; | ||
|
|
||
| extra_set = isDestinationStdout () ? syscall_close | syscall_ctrlset | ||
| : syscall_open | syscall_close | syscall_ctrlset; | ||
| if (iargs->sandbox) | ||
| prepareSandbox (syscall_coreset | extra_set); | ||
|
|
||
| extra_set = isDestinationStdout () ? 0 | ||
| : syscall_open | syscall_close; | ||
| oneshotCommon (iargs->fname, iargs->limit, iargs->sandbox, syscall_coreset | extra_set); | ||
| } | ||
|
|
||
| extern void interactiveOneshot (cookedArgs *args CTAGS_ATTR_UNUSED, void *user) | ||
| { | ||
| struct interactiveModeArgs *iargs = user; | ||
|
|
||
| Assert (iargs->fname); | ||
|
|
||
| if (iargs->sandbox) | ||
| prepareSandbox (syscall_coreset); | ||
|
|
||
| oneshotCommon (iargs->fname, iargs->limit, iargs->sandbox, 0); | ||
| } | ||
|
|
||
| static bool isSafeVar (const char* var) | ||
| { | ||
| const char *safe_vars[] = { | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The man page documents
--oneshot, but the newly introduced--oneshot-limit=<bytes>option is not described here. Consider adding a short paragraph in this section explaining the limit behavior (including that 0 disables the limit and the default is 32MB).