LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Current64: Where does the /.cache file come from? (https://www.linuxquestions.org/questions/slackware-14/current64-where-does-the-cache-file-come-from-4175605075/)

burdi01 05-02-2017 08:00 AM

Current64: Where does the /.cache file come from?
 
Current64: After each boot, before starting X I already have an empty /.cache file, for which I cannot find "who" creates it.
Taking the risk to sound stupid, but is there anyone who knows?
:D

bassmadrigal 05-02-2017 11:51 AM

It doesn't occur on my frankenstein 14.1 install or my normal 14.2 install. I don't have any -current installs to test. However, my first guess is this is a culprit of 3rd-party software you have installed. Maybe an rc.d script that is missing a variable being set?

First thing I'd try is to run fgrep ".cache" /etc/rc.d/* to see if it can find any files containing .cache in them (fgrep prevents regex from being used, so it interprets the . as a literal period, not as a wildcard like in normal regex... I can never remember how to properly escape it for a regular grep). It might also be worth checking any 3rd-party programs you have starting up automatically. If the file isn't being created directly by a script in /etc/rc.d/, it could be by one of the scripts called by one of those rc.d scripts (like rc.program calls /usr/bin/program, which may also be a shell script).

If you don't want to do all that searching, you could try disabling all your 3rd-party items in /etc/rc.d/ (don't forget stuff in rc.local) and see if the file is still created when you reboot. Don't forget to remove the .cache before you restart!

notKlaatu 05-02-2017 12:14 PM

Are you logging in to X as root? KDE Plasma might be creating those dirs for root, and dumping them, incorrectly, in /.

I did two minutes (OK, maybe it was more like 90 seconds) of testing and it appears that this happens on Fedora 25 (I'm at work right now, so that's the machine I have handy).

burdi01 05-03-2017 05:50 AM

I did scan the /etc directory for ".cache" (and even for "cache") and followed the boot sequence up to and including logging in - I boot into lvl3, so no X. As I could not find a "culprit" I posted my question.
Today I repeated this procedure, and again to no avail...
I took the way of the least resistance and delete the /.cache directory in my /etc/rc.d/rc.local.
Thank you for responding.
:D

pan64 05-03-2017 05:57 AM

looks like it was created during installation (at least on ubuntu) and also there is a file inside:
Code:

/.cache/dconf/user
containing 00 (2 times 0).

burdi01 05-03-2017 06:03 AM

@pan64: I delete that directory, but every time after a reboot it is back ...
As an aside, it is not present on my Xubuntu installation.
:D

pan64 05-03-2017 06:08 AM

looks like it is created by apparmor

55020 05-03-2017 06:12 AM

*Lots* of software creates and uses subdirectories of ~/.cache -- it tends to be packages that also use .local and .config. If you're cool with .local and .config (and you probably are, unless you don't want software to remember your config from one login to the next) then you should also be cool with .cache. Life's too short to stop software trying to speed itself with a bit of cacheing.

It's another fdo idea by the way (https://standards.freedesktop.org/ba...ec-latest.html), and yes, that's our friend Mr Lovebucket on the authors list.

From the spec, you can try to specify an alternative name with XDG_CACHE_HOME if it really bothers you.

Edit: here's a totally random list of totally random stuff that uses it:
calibre darktable dconf fontconfig fontforge g-ir-scanner geeqie gegl-0.2 google-chrome gpg-agent-info gstreamer-1.0 guile gvfs-burn inkscape instantfpc keybase keyring-* matplotlib mc moonchild productions mozilla osmgpsmap pip sessions spotify thumbnails thunderbird vlc webkit xfce4

montagdude 05-03-2017 07:34 AM

Quote:

Originally Posted by 55020 (Post 5705581)
*Lots* of software creates and uses subdirectories of ~/.cache -- it tends to be packages that also use .local and .config. If you're cool with .local and .config (and you probably are, unless you don't want software to remember your config from one login to the next) then you should also be cool with .cache. Life's too short to stop software trying to speed itself with a bit of cacheing.

You've convinced me. I'm okay with ~/.cache.

Quote:

Originally Posted by 55020 (Post 5705581)
It's another fdo idea by the way (https://standards.freedesktop.org/ba...ec-latest.html), and yes, that's our friend Mr Lovebucket on the authors list.

Wait, I take it back. Now I hate it! ;)

burdi01 05-03-2017 07:35 AM

Note to everyone: I am talking about an empty /.cache directory, not one like ~/.cache !
:D

55020 05-03-2017 07:54 AM

ooooooo!!! sorry burdi01, I've made myself look stupid again :D

