Use of the information contained in this unapproved document is at your own risk
.Last update: 10 April,2001
1003.1-90 #79
_____________________________________________________________________________
Interpretation Number: XXXX
Topic: unlink
Relevant Sections: 5.5.1
Interpretation Request: (Defect Report)
-----------------------
Date: Dec 3 1996
I wish to request an interpretation of section 5.5.1 of the IEEE Std
1003.1-1990, Information technology--Portable Operating system
Interface (POSIX), Part 1: System Application Program Interface (API)
[C Language].
Section 5.5.1 documents the unlink function. I would like to get
IEEE's interpretation of the compliance of Vendor XXX
implementation of the unlink function on the YYY operating
system. In particular, the unlink function fails to remove the last
directory entry for a file if that file is an executable that some
process is running.
The following two small C programs can be used to demonstrate the
unlink failure on YYY O/S.
This first program should be compiled and run with an argument which
specifies the length of time this program should sleep.
/* Running executable (sleeping). */
/* Run with an integer argument to specify sleep time. */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int seconds = 0;
if ( argc != 2 ) {
fprintf(stderr, "Supply an integer for the sleep argument.\n");
exit(EXIT_FAILURE);
}
seconds = atoi(argv[1]);
if ( !seconds ) {
fprintf(stderr, "Supply an integer for the sleep argument.\n");
exit(EXIT_FAILURE);
}
sleep(seconds);
exit(EXIT_SUCCESS);
}
This second program will attempt to unlink the running executable
which was generated from the previous code. This program needs an
argument which specifies the name of the file which is to be unlinked.
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
if ( argc != 2 ) {
fprintf(stderr, "Supply a filename for the unlink argument.\n");
exit(EXIT_FAILURE);
}
if ( unlink(argv[1]) ) {
fprintf(stderr, "Error unlinking %s\n", argv[1]);
perror(NULL);
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
Local testing has shown that the second program will fail to unlink
the running executable on YYY O/S systems. The unlink succeeds on all
other UNIX systems that I have tested.
Interpretation response
------------------------
The implementation is conforming if the errno returned in this
case is EBUSY or another error not listed in 5.5.1.4, and the
behavior is described in the conformance documentation.
Rationale
-------------
Clause 2.4 allows any function to fail for "additional errors." The
error number generated can be the same as one of those listed if
the corrective action taken by the application is identical to the
condition described in the standard. Since there is nothing a
conforming application can do for an EBUSY error from unlink(),
it is acceptable to return this error when the file itself is busy
instead of the directory.
Forwarded to Interpretations group: Dec 3 1996
Proposed resolution: Feb 23 1997
Finalised: April 17th 1997