1.1 --- a/libfsserver/lib/files/ext2_file_opener.cc Sat Aug 07 22:55:39 2021 +0200
1.2 +++ b/libfsserver/lib/files/ext2_file_opener.cc Sat Aug 07 23:19:20 2021 +0200
1.3 @@ -81,7 +81,7 @@
1.4 {
1.5 /* Subscribe to space and closure notifications on the pipe. */
1.6
1.7 - long err = client_set_blocking(writer, NOTIFY_SPACE_AVAILABLE);
1.8 + long err = client_set_blocking(writer, NOTIFY_SPACE_AVAILABLE | NOTIFY_PEER_CLOSED);
1.9
1.10 if (err)
1.11 {
1.12 @@ -135,16 +135,20 @@
1.13 *size = reader->size;
1.14 *cap = reader->ref;
1.15
1.16 - /* Discard the reader structure but do not close the reader itself. */
1.17 -
1.18 - delete reader;
1.19 -
1.20 /* Spawn a independent thread for reading the directory details and writing
1.21 them to the pipe. */
1.22
1.23 std::thread(_read_directory, this, fileid, writer).detach();
1.24
1.25 - return L4_EOK;
1.26 + /* Discard the reader structure but preserve the capability. */
1.27 +
1.28 + reader->ref = L4_INVALID_CAP;
1.29 + file_close(reader);
1.30 +
1.31 + /* Return an indication that the capability will be propagated and not
1.32 + retained. This is explicitly supported by the opener context. */
1.33 +
1.34 + return IPC_MESSAGE_SENT;
1.35 }
1.36
1.37 /* Thread payload helper method. */
1.38 @@ -195,10 +199,12 @@
1.39
1.40 /* Write the structure to the pipe. */
1.41
1.42 - offset_t nwritten = 0;
1.43 + offset_t nwritten = client_write(dir->writer, (const void *) dirent, reclen);
1.44
1.45 - while (nwritten < reclen)
1.46 - nwritten += client_write(dir->writer, (const void *) (dirent + nwritten), reclen - nwritten);
1.47 + /* Stop writing if the pipe is closed. */
1.48 +
1.49 + if (nwritten < reclen)
1.50 + return DIRENT_ABORT;
1.51
1.52 return 0;
1.53 }