mikeizbicki / ucr-cs100

open source software construction course
Other
485 stars 407 forks source link

get user error while running a script #284

Closed khuan013 closed 9 years ago

khuan013 commented 9 years ago

The getlogin() function works fine on my computer, and on well and hammer, but if I'm running a script I get an error. And then unless I start a new terminal, it continues to give me an error.

How can I fix this?

luizlopezm commented 9 years ago

yeah, I'm having the same issue as well, as having other program issues when running rshell on the script vs running it on the regular terminal

mikeizbicki commented 9 years ago

If you don't report the error message, then there's no way for us to help you figure out what the problem is.

luizlopezm commented 9 years ago

for me I don't get an error, it just doesn't show up on the script, my commands work find, everything works, but it just won't display the user and host name on the script, but it will if I run it on a regular terminal

luizlopezm commented 9 years ago

also some of my error statements won't print in the script, for example if I ran la -a && echo hello it would attempt to run la -a and realize its an error and print out the error, but it won't run echo hello like its supposed to but won't print the associating error message but in an actual terminal it would

khuan013 commented 9 years ago

I get the perror message that checks if getlogin() returns NULL.

Error getting user name: No such file or directory

mikeizbicki commented 9 years ago

Apparently this is a known issue with getlogin and the place in the OS it gets the login info from. It never happened in previous classes, so I wasn't aware of this.

Anyways, this stackoverflow question provides a suggested solution.

2c2c commented 9 years ago

the suggested command there is a syscall within a syscall. is your error detection script going to dock points considering it's technically 2 calls with one perr output?

mikeizbicki commented 9 years ago

@2c2c It is common for people to write the shortest possible code that gets the job done. But you must have proper error checking on all syscalls. So you will have to extend their example code.

2c2c commented 9 years ago

Apparently getuid never fails so there's only one check to be made anyways. Shoulda checked both functions before I asked.

mikeizbicki commented 9 years ago

You're right! Forget what I said before.