ref: c26929cb40221d6efc9f3a8fc83024513cba8540
parent: aa32c604f92e7eca5a5e919c310da199fb4c1c61
author: zamfofex <zamfofex@twdb.moe>
date: Sun Jun 1 02:46:08 EDT 2025
make miscellaneous improvements to the tools
--- a/tools/analyse.c
+++ b/tools/analyse.c
@@ -853,7 +853,7 @@
action.sa_handler = &moonfish_signal;
sigemptyset(&action.sa_mask);
- action.sa_flags = 0;
+ action.sa_flags = SA_RESTART;
if (sigaction(SIGTERM, &action, NULL) || sigaction(SIGINT, &action, NULL) || sigaction(SIGQUIT, &action, NULL)) { perror("sigaction");--- a/tools/lichess.c
+++ b/tools/lichess.c
@@ -7,7 +7,6 @@
#ifndef moonfish_plan9
-#include <sys/wait.h>
#include <signal.h>
#include <cjson/cJSON.h>
@@ -523,18 +522,6 @@
return username;
}
-#ifndef moonfish_plan9
-
-static void moonfish_signal(int signal)
-{- (void) signal;
- for (;;) {- if (waitpid(-1, NULL, WNOHANG) <= 0) break;
- }
-}
-
-#endif
-
int main(int argc, char **argv)
{ static struct moonfish_command cmd = {@@ -616,11 +603,11 @@
#ifndef moonfish_plan9
- action.sa_handler = &moonfish_signal;
+ action.sa_handler = SIG_DFL;
sigemptyset(&action.sa_mask);
- action.sa_flags = 0;
+ action.sa_flags = SA_RESTART | SA_NOCLDWAIT;
- if (sigaction(SIGCHLD, &action, NULL)) {+ if (sigaction(SIGCHLD, &action, NULL) != 0) { perror("sigaction");return 1;
}
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -39,7 +39,6 @@
void moonfish_spawn(char **argv, FILE **in, FILE **out, char *directory);
-char *moonfish_next(FILE *file);
char *moonfish_wait(FILE *file, char *name);
char **moonfish_args(struct moonfish_command *cmd, int argc, char **argv);
void moonfish_usage(struct moonfish_command *cmd, char *argv0);
--- a/tools/utils.c
+++ b/tools/utils.c
@@ -115,25 +115,18 @@
}
}
-char *moonfish_next(FILE *file)
-{- static char line[2048];
- if (fgets(line, sizeof line, file) == NULL) return NULL;
- return line;
-}
-
char *moonfish_wait(FILE *file, char *name)
{- char *line, *arg, *buffer;
+ char line[2048], *arg, *buffer;
for (;;) {- line = moonfish_next(file);
- if (line == NULL) {+ if (fgets(line, sizeof line, file) == NULL) {fprintf(stderr, "file closed unexpectedly\n");
exit(1);
}
+ buffer = NULL;
arg = strtok_r(line, "\r\n\t ", &buffer);
if (arg == NULL) continue;
if (!strcmp(line, name)) return strtok_r(NULL, "\r\n\t ", &buffer);
--
⑨