tags:

views:

65

answers:

2

I have an application running called AppFS. This application has an ext2 filesystem just attached to the end of the file (it's positioned so that the application binary exists in a 1MB spacing area, followed by the ext2 data).

Now I've got FUSE embedded in the program and I've managed to extract the filesystem out of the application data into a temporary file so that FUSE can mount / use it.

The problem I have now is writing the temporary file back into the application file. I get "Text file busy" presumably because the application has locked itself and won't let writes occur.

Is there a way I can force the file to become unlocked so I can write data to it? (It's important to note that I'm not changing the application binary area - just rewriting the ext2 component.) It needs to be unlocked without requiring root permissions (unlocked by the same user who started the application).

A: 

What I would do:

  1. Launch AppFS
  2. Extract only the executable part into a file (without the FS)
  3. Run the extracted executable giving as parameter the original executable (with FS attached)
  4. Modify the original executable from the extracted program (no problems - the executable is no longer running)
  5. Self delete the extracted program when exiting

What you need to do:

  1. Modify the AppFS application to make it do steps 2, 3, 4 and 5 from the previous enumeration.

I don't see any other way for doing this. This architecture resembles the architecture of a SFX.

Iulian Şerbănoiu
Actually the AppFS application runs a FUSE filesystem, so it can't be stopped. Nevertheless I have solved my own problem and will attach the solution below/above.
Hach-Que
+1  A: 

The solution to this problem was to rename the existing application name (to a location within a temporary directory) and to then move the new (generated) file back in it's place and apply the same umask / uid / gid that the old one had. Once it's moved, you can safely just unlink the running executable.

It's a bit of a hacky workaround (I especially don't like the fact that the application is entirely removed and replaced), but it works.

Hach-Que