[PATCH 4/4] hardlink: re-raise SIGINT instead of exiting

наб <[email protected]>
Newsgroups org.kernel.vger.util-linux
Message-ID <2f2733fcf94bf9f1b132904303947b8c5e6f2c3c.1730139540.git.nabijaczleweli@nabijaczleweli.xyz>
Every TRUE return was either exit(1) or "return error;" anyway,
this is more correct (exit-status-wise) and doesn't hang pipelines weirdly

This also removes a seemingly-extraneous newline written to the standard
output stream in the interrupt handler itself?
---
 misc-utils/hardlink.c | 33 ++++++++++-----------------------
 1 file changed, 10 insertions(+), 23 deletions(-)

diff --git a/misc-utils/hardlink.c b/misc-utils/hardlink.c
index 8c5f24aad..e996f53b5 100644
--- a/misc-utils/hardlink.c
+++ b/misc-utils/hardlink.c
@@ -428,23 +428,20 @@ static void print_stats(void)
 
 /**
  * handle_interrupt - Handle a signal
- *
- * Returns: %TRUE on SIGINT, SIGTERM; %FALSE on all other signals.
  */
-static int handle_interrupt(void)
+static void handle_interrupt(void)
 {
 	switch (last_signal) {
-	case SIGINT:
-	case SIGTERM:
-		return TRUE;
 	case SIGUSR1:
 		print_stats();
 		putchar('\n');
 		break;
+	default:
+		signal(last_signal, SIG_DFL);
+		raise(last_signal);
+		break;
 	}
-
 	last_signal = 0;
-	return FALSE;
 }
 
 #ifdef USE_XATTR
@@ -589,8 +586,7 @@ static int file_xattrs_equal(const struct file *a, const struct file *b)
 	// We now have two sorted tables of xattr names.
 
 	for (i = 0; i < n_a; i++) {
-		if (handle_interrupt())
-			goto exit;	// user wants to quit
+		handle_interrupt();
 
 		if (strcmp(name_ptrs_a[i], name_ptrs_b[i]) != 0)
 			goto exit;	// names at same slot differ
@@ -845,8 +841,7 @@ static int inserter(const char *fpath, const struct stat *sb,
 	int included;
 	int excluded;
 
-	if (handle_interrupt())
-		return 1;
+	handle_interrupt();
 	if (typeflag == FTW_DNR || typeflag == FTW_NS)
 		warn(_("cannot read %s"), fpath);
 	if (typeflag != FTW_F || !S_ISREG(sb->st_mode))
@@ -1072,8 +1067,7 @@ static void visitor(const void *nodep, const VISIT which, const int depth)
 		size_t nnodes, memsiz;
 		int may_reflink = 0;
 
-		if (handle_interrupt())
-			exit(EXIT_FAILURE);
+		handle_interrupt();
 		if (master->links == NULL)
 			continue;
 
@@ -1098,8 +1092,7 @@ static void visitor(const void *nodep, const VISIT which, const int depth)
 		for (other = master->next; other != NULL; other = other->next) {
 			int eq;
 
-			if (handle_interrupt())
-				exit(EXIT_FAILURE);
+			handle_interrupt();
 
 			assert(other != other->next);
 			assert(other->st.st_size == master->st.st_size);
@@ -1413,12 +1406,7 @@ static void to_be_called_atexit(void)
 */
 static void sighandler(int i)
 {
-	UL_PROTECT_ERRNO;
-	if (last_signal != SIGINT)
-		last_signal = i;
-	if (i == SIGINT)
-		/* can't use stdio on signal handler */
-		ignore_result(write(STDOUT_FILENO, "\n", sizeof("\n")-1));
+	last_signal = i;
 }
 
 int main(int argc, char *argv[])
@@ -1430,7 +1418,6 @@ int main(int argc, char *argv[])
 	sa.sa_flags = SA_RESTART;
 	sigfillset(&sa.sa_mask);
 
-	/* If we receive a SIGINT, end the processing */
 	sigaction(SIGINT, &sa, NULL);
 	sigaction(SIGUSR1, &sa, NULL);
 
-- 
2.39.2
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEfWlHToQCjFzAxEFjvP0LAY0mWPEFAmcf1ckACgkQvP0LAY0m
WPE1ChAAhNnZLhk3Qhf9NS5VCqjEP/ucbBs5YjtjNEsDhiPfceRZGR386rQ4K/Uk
aNOZ1D6yVA5UlEE4lDdYJu9eAXnfyqgjl6dihIrMTSmkcAtchJINtOfjCIpJLEis
UcXO4lCLhjFmKFrJIJOlikc1WhdK0nuJzwQ5L50VdogFaBrgMzY9D0p5RZ+bHZms
rGxWsnTfcsl59ARE1osZcU16TqkHHKIp8M1DgFGNE289haG5SGt9aozYGx2LayZX
pAe+akonVgCrxwR3KRqEEP1Lqd7ZVImk5BuvZqkMrTjKgNOPxDGsJHdbLlGVmn7L
56rGnxMdoqcNHD9vZarwcDdkwGpBTq3cpczCkIdsEHEYpIMsldSXct2kGrsxtl5b
9I8q2cTjmmJAcSMfr3wrxTZrd2gV+mSm330kcU7ZhHjA+Oq9MJHvLy+mMM9KvOzA
cZI/a5HomvXR01OTjMtmXf+5LW66i/6fS+3vsBtNVB79iMSD0UjLQ2jCN30R2TFo
pOp7E1TR0BqEG8f483yxFbYPE0TahfnjD0q+QxDMtcIlJDCIW5wKV6i3U/A5sIB6
0YbNiqDCpF9qtUd39dVxKKr0zyW4PiTd8ciGiIOda3YeXnigX2WaYY1axJXV6BGu
t55ZH1bGtPnUGeFbAajlK/ro2X3Nls2ZuTBWoFtW7lwi4nK58bA=
=XHLs
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.