From owner-freebsd-questions Mon Jul 8 16:05:56 1996 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id QAA16300 for questions-outgoing; Mon, 8 Jul 1996 16:05:56 -0700 (PDT) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id QAA16289 for ; Mon, 8 Jul 1996 16:05:53 -0700 (PDT) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id QAA22815; Mon, 8 Jul 1996 16:00:52 -0700 From: Terry Lambert Message-Id: <199607082300.QAA22815@phaeton.artisoft.com> Subject: Re: How do you write to an executable (binary)? To: bmc@telebase.com Date: Mon, 8 Jul 1996 16:00:52 -0700 (MST) Cc: tst@titan.cs.mci.com, freebsd-questions@freebsd.org In-Reply-To: <199607061732.NAA01056@current.willscreek.com> from "Brian M. Clapper" at Jul 6, 96 01:32:54 pm X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > 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.