As you say it definitely shouldn't be there (of all places). Thanks for the report! If you can identify its creation time to the nearest second, hopefully that'll narrow down what did it. And then we can smite the damn thing.

bassmadrigal 05-03-2017 08:51 AM

Have you tried stopping any of your custom rc.d entries? That would mean making rc.d and any non-official rc.d script non-executable. If it still occurs, then it would likely be something in -current itself and not any of your 3rd-party software. But I can't think of any official Slackware packages that would create that directory during the boot process, so I'm expecting it is a 3rd-party software that doesn't have its variables set up properly.

The following command will list all executable files in /etc/rc.d/, if you also include your contents of rc.local, it might help us narrow down your possible culprits.

Code:

find /etc/rc.d/ -maxdepth 1 -perm -111 -type f

rworkman 05-03-2017 01:34 PM

I'd lean toward finding out what's running as root (or at least starting as root and maybe dropping privs), then see if any of them have a $HOME directory that is either / or unset (which might cause them to default to /).

gmgf 05-03-2017 02:27 PM

this .cache is recreated after reboot or at boot.

Darth Vader 05-03-2017 02:45 PM

That nasty folder on / appeared after the latest font adventures...

gmgf 05-03-2017 02:51 PM

Quote:

Originally Posted by Darth Vader (Post 5705791)
That nasty folder on / appeared after the latest font adventures...

No i have this since longtime.

Darth Vader 05-03-2017 06:01 PM

In my case, this stray /.cache folder appeared after the last updates in slackware-current.

rkelsen 05-04-2017 04:20 AM

I don't have this problem.

What are you running on boot?

gmgf 05-04-2017 09:48 AM

Robby, it's due to rc.networkmanager, when is inactived the .config isn't created at boot ;)

I think it starts too early in the init, because when you start it under x, there is no problem

burdi01 05-04-2017 10:51 AM

By placing "echo -n "XXX: " ; ls -a /" statements in /etc/rc.{S,M} and drilling down I found that the /.cache file is created by the /usr/sbin/NetworkManager invocation done in /etc/rc.d/rc.networkmanager:
Code:

nm_start()
{
  .....
echo -n "M2cC: " ; ls -a /
  echo "Starting NetworkManager daemon:  $NETWORKMANAGER_BIN"
  $NETWORKMANAGER_BIN
echo -n "M2cD: " ; ls -a /
}

As /usr/sbin/NetworkManager is an "ELF 64-bit executable" my journey ends there.
:D

allend 05-04-2017 10:51 AM

Nice catch!
On my desktop, where I do not use NetworkManager, I do not see a /.cache directory. On my laptop, where I do use NetworkManager, I do see a /.cache directory.

burdi01 05-04-2017 10:57 AM

Yes, after installing wicd the /.cache directory is no longer created.
:D

rworkman 05-04-2017 01:28 PM

Quote:

Originally Posted by gmgf (Post 5706138)
Robby, it's due to rc.networkmanager, when is inactived the .config isn't created at boot ;)

I think it starts too early in the init, because when you start it under x, there is no problem

That is interesting, but it doesn't happen here...
I also don't see anywhere in NM source that uses any .cache directory :/

rworkman 05-04-2017 01:46 PM

Humor me on this. Before the NM invocation stanza, add a "sleep 2" and then your echo/ls line and see what happens. I think it might be bluez doing it but it just takes a bit of time and NM gets started before that cache dir is created...

allend 05-05-2017 03:23 AM

I think bluez is a false trail. The laptop where I observe the problem does not have /etc/rc.d/rc.bluetooth executable.
I added a call in /etc/rc.d/rc.S just before the stanza to configure ISA Plug and Play devices to a script to watch for the creation of a directory in /
Code:

#!/bin/sh

while inotifywait -e create / ; do
  ps axww >> /tmp/clog.txt
done &

The resulting output seems to confirm NetworkManager as the culprit.
Code:

  756 ?        Ss    0:00 /sbin/mount.ntfs /dev/sda2 /xp-c -v -o ro,noexec,nosuid,nodev,umask=022,users
  759 ?        Ss    0:00 /sbin/mount.ntfs-3g /dev/sda3 /xp-d -v -o rw,umask=022
  774 ?        S      0:00 /usr/sbin/cgmanager --daemon
  794 ?        Ss    0:00 /bin/sh /etc/rc.d/rc.M
  806 ?        Ss    0:00 /usr/sbin/syslogd
  810 ?        Ss    0:00 /usr/sbin/klogd -c 3 -x
  811 ?        R      0:01 /usr/bin/fc-cache -f
  920 ?        Ss    0:00 /usr/bin/dbus-daemon --system
  921 ?        S      0:00 sh /etc/rc.d/rc.networkmanager start
  926 ?        D      0:00 /usr/sbin/NetworkManager
  927 ?        R      0:00 ps axww


