reverie-rs / reverie

trace and intercept linux syscalls.
Other
14 stars 5 forks source link

install signal handlers for SIGTTIN/SIGTTOU #21

Closed wangbj closed 5 years ago

wangbj commented 5 years ago

We should install sig handlers for SIGTTIN/SIGTTOU, otherwise commands like:

cat xxx | less

could get stuck, because the tracer sees SIGTTIN/SIGTTOU signals, and the default behavior of these signals is to stop the process.

This is fixed in commit 7ed33fd2, which install SIG_IGN sig handlers for them.

Sample test program:

#include <stdio.h>
#include <stdlib.h>

void
write_data (FILE * stream)
{
  int i;
  for (i = 0; i < 100; i++)
    fprintf (stream, "%d\n", i);
  if (ferror (stream))
    {
      fprintf (stderr, "Output to stream failed.\n");
      exit (EXIT_FAILURE);
    }
}

int
main (void)
{
  FILE *output;

  output = popen ("more", "w");
  if (!output)
    {
      fprintf (stderr,
               "incorrect parameters or too many files.\n");
      return EXIT_FAILURE;
    }
  write_data (output);
  if (pclose (output) != 0)
    {
      fprintf (stderr,
               "Could not run more or other error.\n");
    }
  return EXIT_SUCCESS;
}
wangbj commented 5 years ago

fixed in 7ed33fd as mentioned