Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 7 Jul 1996 13:19:42 +0200 (MESZ)
From:      "Hr.Ladavac" <lada@ws2301.gud.siemens.co.at>
To:        tst@titan.cs.mci.com (Thomas S. Traylor)
Cc:        questions@freebsd.org
Subject:   Re: How do you write to an executable (binary)?
Message-ID:  <199607071119.AA080148382@ws2301.gud.siemens.co.at>
In-Reply-To: <Pine.OSF.3.91.960705112043.18146B-100000@titan.cs.mci.com> from "Thomas S. Traylor" at Jul 6, 96 08:46:46 am

next in thread | previous in thread | raw e-mail | index | archive | help
In his e-mail Thomas S. Traylor wrote:
> Here's what I'm trying to do:
> 
> I have a program that will prompt the user for a value.  I would like to 
> write that value to the executable (binary) file.  (Using open, lseek, 
> write, close)
> 
> Problem:
> 
> When I open the file I get the following error:
> 
> "Error: Text file busy".  The message number is [ETXTBSY].
> 
> I'm able to do this with other OS.  How can I get this to work with 
> FreeBSD? Any ideas or suggestions would be greatly appreciated.

AFAIK, you cannot change the executable image from under itself (nor
while file is in use--being executed).

What you can do is:

	1) copy executable to executable.new
	2) edit executable.new to your heart's content (it is not in use :)
	3) move executable.new to executable.

Beware: all processes that started executing the executable prior to point
3) will not see the changes in the image (namely, they will still be using
or having access to the *old* executable, which is basically marked deleted
but referenced/in use and remains on disk until it is no longer referenced).

/Marino




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199607071119.AA080148382>