CSCI 4061 Lab10: Email Lookup Upgrade
- Due: 11:59pm Mon 4/12/2021 on Gradescope
- Approximately 1.00% of total grade
CODE DISTRIBUTION: lab10-code.zip
- Download the code distribution
- See further setup instructions below
CHANGELOG:
- Mon Mar 29 09:46:08 AM CDT 2021
- The missing
run_simulation.sh
testing script has been added to the codepack. It can be downloaded separately here: run_simulation.sh
Table of Contents
1 Rationale
This Lab revisits the email lookup client/server programs from a
previous HW. These programs use a FIFO to communicate and to get more
experience with them, they will be improved to a "version 2". This
upgrade allows email addresses to be looked up via a GET
request
from the client as well as email addresses to be changed via a PUT
request. This gives some practical experience working with FIFOs and
protocols on them along with practicing how to use a signal handler to
gracefully shut down the server which may be in the middle of a
read()
from the reqeust FIFO.
Grading Policy
Credit for this Lab is earned by completing the exercises here and
submitting a Zip of the work to Gradescope. Students are responsible
to check that the results produced locally via make test
are
reflected on Gradescope after submitting their completed
Zip. Successful completion earns 1 Engagement Point.
Lab Exercises are open resource/open collaboration and students are encouraged to coopearte on labs. Students may submit work as groups of up to 5 to Gradescope: one person submits then adds the names of their group members to the submission.
See the full policies in the course syllabus.
2 Codepack
The codepack for this lab is linked at the top of this document. Always download it and unzip/unpack it. It should contain the following files which are briefly described.
File | Use | Description |
---|---|---|
QUESTIONS.txt |
EDIT | Questions to answer: fill in the multiple choice selections in this file. |
em_client2.c |
EDIT | C file to study to complete for the CODE portion; TODO sections are marked |
em_server2.c |
EDIT | C file to study to complete for the CODE portion; TODO sections are marked |
em.h |
Header | Header file with includes and types for programs |
QUESTIONS.txt.bk |
Backup | Backup copy of the original file to help revert if needed |
Makefile |
Build | Enables make test and make zip |
testy |
Testing | Test running scripts |
test_lab10.org |
Testing | Tests for this lab |
test_pid_filter |
Testing | Used to standardize PIDs during testing |
test_quiz_filter |
Testing | Used to simplify quiz checksum |
3 Review HW09
If you have not yet worked on HW09's em_server / em_client
, you
should spend some time examining the code and exercises there as this
lab builds on them. Briefly, the programs introduced there are
em_server.c
: creates arequests.fifo
FIFO and lists for requests on it which are structs of typerequest_t
. Uses the data passed in to look up an the email address for a person based on their name and respond to it.em_client.c
: accepts a person's name as a command line argument and then communicates withem_server
to get their email address. First creates a personalized FIFO based on the process's PID to receive a response, then writes a request to the server'srequests.fifo
for the given name. Waits on a response and prints it to the screen.
These programs are upgraded to em_client2.c
and em_server2.c
with
some expanded functionality. This upgrade is much easier if one is
already familiar with the old version.
4 Version 2
This lab upgrades the server and client to allow existing email addresses to be changed. This is done via calling the client in one of two ways:
> ./em_client2 GET 'James Moen' # retrieve email address for for person > ./em_client2 PUT 'James Moen' 'NEWADDRESS@MAIL.COM' # assign a new address to person
To facilitate either of PUT / GET
, the structs that go into the
requests.fifo
have been changed to the following type which includes
more information.
// From em.h header file #define BUFSIZE 128 typedef struct { char client_fifo[BUFSIZE]; // filename of FIFO on which to respond char command[BUFSIZE]; // GET or PUT char name[BUFSIZE]; // name of person for GET / PUT command char new_email[BUFSIZE]; // new email address for PUT } request_t;
The new fields allow clients to formulate either a GET / PUT
request
to which the server must respond appropriately.
Study the code in the original version and the provided outlines in
em_server2.c / em_client2.c
and complete the TODO portions of the code.
5 QUESTIONS.txt File Contents
Below are the contents of the QUESTIONS.txt
file for the lab.
Follow the instructions in it to complete the QUIZ and CODE questions
for the lab.
__________________ LAB 10 QUESTIONS __________________ Lab Instructions ================ Follow the instructions below to experiment with topics related to this lab. - For sections marked QUIZ, fill in an (X) for the appropriate response in this file. Use the command `make test-quiz' to see if all of your answers are correct. - For sections marked CODE, complete the code indicated. Use the command `make test-code' to check if your code is complete. - DO NOT CHANGE any parts of this file except the QUIZ sections as it may interfere with the tests otherwise. - If your `QUESTIONS.txt' file seems corrupted, restore it by copying over the `QUESTIONS.txt.bk' backup file. - When you complete the exercises, check your answers with `make test' and if all is well, create a zip file with `make zip' and upload it to Gradescope. Ensure that the Autograder there reflects your local results. - IF YOU WORK IN A GROUP only one member needs to submit and then add the names of their group. QUIZ Questions sigaction() function =================================== When a signal is received while a `read()' call is taking place, the OS will automatically restart the `read()' system call if the `SA_RESTART' flag is used when setting up a signal handler. However, if one wants to cause a program to shut down on receiving a signal, it is best to - ( ) Use SA_RESTART as normal; all `read()' calls will eventually complete. - ( ) Don't use signal handlers at all: it is not possible to perform `read()' calls and perform signal handling. - ( ) NOT use the SA_RESTART flag; then check for `read()' to return -1 along with some global variable being set by a signal handler. The correct system call to create a FIFO / named pipe is with user read/write permission is: - ( ) `pipe("requests.fifo", S_IRUSR | S_IWUSR);' - ( ) `mkfifo("requests.fifo", S_IRUSR | S_IWUSR);' - ( ) `newfifo("requests.fifo", S_IRUSR | S_IWUSR);' - ( ) `creat("requests.fifo", S_IRUSR | S_IWUSR);' CODE Complete em_client2 and em_server2 ======================================= Complete the template for upgraded versions of the em_client / em_server from a previous HW. These programs cooperate in the following way: - em_server2.c maintains a small database of name / email addresses for people and responds to requests concerning that data via `requests.fifo' - em_client2.c allows one to GET email addresses, like the old version or PUT a new email address in associated with an existing person Much of the code in these is provided with some TODO and ??? portions that must be filled in. As indicated above, the improvement over the original version of the server/client is the ability to modify the email address associated with existing names. The basic functionality for the two programs is shown in the following demo. Note that the example intersperses two terminals, the first which runs `em_server2' and the second which runs several instances of `em_client2'. ,---- | $term1>> ./em_server2 | SERVER #167476: starting up | SERVER #167476: created new requests.fifo, now opening it | SERVER #167476: opened requests.fifo, listening for requests | | $term2>> ./em_client2 GET 'Chris Kauffman' | CLIENT #167477: sending request {client_fifo='167477.fifo' command='GET' name='Chris Kauffman' new_email=''} | CLIENT #167477: opening '167477.fifo' | CLIENT #167477: fifo opened, awaiting server response | CLIENT #167477: response for 'GET Chris Kauffman' is: kauffman@umn.edu | | SERVER #167476: received request {client_fifo='167477.fifo' command='GET' name='Chris Kauffman' new_email=''} | SERVER #167476: opening client FIFO '167477.fifo' | SERVER #167476: for name 'Chris Kauffman' writing response 'kauffman@umn.edu' | SERVER #167476: closing connection to fifo '167477.fifo' | | $term2>> ./em_client2 GET 'James Moen' | CLIENT #167482: sending request {client_fifo='167482.fifo' command='GET' name='James Moen' new_email=''} | CLIENT #167482: opening '167482.fifo' | CLIENT #167482: fifo opened, awaiting server response | CLIENT #167482: response for 'GET James Moen' is: moen0017@cs.umn.edu | | SERVER #167476: received request {client_fifo='167482.fifo' command='GET' name='James Moen' new_email=''} | SERVER #167476: opening client FIFO '167482.fifo' | SERVER #167476: for name 'James Moen' writing response 'moen0017@cs.umn.edu' | SERVER #167476: closing connection to fifo '167482.fifo' | | $term2>> ./em_client2 PUT 'James Moen' 'NEWADDRESS@MAIL.COM' | CLIENT #167486: sending request {client_fifo='167486.fifo' command='PUT' name='James Moen' new_email='NEWADDRESS@MAIL.COM'} | CLIENT #167486: opening '167486.fifo' | CLIENT #167486: fifo opened, awaiting server response | CLIENT #167486: response for 'PUT James Moen' is: email for 'James Moen' updated to 'NEWADDRESS@MAIL.COM' | | SERVER #167476: received request {client_fifo='167486.fifo' command='PUT' name='James Moen' new_email='NEWADDRESS@MAIL.COM'} | SERVER #167476: opening client FIFO '167486.fifo' | SERVER #167476: for name 'James Moen' writing response 'email for 'James Moen' updated to 'NEWADDRESS@MAIL.COM'' | SERVER #167476: closing connection to fifo '167486.fifo' | | $term2>> ./em_client2 GET 'James Moen' | CLIENT #167488: sending request {client_fifo='167488.fifo' command='GET' name='James Moen' new_email=''} | CLIENT #167488: opening '167488.fifo' | CLIENT #167488: fifo opened, awaiting server response | CLIENT #167488: response for 'GET James Moen' is: NEWADDRESS@MAIL.COM | | SERVER #167476: received request {client_fifo='167488.fifo' command='GET' name='James Moen' new_email=''} | SERVER #167476: opening client FIFO '167488.fifo' | SERVER #167476: for name 'James Moen' writing response 'NEWADDRESS@MAIL.COM' | SERVER #167476: closing connection to fifo '167488.fifo' | | C-c | SERVER #167476: Signalled to shut down | SERVER #167476: main loop complete, cleaning up | | $term1>> `----
6 Submission
Follow the instructions at the end of Lab01 if you need a refresher on how to upload your completed lab zip to Gradescope.