Skip to content

Commit 4fd9ed0

Browse files
committed
signal support initial changes
1 parent 6ba1ba5 commit 4fd9ed0

File tree

5 files changed

+76
-35
lines changed

5 files changed

+76
-35
lines changed

contrib/win32/win32compat/inc/defs.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,46 @@
2828

2929
/*fd flags*/
3030
#define FD_CLOEXEC 0x1
31+
32+
/* signal related defs*/
33+
typedef void(*sighandler_t)(int);
34+
// Signal types
35+
#define SIGINT 2 // interrupt
36+
#define SIGSEGV 11 // segment violation
37+
38+
#define SIGPIPE 27
39+
#define SIGCHLD 26
40+
#define SIGALRM 14
41+
#define SIGTSTP 5 //"CTRL+Z" - no portable number
42+
43+
#define SIGHUP 1 //Terminate from console
44+
#define SIGQUIT 3
45+
#define SIGTERM 15// Software termination signal from kill
46+
#define SIGTTIN 6//noportabel number
47+
#define SIGTTOU 7 //no portable number
48+
49+
50+
51+
//#define SIGINT 2 // interrupt
52+
//#define SIGILL 4 // illegal instruction - invalid function image
53+
//#define SIGFPE 8 // floating point exception
54+
//#define SIGSEGV 11 // segment violation
55+
//#define SIGTERM 15 // Software termination signal from kill
56+
//#define SIGBREAK 21 // Ctrl-Break sequence
57+
//#define SIGABRT 22 // abnormal termination triggered by abort call
58+
//#define SIGWINCH
59+
//
60+
//#define SIGABRT_COMPAT 6 // SIGABRT compatible with other platforms, same as SIGABRT
61+
//
62+
//#define SIGALRM 14
63+
//#define SIGCHLD 26
64+
//#define SIGHUP 1
65+
//#define SIGPIPE 27
66+
//#define SIGQUIT 3
67+
68+
// Signal action codes
69+
#define SIG_DFL (0) // default signal action
70+
#define SIG_IGN (1) // ignore signal
71+
#define SIG_GET (2) // return current value
72+
#define SIG_SGE (3) // signal gets error
73+
#define SIG_ACK (4) // acknowledge

contrib/win32/win32compat/inc/signal.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,8 @@
88

99
#include "w32posix.h"
1010

11-
// Signal types
12-
#define SIGINT 2 // interrupt
13-
#define SIGILL 4 // illegal instruction - invalid function image
14-
#define SIGFPE 8 // floating point exception
15-
#define SIGSEGV 11 // segment violation
16-
#define SIGTERM 15 // Software termination signal from kill
17-
#define SIGBREAK 21 // Ctrl-Break sequence
18-
#define SIGABRT 22 // abnormal termination triggered by abort call
11+
#define signal(a,b) w32_signal((a), (b))
12+
#define mysignal(a,b) w32_signal((a), (b))
1913

20-
#define SIGABRT_COMPAT 6 // SIGABRT compatible with other platforms, same as SIGABRT
21-
22-
#define SIGALRM 14
23-
#define SIGCHLD 26
24-
#define SIGHUP 1
25-
#define SIGPIPE 27
26-
#define SIGQUIT 3
27-
28-
// Signal action codes
29-
#define SIG_DFL (0) // default signal action
30-
#define SIG_IGN (1) // ignore signal
31-
#define SIG_GET (2) // return current value
32-
#define SIG_SGE (3) // signal gets error
33-
#define SIG_ACK (4) // acknowledge
3414

3515
#endif

contrib/win32/win32compat/inc/w32posix.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ int w32_dup2(int oldfd, int newfd);
6767

6868
/* misc */
6969
unsigned int w32_alarm(unsigned int seconds);
70-
typedef void(*sighandler_t)(int);
71-
#define signal(a,b) w32_signal((a), (b))
72-
#define mysignal(a,b) w32_signal((a), (b))
73-
70+
sighandler_t w32_signal(int signum, sighandler_t handler);
7471

7572
/* Shutdown constants */
7673
#define SHUT_WR SD_SEND

contrib/win32/win32compat/signal.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "w32fd.h"
3232
#include <errno.h>
33+
#include "inc\defs.h"
3334

3435
/* signal handlers */
3536

@@ -47,6 +48,11 @@ signalio_initialize() {
4748
memset(&children, 0, sizeof(children));
4849
}
4950

51+
sighandler_t w32_signal(int signum, sighandler_t handler) {
52+
/*TODO - implement signal()*/
53+
return 0;
54+
}
55+
5056
int
5157
signalio_add_child(HANDLE child) {
5258
if (children.num_children == MAX_CHILDREN) {

contrib/win32/win32compat/w32fd.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,28 @@ w32_close(int fd) {
453453
}
454454
}
455455

456+
static int
457+
w32_io_process_fd_flags(struct w32_io* pio, int flags) {
458+
DWORD shi_flags;
459+
if (flags & ~FD_CLOEXEC) {
460+
debug("fcntl - ERROR unsupported flags %d, io:%p", flags, pio);
461+
errno = ENOTSUP;
462+
return -1;
463+
}
464+
465+
shi_flags = (flags & FD_CLOEXEC) ? 0 : HANDLE_FLAG_INHERIT;
466+
467+
if (SetHandleInformation(WINHANDLE(pio), HANDLE_FLAG_INHERIT, shi_flags) == FALSE) {
468+
debug("fcntl - SetHandleInformation failed %d, io:%p",
469+
GetLastError(), pio);
470+
errno = EOTHER;
471+
return -1;
472+
}
473+
474+
pio->fd_flags = flags;
475+
return 0;
476+
}
477+
456478
int
457479
w32_fcntl(int fd, int cmd, ... /* arg */) {
458480
va_list valist;
@@ -467,11 +489,9 @@ w32_fcntl(int fd, int cmd, ... /* arg */) {
467489
fd_table.w32_ios[fd]->fd_status_flags = va_arg(valist, int);
468490
return 0;
469491
case F_GETFD:
470-
return fd_table.w32_ios[fd]->fd_flags;
471-
return 0;
492+
return fd_table.w32_ios[fd]->fd_flags;
472493
case F_SETFD:
473-
fd_table.w32_ios[fd]->fd_flags = va_arg(valist, int);
474-
return 0;
494+
return w32_io_process_fd_flags(fd_table.w32_ios[fd], va_arg(valist, int));
475495
default:
476496
errno = EINVAL;
477497
debug("fcntl - ERROR not supported cmd:%d", cmd);
@@ -725,11 +745,6 @@ w32_alarm(unsigned int seconds) {
725745
return 0;
726746
}
727747

728-
sighandler_t w32_signal(int signum, sighandler_t handler) {
729-
/*TODO - implement signal()*/
730-
return 0;
731-
}
732-
733748
int
734749
w32_temp_DelChildToWatch(HANDLE processtowatch) {
735750
return 0;

0 commit comments

Comments
 (0)