Question: [C] I am writing a small UDS server for an assignment. The code is tested by a shell script which sends several different test calls
[C]
I am writing a small UDS server for an assignment.
The code is tested by a shell script which sends several different test calls to the main function of my code. The only things passed to main are a log file name, and a UDS path, and then different clients connect to the server, which should simply result in a particular output log to check for correctness of the sever code.
the usage should be myloggerd
The server must create the log file the first time it is started. Thereafter, the server must append messages to the existing log file.
The server must write the messages EXACTLY as received to the log file and in the order received. Further, the server must NOT write any additional data to the log file.
Here is the skeletal file. Please help
/* myloggerd.c * Source file for thread-lab * Creates a server to log messages sent from various connections * in real time. * * Student: */ #include
// forward declarations int usage( char name[] ); // a function to be executed by each thread void * recv_log_msgs( void * arg );
// globals int log_fd; // opened by main() but accessible by each thread
void * recv_log_msgs( void * arg ){ // loops to receive messages from a connection; // when read_msg returns zero, terminate the loop // and close the connection
return NULL; }
int usage( char name[] ){ printf( "Usage: " ); printf( "\t%s
int main( int argc, char * argv[] ) { if ( argc != 3 ) return usage( argv[0] ); // open the log file for appending // permit message connections // loop to wait for connection requests; // as each connection is accepted, // launch a new thread that calls // recv_log_msgs(), which receives // messages and writes them to the log file // when accept_next_connection returns -1, terminate the loop // close the listener // close the log file
return 0; }
If your server works correctly, it will be able to accept multiple client connections simultaneously and record log messages, in the order received, to the log file. Your server will be evaluated using the test-messages executable; it is expected to create the log file based on a command line argument. At the completion of the test, the log file should look substantially similar to the following:
LOGGER 139766793697024: msg 1 LOGGER 139766785304320: msg 1 LOGGER 139766776911616: msg 1 LOGGER 139766793697024: msg 2 LOGGER 139766785304320: msg 2 LOGGER 139766776911616: msg 2 LOGGER 139766793697024: msg 3 LOGGER 139766785304320: msg 3 LOGGER 139766776911616: msg 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