gmgf 05-05-2017 03:40 AM

Yes, i have one other install of current with openrc, and this install, doesn't have this cosmetic problem.

kjhambrick 05-05-2017 04:22 AM

Hmmm ... an interesting, if harmless issue here ...

I've done this to myself from time to time by referencing an unitialized or a misspelled Directory Variable in a /bin/sh script.

Example:
Code:

THE_DIR=                # THE_DIR is unitialized but not on purpose :)
mkdir ${THE_DIR}/.cache  # oops ... ${THE_DIR} will be created as /.cache
#
# or a misspelling ...
#
THE_DIR="$HOME"          # Initialize THE_DIR
mkdir ${THEDIR}/.cache  # but misspell THE_DIR when I reference it and oops[2]

Since I don't run many scripts as root, and because a joe user cannot create a Directory in the fs root, the above code fails if I bother to check RetCodes

OTOH, if I run such code as root, I end up with an unintended directory in the fs root.

Just sayin' :)

Anyhow, like burdi01, I found no references to a .cache directory in any Current NetworkManager files and I am running wicd so I have no /.cache directory on my systems.

But NetworkManager requires dbus (:) another Project with the LoveBucket name on it :)) and I do have a $HOME/.cache/dbus/ directory.

I've not scanned the dbus code but I wonder if the XDG_DATA_HOME variable that 55020 found affects the location of the .cache/dbus/ directory ?

But then, how would one set XDG_DATA_HOME during boot ???

-- kjh

burdi01 05-05-2017 04:37 AM

@rworkman:
Quote:

I think it might be bluez doing it but it just takes a bit of time and NM gets started before that cache dir is created...
That would be in contradiction with my finding that when using wicd (which precludes NM) the /.cache directory is not created.
Also, just as allend, I do not have bluez enabled (actually it is not even installed).

Anyway, I did as requested (and with an even longer sleep):
Code:

nm_start()
{
.....
echo -n "M2cB2: " ; ls -a /
echo "sleep 5" ; sleep 5
echo -n "M2cC: " ; ls -a /
  echo "Starting NetworkManager daemon:  $NETWORKMANAGER_BIN"
  $NETWORKMANAGER_BIN
echo -n "M2cD: " ; ls -a /
}

The .cache directory first pops up with the "M2cD" display.
:D

allend 05-05-2017 08:15 AM

This is working for me to stop the creation of /.cache directory.
Code:

bash-4.4$ diff ./a/rc.networkmanager ./b/rc.networkmanager
36c36
<  $NETWORKMANAGER_BIN
---
>  XDG_CACHE_HOME=/root/.cache $NETWORKMANAGER_BIN

From https://standards.freedesktop.org/ba...ec-latest.html
Quote:

$XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored. If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used.

rworkman 05-05-2017 09:08 AM

Quote:

Originally Posted by burdi01 (Post 5706503)
@rworkman:
That would be in contradiction with my finding that when using wicd (which precludes NM) the /.cache directory is not created.
Also, just as allend, I do not have bluez enabled (actually it is not even installed).

Anyway, I did as requested (and with an even longer sleep):
Code:

nm_start()
{
.....
echo -n "M2cB2: " ; ls -a /
echo "sleep 5" ; sleep 5
echo -n "M2cC: " ; ls -a /
  echo "Starting NetworkManager daemon:  $NETWORKMANAGER_BIN"
  $NETWORKMANAGER_BIN
echo -n "M2cD: " ; ls -a /
}

The .cache directory first pops up with the "M2cD" display.
:D

Well, here's the feedback from thaller in #networkmanager:
Quote:

19:56 < thaller> rworkman, seems related to glib and using the session bus... which uses "$XDG_RUNTIME_DIR/bus" as path... but NM should ever access the
session bus, something is wrong there.
14:05 < rworkman> thaller: re glib & session bus, it's definitely somehow related to NM, but no idea how :/
14:06 < thaller> rworkman, grep in glib sources where they create the .cache directory (not many places), install debugging symbols, and run in debugger with
a breakpoint
14:07 < thaller> I guess, you could also get a backtrace using systemtap, but I am not familiar enough with that.
Anybody feel up to that? :-)

rworkman 05-05-2017 09:18 AM

Quote:

