Forktest Passes when error line commented out

(Zachary Scott Moore) #1

Our forktest is passing when I comment out the errx for waitpid returning < 0. When the comment is included it seems as though the error reporting breaks the test.

I believe our waitpid is returning -1 properly because at some of the calls an ECHILD error should be returned.

What I think the issue is is that our console is not initialized correctly. STDIN STDOUT and STDERR all share the same vnode. I attempted to vfs_open 3 separate times however when passing in “con:” the second 2 opens fail with a file not found return.

I am aware vfs_open destroys the name however, I am casting the const “con:” to a char pointer 3 times rather than reusing a variable.

I have looked through most of the console code and the console just seems like a bit of a mystery to me.

(Geoffrey Challen) #2

These seem like two separate issues.

  1. Like the rest of the system calls, sys_waitpid should not return a negative value. They all return zero on success and non-zero on error. Or at least, that’s how the system call dispatcher expects them to return. If you look at the bottom it handles non-zero returns as errors. But you should not directly return negative values.
  2. Depending on how you are doing things with vfs_open your approach may not work. You need to make sure that the string gets reinitialized each time. For example, this doesn’t work:
const char[] console = "con:";
char * passed = &console;
vfs_open(passed, ...)
char * passed = &console;
vfs_open(passed, ...)

In this case the memory that is allocated to the string at the top is destroyed even if the pointer is reinitialized.

(Zachary Scott Moore) #3

In the forktest is it not appropriate to return -1 on some of the waitpid calls? It seemed when i was testing that some times the pids passed in should actually create an ECHILD error which would return -1.

Also regarding the console would doing something like this not safeguard around the string destroy issue?

vfs_open((char *)"con:", ...)
vfs_open((char *)"con:", ...)

After the first open the second fails on file not found however since I am not using a variable I am not destroying any strings. Does casting it mess up the process?

(David Robert Olsen) #4

I would explicitly duplicate the strings passed into vfs_open. It is possible the compiler tries to optimize it when you hardcode a string with the exact same characters in the same function multiple times.

(Zachary Scott Moore) #5

Looks like duping the str into 3 pointers and using that fixed it.

Also it must have been some overflow or something to the console because now that the console is fixed forktest passes as well.

Thanks for the help.

(Zachary Scott Moore) #7

Figured it out. Waitpid actually had a bug. Feeling pretty foolish right now.

Thanks for the console help fix though.

(Geoffrey Challen) #8

No worries. Glad you got it sorted.