poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/3] Handle and report errors while closing IO spaces.


From: Egeyar Bagcioglu
Subject: [PATCH 2/3] Handle and report errors while closing IO spaces.
Date: Wed, 24 Feb 2021 23:03:33 +0100

2020-02-24  Egeyar Bagcioglu  <egeyar@gmail.com>

        * libpoke/ios-dev-file.c (ios_dev_file_close): Handle errors properly.
        Return IOD_ERROR on failure, IOD_OK otherwise.
        * libpoke/ios-dev-mem.c (ios_dev_mem_close): Return IOD_OK.
        * libpoke/ios-dev-nbd.c (ios_dev_nbd_close): Likewise.
        * libpoke/ios-dev-stream.c (ios_dev_stream_close): Likewise.
        * libpoke/ios-dev.h (close): Return IOD_ERROR on failure, IOD_OK on
        success.
        * libpoke/ios.c (ios_close): Return IOS_OK on success and the error 
code on
        failure. Do not assert that dev_if->close is successful.
        * libpoke/ios.h (ios_close): Likewise.
        * libpoke/pvm.jitter (close): Raise PVM_E_NO_IOS if the IO space to be
        closed does not exist. Raise PVM_E_IO if ios_close fails.
---
 ChangeLog                | 18 +++++++++++++++++-
 libpoke/ios-dev-file.c   | 19 +++++++++++++------
 libpoke/ios-dev-mem.c    |  2 +-
 libpoke/ios-dev-nbd.c    |  2 +-
 libpoke/ios-dev-stream.c |  6 +++++-
 libpoke/ios-dev.h        |  4 ++--
 libpoke/ios.c            | 14 +++++++-------
 libpoke/ios.h            |  5 +++--
 libpoke/pvm.jitter       |  8 +++++---
 9 files changed, 54 insertions(+), 24 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ea3091c4..3dc56889 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2021-02-24  Egeyar Bagcioglu  <egeyar@gmail.com>
+
+       * libpoke/ios-dev-file.c (ios_dev_file_close): Handle errors properly.
+       Return IOD_ERROR on failure, IOD_OK otherwise.
+       * libpoke/ios-dev-mem.c (ios_dev_mem_close): Return IOD_OK.
+       * libpoke/ios-dev-nbd.c (ios_dev_nbd_close): Likewise.
+       * libpoke/ios-dev-stream.c (ios_dev_stream_close): Likewise.
+       * libpoke/ios-dev.h (close): Return IOD_ERROR on failure, IOD_OK on
+       success.
+       * libpoke/ios.c (ios_close): Return IOS_OK on success and the error 
code on
+       failure. Do not assert that dev_if->close is successful.
+       * libpoke/ios.h (ios_close): Likewise.
+       * libpoke/pvm.jitter (close): Raise PVM_E_NO_IOS if the IO space to be
+       closed does not exist. Raise PVM_E_IO if ios_close fails.
+
 2021-02-24  Egeyar Bagcioglu  <egeyar@gmail.com>
 
        * libpoke/ios-dev-file.c (ios_dev_file_handler_normalize): Take error
@@ -13,7 +28,8 @@
        * libpoke/ios-dev.h (handler_normalize): Likewise.
        (open): Likewise.
        (IOS_FILE_HANDLER_NORMALIZE): Rename newhandler as new_handler.
-       * ios.c (ios_open): Adjust calls to handler_normalize and open.
+       * libpoke/ios.c (ios_open): Adjust calls to handler_normalize and
+       open.
 
 2021-02-24  Egeyar  Bagcioglu  <egeyar@gmail.com>
 
diff --git a/libpoke/ios-dev-file.c b/libpoke/ios-dev-file.c
index 5584ed37..e6e7c264 100644
--- a/libpoke/ios-dev-file.c
+++ b/libpoke/ios-dev-file.c
@@ -150,12 +150,19 @@ ios_dev_file_close (void *iod)
 {
   struct ios_dev_file *fio = iod;
 
-  if (fclose (fio->file) != 0)
-    perror (fio->filename);
-  free (fio->filename);
-  free (fio);
-
-  return 1;
+  if (fclose (fio->file) == 0)
+    {
+      free (fio->filename);
+      free (fio);
+      return IOD_OK;
+    }
+  else
+    {
+      perror (fio->filename);
+      free (fio->filename);
+      free (fio);
+      return IOD_ERROR;
+    }
 }
 
 static uint64_t
diff --git a/libpoke/ios-dev-mem.c b/libpoke/ios-dev-mem.c
index 9d853bda..8b8c9006 100644
--- a/libpoke/ios-dev-mem.c
+++ b/libpoke/ios-dev-mem.c
@@ -96,7 +96,7 @@ ios_dev_mem_close (void *iod)
   free (mio->pointer);
   free (mio);
 
-  return 1;
+  return IOD_OK;
 }
 
 static uint64_t