14:12 < rworkman> Without any debugging, looks like it's in glib/gutils.c probably
14:14 < rworkman> in g_get_user_runtime_dir()
I've made an inquiry of mclasen, the guy who does glib releases; let's wait and see what he says before any significant time is invested in debugging...

rworkman 05-05-2017 09:29 AM

In the meantime, something like this near the top of rc.networkmanager should move the problem somewhere other than /:
Code:

XDG_CACHE_HOME=/run
export XDG_CACHE_HOME


rworkman 05-05-2017 09:37 AM

Quote:

Originally Posted by allend (Post 5706554)
This is working for me to stop the creation of /.cache directory.
Code:

bash-4.4$ diff ./a/rc.networkmanager ./b/rc.networkmanager
36c36
<  $NETWORKMANAGER_BIN
---
>  XDG_CACHE_HOME=/root/.cache $NETWORKMANAGER_BIN

From https://standards.freedesktop.org/ba...ec-latest.html

Crap, I just saw this. Yes, this is a nice workaround and essentially what I reposted.

burdi01 05-05-2017 11:08 AM

Quote:

Originally Posted by allend
This is working for me to stop the creation of /.cache directory.
Code:

bash-4.4$ diff ./a/rc.networkmanager ./b/rc.networkmanager
36c36
<  $NETWORKMANAGER_BIN
---
>  XDG_CACHE_HOME=/root/.cache $NETWORKMANAGER_BIN

Crap, I just saw this. Yes, this is a nice workaround and essentially what I reposted.
Confirmed to resolve (work around?) the issue for me too.
:D :D :D

allend 05-25-2017 11:24 AM

Grr - This issue is back in -current with the latest NetworkManager-1.8.0 which silently overwrote my existing /etc/rc.d/rc.networkmanager on upgrade.

rworkman 05-25-2017 01:10 PM

Quote:

Originally Posted by allend (Post 5715080)
Grr - This issue is back in -current with the latest NetworkManager-1.8.0 which silently overwrote my existing /etc/rc.d/rc.networkmanager on upgrade.

I don't see how it overwrote your rc.networkmanager :/

allend 05-26-2017 03:25 AM

The problem is in this function of the doinst.sh
Code:

preserve_perms() {
  NEW="$1"
  OLD="$(dirname ${NEW})/$(basename ${NEW} .new)"
  if [ -e ${OLD} ]; then
    cp -a ${OLD} ${NEW}.incoming
    cat ${NEW} > ${NEW}.incoming
    mv ${NEW}.incoming ${NEW}
  fi
  mv ${NEW} ${OLD}
}

The old file is copied, then immediately overwritten.
Perhaps
Code:

cp -a ${OLD} ${OLD}.orig

GazL 05-26-2017 03:35 PM

preserve_perms() usually has a config $NEW rather than a mv $NEW $OLD where files are to be treated as config files and left for the user to manage. It would probably be more in keeping with the slackware way of doing things to do that than creating a *.orig in this case.

USUARIONUEVO 05-26-2017 09:04 PM

The .cache folder is using by some apps or services.

In my $HOME/.cache i have some folders like gstreamer-1.0 , obexd , google-crome , and others.

Is not an error ,some apps, want this ,if no exists "create a new one".

Thats all.

Didier Spaier 05-26-2017 09:16 PM

Quote:

Originally Posted by USUARIONUEVO (Post 5715738)
The .cache folder is using by some apps or services.

In my $HOME/.cache i have some folders like gstreamer-1.0 , obexd , google-crome , and others.

Is not an error ,some apps, want this ,if no exists "create a new one".

Thats all.

This thread is about /.cache, not ~/.cache as reminded by the OP is post #10

PS The XDG Base Directory Specification states:
Quote:

$XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored. If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used.
But no user should have / as $HOME

Didier Spaier 05-26-2017 09:52 PM

@burdi01:from the ChangeLog for Slackware-Current:
Code:

Fri May 26 22:40:13 UTC 2017
<snip>
  rc.networkmanager: Set XDG_CACHE_HOME=/root/.cache before starting.
  Thanks to allend.

Thus I assume that this thread could be marked as [SOLVED]

PS This complies to the XDG Base Specification as reminded by my previous post. Sounds logical as our friend LP is both NM's author and a co-author of the spec :D(1)

PPS I just checked: when /etc/rc/d.rc.M starts rc.networkmanager, $HOME is set to "/". I have no idea on why nor what sets it, but that sounds weird as POSIX states:
Code:

HOME
    The system shall initialize this variable at the time of login to be a pathname of the user's home directory. See <pwd.h>.

