Re: Missing [/usr/local]/var/lib and [/usr/local]/tmp

2022-07-19 Thread Alejandro Colomar

Hi Alfred,

On 7/19/22 09:26, Alfred M. Szmidt wrote:

> I think the first question is to understand what a "library state
> directory" is?  Whate are you storing under it?  Seems like something
> architecture independent? Are the files shareable between
> installations?

I'm talking about NGINX Unit, which stores the running configuration
(kind of what /etc/nginx/nginx.conf was to NGINX, but Unit uses a
runtime defined JSON file).  It also stores a few other files, but
that's the main one.  If the process is restarted, it picks up that
configuration, so it needs to be kept after reboot (so not /run)

That sounds like a cache file, so why not /var/cache?  I don't
understand why /var/lib though ...


Hmm, it wouldn't be completely unreasonable to use /var/cache.

But since the file doesn't represent a cache of the state, but the 
actual state (modifying the file would modify the state of the program).


Since /var/lib is "variable state information" (according to FHS 3.0), I 
think it makes more sense, but I'm not sure about it.  I've never used 
it before.




It is arch independent.

And it doesn't make sense to share it, as it represents the state of the
running instance of unitd.  Sharing it would probably break other
instances of the process when one of the instances modifies it.

Ok, then something under /var would make sense.


Cheers,

Alex

--
Alejandro Colomar



OpenPGP_signature
Description: OpenPGP digital signature


Re: Missing [/usr/local]/var/lib and [/usr/local]/tmp

2022-07-19 Thread Alfred M. Szmidt
   > I think the first question is to understand what a "library state
   > directory" is?  Whate are you storing under it?  Seems like something
   > architecture independent? Are the files shareable between
   > installations?

   I'm talking about NGINX Unit, which stores the running configuration 
   (kind of what /etc/nginx/nginx.conf was to NGINX, but Unit uses a 
   runtime defined JSON file).  It also stores a few other files, but 
   that's the main one.  If the process is restarted, it picks up that 
   configuration, so it needs to be kept after reboot (so not /run)

That sounds like a cache file, so why not /var/cache?  I don't
understand why /var/lib though ...

   It is arch independent.

   And it doesn't make sense to share it, as it represents the state of the 
   running instance of unitd.  Sharing it would probably break other 
   instances of the process when one of the instances modifies it.

Ok, then something under /var would make sense.



Re: Missing [/usr/local]/var/lib and [/usr/local]/tmp

2022-07-18 Thread Jeffrey Walton
On Mon, Jul 18, 2022 at 10:22 AM Bruno Haible  wrote:
>
> Jeffrey Walton wrote:
> > I believe MacOS maps /etc and /tmp to a private area for the user.
> > They are not world readable/writable. I believe Apple did it for
> > hardening.
> >
> > Here's from a MacOS X 10.5 machine I have:
> >
> > $ ls -l /etc /tmp
> > lrwxr-xr-x@ 1 root  wheel  11 Feb 10  2015 /etc -> private/etc
> > lrwxr-xr-x@ 1 root  wheel  11 Feb 10  2015 /tmp -> private/tmp
>
> /tmp is world-writable, of course:
>
> $ ls -lLd /etc /tmp
> drwxr-xr-x@ 124 root  wheel  3968 27 Jun 01:25 /etc
> drwxrwxrwt@   8 root  wheel   256 18 Jul 14:38 /tmp

I believe Apple creates a copy of /etc, /var and /tmp for the user.
Then, writes occur to the private area the OS provides to the user. I
don't believe users are allowed to write directly to those
directories. In the old days it happened because of NetBoot. Nowadays
it's because of Apple's System Integrity Protection.

Also see 
https://apple.stackexchange.com/questions/1043/why-is-tmp-a-symlink-to-private-tmp
and https://en.wikipedia.org/wiki/System_Integrity_Protection .

Jeff



Re: Missing [/usr/local]/var/lib and [/usr/local]/tmp

2022-07-18 Thread Bruno Haible
Jeffrey Walton wrote:
> I believe MacOS maps /etc and /tmp to a private area for the user.
> They are not world readable/writable. I believe Apple did it for
> hardening.
> 
> Here's from a MacOS X 10.5 machine I have:
> 
> $ ls -l /etc /tmp
> lrwxr-xr-x@ 1 root  wheel  11 Feb 10  2015 /etc -> private/etc
> lrwxr-xr-x@ 1 root  wheel  11 Feb 10  2015 /tmp -> private/tmp

