Re: Write to executable which has done execve
- From: Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx>
- Date: Sun, 12 Aug 2007 03:37:39 +0200
David Schwartz <davids@xxxxxxxxxxxxx> writes:
On Aug 11, 5:30 pm, Bronson <psh...@xxxxxxxxx> wrote:
i am trying to make a program, which will exec another app and this
app will write to the main's program executable. I make execve
(precisely execlp) and try to open old file for writing in new
process. But I returns me ETXTBSY. Why? For example access says, that
i can write to file, but fopen fails with ETXTBSY...
What can i do with that...
You can't do it that way. You cannot modify a program's running image
by modifying the executable file. If you could, self-modifying code
would not work properly.
That's not exactly the point. The problem is that when you exec a
file, it is not loaded into RAM, at least not entirely. It is memory
mapped, and the file is loaded only on demand, when you call the
functions that are not already loaded. Also, swapping out the the
program text can be avoided since we already have a copy in the
program file.
So if modifying the program file was allowed, it would break randomly
the running processes using this program.
What should be done, is to create a new executable, unlink the old one
and rename the new to the old name, so only new processes get the new
program.
Note that even for normal files you should usually do something like
that, to avoid being left with inconsistent data in the files when the
program is killed for any reason in the middle of file writting.
--
__Pascal Bourguignon__ http://www.informatimago.com/
NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.
.
- Follow-Ups:
- Re: Write to executable which has done execve
- From: Bronson
- Re: Write to executable which has done execve
- References:
- Write to executable which has done execve
- From: Bronson
- Re: Write to executable which has done execve
- From: David Schwartz
- Write to executable which has done execve
- Prev by Date: Re: Write to executable which has done execve
- Next by Date: Re: One last questions about daemons
- Previous by thread: Re: Write to executable which has done execve
- Next by thread: Re: Write to executable which has done execve
- Index(es):
Relevant Pages
|