In the previous assignment you used two named pipes to communicate with a pipecompiler program that executed lines of commands on the same machine. In this assignment you will replace this with a networkcompiler program that will execute these commands on a different machine.
Unless precautions are taken, when networkcompiler is running it allows anyone on the network to execute programs on your account. We will require that a password be sent to pipecompiler before it executes anything.
Think up a password to use for this assignment. It should be a short line of characters that will be hard coded into your networkcompiler and mymake programs. Do not show this password to anyone in the class and do not use the password you normally use to log into the CS network. As an added precaution, do not leave the networkcompiler program running when you are not using it.
Part 1
Write a networkcompiler program that takes a single command line
argument, a port number. It will be a parallel server like Program 18.2
from USP. When a connection is made, it will fork a child to handle the
connection. Write a handle_connection function that the
child will execute. Other than the call to handle_connection
instead of copyfile,
the networkcompiler program should be similar to the program
serverp from USP that you used in Recitation 9.
The handle_connection function will start by reading a line from the network and comparing it to your password. If it does not match, close the connection and have the child process terminate. Otherwise, read lines from the network and execute them as in your pipecompiler program, but send the response over the same network connection rather than through a separate replypipe. The child will continue reading and executing lines until the connection is closed. Notice that in this program, the lines are executed by a grandchild of the original process.
Note that the networkcompiler program is a parallel server and can handle several simultaneous connections. It should never terminate (unless it receives a signal, say from CTRL-C) once it is able to listen for connections on the given port number.
Be sure to terminate this program before you log off the machine.
Test this program by using a copy of client2, Program 18.5, from USP to send the password and lines to execute to your networkcompiler program.
Part 2
Rewrite you mymake program from Part 3
of the previous assignment so that it works with your networkcompiler
program of Part 1.
The command line arguments will be the filefile filename, a port number and
an arbitrary number of host names. These hosts will be assumed
to be running the networkcompiler program using the given port number.
The program should start by opening network connections to each of the given machines and sending them the password so that they will accept lines to execute. Other than that, it should work pretty much like your mymake from the previous assignment. Make any other modifications necessary.
Questions:
Testing your program.
You may use the first 4 makefiles from the previous assignment to test
your program. Modify the calls to mymake to use your port number
and two hosts on our network. Save the output as before for turning in.
In addition you will be demonstrating your programs in the lab on the due date during the normal class time. Instructions for doing so will be available at that time.
If you have nothing to demonstrate, hand this in to me in the lab at 12:30. Otherwise, wait for instructions in the lab. You will hand in your printouts after you demonstrate the programs.
If a part of this assignment is not completely working, you must describe in detail exactly how far you got in trying to get it to work, what you tested, and what results you got from these tests. This is necessary if you want to receive partial credit for the work you did.