-
Notifications
You must be signed in to change notification settings - Fork 585
WIP Add resolving of $PROGRAM_NAME from /dev/fd/number #23358
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
base: blead
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -4227,6 +4227,19 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, bool *suidscript) | |||
Safefree(PL_origfilename); | ||||
PL_origfilename = (char *)scriptname; | ||||
} | ||||
else { | ||||
char proc_fd_path[64]; | ||||
snprintf(proc_fd_path, sizeof(proc_fd_path), "/proc/self/fd/%d", fdscript); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The c stack buffer should really be The CC will round up C auto var There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point |
||||
char target_path[MAXPATHLEN]; | ||||
SSize_t len = readlink(proc_fd_path, target_path, sizeof(target_path) - 1); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should use The else block should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
At work, I have to use these constants and throw in the original string constant with Ive never seen any max expansion constants like the MS ones in the Perl headers for I've looked at these briefly Line 2461 in 8711297
but I dont trust them. I won't myself use them. macro UV_DIG has ZERO users in the repo. IV_DIG exactly ONE grep hit for proc_fd_path id rather see STRLENs("/proc/self/fd/%d") + 21 +1 +12_whatever_padding_34 than just a random number like 64 which always make me paranoid when I see it b/c I can't verify it visually against the actual sprintf() args a few lines below, and IDK if someone before me quickly edited the fmt str and never updated the stk buf byte length to match. If the expression includes STRLENs("/proc/self/fd/%d")+whatever, paranoia gone. |
||||
if (len != -1) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Linux and FooNix OSes, MAXPATHLEN is constant Those 3 buffer lengths are an alligator [ Since this huge C stk buffer is not used on all control flow paths through I have no tech/coding problem with this huge size + very short life span C stack buffer. I don't want to see it become another bloated wasteful On WinPerl because of a P5P bug, CPP macro There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I'm not fond of large buffers on the stack we don't have a general solution at this point beyond using an SV or Newx(). At this point the stack is close to the least consumed it will be, so I think this buffer is as reasonable as it could be. Some sort of cheap C level path abstraction would be useful - a relatively small built-in buffer, but can keep a dynamically allocated buffer if that's too small. But for now I think this is the practical choice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
is my typical recipe. I don't expect anyone to do this but me, b/c its overkill to tweak char stk buffers against -O2 disassembly, I will sometimes adjust 128 downwards or upwards to a formula like For generic guesstimates, I'd say len 96 (sse 166=96, 167=112) covers all sane src code identifiers and consts and paths with some breathing room. 128 is the max I'd put generically, its rare to see a function with more than 8 c stk vars active (liveness) at any time on x64 on top of whatever CC keeps in Win64's 8 non-vol regs. C99's variable length arrays feature and VLA doesn't exist in C++ so alloca() is the tool to use in C++ mode. If someone wants to be standards pedantic about alloca/vla'es, alloca/vlas have to exist internally in the C compiler and in the ABI/machine code level or its not C anymore. Recursion is part of the spec. 1960s HW where recursion or function reentry was electronically impossible, since the pre-allocated C stack and the functions machine code are adjacent on the same magnetic tape is irrelevant alloca() can always be synthesized per ISO C spec. I can always write a dispatcher function, that takes a length, a function ptr, and Each of 48 functions takes a function ptr and a
I did some breakpoints, your right, |
||||
Stat_t statbuf; | ||||
target_path[len] = '\0'; | ||||
if (PerlLIO_stat(target_path, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) { | ||||
scriptname = PL_origfilename = find_script(target_path, dosearch, NULL, 1); | ||||
} | ||||
} | ||||
} | ||||
} | ||||
} | ||||
|
||||
|
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.
this
else {
block starting here really should be split off into a separate static, not-inline function, see my other comment below why this is needed