Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 22125 - ccache directory created with wrong permissions when userpriv set
Summary: ccache directory created with wrong permissions when userpriv set
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Unclassified (show other bugs)
Hardware: All Linux
: High major (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2003-06-02 18:07 UTC by Paul Duran
Modified: 2011-10-30 22:20 UTC (History)
7 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Duran 2003-06-02 18:07:35 UTC
When FEATURES includes ccache and userpriv, a ccache directory is created in
/var/tmp/ccache however all of the subdirectories are owned by root, instead of
portage.

This means that when compiling, nothing gets written to the ccache directory
because of insufficient permissions.

The fix I did was to chown -R portage:portage /var/tmp/ccache


Reproducible: Always
Steps to Reproduce:
1. install ccache
2. make sure in /etc/make.conf, FEATURES includes ccache and userpriv (and that
CCACHE_SIZE is set)
3. emerge something

Actual Results:  
/var/tmp/ccache directory is created
subdirectories are all owned by root instead of portage resulting in no
permission to write to the directory

Expected Results:  
portage should chown -R portage:portage /var/run/ccache if running with userpriv
.. or else it should run the ccache command as user portage instead of user root.

my actual features line is:
FEATURES="sandbox userpriv ccache distcc usersandbox"
and CCACHE_SIZE="1G"
Comment 1 Haroon Rafique 2003-06-09 13:00:26 UTC
I have the same experience. A "chown -R portage:portage /var/tmp/ccache" makes the ccache useable again.

Browsing through the sources for portage, I saw this piece of code (Disclaimer: I don't know python and know little about portage's inner workings) in pym/portage.py:

        try:
            mystat=os.stat(settings["CCACHE_DIR"])
            if (mystat[ST_GID]!=portage_gid) or ((mystat[ST_MODE]&02070)!=02070)
:
                print "*** Adjusting ccache permissions for portage user..."
                os.chown(settings["CCACHE_DIR"],portage_uid,portage_gid)
                os.chmod(settings["CCACHE_DIR"],02770)
                if mystat[ST_GID]!=portage_gid:
                    spawn("chown -R "+str(portage_uid)+":"+str(portage_gid)+" "+
settings["CCACHE_DIR"], free=1)
                    spawn("chmod -R g+rw "+settings["CCACHE_DIR"], free=1)
        except:
            pass

How is the second "if mystat" call ever going to be successful since 2 lines earlier we just did set the gid to portage_gid? Am I missing something obvious here os is this a bug?
Comment 2 Haroon Rafique 2003-06-09 14:22:43 UTC
carpaski should know since he made the change that added the fix for permissions for ccache. From the changelog at http://cvs.gentoo.org/cgi-bin/viewcvs.cgi/gentoo-src/portage/pym/portage.py#rev1.304

Revision 1.304 / (as text) / (view) - annotate - [select for diffs] , Mon Mar 10 18:20:52 2003 UTC (2 months, 4 weeks ago) by carpaski
Branch: MAIN
Changes since 1.303: +35 -12 lines
Diff to previous 1.303

Permission fix for cvs-src and ccache
Comment 3 Martin Holzer (RETIRED) gentoo-dev 2003-07-29 14:22:39 UTC
closing as fixed
Comment 4 Haroon Rafique 2003-07-31 07:06:25 UTC
I am not the original reporter of this bug so I cant reopen. However, I don't think this bug is fixed. In comment 2, I meant to say that since carpaski wrote the ORIGINAL code, he would know WHY he wrote it the way he did. Please look at the code listing posted in comment 1. The second if statement will never be true, since 2 lines above it, the gid was set to portage_gid. Hence the 2 spawn statements would never be executed.
Comment 5 Michael Imhof (RETIRED) gentoo-dev 2003-08-29 17:02:12 UTC
I can confirm that this bug is NOT fixed...
i had to adjust my perms by hand two minutes ago...
Comment 6 Marius Mauch (RETIRED) gentoo-dev 2004-02-04 20:01:29 UTC
either the chown or chmod call should be outside of the second if block
Comment 7 Haroon Rafique 2004-02-05 06:22:00 UTC
Not trying to be sarcastic here, but it took 8 months to realize that the chmod/chown calls never get executed.
Comment 8 Masatomo Nakano (RETIRED) gentoo-dev 2004-02-11 21:27:12 UTC
Fixed in CVS.
Comment 9 Nick Brown 2004-04-30 04:18:59 UTC
This would appear to still be a problem.
I'm using 2.0.50-r6

I have ccache and userpriv in my options. I am using the defaults for everything else, so /var/tmp/ccache is being used for the cache.
However "CCACHE_DIR=/var/tmp/ccache ccache -s" reveal that there are no files in the cache.
I am seeing "adjusting ccache permissions for portage user..." message, but the cache directories all seem to be owned by root rather than portage (though the group is correct). If I delete /var/tmp/ccache it is recreated but still with wrong ownership, and thus appears to not be used.
If I manually change the ownership to portage it all works fine.

I think the code in usr/lib/portage/pym/portage.py to adjust the ownership must be wrong.


root@littlebox ccache # pwd
/var/tmp/ccache
root@littlebox ccache # ls -la
total 13
drwxrws---   18 portage  portage       456 Apr 29 19:25 .
drwxrwxrwt    6 root     root          272 Apr 29 21:45 ..
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 0
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 1
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 2
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 3
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 4
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 5
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 6
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 7
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 8
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 9
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 a
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 b
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 c
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 d
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 e
drwxr-sr-x    2 root     portage        72 Apr 29 19:12 f
-rw-r--r--    1 portage  portage        50 Apr 29 19:25 stats
root@littlebox ccache #
Comment 10 Nick Brown 2004-04-30 04:21:13 UTC
#16664, which is marked FIXED incorrectly in my opinion, is really a DUP of this bug report, and should be marked as such.
Comment 11 Martin Rieder 2004-08-30 21:09:16 UTC
I'm using Portage 2.0.50-r10 and had to manually adjust the permissions, too. Why isn't this fixed yet?
Comment 12 Chris Gottbrath 2004-09-03 17:19:29 UTC
Had to change the permissions manually as well. I am using 
sys-apps/portage-2.0.50-r10. 

Comment 13 Gregory P. Smith 2004-09-24 11:35:04 UTC
just used ccache for the first time today.  same problem.  chown -R portage /var/tmp/ccache fixes it.  Alternatively it looks like the subdirs are all root.portage mode 2755.  If there were mode 2775 it would probably work as well.
Comment 14 Nicholas Jones (RETIRED) gentoo-dev 2004-10-22 08:47:57 UTC
Bug has been fixed and released in stable portages on or before 2.0.51-r2
Comment 15 Jakub Moc (RETIRED) gentoo-dev 2005-03-03 18:08:26 UTC
No, it was not fixed... It simply does not work without manually running "chown -R portage:portage /var/tmp/ccache". Will celebrate two years soon and still alive and kicking. :-/

Just for the record:

Portage 2.0.51.19 (default-linux/x86/2004.3, gcc-3.3.5, glibc-2.3.4.20040808-r1, 2.6.9-gentoo-r13 i686)

FEATURES="autoaddcvs autoconfig ccache collision-protect distlocks makecheck sandbox sfperms userpriv usersandbox" 
Comment 16 Jason Stubbs (RETIRED) gentoo-dev 2005-04-02 22:35:06 UTC
if ("userpriv" in features) and ("ccache" in features):
  if (not mysettings.has_key("CCACHE_DIR")) or (mysettings["CCACHE_DIR"]==""):
    mysettings["CCACHE_DIR"]=mysettings["PORTAGE_TMPDIR"]+"/ccache"
  if not os.path.exists(mysettings["CCACHE_DIR"]):
    os.makedirs(mysettings["CCACHE_DIR"])
  os.chown(mysettings["CCACHE_DIR"],portage_uid,portage_gid)
  os.chmod(mysettings["CCACHE_DIR"],02770)

Looks fixed to me... The only time there could be a problem is if you've used ccache with a buggy portage first and thus have subdirs that don't have the correct permissions.
Comment 17 Jakub Moc (RETIRED) gentoo-dev 2005-04-03 06:03:38 UTC
I get this again on another machine with a fresh new install. So sorry, but it is not fixed. :/
Comment 18 Jason Stubbs (RETIRED) gentoo-dev 2005-04-03 08:34:46 UTC
What is "it" exactly? Comment #9 looks like ccache is being run as root after portage sets up the ccache dir. Is "it" the same as that?
Comment 19 Jakub Moc (RETIRED) gentoo-dev 2005-04-04 02:18:03 UTC
I mean the permission are broken, plain and simple. Everyone can verify it, this is easily reproducible anywhere, so I really don
Comment 20 Jakub Moc (RETIRED) gentoo-dev 2005-04-04 02:18:03 UTC
I mean the permission are broken, plain and simple. Everyone can verify it, this is easily reproducible anywhere, so I really don´t know why is it so hard to fix the error and why the argument still comes that it is fixed. No, it is NOT fixed, FEATURES="userpriv usersandbox" breaks ccache - please try and you will see yourself. Also see 16664, 22125, 33162 properly"
   href="show_bug.cgi?id=84062">Bug 84062. 

The permissions check in portage.py actually always returns false so the other chmod actions are never taken --> broken permissions, ccache not working. See Comment #1 for reason why it fails.