diff --git a/src/io.c b/src/io.c
index e9676dd4bdde2848ccd6c71066921b1d743cfc4b..72788457bce5818948a2eadb921d1fa9f06bc75c 100644
--- a/src/io.c
+++ b/src/io.c
@@ -710,9 +710,9 @@ struct io_fd *io_write(struct io_backend *b,
 /* Marks a file for closing, at the end of the current iteration.
  * FIXME: Could be generalized for other fd:s than read-write fds. */
 
-void close_fd(struct lsh_fd *fd)
+void close_fd(struct lsh_fd *fd, int reason)
 {
   debug("Marking fd %d for closing.\n", fd->fd);
-  
+  fd->close_reason = reason;
   fd->close_now = 1;
 }
diff --git a/src/io.h b/src/io.h
index 5d19f0653b5de69e1c16b8eab02f129c6b206273..e7dabf91a23afc0b9af15f5f04a35f033661c409 100644
--- a/src/io.h
+++ b/src/io.h
@@ -187,6 +187,7 @@ struct io_fd *io_write(struct io_backend *b,
 		       UINT32 block_size,
 		       struct close_callback *close_callback);
 
-void close_fd(struct lsh_fd *fd);
+void close_fd(struct lsh_fd *fd, int reason);
+
 
 #endif /* LSH_IO_H_INCLUDED */