0

To run some tests, I want to revoke write permissions for a folder. This is a minimal example:

$ mkdir test
$ chmod a-w test
$ touch test/test || printf '%s\n' "write permissions successfully revoked"
touch: cannot touch 'test/test': Permission denied
write permissions successfully revoked

However, if I run it with fakeroot, this doesn't work:

$ fakeroot sh  
# mkdir test
# chmod a-w test
# touch test/test || printf '%s\n' "write permissions successfully revoked"
# ls test
test

For an explanation why this doesn't work, see this question, for example: Issue with changing permissions

However, my question is: how can I get around this? Can I temporarily disable fakeroot for the chmod command? Or can I make fakeroot permission changes permanent anyway?

finefoot
  • 2,940
  • 2
  • 21
  • 41

1 Answers1

3

fakeroot is using a LD_PRELOAD hack to load a small shared library which overrides some library functions like chmod(2), chown(2), etc. See the ld.so(8) manpage for details (there are also a lot of examples on this site).

Just run a command with the LD_PRELOAD environment variable unset or set to an empty string, and that library will not be loaded:

$ fakeroot sh
$ chown root:root fo.c
$ LD_PRELOAD= chown root:root fo.c
chown: changing ownership of 'fo.c': Operation not permitted