mirror of
https://github.com/bjc/prosody.git
synced 2025-04-01 20:27:39 +03:00
util.signal: Factor out single #define that enables signalfd(2) use
Makes it easier to test by disabling this #define
This commit is contained in:
parent
4919301ad4
commit
ea7bf939d5
1 changed files with 10 additions and 6 deletions
|
@ -30,10 +30,14 @@
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
#define HAVE_SIGNALFD
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#ifdef __linux__
|
#ifdef HAVE_SIGNALFD
|
||||||
#include <sys/signalfd.h>
|
#include <sys/signalfd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -375,12 +379,12 @@ static int l_kill(lua_State *L) {
|
||||||
struct lsignalfd {
|
struct lsignalfd {
|
||||||
int fd;
|
int fd;
|
||||||
sigset_t mask;
|
sigset_t mask;
|
||||||
#ifndef __linux__
|
#ifndef HAVE_SIGNALFD
|
||||||
int write_fd;
|
int write_fd;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef __linux__
|
#ifndef HAVE_SIGNALFD
|
||||||
#define MAX_SIGNALFD 32
|
#define MAX_SIGNALFD 32
|
||||||
struct lsignalfd signalfds[MAX_SIGNALFD];
|
struct lsignalfd signalfds[MAX_SIGNALFD];
|
||||||
static int signalfd_num = 0;
|
static int signalfd_num = 0;
|
||||||
|
@ -400,7 +404,7 @@ static int l_signalfd(lua_State *L) {
|
||||||
sigemptyset(&sfd->mask);
|
sigemptyset(&sfd->mask);
|
||||||
sigaddset(&sfd->mask, sig);
|
sigaddset(&sfd->mask, sig);
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef HAVE_SIGNALFD
|
||||||
if (sigprocmask(SIG_BLOCK, &sfd->mask, NULL) != 0) {
|
if (sigprocmask(SIG_BLOCK, &sfd->mask, NULL) != 0) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -455,7 +459,7 @@ static int l_signalfd_getfd(lua_State *L) {
|
||||||
|
|
||||||
static int l_signalfd_read(lua_State *L) {
|
static int l_signalfd_read(lua_State *L) {
|
||||||
struct lsignalfd *sfd = luaL_checkudata(L, 1, "signalfd");
|
struct lsignalfd *sfd = luaL_checkudata(L, 1, "signalfd");
|
||||||
#ifdef __linux__
|
#ifdef HAVE_SIGNALFD
|
||||||
struct signalfd_siginfo siginfo;
|
struct signalfd_siginfo siginfo;
|
||||||
|
|
||||||
if(read(sfd->fd, &siginfo, sizeof(siginfo)) < 0) {
|
if(read(sfd->fd, &siginfo, sizeof(siginfo)) < 0) {
|
||||||
|
@ -487,7 +491,7 @@ static int l_signalfd_close(lua_State *L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __linux__
|
#ifndef HAVE_SIGNALFD
|
||||||
|
|
||||||
if(close(sfd->write_fd) != 0) {
|
if(close(sfd->write_fd) != 0) {
|
||||||
lua_pushboolean(L, 0);
|
lua_pushboolean(L, 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue