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

mkdir -p $runstatedir at run time, not install time (round 2) #1235

Merged
merged 11 commits into from
Jun 18, 2024

Conversation

alejandro-colomar
Copy link
Contributor

@alejandro-colomar alejandro-colomar commented Apr 24, 2024

Here are all the patches I prepared, in a single PR, tu allow you to understand the global idea I have in mind.

Feel free to apply this branch, or apply refactoring patches separately.

Cc: @ac000 , @andypost, @lcrilly , @thresheek

Supersedes: #1227
Closes: #742

@alejandro-colomar
Copy link
Contributor Author

Not tested.

@alejandro-colomar alejandro-colomar changed the title mkdir -p $runstatedir at run time, not install time (second implementation) mkdir -p $runstatedir at run time, not install time (round 2) Apr 24, 2024
@andypost
Copy link

Thank you! getting to test

meantime ag shows that defaults still point to /var/run/unit

auto/help
26:  --runstatedir=DIR    default: "\$localstatedir/run/unit"
35:  --pid=FILE           set pid filename, default: "\$runstatedir/unit.pid"
39:                       default: "unix:\$runstatedir/control.unit.sock"

auto/options
84:        --runstatedir=*)                 NXT_RUNSTATEDIR="$value"            ;;
168:NXT_RUNSTATEDIR="${NXT_RUNSTATEDIR-"$NXT_LOCALSTATEDIR/run/unit"}"
169:NXT_CONTROL="${NXT_CONTROL-"unix:$NXT_RUNSTATEDIR/control.unit.sock"}"
170:NXT_PID="${NXT_PID-"$NXT_RUNSTATEDIR/unit.pid"}"

@alejandro-colomar
Copy link
Contributor Author

alejandro-colomar commented Apr 24, 2024

Thank you! getting to test

meantime ag shows that defaults still point to /var/run/unit

The default is actually /usr/local/var/run/unit. See:

$ ./configure --help | grep -e =DIR -e =FILE -e =ADDRESS
  --cc=FILE            set C compiler filename, default: "cc"
  --prefix=DIR         default: "/usr/local"
  --exec-prefix=DIR    default: "$prefix"
  --bindir=DIR         default: "$exec_prefix/bin"
  --sbindir=DIR        default: "$exec_prefix/sbin"
  --includedir=DIR     default: "$prefix/include"
  --libdir=DIR         default: "$exec_prefix/lib"
  --modulesdir=DIR     default: "$libdir/unit/modules"
  --datarootdir=DIR    default: "$prefix/share"
  --mandir=DIR         default: "$datarootdir/man"
  --pkgconfigdir=DIR   default: "$datarootdir/pkgconfig"
  --localstatedir=DIR  default: "$prefix/var"
  --statedir=DIR       default: "$localstatedir/lib/unit"
  --runstatedir=DIR    default: "$localstatedir/run/unit"
  --logdir=DIR         default: "$localstatedir/log/unit"
  --tmpdir=DIR         default: "/tmp"
  --incdir=DIR         [deprecated] synonym for --includedir
  --modules=DIR        [deprecated] synonym for --modulesdir
  --state=DIR          [deprecated] synonym for --statedir
  --tmp=DIR            [deprecated] synonym for --tmpdir
  --pid=FILE           set pid filename, default: "$runstatedir/unit.pid"
  --log=FILE           set log filename, default: "$logdir/unit.log"
  --control=ADDRESS    set address of control API socket

But yeah, assuming that you specify --localstatedir=/var, you'll end up with $runstatedir being /var/run/unit.

Regarding the FHS 3.0, I discussed about it with an OpenBSD maintainer, and he criticized the FHS as something Linux-centric that didn't take into account the BSDs. As a consequence, the BSDs don't consider the FHS as a valid standard; it's still a good reference, but in this specific case, the BSDs disagree, and so we need to use a value that will work in all systems.

In your case, I suggest specifying --runstatedir to your favourite value, likely /run/unit, I guess.

Or do you mean that even if you specify that some things are hardcoded?

@alejandro-colomar
Copy link
Contributor Author

v2 changes:

  • Consistently use octal mode.
