git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/2] compat/mingw.c: expand MinGW support for sigaction

From
Jeremiah Mahler <jmmahler@gmail.com>
Date
May 30, 2014, 20:58 UTC
Message-ID
<d5fc7d72b2d51d1b90fb7f238eff120cb4c6d0e7.1401482787.git.jmmahler@gmail.com>
In-Reply-To
<cover.1401482787.git.jmmahler@gmail.com>

Due to portability issues across UNIX versions sigaction(2) should be used instead of signal(2).

From the signal(2) man page:
  The behavior of signal() varies across UNIX versions, and has also var‐
  ied historically across different versions of Linux.   Avoid  its  use:
  use sigaction(2) instead.

Unfortunately MinGW under Windows has limited support for signal and no support for sigaction. And this prevents sigaction from being used across the entire Git project.

In compat/mingw.c there is a faux sigaction function but it only supports SIGALARM. Hence the need for continuing to use signal() in other cases.

This patch expands the faux sigaction function so that it calls signal in cases other than SIGALRM. Now sigaction can be used across the entire Git project and MinGW will still work with signal as it did before.

Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com>
---
 compat/mingw.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index e9892f8..e504cef 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1651,14 +1651,15 @@ int setitimer(int type, struct itimerval *in, struct itimerval *out)
 
 int sigaction(int sig, struct sigaction *in, struct sigaction *out)
 {
-	if (sig != SIGALRM)
-		return errno = EINVAL,
-			error("sigaction only implemented for SIGALRM");
 	if (out != NULL)
 		return errno = EINVAL,
 			error("sigaction: param 3 != NULL not implemented");
 
-	timer_fn = in->sa_handler;
+	if (sig == SIGALRM)
+		timer_fn = in->sa_handler;
+	else
+		signal(sig, in->sa_handler);
+
 	return 0;
 }
 
-- 
2.0.0.2.g1d11d5d
Previous: Jeremiah MahlerNext: Jeremiah Mahler
Message 2 of 6 in “replace signal() with sigaction()”
  1. 0/2 replace signal() with sigaction()Jeremiah Mahler, May 30, 2014
  2. 1/2 compat/mingw.c: expand MinGW support for sigactionJeremiah Mahler, May 30, 2014
  3. 2/2 connect.c: replace signal() with sigaction()Jeremiah Mahler, May 30, 2014
  4. Andreas SchwabMay 30, 2014
  5. Chris PackhamMay 31, 2014
  6. Jeremiah MahlerMay 31, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.