Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Jul 1996 16:00:52 -0700 (MST)
From:      Terry Lambert <terry@lambert.org>
To:        bmc@telebase.com
Cc:        tst@titan.cs.mci.com, freebsd-questions@freebsd.org
Subject:   Re: How do you write to an executable (binary)?
Message-ID:  <199607082300.QAA22815@phaeton.artisoft.com>
In-Reply-To: <199607061732.NAA01056@current.willscreek.com> from "Brian M. Clapper" at Jul 6, 96 01:32:54 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> Thomas> Here's what I'm trying to do:
> 
> Thomas> I have a program that will prompt the user for a value.  I would
> Thomas> like to write that value to the executable (binary) file.  (Using
> Thomas> open, lseek, write, close)
> 
> Thomas> Problem:
> 
> Thomas> When I open the file I get the following error:
> 
> Thomas> "Error: Text file busy".  The message number is [ETXTBSY].
> 
> Thomas> I'm able to do this with other OS.  How can I get this to work with
> Thomas> FreeBSD? Any ideas or suggestions would be greatly appreciated.
> 
> That means the executable is in use--i.e., someone's running it.  If you
> have enough space on the file system, you can eliminate that problem this
> way:
> 
> 1. Copy the executable to a uniquely temporary file in the same directory,
>    and be sure to preserve the ownership and permission settings.
> 2. Update the temporary file with your value.
> 3. Unlink the original.
> 4. Rename the temporary to the original.
> 
> Of course, this whole topic begs the obvious question: Why are you updating
> an executable in this way?

I presume he is attempting to institute some type of licensing or
self-serialization as a means of copy protection through identification
of where a working copy came from.

He will need to use two files.

This is one of the problems with memory overcommit that can be fixed
in the kernel... basically anywhere ETXTBSY is being returned to user
space, someone has been lazy about hiding overcommit.  The program file
is being used as swap-store, in particular, and it is possible to mark
the vnode aliased in the kernel and copy-on-write it to swap, letting
you modify the real executable without returning an ETXTBSY.  Only it
isn't being done.


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.



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