$ git range-diff master gh/fs fs 
 1:  a97da9fb =  1:  a97da9fb fs: Use branchless code
 2:  990b238f =  2:  990b238f fs: Use a temporary variable for the return value
 3:  8a72be25 =  3:  8a72be25 fs: Accept relative paths in nxt_fs_mkdir_all()
 4:  2381359d =  4:  2381359d fs: Accept path names of length 1
 5:  1d60a9b3 =  5:  1d60a9b3 fs: Rename function
 6:  f2ce48fb =  6:  f2ce48fb fs: Rename function
 7:  cff46fe8 =  7:  cff46fe8 fs: Invert logic to reduce indentation
 8:  1144b573 =  8:  1144b573 fs: Correctly handle "/" in nxt_fs_mkdir_parent()
 9:  8853946e =  9:  8853946e fs: Make parents recursively for the pid file and the control socket
10:  ec0bdf3a = 10:  ec0bdf3a auto: Don't install $runstatedir
 -:  -------- > 11:  e29e134b Use octal instead of mode macros

@andypost
Copy link

andypost commented Apr 24, 2024

Thank you! specified --runstatedir="/run" for configure and looks like all tests passed (sadly armv7 and armhf hanging after packaging in CI but that's preexisting)

EDIT ref https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/64807

@andypost
Copy link

Is there any specific need to have /run/unit if it used for socket and pid-file only?

@alejandro-colomar
Copy link
Contributor Author

Is there any specific need to have /run/unit if it used for socket and pid-file only?

The FHS 3.0 :-)

Programs may have a subdirectory of /run; this is encouraged for programs that use more than one run-time file.

We have two run-time files, which is "more than one run-time file".

@alejandro-colomar
Copy link
Contributor Author

alejandro-colomar commented Apr 25, 2024

BTW, I see in https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/64807/diffs that you specify --control="unix:/run/control.unit.sock" and --pid="/run/unit.pid". You can drop those definitions now that you specify $runstatedir.

You also specify --statedir="/var/lib/unit", and you can also drop it, since you specify $localstatedir:

$ ./configure --help | grep '\<statedir'
  --statedir=DIR       default: "$localstatedir/lib/unit"
  --state=DIR          [deprecated] synonym for --statedir

