nixio: Implement protable behaviour of signal(), export more error
constants
This commit is contained in:
parent
2e79c969c0
commit
68a95e6806
2 changed files with 48 additions and 1 deletions
|
@ -130,7 +130,7 @@ LUALIB_API int luaopen_nixio(lua_State *L) {
|
|||
lua_setfield(L, -2, "version");
|
||||
|
||||
/* some constants */
|
||||
lua_createtable(L, 0, 16);
|
||||
lua_createtable(L, 0, 49);
|
||||
|
||||
NIXIO_PUSH_CONSTANT(EACCES);
|
||||
NIXIO_PUSH_CONSTANT(EINTR);
|
||||
|
@ -140,6 +140,33 @@ LUALIB_API int luaopen_nixio(lua_State *L) {
|
|||
NIXIO_PUSH_CONSTANT(EAGAIN);
|
||||
NIXIO_PUSH_CONSTANT(ENOMEM);
|
||||
NIXIO_PUSH_CONSTANT(ENOENT);
|
||||
NIXIO_PUSH_CONSTANT(ECHILD);
|
||||
NIXIO_PUSH_CONSTANT(EIO);
|
||||
NIXIO_PUSH_CONSTANT(EBADF);
|
||||
NIXIO_PUSH_CONSTANT(EFAULT);
|
||||
NIXIO_PUSH_CONSTANT(EFBIG);
|
||||
NIXIO_PUSH_CONSTANT(ENOSPC);
|
||||
NIXIO_PUSH_CONSTANT(EPIPE);
|
||||
NIXIO_PUSH_CONSTANT(ESPIPE);
|
||||
NIXIO_PUSH_CONSTANT(EISDIR);
|
||||
NIXIO_PUSH_CONSTANT(EPERM);
|
||||
NIXIO_PUSH_CONSTANT(EEXIST);
|
||||
NIXIO_PUSH_CONSTANT(ELOOP);
|
||||
NIXIO_PUSH_CONSTANT(EMFILE);
|
||||
NIXIO_PUSH_CONSTANT(ENAMETOOLONG);
|
||||
NIXIO_PUSH_CONSTANT(ENFILE);
|
||||
NIXIO_PUSH_CONSTANT(ENODEV);
|
||||
NIXIO_PUSH_CONSTANT(ENOTDIR);
|
||||
NIXIO_PUSH_CONSTANT(ENXIO);
|
||||
NIXIO_PUSH_CONSTANT(EOVERFLOW);
|
||||
NIXIO_PUSH_CONSTANT(EROFS);
|
||||
NIXIO_PUSH_CONSTANT(ETXTBSY);
|
||||
NIXIO_PUSH_CONSTANT(EAFNOSUPPORT);
|
||||
NIXIO_PUSH_CONSTANT(ENOBUFS);
|
||||
NIXIO_PUSH_CONSTANT(EPROTONOSUPPORT);
|
||||
NIXIO_PUSH_CONSTANT(ENOPROTOOPT);
|
||||
NIXIO_PUSH_CONSTANT(EBUSY);
|
||||
NIXIO_PUSH_CONSTANT(ESRCH);
|
||||
NIXIO_PUSH_CONSTANT(SIGALRM);
|
||||
NIXIO_PUSH_CONSTANT(SIGINT);
|
||||
NIXIO_PUSH_CONSTANT(SIGTERM);
|
||||
|
@ -148,6 +175,12 @@ LUALIB_API int luaopen_nixio(lua_State *L) {
|
|||
NIXIO_PUSH_CONSTANT(SIGSTOP);
|
||||
NIXIO_PUSH_CONSTANT(SIGCONT);
|
||||
NIXIO_PUSH_CONSTANT(SIGSEGV);
|
||||
NIXIO_PUSH_CONSTANT(SIGCHLD);
|
||||
NIXIO_PUSH_CONSTANT(SIGQUIT);
|
||||
NIXIO_PUSH_CONSTANT(SIGUSR1);
|
||||
NIXIO_PUSH_CONSTANT(SIGUSR2);
|
||||
NIXIO_PUSH_CONSTANT(SIGPOLL);
|
||||
NIXIO_PUSH_CONSTANT(SIGURG);
|
||||
|
||||
lua_setfield(L, -2, "const");
|
||||
|
||||
|
|
|
@ -36,6 +36,19 @@ static int nixio_fork(lua_State *L) {
|
|||
}
|
||||
}
|
||||
|
||||
static int nixio_signal(lua_State *L) {
|
||||
int sig = luaL_checkinteger(L, 1);
|
||||
const char *val = luaL_checkstring(L, 2);
|
||||
|
||||
if (!strcmp(val, "ign") || !strcmp(val, "ignore")) {
|
||||
return nixio__pstatus(L, signal(sig, SIG_IGN) != SIG_ERR);
|
||||
} else if (!strcmp(val, "dfl") || !strcmp(val, "default")) {
|
||||
return nixio__pstatus(L, signal(sig, SIG_DFL) != SIG_ERR);
|
||||
} else {
|
||||
return luaL_argerror(L, 2, "supported values: ign, dfl");
|
||||
}
|
||||
}
|
||||
|
||||
static int nixio_wait(lua_State *L) {
|
||||
pid_t pidin = luaL_optinteger(L, 1, -1), pidout;
|
||||
int options = 0, status;
|
||||
|
@ -148,6 +161,7 @@ static const luaL_reg R[] = {
|
|||
{"getgid", nixio_getgid},
|
||||
{"setuid", nixio_setuid},
|
||||
{"setgid", nixio_setgid},
|
||||
{"signal", nixio_signal},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue