Compare commits

...

2 Commits

Author SHA1 Message Date
Thien-Thi Nguyen
0b6ebc6160
fix FTBFS (Linux) for 2022-01-18, "use 'pipe' instead of 'eventfd' on non-Linux systems"
add back #include <sys/eventfd.h>, but conditionalize on #ifdef __linux__

(This fix follows the spirit of the other changes (i.e.,
adding #ifdef __linux__) but might not be the best solution.)
2022-01-18 19:34:41 -05:00
Jonathan Buchanan
c10b783521
use 'pipe' instead of 'eventfd' on non-Linux systems 2022-01-18 09:15:54 -05:00
8 changed files with 204 additions and 32 deletions

View File

@ -26,7 +26,9 @@
#include "platform.h"
#include <pthread.h>
#include <poll.h>
#ifdef __linux__
#include <sys/eventfd.h>
#endif
#include "taler_fakebank_lib.h"
#include "taler_bank_service.h"
#include "taler_mhd_lib.h"
@ -414,11 +416,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 +496,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 +561,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 +585,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 +1023,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 +1236,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 +1253,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 +1266,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 +1386,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 +1510,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 +1837,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 +1973,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 +2504,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 +2581,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 +2619,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 +2710,7 @@ TALER_FAKEBANK_start2 (uint16_t port,
}
else
{
#ifdef __linux__
h->lp_event = eventfd (0,
EFD_CLOEXEC);
if (-1 == h->lp_event)
@ -2651,6 +2720,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 +2742,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;
}

View File

@ -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"

View File

@ -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

View File

@ -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,

View File

@ -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
};

View File

@ -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"

View File

@ -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"

View File

@ -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 */