sysprog21/lab0-c

In qtest.c, using non-reentrant function in signal handler can lead to unpredictable result.

Closed this issue · 2 comments

In sigsegvhandler(), report() is called, which invocates non-reentrant stdio functions.

I check signal-safety(7) — Linux manual page to determine whether a function is reentrant, and I wonder if this should be taken into consideration in this case.

In my opinion, using write() to stderr to replace stdio functions might be a solution.

@soyWXY , vfprintf would internally call write, thus, there is no need to consider reentrant issue in this case. Also, I suppose this lab would not raise reentrant problem. If there is no other concern, I will close the issue.

First, stdio is non-reentrant for some reasons. Explanation is in the second and third paragraph in description section over here. Further, stdio call might implicitly invocate malloc() which is also non-reentrant, so it is better to check the manual to determine if a library function is reentrant.

Second, about this lab, I'll say if any stdio function triggers SIGSEGV, the non-reentrant problem is raised, and formatted output can possibly do that.