Editing files in place
Reading the rsync(1) manpages, the option --inplace documentation alerts of:
In-use binaries cannot be updated (either the OS will prevent this from happening, or binaries that attempt to swap-in their data will misbehave or crash).
Some time ago I tried to write a program which would modify it's own binary to save data (without a specific motivation), but it resulted in errors when modifing it's binary while in use, also, it's possible (in POSIX systems) to delete files used in that moment. The read of the option above showed a viable path to do this, so here is the program which modifies it's own binary to save a number, it does this by loading the file in memory, unlinking it and creating a new one... probably the memory address location could be done in a more sofisticated manner, but it's only a test program.
May give a warning at compile-time, memmem doesn't get away well with volatile values, but this property is needed to make sure that structure is not optimized out.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Now... the problem is to find a use case for this :P