Skip to content

Commit 538510c

Browse files
Refactored signal compatibility
Moved signal.h compatibility into nvme/signal.h
1 parent d061d3a commit 538510c

4 files changed

Lines changed: 51 additions & 31 deletions

File tree

libnvme/src/nvme/signal.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2+
/*
3+
* This file is part of libnvme.
4+
* Copyright (c) 2026 Micron Technology, Inc.
5+
*
6+
* Cross-platform compatibility for signal.h.
7+
* Provides functionality that may be missing on some platforms.
8+
* Compatibility is not comprehensive. Only functionality required by
9+
* nvme-cli and libnvme is included.
10+
*
11+
* Authors: Brandon Busacker <[email protected]>
12+
* Broc Going <[email protected]>
13+
*/
14+
#pragma once
15+
16+
#include <signal.h>
17+
18+
#if defined(_WIN32) || defined(_WIN64)
19+
20+
/* signal.h POSIX compatibility - Windows doesn't have sigaction */
21+
22+
struct sigaction {
23+
void (*sa_handler)(int);
24+
int sa_flags;
25+
int sa_mask; /* simplified - normally sigset_t */
26+
};
27+
28+
static inline int sigemptyset(int *set)
29+
{
30+
*set = 0;
31+
return 0;
32+
}
33+
34+
/*
35+
* Simplified signal handling using Windows signal() function
36+
* This is sufficient for handling SIGINT with no mask or flags.
37+
*/
38+
static inline int sigaction(int signum, const struct sigaction *act,
39+
struct sigaction *oldact)
40+
{
41+
(void)oldact; /* ignore old action for simplicity */
42+
if (act && act->sa_handler) {
43+
signal(signum, act->sa_handler);
44+
return 0;
45+
}
46+
return -1;
47+
}
48+
49+
#endif

libnvme/src/platform/windows.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,3 @@ static inline void libnvme_init(void)
4343
_setmode(_fileno(stdout), O_BINARY);
4444
_setmode(_fileno(stderr), O_BINARY);
4545
}
46-
47-
48-
/* signal.h POSIX compatibility - Windows doesn't have sigaction */
49-
50-
struct sigaction {
51-
void (*sa_handler)(int);
52-
int sa_flags;
53-
int sa_mask; /* simplified - normally sigset_t */
54-
};
55-
56-
static inline int sigemptyset(int *set)
57-
{
58-
*set = 0;
59-
return 0;
60-
}
61-
62-
/*
63-
* Simplified signal handling using Windows signal() function
64-
* This is sufficient for handling SIGINT with no mask or flags.
65-
*/
66-
static inline int sigaction(int signum, const struct sigaction *act,
67-
struct sigaction *oldact)
68-
{
69-
(void)oldact; /* ignore old action for simplicity */
70-
if (act && act->sa_handler) {
71-
signal(signum, act->sa_handler);
72-
return 0;
73-
}
74-
return -1;
75-
}

plugins/amzn/amzn-nvme.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <unistd.h>
88
#include <inttypes.h>
99

10+
#include <nvme/signal.h>
1011
#include <libnvme.h>
1112

1213
#include "common.h"

util/sighdl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <errno.h>
44
#include <stddef.h>
55

6-
#include <platform/includes.h>
6+
#include <nvme/signal.h>
77

88
#include "sighdl.h"
99

0 commit comments

Comments
 (0)