Request for review: 6749267: Signal handler should save/restore errno

harold seigel harold.seigel at
Mon Feb 18 12:29:12 PST 2013

Hi Serguei,

Thanks for reviewing this!

I think that the perror() message will also be preserved.  I tried this 
with a small C++ program:

    #include <stdio.h>
    #include <errno.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <unistd.h>

    int main(int argc, char * argv[]) {
       char buf[20];
       int old_errno;
       int bad_fd = 23;
       int res = open("/i/dont/exist", O_RDONLY);
       old_errno = errno;
       perror("errno: ");

       res = read(bad_fd, buf, 10);
       perror("errno: ");

       errno = old_errno;
       perror("errno: ");
       return 0;

When I ran this program, I got the following result:

    % ./a.out
    errno: : No such file or directory
    errno: : Bad file descriptor
    errno: : No such file or directory

Hopefully, our code will behave the same way.

Thanks, Harold

On 2/18/2013 3:10 PM, serguei.spitsyn at wrote:
> Looks good.
> I'm not sure it is an ultimate solution though.
> The error message that is reported by the perror() might be lost as well,
> but I'm not sure yet if it is possible to restore it as well.
> A link:
> Thanks,
> Serguei
> On 2/18/13 6:07 AM, harold seigel wrote:
>> Hi,
>> Please review the following change.
>> Summary: With this change, the actual signal handler saves the errno 
>> before calling the function that does most of the signal handling 
>> processing.  It then restores the value of errno when the signal 
>> handling processing function returns.
>> Open webrev: 
>> <>
>> Bug link at:
>> The changes were tested with JPRT, JCK Lang and VM tests, UTE tests, 
>> and with JPRT.  Also, I used the debugger to change the value of 
>> errno inside of the signal handling processing method and then 
>> verified that it got restored properly.
>> Thanks!  Harold

-------------- next part --------------
An HTML attachment was scrubbed...

More information about the hotspot-runtime-dev mailing list