Next: My Home Page
Answers
- This is just a case of adding the daemon startup code to the beginning of the previous exercise. You might also take the opportunity to make your chat program more robust in its error checking and more fully featured in its facilities. For example, you might like to get users to follow some login protocol so that their login names can be added to all their messages to identify message sources to other chat users.
- Adding a message command to the tiny shell just involves adding a call to a do_message() function into builtin(). The do_message() function will extract the user's login name from the system (look at getenv("LOGNAME") or getpwuid()) and the message from the line[] array and write() these to the named pipe. The daemon will open the named pipe for read() access take message lines from the pipe as they arrive, read the wall clock time with the time() call and write the message and time information to the message file. With root access you can make the daemon program, the pipe and the message file owned by root. Then give the daemon program read access to the pipe and write access to the message file. Other users should get write access to the pipe and no access to the message file.
Next: My Home Page