Hello friends of OpenBSD,

I have been porting OpenBSD to MS Windows. If I use BSD vi to edit and save
a file, vi throws an error because the write() system call is failing
(EAGAIN), and leaves me with a truncated file.

Studying the source code reveals that the authors of vi have gone through
to great lengths to prevent just that in case of a system crash but failed
to do the same for the program itself. Apparently, they just assumed vi
will never have write errors.

When editing a file, vi saves multiple copies of the original file, calling
flock() on both the copies and the original. It then proceeds opening the
original file a second time with the O_TRUNC flag. After some editing and
issuing the 'wq' commands, the error occurs.

In my case, this is because in Windows, a process is not allowed to write
to a file which has been locked and opened a second time by the same
process.

But that is not the issue. My question is: shouldn't vi invoke the same
procedure as if there had been a system failure? That is: restoring the
backup copies of the file.

I would even suggest leaving the original file intact (locking it, but not
opening it a second time) until it is time to write(). Vi could then
truncate the temporary file, write the changes to that and just copy it to
the original location. This way, in case of a write error or any other
error, the original is left completely untouched.

What are your thoughts and is this the right mailing list to post this?

Daniel

PS. For people who are interested, here's the home page of my emulator:

https://minc.commandlinerevolution.nl/english/home.html

PS. If I use my own mail server I get this error in my mail log:

Temporary failure. Please try again later.

I assume this is because I use my own mail server, which is greylisted. How
can I resolve this?

Reply via email to