fixing compiler warnings with "-O2 -Wall"

* mostly checking return values of chdir()/chown()/link()