On Mon, 1 Jul 2024 20:43:28 +0900
Takashi Yano wrote:
> On Mon, 1 Jul 2024 20:40:38 +0900
> Takashi Yano wrote:
> > On Mon, 6 May 2024 23:01:49 +0300
> > ilya Basin wrote:
> > > I need your help with troubleshooting an issue with "pv": 
> > > https://codeberg.org/a-j-wood/pv/issues/87
> > > 
> > > This app uses SIGALRM to interrupt a blocking write to STDOUT and read 
> > > more data into the buffer.
> > > On Linuxes write() returns 0 after the signal, but on Cygwin even though 
> > > the signal handler is called, the write call does not return, at least 
> > > when writing to a pipe.
> > 
> > What Linux environment you assume? I run the STC below on Debuan GNU/Linux,
> > 
> > #include <stdio.h>
> > #include <unistd.h>
> > #include <signal.h>
> > #include <errno.h>
> > #include <signal.h>
> > #include <string.h>
> > 
> > void handler(int sig)
> > {
> >     printf("sig=%d\n", sig);
> > }
> > 
> > int main()
> > {
> >     int fd[2];
> > 
> >     signal(SIGALRM, handler);
> >     pipe(fd);
> >     for (;;) {
> >             int l = write(fd[1], "A", 1);
> >             if (l == 1) {
> >                     printf("."); fflush(stdout); /* Normal */
> >             } else {
> >                     printf("%d: %s\n", l, strerror(errno)); /* Interrupt */
> >             }
> >     }
> > }
> > 
> > but,
> > kill -ALRM <pid of STC>
> > does not make output /* Interrupt */ line, but only /* Normal */ line.
> 
> and
> sig=14
> as well.
> 
> > uname -a:
> > Linux debian2 6.1.0-21-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.90-1 
> > (2024-05-03) x86_64 GNU/Linux
> > 
> > The behaviour is same with cygwin.

I got it. signal() sets SA_RESTART flag which prevent write()
from interrupt. Without SA_RESTART, I can see the behaviour
difference between linux and cygwin.

Now we are discussing how to fix that problem. Thansk.

P.S.
Attached is the my second STC. The STC without argument behaves
differently on cygwin from linux.

-- 
Takashi Yano <takashi.y...@nifty.ne.jp>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <string.h>

void handler(int sig)
{
	fprintf(stderr, "sig=%d\n", sig);
}

int main(int argc, char *argv[])
{
	int fd[2] = {0, 1};
	struct sigaction sa = {0,};

	sa.sa_handler = handler;
	if (argc > 1 && atoi(argv[1])) {
		sa.sa_flags = SA_RESTART;
	}
	sigaction(SIGALRM, &sa, NULL);

	if (isatty(1)) {
		pipe(fd);
	}

	for (;;) {
		int l = write(fd[1], "A", 1);
		if (l == 1) {
			fprintf(stderr, "."); fflush(stderr);
		} else {
			fprintf(stderr, "%d: %s\n", l, strerror(errno));
		}
	}
}
-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to