Stopping server message comes from the
stop() function defined here:
* Stop server, deallocating any resources.
// preserve errno across this function's library calls
int errsv = errno;
// announce stop
// free root, which was allocated by realpath
if (root != NULL)
// close server socket
if (sfd != -1)
// stop server
This function is called at seven other places in the code.
// check for control-c
The other six calls to
stop() are all part of the
start() function, which is worth a close reading even though you don't have to write any part of it. There are six different ways that the
start() function can fail, and if any of them occur, the
stop() function is called so that the server will fail gracefully and
free() any memory that has been allocated.
The first two tests are particularly important to understand:
// path to server's root
root = realpath(path, NULL);
if (root == NULL)
// ensure root is executable
if (access(root, X_OK) == -1)
What this means is that the server's root must exist (i.e., you cannot just start
./server asdf;lksdfha;sdlfkhdlkfh;l and expect it to work), and that the server's root must be a directory with the executable bit set (i.e., you cannot set the root directory to a file, as by starting
./server ~/workspace/pset6/public/cat.html and expect it to work).
Furthermore, you need to understand that the full
/path/to/root may be specified as either an absolute or relative pathname.
If you have set your current working directory to the pset directory via
cd ~/workspace/pset6/, then you can simply start
./server public and it should work with the relative pathname, since
./public is in the current directory.
But if you start the pathname with a slash (
/) character, that's an absolute pathname and needs to be specified all the way from the root directory, like so:
If this answers your question, be sure to accept my answer by clicking on the green check mark. Otherwise, the forum will continue to list this as a zombie unanswered question, and it will haunt the lists of unanswered questions forever!