Dolda2000 GitWeb
/
ashd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
lib: Fixed stdinit bug.
[ashd.git]
/
lib
/
mtio-epoll.c
diff --git
a/lib/mtio-epoll.c
b/lib/mtio-epoll.c
index
940ba3d
..
72468e0
100644
(file)
--- a/
lib/mtio-epoll.c
+++ b/
lib/mtio-epoll.c
@@
-17,6
+17,9
@@
*/
#include <stdlib.h>
*/
#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <fcntl.h>
#include <string.h>
#include <sys/epoll.h>
#include <errno.h>
#include <string.h>
#include <sys/epoll.h>
#include <errno.h>
@@
-40,6
+43,7
@@
struct blocker {
};
static int epfd = -1, fdln = 0;
};
static int epfd = -1, fdln = 0;
+static int exitstatus;
static struct blocker **fdlist;
static int regfd(struct blocker *bl)
static struct blocker **fdlist;
static int regfd(struct blocker *bl)
@@
-122,6
+126,7
@@
static void remfd(struct blocker *bl)
flog(LOG_ERR, "epoll_mod on fd %i: %s", bl->fd, strerror(errno));
}
}
flog(LOG_ERR, "epoll_mod on fd %i: %s", bl->fd, strerror(errno));
}
}
+ bl->reg = 0;
}
int block(int fd, int ev, time_t to)
}
int block(int fd, int ev, time_t to)
@@
-155,14
+160,16
@@
int block(int fd, int ev, time_t to)
return(rv);
}
return(rv);
}
-
void
ioloop(void)
+
int
ioloop(void)
{
struct blocker *bl, *nbl;
struct epoll_event evr[16];
int i, fd, nev, ev, toval;
time_t now, timeout;
{
struct blocker *bl, *nbl;
struct epoll_event evr[16];
int i, fd, nev, ev, toval;
time_t now, timeout;
+ exitstatus = 0;
epfd = epoll_create(128);
epfd = epoll_create(128);
+ fcntl(epfd, F_SETFD, FD_CLOEXEC);
for(bl = blockers; bl; bl = nbl) {
nbl = bl->n;
if(regfd(bl))
for(bl = blockers; bl; bl = nbl) {
nbl = bl->n;
if(regfd(bl))
@@
-181,10
+188,12
@@
void ioloop(void)
toval = (timeout - now) * 1000;
else
toval = 1000;
toval = (timeout - now) * 1000;
else
toval = 1000;
+ if(exitstatus)
+ break;
nev = epoll_wait(epfd, evr, sizeof(evr) / sizeof(*evr), toval);
if(nev < 0) {
if(errno != EINTR) {
nev = epoll_wait(epfd, evr, sizeof(evr) / sizeof(*evr), toval);
if(nev < 0) {
if(errno != EINTR) {
- flog(LOG_CRIT, "ioloop:
selec
t errored out: %s", strerror(errno));
+ flog(LOG_CRIT, "ioloop:
epoll_wai
t errored out: %s", strerror(errno));
/* To avoid CPU hogging in case it's bad, which it
* probably is. */
sleep(1);
/* To avoid CPU hogging in case it's bad, which it
* probably is. */
sleep(1);
@@
-213,6
+222,14
@@
void ioloop(void)
resume(bl->th, 0);
}
}
resume(bl->th, 0);
}
}
+ for(bl = blockers; bl; bl = bl->n)
+ remfd(bl);
close(epfd);
epfd = -1;
close(epfd);
epfd = -1;
+ return(exitstatus);
+}
+
+void exitioloop(int status)
+{
+ exitstatus = status;
}
}