Third FAQ

for

Project 4 -- IPC

Q. Ok, I just started getting my command line formatting functions working, and there seems to be an issue. If I pass ~user1234 into the system, it automatically converts this to /home/user1234/ for me. Can I count on this happening, or should I find some way to disable it and use the passwd file?

Gotta love walking blindly into features.

A. When I specified in the assignment that the address of server FIFO should be of the form "~<username>/primeserv", I just meant to indicate that it should be in the home directory of the user running the server, not that your program would need to know how to parse "~<username>".

This means that I am requiring that the server use a function for getting a user's home directory from the password file based on the UID of the user running the server.

However, I will allow the client to simply accept whatever addresses it gets in argv[], without needing to covert "~<username>" into the user's home directory. (You are already getting the experience of pulling home directory information out of the password file from doing the server code. Asking you to covert "~<username>" into the user's home directory in the client code would mostly be an exercise in string manipulation in C -- mostly pain but little gain.)


Q. I have been having problems opening FIFO's in primeatschool program.

 
if(mkfifo(fifo,0666) == -1)       
        {
                if(errno != EEXIST) 
                        perror("receiver: mkfifo");
        }
  
        if((fd = open(fifo, O_WRONLY|O_NONBLOCK)) < 0)
        {
                perror("FIFO open failed");
        }
  
  
FIFO open failed: No such file or directory 
message write failed: Bad file number

Would you happen to know the reason why i'm having these problems?

A. Without seeing more of your code and the situation in which it is running, I can only make an educated guess but here goes.

You are getting a message that corresponds with ENOENT which means that there is no entry in the file system under the name you have provided to the system call. So, for example, if I set the value of fifo to "~hougen/myfifo" (with, for example, char *fifo="~hougen/myfifo";) before the code that you have provided, it would give me an ENOENT error, because there is no "~hougen" directory on our machines. (Note that I can type "cd ~hougen" on the command line to my shell and have it work because the shell -- NOT the O/S -- translates this into "/home/hougen" for me.)

On the other hand, if you had used a non-existent file name, you should have seen the message "No such file or directory" appear twice -- once for the failure to make the FIFO and again for the failure to open it. Did you by any chance snip off one of the error messages when you copied them into your email?


Q. I have a problem in my project in the first part. For a client, everytime when Itype primeatchool.c <server address> <client address>. It will produce a client fifo. But when the next time, if I want to run primeatschool.c <server address> <client address>, I have to remove the client fifo. Otherwise, the screen will show up the error message. It said the client fifo open failed. I don't know what is the problem. Do you know what is the problem?

A. The O/S is just doing what is it supposed to do -- mkfifo should fail with the error EEXIST (File exists) if you try to create a FIFO that is already there. This is just the same type of behavior that you would get if you tried to open a file using the O_CREAT and O_EXCL flags.

Probably the easiest thing to do is to check the value of errno after mkfifo fails. If errno is set to EEXIST, then go ahead and try to open the FIFO. If you can open the FIFO, check its permissions, change them if needed, and go on.


Q. Ihave a doubt regarding primeatschoolfile..when some runs my server program (part1) ,does my server starts sending the numbers from the start as if it started just then, or should the user running my server import my primeatschoolfile and get the numbers as per the missed number sequence . can you please clarify doubt asap..

A. As the assignment indicates, when primeatschoold starts up, it should read primeatschoolfile. This is true regardless of who runs primeatschoold.

Note, however, that there is no reason that anyone other than the owner of primeatschoold. should be running it. You do not need to, and should not, give execute permissions for primeatschoold to anyone other than its owner.


Q. What sort of data structures should we use to hold the numbers that we are checking for primality?

A. long