diff --git a/libpoke/ios-dev-nbd.c b/libpoke/ios-dev-nbd.c
index 2ff65c39..692465ba 100644
--- a/libpoke/ios-dev-nbd.c
+++ b/libpoke/ios-dev-nbd.c
@@ -149,7 +149,7 @@ ios_dev_nbd_close (void *iod)
   free (nio->uri);
   free (nio);
 
-  return 1;
+  return IOD_OK;
 }
 
 static uint64_t
diff --git a/libpoke/ios-dev-stream.c b/libpoke/ios-dev-stream.c
index 5184c388..1d658611 100644
--- a/libpoke/ios-dev-stream.c
+++ b/libpoke/ios-dev-stream.c
@@ -134,11 +134,15 @@ ios_dev_stream_close (void *iod)
 {
   struct ios_dev_stream *sio = iod;
 
+  /* Do not close std IO files.
+     The user may be in interactive mode.  */
+
   if (sio->flags & IOS_F_READ)
     ios_buffer_free (sio->buffer);
+  free (sio->handler);
   free (sio);
 
-  return 1;
+  return IOD_OK;
 }
 
 static uint64_t
diff --git a/libpoke/ios-dev.h b/libpoke/ios-dev.h
index 4fbbcc1a..3dde4abf 100644
--- a/libpoke/ios-dev.h
+++ b/libpoke/ios-dev.h
@@ -66,8 +66,8 @@ struct ios_dev_if
 
   void * (*open) (const char *handler, uint64_t flags, int *error);
 
-  /* Close the given device.  Return 0 if there was an error during
-     the operation, 1 otherwise.  */
+  /* Close the given device.  Return the error code if there was an error
+     during the operation, IOD_OK otherwise.  */
 
   int (*close) (void *dev);
 
diff --git a/libpoke/ios.c b/libpoke/ios.c
index 8db45f5b..75ea05de 100644
--- a/libpoke/ios.c
+++ b/libpoke/ios.c
@@ -186,22 +186,20 @@ ios_open (const char *handler, uint64_t flags, int 
set_cur)
   return error;
 }
 
-void
+int
 ios_close (ios io)
 {
   struct ios *tmp;
-  int r;
+  int ret;
 
   /* XXX: if not saved, ask before closing.  */
 
   /* Close the device operated by the IO space.
-     XXX: handle errors.  */
-  r = io->dev_if->close (io->dev);
-  assert (r);
+     XXX: Errors may be received from fclose.  What do we do in that case?  */
+  ret = io->dev_if->close (io->dev);
 
   /* Unlink the IOS from the list.  */
-  assert (io_list != NULL); /* The list must contain at least one IO
-                               space.  */
+  assert (io_list != NULL); /* The list contains at least this IO space.  */
   if (io_list == io)
     io_list = io_list->next;
   else
@@ -216,6 +214,8 @@ ios_close (ios io)
     cur_io = io_list;
 
   free (io);
+
+  return IOD_ERROR_TO_IOS_ERROR (ret);
 }
 
 uint64_t
diff --git a/libpoke/ios.h b/libpoke/ios.h
index 52c40d9e..8c0365d0 100644
--- a/libpoke/ios.h
+++ b/libpoke/ios.h
@@ -158,9 +158,10 @@ typedef int64_t ios_off;
 int ios_open (const char *handler, uint64_t flags, int set_cur);
 
 /* Close the given IO space, freing all used resources and flushing
-   the space cache associated with the space.  */
+   the space cache associated with the space.  Return IOS_OK on success
+   and the error code on failure.  */
 
-void ios_close (ios io);
+int ios_close (ios io);
 
 /* Return the flags which are active in a given IO.  Note that this
    doesn't necessarily correspond to the flags passed when opening the
diff --git a/libpoke/pvm.jitter b/libpoke/pvm.jitter
index be514464..b0ed8afe 100644
--- a/libpoke/pvm.jitter
+++ b/libpoke/pvm.jitter
@@ -1373,10 +1373,10 @@ end
 # on the stack as a signed integer.
 #
 # If the specified IO space doesn't exist, this instruction raises
-# PVM_E_IO.
+# PVM_E_NO_IOS. If the operation fails, it raises PVM_E_IO.
 #
 # Stack: ( INT -- )
-# Exceptions: PVM_E_IO
+# Exceptions: PVM_E_NO_IOS, PVM_E_IO
 
 instruction close ()
   code
@@ -1384,9 +1384,11 @@ instruction close ()
     ios io = ios_search_by_id (io_id);
 
     if (io == NULL)
+      PVM_RAISE_DFL (PVM_E_NO_IOS);
+
+    if (ios_close (io) != IOS_OK)
       PVM_RAISE_DFL (PVM_E_IO);
 
-    ios_close (io);
     JITTER_DROP_STACK ();
   end
 end
-- 
2.29.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]