https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89020
--- Comment #9 from Steve Kargl <sgk at troutmask dot apl.washington.edu> --- On Sat, Jan 26, 2019 at 03:49:48AM +0000, jvdelisle at gcc dot gnu.org wrote: > --- Comment #8 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> --- > OK yes we are not doing anything with the return values of the calls to > 'remove'. > > The error machinery of generate_error takes care of actually assigning the > values to iostat or iomsg. I suggest the following patch. > > diff --git a/libgfortran/io/close.c b/libgfortran/io/close.c > index cbcbf4e71a1..c5167bcbbc7 100644 > --- a/libgfortran/io/close.c > +++ b/libgfortran/io/close.c > @@ -99,7 +99,11 @@ st_close (st_parameter_close *clp) > else > { > #if HAVE_UNLINK_OPEN_FILE > - remove (u->filename); > + > + if (remove (u->filename)) > + generate_error (&clp->common, LIBERROR_OS, > + "File can not be deleted, possibly in use by" > + " another process"); > #else > path = strdup (u->filename); > #endif > @@ -112,7 +116,10 @@ st_close (st_parameter_close *clp) > #if !HAVE_UNLINK_OPEN_FILE > if (path != NULL) > { > - remove (path); > + if (remove (u->filename)) > + generate_error (&clp->common, LIBERROR_OS, > + "File can not be deleted, possibly in use by" > + " another process"); > free (path); > } > #endif > > I have not dreamt up a way to test this in a test case. I suppose I could > recreate the virtualbox environment Luke found this in. Reardless we should at > a minimum try to check for an OS error here. There are many possibilities so > I > think the generic LIBERROR_OS we already have is sufficient. (The iostat code > will be 5000) > Thanks for taking a look at the problem! Learned something new today with the setting of iostat and iomsg via generate_error. The patch looks good to me. As for a test, I think that that might be difficult to dream up. The code already checked if one has permission to manipulate the file, so creating a file and using chmod probably won't work. The failure seems to be a possible race condition from virtualbox's pseudo-filesystem.