Unless you want to keep them to be stable even if we change the defaults (hopefully, shouldn't happen, but might).

@alejandro-colomar
Copy link
Contributor Author

v2b changes:

  • Add some Fixes: fields
$ git range-diff master gh/fs fs 
 1:  a97da9fb =  1:  a97da9fb fs: Use branchless code
 2:  990b238f =  2:  990b238f fs: Use a temporary variable for the return value
 3:  8a72be25 =  3:  8a72be25 fs: Accept relative paths in nxt_fs_mkdir_all()
 4:  2381359d !  4:  4a63d651 fs: Accept path names of length 1
    @@ Commit message
     
         That is, accept "/", or relative path names of a single byte.
     
    +    Fixes: 57fc9201cb91 ("Socket: Created control socket & pid file directories.")
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_fs.c ##
 5:  1d60a9b3 =  5:  1b56419a fs: Rename function
 6:  f2ce48fb =  6:  feeea759 fs: Rename function
 7:  cff46fe8 =  7:  c87e2911 fs: Invert logic to reduce indentation
 8:  1144b573 !  8:  41f87976 fs: Correctly handle "/" in nxt_fs_mkdir_parent()
    @@ Commit message
         The previous code attempted to mkdir(""), that is an empty string.
         Since "/" necessarily exists, just goto out_free.
     
    +    Fixes: 57fc9201cb91 ("Socket: Created control socket & pid file directories.")
         Link: <https://github.com/nginx/unit/issues/742>
         Cc: Andrew Clayton <a.clayton@nginx.com>
         Cc: Liam Crilly <liam@nginx.com>
 9:  8853946e =  9:  e0eaaf06 fs: Make parents recursively for the pid file and the control socket
10:  ec0bdf3a = 10:  3d1b94df auto: Don't install $runstatedir
11:  e29e134b = 11:  09fd8bc8 Use octal instead of mode macros

@alejandro-colomar
Copy link
Contributor Author

alejandro-colomar commented Apr 25, 2024

Thank you! specified --runstatedir="/run" for configure and looks like all tests passed (sadly armv7 and armhf hanging after packaging in CI but that's preexisting)

EDIT ref https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/64807

I transformed this comment into a Tested-by: Andy Postnikov <...> field for all the commits (except for the last one; since I added that one later and don't know if you tested it). Please express yourself if you want to modify that.

Thanks!

v2c changes:

$ git range-diff master gh/fs fs 
 1:  a97da9fb !  1:  fd618a14 fs: Use branchless code
    @@ Commit message
         in each iteration.
     
         Tested-by: Andrew Clayton <a.clayton@nginx.com>
    +    Tested-by: Andy Postnikov <apostnikov@gmail.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_fs.c ##
 2:  990b238f !  2:  e9b3b2fe fs: Use a temporary variable for the return value
    @@ Commit message
     
         This avoids breaking a long line.
     
    +    Tested-by: Andy Postnikov <apostnikov@gmail.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_fs.c ##
 3:  8a72be25 !  3:  472069f8 fs: Accept relative paths in nxt_fs_mkdir_all()
    @@ Metadata
      ## Commit message ##
         fs: Accept relative paths in nxt_fs_mkdir_all()
     
    +    Tested-by: Andy Postnikov <apostnikov@gmail.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_fs.c ##
 4:  4a63d651 !  4:  ee134aa1 fs: Accept path names of length 1
    @@ Commit message
         That is, accept "/", or relative path names of a single byte.
     
         Fixes: 57fc9201cb91 ("Socket: Created control socket & pid file directories.")
    +    Tested-by: Andy Postnikov <apostnikov@gmail.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_fs.c ##
 5:  1b56419a !  5:  4ab479f8 fs: Rename function
    @@ Commit message
         to mkdir -p, which is too similar to "parent", so it can lead to
         confusion.
     
    +    Tested-by: Andy Postnikov <apostnikov@gmail.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_controller.c ##
 6:  feeea759 !  6:  3d2a6f3c fs: Rename function
    @@ Commit message
         of mkdir(), "parents" is used for this meaning, as in mkdir -p, so it
         should be more straightforward to readers.
     
    +    Tested-by: Andy Postnikov <apostnikov@gmail.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_cgroup.c ##
 7:  c87e2911 !  7:  b2706fed fs: Invert logic to reduce indentation
    @@ Commit message
         the following commits.
     
         Link: <https://github.com/nginx/unit/issues/742>
    +    Tested-by: Andy Postnikov <apostnikov@gmail.com>
         Cc: Andrew Clayton <a.clayton@nginx.com>
         Cc: Liam Crilly <liam@nginx.com>
         Cc: Konstantin Pavlov <thresh@nginx.com>
    -    Cc: Andy Postnikov <apostnikov@gmail.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_fs.c ##
 8:  41f87976 !  8:  5d3a1fd4 fs: Correctly handle "/" in nxt_fs_mkdir_parent()
    @@ Commit message
     
         Fixes: 57fc9201cb91 ("Socket: Created control socket & pid file directories.")
         Link: <https://github.com/nginx/unit/issues/742>
    +    Tested-by: Andy Postnikov <apostnikov@gmail.com>
         Cc: Andrew Clayton <a.clayton@nginx.com>
         Cc: Liam Crilly <liam@nginx.com>
         Cc: Konstantin Pavlov <thresh@nginx.com>
    -    Cc: Andy Postnikov <apostnikov@gmail.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_fs.c ##
 9:  e0eaaf06 !  9:  1feec376 fs: Make parents recursively for the pid file and the control socket
    @@ Commit message
         Fixes: 57fc9201cb91 ("Socket: Created control socket & pid file directories.")
         Link: <https://github.com/nginx/unit/issues/742>
         Reported-by: Andy Postnikov <apostnikov@gmail.com>
    +    Tested-by: Andy Postnikov <apostnikov@gmail.com>
         Cc: Andrew Clayton <a.clayton@nginx.com>
         Cc: Liam Crilly <liam@nginx.com>
         Cc: Konstantin Pavlov <thresh@nginx.com>
10:  3d1b94df ! 10:  bd1f96fb auto: Don't install $runstatedir
    @@ Commit message
         Fixes: 57fc9201cb91 ("Socket: Created control socket & pid file directories.")
         Closes: <https://github.com/nginx/unit/issues/742>
         Reported-by: Andy Postnikov <apostnikov@gmail.com>
    +    Tested-by: Andy Postnikov <apostnikov@gmail.com>
         Cc: Andrew Clayton <a.clayton@nginx.com>
         Cc: Liam Crilly <liam@nginx.com>
         Cc: Konstantin Pavlov <thresh@nginx.com>
11:  09fd8bc8 = 11:  4ab657ad Use octal instead of mode macros

@ac000
Copy link
Member

ac000 commented Apr 25, 2024

 fs: Correctly handle "/" in nxt_fs_mkdir_parent()

The previous code attempted to mkdir(""), that is an empty string.
Since "/" necessarily exists, just goto out_free.

Only if they attempted something bonkers like --pid /

@@ -1,5 +1,6 @@
/*
* Copyright (C) NGINX, Inc.
* Copyright 2024, Alejandro Colomar <alx@kernel.org>
Copy link
Member

Choose a reason for hiding this comment

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

Heh, I'm not sure the below change constitutes a significant contribution...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess I could move it to the next commit, but that one was already better than the previous ones, which are trivial refactors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since that one already accumulates several changes to that page, I guess it's fair.

Copy link
Contributor Author

@alejandro-colomar alejandro-colomar Apr 25, 2024

Choose a reason for hiding this comment

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

(Although, thanks to all the refactors, the next commit is also just 2 lines in that file, and one is a rename :D)

@@ -58,7 +59,7 @@ nxt_fs_mkdir_dirname(const u_char *path, mode_t mode)
ret = NXT_OK;

ptr = strrchr(dir, '/');
if (nxt_slow_path(ptr == NULL)) {
if (ptr == dir || nxt_slow_path(ptr == NULL)) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if path == "/" should constitute an error?, as that's clearly not what you'd want.

Copy link
Contributor Author

@alejandro-colomar alejandro-colomar Apr 25, 2024

Choose a reason for hiding this comment

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

One may legitimatelly want to --control=/unit.control.sock, if they don't care about FHS and having an organized system.

We probably agree that they should be punished by such an offense, but misbehaving, or even prohibiting, is probably not a fair punishment.

@alejandro-colomar
Copy link
Contributor Author

alejandro-colomar commented Apr 25, 2024

 fs: Correctly handle "/" in nxt_fs_mkdir_parent()

The previous code attempted to mkdir(""), that is an empty string.
Since "/" necessarily exists, just goto out_free.

Only if they attempted something bonkers like --pid /

Actually, --pid /unit.pid would also result in that, since we get the dirname of it. These days, people often place stuff in the root of docker containers (I don't approve that practice, but people do it). It's unlikely, but it could happen.

Copy link
Member

@ac000 ac000 left a comment

Choose a reason for hiding this comment

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

fs: Make parents recursively for the pid file and the control socket 

I'm not sure recursively is the right term to use here. perhaps

fs: Make the full directory path for the pid file and control socket

@alejandro-colomar
Copy link
Contributor Author

fs: Make parents recursively for the pid file and the control socket 

I'm not sure recursively is the right term to use here. perhaps

fs: Make the full directory path for the pid file and control socket

Ahh, yeah, I just pasted the commit message from the old implementation. I'll revise that.

@ac000
Copy link
Member

ac000 commented Apr 25, 2024

Actually, --pid /unit.pid would also result in that, since we get the dirname of it. These days, people often place stuff in the root of docker containers (I don't approve that practice, but people do it). It's unlikely, but it could happen.

Heh, OK, but equally bonkers!

@alejandro-colomar alejandro-colomar force-pushed the fs branch 2 times, most recently from 4ab657a to 66c94bc Compare April 25, 2024 12:49
@alejandro-colomar
Copy link
Contributor Author

v2d changes:

  • wfix commit message
$ git range-diff master gh/fs fs 
 1:  fd618a14 =  1:  fd618a14 fs: Use branchless code
 2:  e9b3b2fe =  2:  e9b3b2fe fs: Use a temporary variable for the return value
 3:  472069f8 =  3:  472069f8 fs: Accept relative paths in nxt_fs_mkdir_all()
 4:  ee134aa1 =  4:  ee134aa1 fs: Accept path names of length 1
 5:  4ab479f8 =  5:  4ab479f8 fs: Rename function
 6:  3d2a6f3c =  6:  3d2a6f3c fs: Rename function
 7:  b2706fed =  7:  b2706fed fs: Invert logic to reduce indentation
 8:  5d3a1fd4 =  8:  5d3a1fd4 fs: Correctly handle "/" in nxt_fs_mkdir_parent()
 9:  1feec376 !  9:  5ab148a8 fs: Make parents recursively for the pid file and the control socket
    @@ Metadata
     Author: Alejandro Colomar <alx@kernel.org>
     
      ## Commit message ##
    -    fs: Make parents recursively for the pid file and the control socket
    +    fs: Make the full directory path for the pid file and the control socket
     
         Build systems should not attempt to create $runstatedir (or anything
         under it).  Doing so causes warnings in packaging systems, such as in
    @@ Commit message
         But unitd(8) can be configured to be installed under /opt, or other
         trees, where no directories exist before hand.  Expecting that the user
         creates the entire directory trees that unit will need is a bit
    -    unreasonable.  Instead, we can just create any directories that we need,
    -    with all their parents.
    +    unreasonable.  Instead, let's just create any directories that we need,
    +    with all their parents, at run time.
     
         Fixes: 57fc9201cb91 ("Socket: Created control socket & pid file directories.")
         Link: <https://github.com/nginx/unit/issues/742>
10:  bd1f96fb = 10:  c8e54495 auto: Don't install $runstatedir
11:  4ab657ad = 11:  66c94bc2 Use octal instead of mode macros

Copy link
Member

@ac000 ac000 left a comment

Choose a reason for hiding this comment

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

fs: Rename function

"dirname" is the usual way to refer to the directory part of a path
name.  See for example dirname(1), or the dirname builtin in several
languages.  Also, in the context of mkdir(), "parents" is used to refer
to mkdir -p, which is too similar to "parent", so it can lead to
confusion.

Perhaps rather than simply 'Rename function' you could specify the function name, i.e

fs: Rename nxt_fs_mkdir_parent()`

Same for other rename commit.

Copy link
Member

@ac000 ac000 left a comment

Choose a reason for hiding this comment

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

 fs: Use branchless code 

Could we make that

fs: Use branchless code in nxt_fs_mkdir_all()

Comment on lines -14 to +18
char *start, *end, *dst;
size_t dirlen;
char path[PATH_MAX];
char *start, *end, *dst;
size_t dirlen;
nxt_int_t ret;
char path[PATH_MAX];
Copy link
Member

Choose a reason for hiding this comment

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

Personally I'm not fussed about having Christmas tree variable type ordering and it was 'wrong' before, so meh...

( I could also quite happily live without the alignment, and the multiple variable declaration on a single line for that matter, it would make changes like this simpler)

Copy link
Member

@ac000 ac000 left a comment

Choose a reason for hiding this comment

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

Perhaps the subject

 fs: Use a temporary variable for the return value

Could be expanded to

fs: Use a temporary variable for the return value in nxt_fs_mkdir_all()

@alejandro-colomar
Copy link
Contributor Author

alejandro-colomar commented Apr 25, 2024 via email

@alejandro-colomar
Copy link
Contributor Author

alejandro-colomar commented Apr 25, 2024 via email

@alejandro-colomar
Copy link
Contributor Author

alejandro-colomar commented Apr 25, 2024 via email

@ac000
Copy link
Member

ac000 commented Apr 26, 2024

You can add my

Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>

Where they're not already...

(Also tested the ./configure --prefix=./build use case)

@alejandro-colomar
Copy link
Contributor Author

Lovely! Thanks.

@alejandro-colomar
Copy link
Contributor Author

v2f changes:

$ git range-diff master gh/fs fs 
 1:  09340996 !  1:  4af5714d fs: Rename nxt_fs_mkdir_parent() => nxt_fs_mkdir_dirname()
    @@ Commit message
         confusion.
     
         Tested-by: Andy Postnikov <apostnikov@gmail.com>
    -    Cc: Andrew Clayton <a.clayton@nginx.com>
    +    Tested-by: Andrew Clayton <a.clayton@nginx.com>
    +    Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_controller.c ##
 2:  e8a68a85 !  2:  b9164b1b fs: Rename nxt_fs_mkdir_all() => nxt_fs_mkdir_p()
    @@ Commit message
         should be more straightforward to readers.
     
         Tested-by: Andy Postnikov <apostnikov@gmail.com>
    -    Cc: Andrew Clayton <a.clayton@nginx.com>
    +    Tested-by: Andrew Clayton <a.clayton@nginx.com>
    +    Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_cgroup.c ##
 3:  fd3ed9a7 !  3:  76547576 fs: Use branchless code in nxt_fs_mkdir_p()
    @@ Commit message
         achieve the same by using a +1 to make sure we advance at least 1 byte
         in each iteration.
     
    -    Tested-by: Andrew Clayton <a.clayton@nginx.com>
         Tested-by: Andy Postnikov <apostnikov@gmail.com>
    +    Tested-by: Andrew Clayton <a.clayton@nginx.com>
    +    Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_fs.c ##
 4:  5217653d !  4:  30d86ba3 fs: Use a temporary variable in nxt_fs_mkdir_p()
    @@ Commit message
         This avoids breaking a long line.
     
         Tested-by: Andy Postnikov <apostnikov@gmail.com>
    +    Tested-by: Andrew Clayton <a.clayton@nginx.com>
    +    Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_fs.c ##
 5:  c416ff88 !  5:  5bad130b fs: Accept relative paths in nxt_fs_mkdir_p()
    @@ Commit message
         fs: Accept relative paths in nxt_fs_mkdir_p()
     
         Tested-by: Andy Postnikov <apostnikov@gmail.com>
    +    Tested-by: Andrew Clayton <a.clayton@nginx.com>
    +    Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_fs.c ##
 6:  dd704f4e !  6:  7f66687a fs: Accept path names of length 1 in nxt_fs_mkdir_p()
    @@ Commit message
     
         Fixes: e2b53e16c60b ("Added "rootfs" feature.")
         Tested-by: Andy Postnikov <apostnikov@gmail.com>
    -    Cc: Andrew Clayton <a.clayton@nginx.com>
    +    Tested-by: Andrew Clayton <a.clayton@nginx.com>
    +    Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_fs.c ##
 7:  24dc2322 !  7:  c10f572f fs: Invert logic to reduce indentation in nxt_fs_mkdir_dirname()
    @@ Commit message
     
         Link: <https://github.com/nginx/unit/issues/742>
         Tested-by: Andy Postnikov <apostnikov@gmail.com>
    -    Cc: Andrew Clayton <a.clayton@nginx.com>
    +    Tested-by: Andrew Clayton <a.clayton@nginx.com>
    +    Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
         Cc: Liam Crilly <liam@nginx.com>
         Cc: Konstantin Pavlov <thresh@nginx.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
 8:  739df6c8 !  8:  73166a92 fs: Correctly handle "/" in nxt_fs_mkdir_dirname()
    @@ Commit message
         Fixes: 57fc9201cb91 ("Socket: Created control socket & pid file directories.")
         Link: <https://github.com/nginx/unit/issues/742>
         Tested-by: Andy Postnikov <apostnikov@gmail.com>
    -    Cc: Andrew Clayton <a.clayton@nginx.com>
    +    Tested-by: Andrew Clayton <a.clayton@nginx.com>
    +    Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
         Cc: Liam Crilly <liam@nginx.com>
         Cc: Konstantin Pavlov <thresh@nginx.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
 9:  4462a15a !  9:  cdde66f7 fs: Make the full directory path for the pid file and the control socket
    @@ Commit message
         Link: <https://github.com/nginx/unit/issues/742>
         Reported-by: Andy Postnikov <apostnikov@gmail.com>
         Tested-by: Andy Postnikov <apostnikov@gmail.com>
    -    Cc: Andrew Clayton <a.clayton@nginx.com>
    +    Tested-by: Andrew Clayton <a.clayton@nginx.com>
    +    Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
         Cc: Liam Crilly <liam@nginx.com>
         Cc: Konstantin Pavlov <thresh@nginx.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
10:  7606860b ! 10:  9ff0ba82 auto: Don't install $runstatedir
    @@ Commit message
         Closes: <https://github.com/nginx/unit/issues/742>
         Reported-by: Andy Postnikov <apostnikov@gmail.com>
         Tested-by: Andy Postnikov <apostnikov@gmail.com>
    -    Cc: Andrew Clayton <a.clayton@nginx.com>
    +    Tested-by: Andrew Clayton <a.clayton@nginx.com>
    +    Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
         Cc: Liam Crilly <liam@nginx.com>
         Cc: Konstantin Pavlov <thresh@nginx.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
11:  11d26d33 ! 11:  79b777c1 Use octal instead of mode macros
    @@ Commit message
     
         And we had a mix of both styles; there wasn't really a consistent style.
     
    +    Tested-by: Andrew Clayton <a.clayton@nginx.com>
    +    Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## auto/shmem ##

@alejandro-colomar
Copy link
Contributor Author

Boogy ruby test.

@callahad
Copy link
Collaborator

This looks reasonable enough to me.

@ac000 do we need anything more before approving and merging?

@ac000
Copy link
Member

ac000 commented Jun 18, 2024

Overall I'm OK with it.

I think this comment still applies as @thresheek did reject the idea of creating full directory paths when we did this the first time around...

@thresheek
Copy link
Member

I guess my only concern is that typos can go unchecked and create a mess of a hierarchy. Other than that, we'd probably need to adjust some packaging for that change, but that can be fixed after this PR is merged.

@alejandro-colomar
Copy link
Contributor Author

alejandro-colomar commented Jun 18, 2024

I guess my only concern is that typos can go unchecked and create a mess of a hierarchy. Other than that, we'd probably need to adjust some packaging for that change, but that can be fixed after this PR is merged.

Hi @thresheek, @ac000 , @callahad ,

Hmmmm, just yesterday, something like that happened to me:

I was using scp(1), and I made a typo in the (remote) destination. I was very lucky that scp(1) rejected the copy instead of creating all parents. I remembered you (@thresheek). :-)

But in this case, I'm not sure of how to do it in a different way. If you have any idea, please let me know.

Anyway, since in this case that's usually specified in the packaging, and not by the end users (or if they do so, it's in a Dockerfile, or something else controlled by git(1) (or else)), I expect it to be unlikely to have typos. It's not like one is running unitd with --pid manually specified all the time; unlike with cp(1) or scp(1).

Have a lovely day!
Alex

@ac000
Copy link
Member

ac000 commented Jun 18, 2024

I guess my only concern is that typos can go unchecked and create a mess of a hierarchy. Other than that, we'd probably need to adjust some packaging for that change, but that can be fixed after this PR is merged.

@thresheek

In that case can we add your

Acked-by: Konstantin Pavlov <thresh@nginx.com>

to fs: Make the full directory path for the pid file and the control socket ?

@thresheek
Copy link
Member

In that case can we add your

Acked-by: Konstantin Pavlov <thresh@nginx.com>

Sure!

@ac000
Copy link
Member

ac000 commented Jun 18, 2024

In that case can we add your

Acked-by: Konstantin Pavlov <thresh@nginx.com>

Sure!

Cheers!

@alejandro-colomar

Do you want to the do honours and rebase to master?

"dirname" is the usual way to refer to the directory part of a path
name.  See for example dirname(1), or the dirname builtin in several
languages.  Also, in the context of mkdir(), "parents" is used to refer
to mkdir -p, which is too similar to "parent", so it can lead to
confusion.

Tested-by: Andy Postnikov <apostnikov@gmail.com>
Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
"all" is too generic of an attribute to be meaningful.  In the context
of mkdir(), "parents" is used for this meaning, as in mkdir -p, so it
should be more straightforward to readers.

Tested-by: Andy Postnikov <apostnikov@gmail.com>
Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
That branch was to avoid an infinite loop on the slash.  However, we can
achieve the same by using a +1 to make sure we advance at least 1 byte
in each iteration.

Tested-by: Andy Postnikov <apostnikov@gmail.com>
Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This avoids breaking a long line.

Tested-by: Andy Postnikov <apostnikov@gmail.com>
Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Tested-by: Andy Postnikov <apostnikov@gmail.com>
Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
That is, accept "/", or relative path names of a single byte.

Fixes: e2b53e1 ("Added "rootfs" feature.")
Tested-by: Andy Postnikov <apostnikov@gmail.com>
Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This refactor isn't very appealing alone, but it prepares the code for
the following commits.

Link: <nginx#742>
Tested-by: Andy Postnikov <apostnikov@gmail.com>
Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Cc: Liam Crilly <liam@nginx.com>
Cc: Konstantin Pavlov <thresh@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
The previous code attempted to mkdir(""), that is an empty string.
Since "/" necessarily exists, just goto out_free.

Fixes: 57fc920 ("Socket: Created control socket & pid file directories.")
Link: <nginx#742>
Tested-by: Andy Postnikov <apostnikov@gmail.com>
Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Cc: Liam Crilly <liam@nginx.com>
Cc: Konstantin Pavlov <thresh@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Build systems should not attempt to create $runstatedir (or anything
under it).  Doing so causes warnings in packaging systems, such as in
Alpine Linux, as reported by Andy.

But unitd(8) can be configured to be installed under /opt, or other
trees, where no directories exist before hand.  Expecting that the user
creates the entire directory trees that unit will need is a bit
unreasonable.  Instead, let's just create any directories that we need,
with all their parents, at run time.

Fixes: 57fc920 ("Socket: Created control socket & pid file directories.")
Link: <nginx#742>
Reported-by: Andy Postnikov <apostnikov@gmail.com>
Tested-by: Andy Postnikov <apostnikov@gmail.com>
Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Acked-by: Konstantin Pavlov <thresh@nginx.com>
Cc: Liam Crilly <liam@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This directory should exist already in the system, and if not, it should
(and will) be created at run time, not at install time.

It triggered a warning in Alpine Linux's packaging system:

    ERROR: unit*: Packages must not put anything under /var/run

Fixes: 5a37171 ("Added default values for pathnames.")
Fixes: 57fc920 ("Socket: Created control socket & pid file directories.")
Closes: <nginx#742>
Reported-by: Andy Postnikov <apostnikov@gmail.com>
Tested-by: Andy Postnikov <apostnikov@gmail.com>
Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Cc: Liam Crilly <liam@nginx.com>
Cc: Konstantin Pavlov <thresh@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
They are more readable.

And we had a mix of both styles; there wasn't really a consistent style.

Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
@alejandro-colomar
Copy link
Contributor Author

In that case can we add your

Acked-by: Konstantin Pavlov <thresh@nginx.com>

Sure!

Cheers!

@alejandro-colomar

Do you want to the do honours and rebase to master?

Sure! :-)

v2g
$ git range-diff master..gh/fs ngx/master..fs
 1:  4af5714d =  1:  3db000a5 fs: Rename nxt_fs_mkdir_parent() => nxt_fs_mkdir_dirname()
 2:  b9164b1b =  2:  40eaf4e4 fs: Rename nxt_fs_mkdir_all() => nxt_fs_mkdir_p()
 3:  76547576 =  3:  af6a67ff fs: Use branchless code in nxt_fs_mkdir_p()
 4:  30d86ba3 =  4:  2eb2f60b fs: Use a temporary variable in nxt_fs_mkdir_p()
 5:  5bad130b =  5:  c6ce0381 fs: Accept relative paths in nxt_fs_mkdir_p()
 6:  7f66687a =  6:  3873f98f fs: Accept path names of length 1 in nxt_fs_mkdir_p()
 7:  c10f572f =  7:  7b7b303a fs: Invert logic to reduce indentation in nxt_fs_mkdir_dirname()
 8:  73166a92 =  8:  a9aed204 fs: Correctly handle "/" in nxt_fs_mkdir_dirname()
 9:  cdde66f7 !  9:  eca38349 fs: Make the full directory path for the pid file and the control socket
    @@ Commit message
         Tested-by: Andy Postnikov <apostnikov@gmail.com>
         Tested-by: Andrew Clayton <a.clayton@nginx.com>
         Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
    +    Acked-by: Konstantin Pavlov <thresh@nginx.com>
         Cc: Liam Crilly <liam@nginx.com>
    -    Cc: Konstantin Pavlov <thresh@nginx.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/nxt_controller.c ##
10:  9ff0ba82 = 10:  2e2e5d1e auto: Don't install $runstatedir
11:  79b777c1 = 11:  d96d5833 Use octal instead of mode macros

@ac000 ac000 self-requested a review June 18, 2024 21:23
Copy link
Member

@ac000 ac000 left a comment

Choose a reason for hiding this comment

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

Thanks Alex!

@ac000 ac000 merged commit d96d583 into nginx:master Jun 18, 2024
21 of 23 checks passed
@alejandro-colomar
Copy link
Contributor Author

You're welcome Andrew!

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.

The $runstatedir is not being created at runtime
5 participants