But as nobody is logged in when rc.M starts rc.networkmanager, why is HOME already set?

Anyway as rc.M runs on behalf of root, setting XDG_CACHE_HOME as /root/.cache in rc.networkmanager is indeed the right thing to do.

EDIT (1) No LP is not author of NM, sorry for this mistake. As we say here on ne prête qu'aux riches.

burdi01 05-27-2017 04:26 AM

I still cannot help feeling that this solution is working around the problem rather that resolving the cause.
Anyway, marking this thread as solved.
Thks everyone.
:D

Edit: Hmm, when reading back this post I notice that it sounds more negative than I meant it to be.

GazL 05-27-2017 04:32 AM

Quote:

Originally Posted by burdi01 (Post 5715828)
I still cannot help feeling that this solution is working around the problem rather that resolving the cause.
Anyway, marking this thread as solved.
Thks everyone.
:D

Edit: Hmm, when reading back this post I notice that it sounds more negative than I meant it to be.

Yes, it does feel kind of ugly, but then, that's NetworkManager for you.

Didier Spaier 05-27-2017 04:48 AM

Quote:

Originally Posted by GazL (Post 5715830)
Yes, it does feel kind of ugly, but then, that's NetworkManager for you.

Well NM just does what's written in the aforementioned spec. How is that wrong or ugly?

The alternative would be that if HOME is set to / NM sets it to /root. I wouldn't like that at all, as it would be too much intrusive: it's simply not NM's job to set HOME. Doing that in the startup script instead is way better, as the admin can easily change this setting if so inclined.

Didier Spaier 05-27-2017 05:11 AM

Previous content deleted: I mistakenly quoted my post #41 instead of editing it, sorry.

GazL 05-27-2017 05:14 AM

XDG is a user centric desktop spec. NM is clearly designed to be a component of a desktop but it's being run here in the role of a system-wide network interface management daemon. XDG should have no role in the operation of system daemons, in the UI control applets run by their users certainly, but not the backend daemons themselves.

It's much the same issue as pulseaudio, which also fails to respect the separation between user desktop component and system-daemon. IMO it's just architecturally flawed design and a very non UNIXish way of going about things.

If a daemon needs to store state, cache files etc, then there are locations in the /var hierarchy designed to cater to that need.

chris.willing 05-27-2017 05:25 AM

Quote:

Originally Posted by Didier Spaier (Post 5715748)
...
PPS I just checked: when /etc/rc/d.rc.M starts rc.networkmanager, $HOME is set to "/". I have no idea on why nor what sets it, but that sounds weird as POSIX states:
Code:

HOME
    The system shall initialize this variable at the time of login to be a pathname of the user's home directory. See <pwd.h>.

But as nobody is logged in when rc.M starts rc.networkmanager, why is HOME already set?
...

I think the twist is that at this point (while running boot scripts) root hasn't actually logged in - at least not in the way that anyone logs in as root once the system is up & running. Therefore that instance of root that's running the boot scripts hasn't (I presume) sourced /etc/profile etc., to obtain a normal environment. In this case, it's sort of understandable that root's "home" is /. What should it be without having been allocated a home directory elsewhere? At least / is guaranteed to be there.

Consider also the case of an ordinary user whose allocated home directory is not available at login time for some reason (unavailable nfs mounted home directory springs to mind); in that case the use is logged into /. To my mind, this is just like root at boot time with no home directory set.

chris

Didier Spaier 05-27-2017 06:12 AM

Just wondering what would happen in case HOME be not set at all then. Maybe I'll unset it early in the startup sequence just to see what happens. In a VM, not to break my real systems.

gmgf 05-27-2017 07:49 AM

Just, for info, i have one other install of slack-current on other partition, with openrc, doesn't /.cache appears, it seem the networkmanager service in open rc service start with timeout, But I do not know if this is the problem.

burdi01 05-27-2017 08:42 AM

As the discussion in this thread shows, NetworkManager (NM for short) expects XDG_CACHE_HOME to be set. As NM is started at boot (in rc.M) this implies that it expects this "user" setting to be set when no user is logged in yet.
For as far as I am aware NM is developed and tested on the systemd side of the house. Maybe systemd sets those "user" settings at boot, reasoning that as root is the owner of the system he is the implicit user at boot. If that is the case chances are that more applications will now or in the future tacitly assume the "user" settings to be set at boot.
To prevent future "surprises" it might be cautious to set those XDG "user" settings and/or e.g. $HOME as for root at boot (in rc.M or even in rc.S).

I know I am "cursing in the church", please do not shoot me.
:D


All times are GMT -5. The time now is 01:03 AM.