-
Notifications
You must be signed in to change notification settings - Fork 382
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
Simplify key=val argument handling #4272
Conversation
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.
s/unit/unix/ in the commit message.
bin/varnishd/mgt/mgt_jail_unix.c
Outdated
if (vju_getuid((*args) + l_user)) | ||
val = keyval(*args, "user="); | ||
if (val != NULL) { | ||
if (vju_getuid(val)) | ||
ARGV_ERR( | ||
"Unix jail: %s user not found.\n", | ||
(*args) + 5); |
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.
Not ready to replace #4202 until you get rid of (*args) + ...
occurrences.
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.
oops! thank you!
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.
That I had already overlooked in 4001ea2 🤦🏽♂️
bin/varnishd/mgt/mgt_jail_unix.c
Outdated
if (vju_getwrkuid((*args) + l_workuser)) | ||
val = keyval(*args, "workuser="); | ||
if (val != NULL) { | ||
if (vju_getwrkuid(val)) | ||
ARGV_ERR( | ||
"Unix jail: %s user not found.\n", | ||
(*args) + 9); |
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.
Not ready to replace #4202 until you get rid of (*args) + ...
occurrences.
bin/varnishd/mgt/mgt_jail_unix.c
Outdated
if (vju_getccgid((*args) + l_ccgroup)) | ||
val = keyval(*args, "ccgroup="); | ||
if (val != NULL) { | ||
if (vju_getccgid(val)) | ||
ARGV_ERR( | ||
"Unix jail: %s group not found.\n", | ||
(*args) + 8); |
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.
Not ready to replace #4202 until you get rid of (*args) + ...
occurrences.
we add a simple utility function to return the pointer to the thing after "key=" if the first argument begins with "key=". Note that this is no worse than a macro with a "reasonable good" compiler *) and default (-O2) optimization, because the function call gets inlined and the strlen() turned into a constant. 0x00000000000a1bd1 <+49>: lea 0x6ed49(%rip),%r14 # 0x110921 ... 0x00000000000a1c01 <+97>: mov $0x5,%edx 0x00000000000a1c06 <+102>: mov %rbx,%rdi 0x00000000000a1c09 <+105>: mov %r14,%rsi 0x00000000000a1c0c <+108>: call 0x2d360 <strncmp@plt> 0x00000000000a1c11 <+113>: lea 0x5(%rbx),%rbp 0x00000000000a1c15 <+117>: test %eax,%eax (gdb) p (const char *)0x110921 $2 = 0x110921 "user=" Replaces varnishcache#4202 Polishes 4001ea2 *) tested: gcc version 12.2.0 (Debian 12.2.0-14) Debian clang version 14.0.6
a76d832
to
45cdc60
Compare
@dridi I would use this in place of #4202. Do you agree?
This is a Draft because I still want to look if we can replace other similar cases and probably move the helper function to a better place as a
static inline
1we add a simple utility function to return the pointer to the thing after "key=" if the first argument begins with "key=".
Note that this is no worse than a macro with a "reasonable good" compiler *) and default (-O2) optimization, because the function call gets inlined and the strlen() turned into a constant.
Replaces #4202
Polishes 4001ea2
*) tested:
gcc version 12.2.0 (Debian 12.2.0-14)
Debian clang version 14.0.6
Footnotes
Reminder that
inline
has no other relevance than "do not complain if unused", as the compiler is free to inline no matter what ↩