diff --git a/contrib/win32/win32compat/inc/defs.h b/contrib/win32/win32compat/inc/defs.h index 0090baf..f68b33e 100644 --- a/contrib/win32/win32compat/inc/defs.h +++ b/contrib/win32/win32compat/inc/defs.h @@ -28,3 +28,46 @@ /*fd flags*/ #define FD_CLOEXEC 0x1 + +/* signal related defs*/ +typedef void(*sighandler_t)(int); +// Signal types +#define SIGINT 2 // interrupt +#define SIGSEGV 11 // segment violation + +#define SIGPIPE 27 +#define SIGCHLD 26 +#define SIGALRM 14 +#define SIGTSTP 5 //"CTRL+Z" - no portable number + +#define SIGHUP 1 //Terminate from console +#define SIGQUIT 3 +#define SIGTERM 15// Software termination signal from kill +#define SIGTTIN 6//noportabel number +#define SIGTTOU 7 //no portable number + + + +//#define SIGINT 2 // interrupt +//#define SIGILL 4 // illegal instruction - invalid function image +//#define SIGFPE 8 // floating point exception +//#define SIGSEGV 11 // segment violation +//#define SIGTERM 15 // Software termination signal from kill +//#define SIGBREAK 21 // Ctrl-Break sequence +//#define SIGABRT 22 // abnormal termination triggered by abort call +//#define SIGWINCH +// +//#define SIGABRT_COMPAT 6 // SIGABRT compatible with other platforms, same as SIGABRT +// +//#define SIGALRM 14 +//#define SIGCHLD 26 +//#define SIGHUP 1 +//#define SIGPIPE 27 +//#define SIGQUIT 3 + +// Signal action codes +#define SIG_DFL (0) // default signal action +#define SIG_IGN (1) // ignore signal +#define SIG_GET (2) // return current value +#define SIG_SGE (3) // signal gets error +#define SIG_ACK (4) // acknowledge diff --git a/contrib/win32/win32compat/inc/signal.h b/contrib/win32/win32compat/inc/signal.h index 7b2f6e7..506706a 100644 --- a/contrib/win32/win32compat/inc/signal.h +++ b/contrib/win32/win32compat/inc/signal.h @@ -8,28 +8,8 @@ #include "w32posix.h" -// Signal types -#define SIGINT 2 // interrupt -#define SIGILL 4 // illegal instruction - invalid function image -#define SIGFPE 8 // floating point exception -#define SIGSEGV 11 // segment violation -#define SIGTERM 15 // Software termination signal from kill -#define SIGBREAK 21 // Ctrl-Break sequence -#define SIGABRT 22 // abnormal termination triggered by abort call +#define signal(a,b) w32_signal((a), (b)) +#define mysignal(a,b) w32_signal((a), (b)) -#define SIGABRT_COMPAT 6 // SIGABRT compatible with other platforms, same as SIGABRT - -#define SIGALRM 14 -#define SIGCHLD 26 -#define SIGHUP 1 -#define SIGPIPE 27 -#define SIGQUIT 3 - -// Signal action codes -#define SIG_DFL (0) // default signal action -#define SIG_IGN (1) // ignore signal -#define SIG_GET (2) // return current value -#define SIG_SGE (3) // signal gets error -#define SIG_ACK (4) // acknowledge #endif \ No newline at end of file diff --git a/contrib/win32/win32compat/inc/w32posix.h b/contrib/win32/win32compat/inc/w32posix.h index 5f6f3ce..20c107d 100644 --- a/contrib/win32/win32compat/inc/w32posix.h +++ b/contrib/win32/win32compat/inc/w32posix.h @@ -67,10 +67,7 @@ int w32_dup2(int oldfd, int newfd); /* misc */ unsigned int w32_alarm(unsigned int seconds); -typedef void(*sighandler_t)(int); -#define signal(a,b) w32_signal((a), (b)) -#define mysignal(a,b) w32_signal((a), (b)) - +sighandler_t w32_signal(int signum, sighandler_t handler); /* Shutdown constants */ #define SHUT_WR SD_SEND diff --git a/contrib/win32/win32compat/signal.c b/contrib/win32/win32compat/signal.c index e662d45..654ccf3 100644 --- a/contrib/win32/win32compat/signal.c +++ b/contrib/win32/win32compat/signal.c @@ -30,6 +30,7 @@ #include "w32fd.h" #include +#include "inc\defs.h" /* signal handlers */ @@ -47,6 +48,11 @@ signalio_initialize() { memset(&children, 0, sizeof(children)); } +sighandler_t w32_signal(int signum, sighandler_t handler) { + /*TODO - implement signal()*/ + return 0; +} + int signalio_add_child(HANDLE child) { if (children.num_children == MAX_CHILDREN) { diff --git a/contrib/win32/win32compat/w32fd.c b/contrib/win32/win32compat/w32fd.c index 0bf9c71..0b46df9 100644 --- a/contrib/win32/win32compat/w32fd.c +++ b/contrib/win32/win32compat/w32fd.c @@ -453,6 +453,28 @@ w32_close(int fd) { } } +static int +w32_io_process_fd_flags(struct w32_io* pio, int flags) { + DWORD shi_flags; + if (flags & ~FD_CLOEXEC) { + debug("fcntl - ERROR unsupported flags %d, io:%p", flags, pio); + errno = ENOTSUP; + return -1; + } + + shi_flags = (flags & FD_CLOEXEC) ? 0 : HANDLE_FLAG_INHERIT; + + if (SetHandleInformation(WINHANDLE(pio), HANDLE_FLAG_INHERIT, shi_flags) == FALSE) { + debug("fcntl - SetHandleInformation failed %d, io:%p", + GetLastError(), pio); + errno = EOTHER; + return -1; + } + + pio->fd_flags = flags; + return 0; +} + int w32_fcntl(int fd, int cmd, ... /* arg */) { va_list valist; @@ -467,11 +489,9 @@ w32_fcntl(int fd, int cmd, ... /* arg */) { fd_table.w32_ios[fd]->fd_status_flags = va_arg(valist, int); return 0; case F_GETFD: - return fd_table.w32_ios[fd]->fd_flags; - return 0; + return fd_table.w32_ios[fd]->fd_flags; case F_SETFD: - fd_table.w32_ios[fd]->fd_flags = va_arg(valist, int); - return 0; + return w32_io_process_fd_flags(fd_table.w32_ios[fd], va_arg(valist, int)); default: errno = EINVAL; debug("fcntl - ERROR not supported cmd:%d", cmd); @@ -725,11 +745,6 @@ w32_alarm(unsigned int seconds) { return 0; } -sighandler_t w32_signal(int signum, sighandler_t handler) { - /*TODO - implement signal()*/ - return 0; -} - int w32_temp_DelChildToWatch(HANDLE processtowatch) { return 0;