/tmp is world-writable, of course:

$ ls -lLd /etc /tmp
drwxr-xr-x@ 124 root  wheel  3968 27 Jun 01:25 /etc
drwxrwxrwt@   8 root  wheel   256 18 Jul 14:38 /tmp

Bruno






Re: Missing [/usr/local]/var/lib and [/usr/local]/tmp

2022-07-18 Thread Jeffrey Walton
On Mon, Jul 18, 2022 at 8:18 AM Edward Welbourne  wrote:
>
> Alejandro Colomar (Monday, July 18, 2022 14:07)
> > MacOS seems to be setting TMPDIR (or at least some script run at
> > startup seems to be setting it in my system), and it's set to something
> > really weird that I don't trust will exist after reboot.
>
> Then I think the way you're using tmpdir doesn't match its usual
> semantics, namely that it's exactly a directory that's routinely blown
> away and recreated, at least as often as boot-time and ideally more
> often.  If what you need is a place to store (even semi-) persistent
> state for a program, that should survive reboots, then you want
> $prefix/var/, not /tmp/ (which may well be a tmpfs partition, indeed).

I believe MacOS maps /etc and /tmp to a private area for the user.
They are not world readable/writable. I believe Apple did it for
hardening.

Here's from a MacOS X 10.5 machine I have:

$ ls -l /etc /tmp
lrwxr-xr-x@ 1 root  wheel  11 Feb 10  2015 /etc -> private/etc
lrwxr-xr-x@ 1 root  wheel  11 Feb 10  2015 /tmp -> private/tmp

Jeff



Re: Missing [/usr/local]/var/lib and [/usr/local]/tmp

2022-07-18 Thread Alejandro Colomar

Hi Eddy,

On 7/18/22 14:17, Edward Welbourne wrote:

Alejandro Colomar (Monday, July 18, 2022 14:07)

MacOS seems to be setting TMPDIR (or at least some script run at
startup seems to be setting it in my system), and it's set to something
really weird that I don't trust will exist after reboot.


Then I think the way you're using tmpdir doesn't match its usual
semantics, namely that it's exactly a directory that's routinely blown
away and recreated, at least as often as boot-time and ideally more
often.  If what you need is a place to store (even semi-) persistent
state for a program, that should survive reboots, then you want
$prefix/var/, not /tmp/ (which may well be a tmpfs partition, indeed).


This isn't my code, so I'm not entirely familiar with why it was 
implemented that way.  I agree it's probably wrong.


But from I know, the data stored there shouldn't survive reboots.  But 
the directory itself should, because it's hardcoded at compile time, and 
so the program tries to find it when creating temporary files in it.


I'm not sure if the program handles correctly `TMPDIR=/foo/bar unitd`, 
but it should.  I guess $tmpdir would be the string to fallback if no 
TMPDIR is specified.  Is it good to hardcode it in the binary to be 
/tmp, or should we allow compile-time modification at compile time 
thorugh $tmpdir?


Thanks,

Alex


--
Alejandro Colomar



OpenPGP_signature
Description: OpenPGP digital signature


Re: Missing [/usr/local]/var/lib and [/usr/local]/tmp

2022-07-18 Thread Alejandro Colomar

Hi Alfred,

On 7/18/22 13:51, Alfred M. Szmidt wrote:

I'm improving a Makefile for a project which uses [/usr/local]/var/lib
and [/usr/local]/tmp.  I see there's no standard in the GNU coding
standards for directory variables.

I used the following:

tmpdir := $(prefix)/tmp
libstatedir := $(localstatedir)/lib

I developed the name $libstatedir for symmetry with $runstatedir, which
is also a child of $localstatedir, with the first part of the name as
the name of the child dir.

Would you mind adding those to your directory variables?

I think the first question is to understand what a "library state
directory" is?  Whate are you storing under it?  Seems like something
architecture independent? Are the files shareable between
installations?


I'm talking about NGINX Unit, which stores the running configuration 
(kind of what /etc/nginx/nginx.conf was to NGINX, but Unit uses a 
runtime defined JSON file).  It also stores a few other files, but 
that's the main one.  If the process is restarted, it picks up that 
configuration, so it needs to be kept after reboot (so not /run)


It is arch independent.

And it doesn't make sense to share it, as it represents the state of the 
running instance of unitd.  Sharing it would probably break other 
instances of the process when one of the instances modifies it.




For /tmp, the only thing that should realy be used is /tmp (or
/var/tmp).  /usr/tmp would be strange, and very non-standard.


Yup, I replied to Bruno's message, which was more or less like this.

Thanks,

Alex

--
Alejandro Colomar



OpenPGP_signature
Description: OpenPGP digital signature


Re: Missing [/usr/local]/var/lib and [/usr/local]/tmp

2022-07-18 Thread Edward Welbourne
Alejandro Colomar (Monday, July 18, 2022 14:07)
> MacOS seems to be setting TMPDIR (or at least some script run at 
> startup seems to be setting it in my system), and it's set to something 
> really weird that I don't trust will exist after reboot.

Then I think the way you're using tmpdir doesn't match its usual
semantics, namely that it's exactly a directory that's routinely blown
away and recreated, at least as often as boot-time and ideally more
often.  If what you need is a place to store (even semi-) persistent
state for a program, that should survive reboots, then you want
$prefix/var/, not /tmp/ (which may well be a tmpfs partition, indeed).

Eddy.



Re: Missing [/usr/local]/var/lib and [/usr/local]/tmp

2022-07-18 Thread Alejandro Colomar



On 7/18/22 13:41, Bruno Haible wrote:

Alejandro Colomar wrote:

I used the following:

tmpdir := $(prefix)/tmp


Writing it like this has two drawbacks:
   1) The user cannot force a specific temporary directory by setting
  the TMPDIR environment variable. This may be blocking if the
  default temporary directory has not enough room.
   2) It creates one more directory that requires either regular attention
  (so that it does not fill up over time) or a fascist policy of the
  kind "let's remove the contents of this directory regularly".

Suggestion: Use ${TMPDIR-/tmp} instead.


Thanks for the suggestion.  That was indeed my first implementation.
But, MacOS seems to be setting TMPDIR (or at least some script run at 
startup seems to be setting it in my system), and it's set to something 
really weird that I don't trust will exist after reboot.


That's why I wasn't comfortable setting $tmpdir to ${TMPDIR-/tmp}.

Although... now that I think, the program shouldn't have a hardcoded 
$tmpdir at install time, at all.  It should probably have the 
${TMPDIR-/tmp} behavior inside the program.


So maybe I should patch the program in that sense.

Right?



See also [1].

Bruno

[1] 
https://superuser.com/questions/332610/where-is-the-temporary-directory-in-linux





What about $libstatedir?

Cheers,

Alex

--
Alejandro Colomar



OpenPGP_signature
Description: OpenPGP digital signature


Re: Missing [/usr/local]/var/lib and [/usr/local]/tmp

2022-07-18 Thread Alfred M. Szmidt
   I'm improving a Makefile for a project which uses [/usr/local]/var/lib 
   and [/usr/local]/tmp.  I see there's no standard in the GNU coding 
   standards for directory variables.

   I used the following:

   tmpdir := $(prefix)/tmp
   libstatedir := $(localstatedir)/lib

   I developed the name $libstatedir for symmetry with $runstatedir, which 
   is also a child of $localstatedir, with the first part of the name as 
   the name of the child dir.

   Would you mind adding those to your directory variables?

I think the first question is to understand what a "library state
directory" is?  Whate are you storing under it?  Seems like something
architecture independent? Are the files shareable between
installations?

For /tmp, the only thing that should realy be used is /tmp (or
/var/tmp).  /usr/tmp would be strange, and very non-standard.



Re: Missing [/usr/local]/var/lib and [/usr/local]/tmp

2022-07-18 Thread Bruno Haible
Alejandro Colomar wrote:
> I used the following:
> 
> tmpdir := $(prefix)/tmp

Writing it like this has two drawbacks:
  1) The user cannot force a specific temporary directory by setting
 the TMPDIR environment variable. This may be blocking if the
 default temporary directory has not enough room.
  2) It creates one more directory that requires either regular attention
 (so that it does not fill up over time) or a fascist policy of the
 kind "let's remove the contents of this directory regularly".

Suggestion: Use ${TMPDIR-/tmp} instead.

See also [1].

Bruno

[1] 
https://superuser.com/questions/332610/where-is-the-temporary-directory-in-linux