gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-mdb] branch master updated: misc bugfixes in error handling


From: gnunet
Subject: [taler-taler-mdb] branch master updated: misc bugfixes in error handling
Date: Sun, 01 Mar 2020 17:53:35 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository taler-mdb.

The following commit(s) were added to refs/heads/master by this push:
     new 4a03b06  misc bugfixes in error handling
4a03b06 is described below

commit 4a03b065cfd269d8f94b5924bf89131492475c9d
Author: Christian Grothoff <address@hidden>
AuthorDate: Sun Mar 1 17:53:33 2020 +0100

    misc bugfixes in error handling
---
 src/main.c | 76 ++++++++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 54 insertions(+), 22 deletions(-)

diff --git a/src/main.c b/src/main.c
index 953d890..ff46a7e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1056,7 +1056,8 @@ shutdown_task (void *cls)
     rc = NULL;
   }
 
-  if (NULL != qrDisplay.memory)
+  if ( (MAP_FAILED != qrDisplay.memory) &&
+       (NULL != qrDisplay.memory) )
   {
     /* free the display data  */
     munmap (qrDisplay.memory,
@@ -1518,6 +1519,7 @@ proposal_cb (void *cls,
                                           pa);
 }
 
+
 static void
 start_read_cancel_button ();
 
@@ -1821,6 +1823,7 @@ read_keyboard_command (void *cls)
   start_read_keyboard ();
 }
 
+
 /**
  * @brief Read the state of the cancel button GPIO pin
  *
@@ -1916,6 +1919,7 @@ start_read_keyboard ()
                                                   NULL);
 }
 
+
 /**
  * @brief Wait for cancel button during payment activity
  */
@@ -1932,6 +1936,7 @@ start_read_cancel_button ()
     NULL);
 }
 
+
 /**
  * @brief Send data to the vmc via the uart bus
  *
@@ -2141,7 +2146,8 @@ handle_command (const char *hex,
           /* Calculate the checksum and check it */
           chkSum = cmd;
 
-          for ( size_t offset = 1; offset < ((hex_len / 2)); offset++ ) {
+          for (size_t offset = 1; offset < ((hex_len / 2)); offset++)
+          {
             chkSum += tmp;
             if (1 != sscanf (hex + (2 * offset),
                              "%2X",
@@ -2155,7 +2161,7 @@ handle_command (const char *hex,
               return;
             }
           }
-          if ( ((uint8_t) (chkSum & 0xFF)) != tmp )
+          if ( ((uint8_t) (chkSum & 0xFF)) != tmp)
           {
             mdb.cmd = &cmd_reader_display_internal_error;
             GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -2935,6 +2941,7 @@ run (void *cls,
     global_ret = EXIT_FAILURE;
     return;
   }
+
   /* parse the products */
   GNUNET_CONFIGURATION_iterate_sections (cfg,
                                          &read_products,
@@ -2974,33 +2981,58 @@ run (void *cls,
                  GNUNET_CURL_append_header (ctx,
                                             authorization));
 
-  /* open gpio pin for cance button */
-  cancel_button.cancelbuttonfd = open ("/sys/class/gpio/export",
-                                       O_WRONLY);
-  if (0 > cancel_button.cancelbuttonfd)
+  /* open gpio pin for cancel button */
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Unable to open /gpio/export for cancel button\n");
+    int efd;
+
+    efd = open ("/sys/class/gpio/export",
+                O_WRONLY);
+    if (-1 == efd)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Unable to open /gpio/export for cancel button\n");
+      global_ret = EXIT_FAILURE;
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+    if (2 != write (efd, "23", 2))
+      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+                                "write",
+                                "/sys/class/gpio/export");
+    GNUNET_assert (0 == close (efd));
   }
-  (void) ! write (cancel_button.cancelbuttonfd, "23", 2);
-  close (cancel_button.cancelbuttonfd);
 
-  cancel_button.cancelbuttonfd = open ("/sys/class/gpio/gpio23/direction",
-                                       O_WRONLY);
-  if (0 > cancel_button.cancelbuttonfd)
+  /* set direction: input */
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Unable to open /gpio/gpio23/direction for cancel button\n");
+    int dfd;
+
+    dfd = open ("/sys/class/gpio/gpio23/direction",
+                O_WRONLY);
+    if (-1 == dfd)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Unable to open /gpio/gpio23/direction for cancel button\n");
+      global_ret = EXIT_FAILURE;
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+    if (2 != write (dfd, "in", 2))
+      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+                                "write",
+                                "/sys/class/gpio/gpio23/direction");
+    GNUNET_assert (0 == close (dfd));
   }
-  (void) ! write (cancel_button.cancelbuttonfd, "in", 2);
-  close (cancel_button.cancelbuttonfd);
 
+  /* actually open fd for reading the state */
   cancel_button.cancelbuttonfd = open ("/sys/class/gpio/gpio23/value",
                                        O_RDONLY);
-  if (0 > cancel_button.cancelbuttonfd)
+  if (-1 == cancel_button.cancelbuttonfd)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Unable to open /gpio/gpio23/value for cancel button\n");
+    global_ret = EXIT_FAILURE;
+    GNUNET_SCHEDULER_shutdown ();
+    return;
   }
 
 
@@ -3008,7 +3040,7 @@ run (void *cls,
   /* open the framebuffer device */
   qrDisplay.devicefd = open (framebuffer_device_filename,
                              O_RDWR);
-  if (0 < qrDisplay.devicefd)
+  if (-1 != qrDisplay.devicefd)
   {
     /* read information about the screen */
     ioctl (qrDisplay.devicefd,
@@ -3048,7 +3080,7 @@ run (void *cls,
                               PROT_READ | PROT_WRITE, MAP_SHARED,
                               qrDisplay.devicefd,
                               0);
-    if (0 > qrDisplay.memory)
+    if (MAP_FAILED == qrDisplay.memory)
     {
       GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
                            "mmap");

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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