Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[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 . This main function listens for any client connections, and when one is accepted, it creates a new thread at the thread routine function called recv_log_msgs

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 #include #include #include #include #include #include #include #include #include "message-lib.h"

// 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 ", name ); return 1; }

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

(12) What gaps are there in the current approach to development?

Answered: 1 week ago

Question

(3) What does a good leader look like now and in the future?

Answered: 1 week ago