Skip to content
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

Merged
merged 1 commit into from
Feb 13, 2025

Conversation

nigoroll
Copy link
Member

@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 1


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 #4202
Polishes 4001ea2

*) tested:
gcc version 12.2.0 (Debian 12.2.0-14)
Debian clang version 14.0.6

Footnotes

  1. Reminder that inline has no other relevance than "do not complain if unused", as the compiler is free to inline no matter what

@nigoroll nigoroll marked this pull request as draft February 13, 2025 10:08
Copy link
Member

@dridi dridi left a 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.

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);
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops! thank you!

Copy link
Member Author

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 🤦🏽‍♂️

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);
Copy link
Member

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.

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);
Copy link
Member

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
@nigoroll nigoroll merged commit 45cdc60 into varnishcache:master Feb 13, 2025
1 of 10 checks passed
@nigoroll nigoroll deleted the jail_keyval branch February 14, 2025 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants