I have a binary foo
, generated from C++ code, which has special capabilities set on it with:
sudo setcap cap_sys_rawio=ep ./foo
Now I want to build another version of this binary, and the output of the build (the new binary) goes into a file named bar
. Evidently, bar
will not have the same capabilities as foo
. I would like to copy the content of bar
over foo
, so that foo
represents the new binary, but without removing the capabilities.
This answer indicates that modifying the file does not affect the capabilities, but when I try with cp
(which uses open(..., O_TRUNC)
under the covers) the capabilities are removed.