summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2022-01-18 09:15:54 -0500
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2022-01-18 09:15:54 -0500
commitc10b783521cf312a29d78aef103b548a3d20e5e0 (patch)
tree6e44fe6468a306bb7280a19e639e58478443cfa6
parent766a291151e18ff08cfbf7bee0a322588e846cce (diff)
downloadexchange-c10b783521cf312a29d78aef103b548a3d20e5e0.tar.gz
exchange-c10b783521cf312a29d78aef103b548a3d20e5e0.tar.bz2
exchange-c10b783521cf312a29d78aef103b548a3d20e5e0.zip
use 'pipe' instead of 'eventfd' on non-Linux systems
-rw-r--r--src/bank-lib/fakebank.c145
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c1
-rw-r--r--src/include/taler_util.h14
-rw-r--r--src/util/secmod_common.c44
-rw-r--r--src/util/secmod_common.h12
-rw-r--r--src/util/taler-exchange-secmod-eddsa.c1
-rw-r--r--src/util/taler-exchange-secmod-rsa.c1
-rw-r--r--src/util/util.c17
8 files changed, 202 insertions, 33 deletions
diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c
index 2ccc2c751..036fd85a1 100644
--- a/src/bank-lib/fakebank.c
+++ b/src/bank-lib/fakebank.c
@@ -26,7 +26,6 @@
#include "platform.h"
#include <pthread.h>
#include <poll.h>
-#include <sys/eventfd.h>
#include "taler_fakebank_lib.h"
#include "taler_bank_service.h"
#include "taler_mhd_lib.h"
@@ -414,11 +413,25 @@ struct TALER_FAKEBANK_Handle
*/
uint16_t port;
+#ifdef __linux__
/**
* Event FD to signal @a lp_thread a change in
* @a lp_heap.
*/
int lp_event;
+#else
+ /**
+ * Pipe input to signal @a lp_thread a change in
+ * @a lp_heap.
+ */
+ int lp_event_in;
+
+ /**
+ * Pipe output to signal @a lp_thread a change in
+ * @a lp_heap.
+ */
+ int lp_event_out;
+#endif
/**
* Set to true once we are shutting down.
@@ -480,7 +493,11 @@ lp_trigger (struct LongPoller *lp,
MHD_resume_connection (lp->conn);
GNUNET_free (lp);
h->mhd_again = true;
+#ifdef __linux__
if (-1 != h->lp_event)
+#else
+ if (-1 != h->lp_event_in && -1 != h->lp_event_out)
+#endif
{
if (NULL != h->mhd_task)
GNUNET_SCHEDULER_cancel (h->mhd_task);
@@ -541,7 +558,11 @@ lp_expiration_thread (void *cls)
pthread_mutex_unlock (&h->big_lock));
{
struct pollfd p = {
+#ifdef __linux__
.fd = h->lp_event,
+#else
+ .fd = h->lp_event_out,
+#endif
.events = POLLIN
};
int ret;
@@ -561,7 +582,11 @@ lp_expiration_thread (void *cls)
uint64_t ev;
ssize_t iret;
+#ifdef __linux__
iret = read (h->lp_event,
+#else
+ iret = read (h->lp_event_out,
+#endif
&ev,
sizeof (ev));
if (-1 == iret)
@@ -995,7 +1020,7 @@ make_transfer (
if (NULL != t)
{
if ( (debit_acc != t->debit_account) ||
- (credit_acc != t->credit_account) ||
+ (credit_acc != t->credit_account) ||
(0 != TALER_amount_cmp (amount,
&t->amount)) ||
(T_DEBIT != t->type) ||
@@ -1208,7 +1233,11 @@ TALER_FAKEBANK_stop (struct TALER_FAKEBANK_Handle *h)
h->mhd_rfd = NULL;
}
#endif
+#ifdef __linux__
if (-1 != h->lp_event)
+#else
+ if (-1 != h->lp_event_in && -1 != h->lp_event_out)
+#endif
{
uint64_t val = 1;
void *ret;
@@ -1221,7 +1250,11 @@ TALER_FAKEBANK_stop (struct TALER_FAKEBANK_Handle *h)
lp_trigger (lp,
h);
GNUNET_break (sizeof (val) ==
+#ifdef __linux__
write (h->lp_event,
+#else
+ write (h->lp_event_in,
+#endif
&val,
sizeof (val)));
GNUNET_assert (0 ==
@@ -1230,8 +1263,15 @@ TALER_FAKEBANK_stop (struct TALER_FAKEBANK_Handle *h)
pthread_join (h->lp_thread,
&ret));
GNUNET_break (NULL == ret);
+#ifdef __linux__
GNUNET_break (0 == close (h->lp_event));
h->lp_event = -1;
+#else
+ GNUNET_break (0 == close (h->lp_event_in));
+ GNUNET_break (0 == close (h->lp_event_out));
+ h->lp_event_in = -1;
+ h->lp_event_out = -1;
+#endif
}
else
{
@@ -1343,19 +1383,19 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
&json);
switch (pr)
{
- case GNUNET_JSON_PR_OUT_OF_MEMORY:
- GNUNET_break (0);
- return MHD_NO;
- case GNUNET_JSON_PR_CONTINUE:
- return MHD_YES;
- case GNUNET_JSON_PR_REQUEST_TOO_LARGE:
- GNUNET_break (0);
- return MHD_NO;
- case GNUNET_JSON_PR_JSON_INVALID:
- GNUNET_break (0);
- return MHD_NO;
- case GNUNET_JSON_PR_SUCCESS:
- break;
+ case GNUNET_JSON_PR_OUT_OF_MEMORY:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_CONTINUE:
+ return MHD_YES;
+ case GNUNET_JSON_PR_REQUEST_TOO_LARGE:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_JSON_INVALID:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_SUCCESS:
+ break;
}
{
const char *debit_account;
@@ -1467,19 +1507,19 @@ handle_transfer (struct TALER_FAKEBANK_Handle *h,
&json);
switch (pr)
{
- case GNUNET_JSON_PR_OUT_OF_MEMORY:
- GNUNET_break (0);
- return MHD_NO;
- case GNUNET_JSON_PR_CONTINUE:
- return MHD_YES;
- case GNUNET_JSON_PR_REQUEST_TOO_LARGE:
- GNUNET_break (0);
- return MHD_NO;
- case GNUNET_JSON_PR_JSON_INVALID:
- GNUNET_break (0);
- return MHD_NO;
- case GNUNET_JSON_PR_SUCCESS:
- break;
+ case GNUNET_JSON_PR_OUT_OF_MEMORY:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_CONTINUE:
+ return MHD_YES;
+ case GNUNET_JSON_PR_REQUEST_TOO_LARGE:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_JSON_INVALID:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_SUCCESS:
+ break;
}
{
struct GNUNET_HashCode uuid;
@@ -1794,12 +1834,20 @@ reschedule_lp_timeout (struct TALER_FAKEBANK_Handle *h,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Scheduling timeout task for %s\n",
GNUNET_STRINGS_absolute_time_to_string (t));
+#ifdef __linux__
if (-1 != h->lp_event)
+#else
+ if (-1 != h->lp_event_in && -1 != h->lp_event_out)
+#endif
{
uint64_t num = 1;
GNUNET_break (sizeof (num) ==
+#ifdef __linux__
write (h->lp_event,
+#else
+ write (h->lp_event_in,
+#endif
&num,
sizeof (num)));
}
@@ -1922,7 +1970,7 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h,
/* If account does not match, linear scan for
first matching account. */
while ( (! overflow) &&
- (NULL != t) &&
+ (NULL != t) &&
(t->debit_account != acc) )
{
skip = false;
@@ -2453,7 +2501,12 @@ schedule_httpd (struct TALER_FAKEBANK_Handle *h)
MHD_UNSIGNED_LONG_LONG timeout;
struct GNUNET_TIME_Relative tv;
+#ifdef __linux__
GNUNET_assert (-1 == h->lp_event);
+#else
+ GNUNET_assert (-1 == h->lp_event_in);
+ GNUNET_assert (-1 == h->lp_event_out);
+#endif
FD_ZERO (&rs);
FD_ZERO (&ws);
FD_ZERO (&es);
@@ -2525,7 +2578,12 @@ run_mhd (void *cls)
h->mhd_again = false;
MHD_run (h->mhd_bank);
}
+#ifdef __linux__
GNUNET_assert (-1 == h->lp_event);
+#else
+ GNUNET_assert (-1 == h->lp_event_in);
+ GNUNET_assert (-1 == h->lp_event_out);
+#endif
schedule_httpd (h);
}
@@ -2558,8 +2616,15 @@ TALER_FAKEBANK_start2 (uint16_t port,
}
GNUNET_assert (strlen (currency) < TALER_CURRENCY_LEN);
h = GNUNET_new (struct TALER_FAKEBANK_Handle);
+#ifdef __linux__
h->lp_event = -1;
+#else
+ h->lp_event_in = -1;
+ h->lp_event_out = -1;
+#endif
+#if EPOLL_SUPPORT
h->mhd_fd = -1;
+#endif
h->port = port;
h->ram_limit = ram_limit;
h->serial_counter = 0;
@@ -2642,6 +2707,7 @@ TALER_FAKEBANK_start2 (uint16_t port,
}
else
{
+#ifdef __linux__
h->lp_event = eventfd (0,
EFD_CLOEXEC);
if (-1 == h->lp_event)
@@ -2651,6 +2717,20 @@ TALER_FAKEBANK_start2 (uint16_t port,
TALER_FAKEBANK_stop (h);
return NULL;
}
+#else
+ {
+ int pipefd[2];
+ if (0 != pipe (pipefd))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+ "pipe");
+ TALER_FAKEBANK_stop (h);
+ return NULL;
+ }
+ h->lp_event_out = pipefd[0];
+ h->lp_event_in = pipefd[1];
+ }
+#endif
if (0 !=
pthread_create (&h->lp_thread,
NULL,
@@ -2659,8 +2739,15 @@ TALER_FAKEBANK_start2 (uint16_t port,
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
"pthread_create");
+#ifdef __linux__
GNUNET_break (0 == close (h->lp_event));
h->lp_event = -1;
+#else
+ GNUNET_break (0 == close (h->lp_event_in));
+ GNUNET_break (0 == close (h->lp_event_out));
+ h->lp_event_in = -1;
+ h->lp_event_out = -1;
+#endif
TALER_FAKEBANK_stop (h);
return NULL;
}
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index a0bc14d52..4b0096078 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -31,7 +31,6 @@
#include "taler_exchangedb_plugin.h"
#include <poll.h>
#include <pthread.h>
-#include <sys/eventfd.h>
#include <libpq-fe.h>
#include "plugin_exchangedb_common.c"
diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index 8d7f5f754..26440cb1d 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -435,4 +435,18 @@ const char *
TALER_yna_to_string (enum TALER_EXCHANGE_YesNoAll yna);
+#ifdef __APPLE__
+/**
+ * Returns the first occurence of `c` in `s`, or returns the null-byte
+ * terminating the string if it does not occur.
+ *
+ * @param s the string to search in
+ * @param c the character to search for
+ * @return char* the first occurence of `c` in `s`
+ */
+char * strchrnul (const char *s, int c);
+
+#endif
+
+
#endif
diff --git a/src/util/secmod_common.c b/src/util/secmod_common.c
index 975bae3f7..87ce17e06 100644
--- a/src/util/secmod_common.c
+++ b/src/util/secmod_common.c
@@ -23,7 +23,9 @@
#include "taler_signatures.h"
#include "secmod_common.h"
#include <poll.h>
+#ifdef __linux__
#include <sys/eventfd.h>
+#endif
/**
@@ -217,7 +219,11 @@ TES_wake_clients (void)
client = client->next)
{
GNUNET_assert (sizeof (num) ==
+#ifdef __linux__
write (client->esock,
+#else
+ write (client->esock_in,
+#endif
&num,
sizeof (num)));
}
@@ -243,7 +249,7 @@ TES_read_work (void *cls,
recv_size = recv (client->csock,
&buf[off],
sizeof (client->iobuf) - off,
- 0);
+ 0);
if (-1 == recv_size)
{
if ( (0 == off) &&
@@ -309,7 +315,11 @@ TES_await_ready (struct TES_Client *client)
.events = POLLIN
},
{
+#ifdef __linux__
.fd = client->esock,
+#else
+ .fd = client->esock_out,
+#endif
.events = POLLIN
},
};
@@ -324,13 +334,21 @@ TES_await_ready (struct TES_Client *client)
"poll");
for (int i = 0; i<2; i++)
{
+#ifdef __linux__
if ( (pfds[i].fd == client->esock) &&
+#else
+ if ( (pfds[i].fd == client->esock_out) &&
+#endif
(POLLIN == pfds[i].revents) )
{
uint64_t num;
GNUNET_assert (sizeof (num) ==
+#ifdef __linux__
read (client->esock,
+#else
+ read (client->esock_out,
+#endif
&num,
sizeof (num)));
return true;
@@ -349,7 +367,12 @@ TES_free_client (struct TES_Client *client)
client);
GNUNET_assert (0 == pthread_mutex_unlock (&TES_clients_lock));
GNUNET_break (0 == close (client->csock));
+#ifdef __linux__
GNUNET_break (0 == close (client->esock));
+#else
+ GNUNET_break (0 == close (client->esock_in));
+ GNUNET_break (0 == close (client->esock_out));
+#endif
pthread_detach (client->worker);
GNUNET_free (client);
}
@@ -401,7 +424,11 @@ listen_job (void *cls)
{
const struct TES_Callbacks *cb = cls;
int s;
+#ifdef __linux__
int e;
+#else
+ int e[2];
+#endif
struct sockaddr_storage sa;
socklen_t sa_len = sizeof (sa);
@@ -418,6 +445,7 @@ listen_job (void *cls)
"accept");
return;
}
+#ifdef __linux__
e = eventfd (0,
EFD_CLOEXEC);
if (-1 == e)
@@ -427,13 +455,27 @@ listen_job (void *cls)
GNUNET_break (0 == close (s));
return;
}
+#else
+ if (0 != pipe (e))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "pipe");
+ GNUNET_break (0 == close (s));
+ return;
+ }
+#endif
{
struct TES_Client *client;
client = GNUNET_new (struct TES_Client);
client->cb = *cb;
client->csock = s;
+#ifdef __linux__
client->esock = e;
+#else
+ client->esock_in = e[1];
+ client->esock_out = e[0];
+#endif
GNUNET_assert (0 == pthread_mutex_lock (&TES_clients_lock));
GNUNET_CONTAINER_DLL_insert (TES_clients_head,
TES_clients_tail,
diff --git a/src/util/secmod_common.h b/src/util/secmod_common.h
index b24e91cb2..304acebdf 100644
--- a/src/util/secmod_common.h
+++ b/src/util/secmod_common.h
@@ -155,10 +155,22 @@ struct TES_Client
*/
int csock;
+#ifdef __linux__
/**
* Event socket.
*/
int esock;
+#else
+ /**
+ * Input end of the event pipe.
+ */
+ int esock_in;
+
+ /**
+ * Output end of the event pipe.
+ */
+ int esock_out;
+#endif
};
diff --git a/src/util/taler-exchange-secmod-eddsa.c b/src/util/taler-exchange-secmod-eddsa.c
index 02b36fb9a..21aedbc2a 100644
--- a/src/util/taler-exchange-secmod-eddsa.c
+++ b/src/util/taler-exchange-secmod-eddsa.c
@@ -37,7 +37,6 @@
#include "taler-exchange-secmod-eddsa.h"
#include <gcrypt.h>
#include <pthread.h>
-#include <sys/eventfd.h>
#include "taler_error_codes.h"
#include "taler_signatures.h"
#include "secmod_common.h"
diff --git a/src/util/taler-exchange-secmod-rsa.c b/src/util/taler-exchange-secmod-rsa.c
index e40c8e39f..433879299 100644
--- a/src/util/taler-exchange-secmod-rsa.c
+++ b/src/util/taler-exchange-secmod-rsa.c
@@ -36,7 +36,6 @@
#include "taler-exchange-secmod-rsa.h"
#include <gcrypt.h>
#include <pthread.h>
-#include <sys/eventfd.h>
#include "taler_error_codes.h"
#include "taler_signatures.h"
#include "secmod_common.h"
diff --git a/src/util/util.c b/src/util/util.c
index 274dad3cd..2ff295b0b 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -46,4 +46,21 @@ TALER_b2s (const void *buf,
}
+#ifdef __APPLE__
+char *
+strchrnul (const char *s,
+ int c)
+{
+ char *value;
+ value = strchr (s,
+ c);
+ if (NULL == value)
+ value = &s[strlen (s)];
+ return value;
+}
+
+
+#endif
+
+
/* end of util.c */