diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-03-01 17:53:33 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-03-01 17:53:33 +0100 |
commit | 4a03b065cfd269d8f94b5924bf89131492475c9d (patch) | |
tree | 798853f08a804055a28c83550f65db1dc709a6e6 | |
parent | cdacf03ededf8c6f18df9ec11067e6c116801594 (diff) | |
download | taler-mdb-4a03b065cfd269d8f94b5924bf89131492475c9d.tar.gz taler-mdb-4a03b065cfd269d8f94b5924bf89131492475c9d.tar.bz2 taler-mdb-4a03b065cfd269d8f94b5924bf89131492475c9d.zip |
misc bugfixes in error handling
-rw-r--r-- | src/main.c | 76 |
1 files changed, 54 insertions, 22 deletions
@@ -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"); |