Logged-In As
Not Logged In
Fix bug bin/47065: /bin/sh returns success for Bad file descriptor The NetBSD Project
Status: Closed Time to complete: 240 hrs Mentors: Julian Coleman, Julian Fagir Tags: C, system

The shell returns a wrong error code when it should return an error (on a bad file descriptor).
In this task, you will go through the whole work of fixing a bug: You have to analyze the situation, find the source of that bug in the code, and finally fix it.

In this task, you will also learn much about how a shell internally works. This will help you definetely if you want to do shell programming some day, or just want to dig more into the internals of file descriptors.


Uploaded Work
File name/URL File size Date submitted
fixdiff.txt 118 bytes December 08 2012 10:31 UTC
diff.diff 21 bytes December 08 2012 10:32 UTC
Matthew on December 3 2012 00:37 UTC Preclaim

As soon as my other task gets reviewed, I'm going to claim this one.

Puck Meerburg on December 4 2012 06:47 UTC Task Claimed

I would like to work on this task.

Aleksej Saushev on December 4 2012 07:17 UTC Task Assigned

This task has been assigned to Puck Meerburg. You have 240 hours to complete this task, good luck!

Puck Meerburg on December 5 2012 15:46 UTC Problem building


I've got some problems compiling the /bin/sh sources. I got them, but got gcc: printf.o: No such file or directory when compiling. Do you know what the problem is?

Julian Fagir on December 6 2012 00:49 UTC How do you build it exactly?

What exactly are you doing to build it? If sh depends on other files, you have to build these first. I think building a whole release would solve the issue. Maybe you need less, but this would be the safe way.

Anyway, you can come to #netbsd-code on freenode to ask us questions. This is more direct than Google Melange (but be careful - at some times there won't be anybody awake on this channel). 

Puck Meerburg on December 6 2012 20:47 UTC Fixed

I fixed it by cvsing some other dependencies, but now *.netbsd.org is offline :(

Julian Fagir on December 7 2012 13:28 UTC It should be up again

Yep, there was a downtime yesterday. Anyway, things should be up and running now. You can always use one of the anoncvs servers, but probably didn't see them.

Puck Meerburg on December 7 2012 22:14 UTC Problems


I have some problems, mostly because the problem seems to ly in _exit, not sh: 

  • When being debugged, even without breakpoints, it just works.

  • The same binary not being debugged returns 0.

I can't seem to find the logic in this, even turning on DEBUG=2 makes it work...

Puck Meerburg on December 8 2012 10:31 UTC Ready for review

The work on this task is ready to be reviewed.

Puck Meerburg on December 8 2012 10:33 UTC Fixed it!

To make it work:

cvs checkout, then patch error.c with the included .diff!

Julian Fagir on December 9 2012 18:13 UTC The patch is correct

I just checked the patch, and it works, though I don't know what exactly you did. Apparently, you set the return code when an exception occurs, but I didn't dig deep enough into the code to evaluate how this affects other code.

Could you please elaborate what did not work and what you did now (also to have a commit message)? Anyway, the task is done, so I will mark it as closed now.

Julian Fagir on December 9 2012 18:13 UTC Task Closed

Congratulations, this task has been completed successfully.

Puck Meerburg on December 9 2012 18:47 UTC Message


I wrote this:

In eval.c, line 870 another handler is set for handling exceptions for when a command is running. When an error (EXERROR) occurs, this line will exit with value `exerrno`. This value, however, wasn't set when `exraise`ing (error.c) the exception. Therefore, all exceptions that happened while running a command would return 0.
This is fixed by adding `exerrno = e` to `exraise`, making generic errors exit with `1`.


Julian Fagir on December 9 2012 19:25 UTC Ok, fine

Ok, thank you, that is sufficient! Good luck with the next task (which is already assigned)!