Question: 3 . 2 logservice . c 3 . 4 logserver . c 3 . 5 makefile 3 . 6 launch _ s Pl write a
logservicec logserverc makefile
launchs
Pl write a complete working code in detail for below one. Thanks
logserviceh Specification
The task is broken into two parts, a message logging server, and a library to log messages. The
message server listens to a message queue and extracts the log messages from it The library
provides a more convenient way access the message queue.
You have been provided with a program to test that your library communicates with your
server. You will need to review the lecture notes, and the documentation supplied in Section
to implement these programs.
Message Logging Server
The message logging server should attempt to create the message queue, if this fails then it
should terminate with an error message, it should not run if the message queue actually exists
IPCEXCL will help here
Once connected to the message queue, the program should sit in a loop, receiving a message, and printing it to the stdout. Messages should be formatted:
id: message
where id is the type from the message structure and message is the message field.
The server should shutdown cleanly ie delete the message queue on receipt of a SIGINT
generated by pressing control and C keys at the same time
The sample code files logserviceh and logserverc should form the basis of
your solution for this part. There are a number of comments in this file to help you structure
your code.
Messaging library
The messaging library consists of two functions, both defined in logserviceh:
int initLogService
This function should initialise the message queue to log messages to returning
an id if successful, and on error.
This function should not attempt to create the message queue, only attach it to
the process.
int logMessageint id char message
This function logs the message passed as the string message to the log
service id It should return on success and on error.
When sending a message, the function should encode the processes pid into
the type field of the message, and the string into the message field.
It is your choice what to do if the message is too long ie longer than
MSGCHARS sample behaviours include breaking the message up into
smaller pieces or simply rejecting it Whatever the choice, the documentation in
the header file should reflect this choice.
The sample code files logserviceh and logservicec should form the basis of
your solution for this part.
Sample Code
In addition to the sample code files, two additional files have been provided, a makefile
that contains build rules, and a server launch script.
The make utility simplifies the build process for large projects, introductory documentation for make is included in the documentation section Sec To use make to automate compile process simply type make at the terminal in the same directory as the other
files it will use the rules defined in the makefile to build both the logserver and
logclient executables from the source files, and it will also ensure that the
launch server.sh script is executable. If none of the source files have changed since
the last build based on their timestamps the make utility will not rebuild the executables.
There should be no need to modify the makefile, its format is a bit fussy so it is safer to
download the file from vUWS than type it up
The launch server.sh script will open the logserver program in a new terminal window for you. This script detects the host operating system and performs an equivalent action after this detection. There is nop need to understand how this file achieves its goal. Validate message length here
logservicec
logservicec implementation of the log service
Dr Evan Crawford ecrawford@westernsydney.edu.au
COMP Operating Systems Programming
Practical Case Study C
This is the sample file
#include "logservice.h
int logServiceInit
int id;
TODO: connect to message queue here
return id;
int logMessageint serviceId,char message
int rv;
printfThe message is s
message;
TODO: Validate message length here
TODO: Send the message
return rv;
logclientc
logclientc implements a simple log service client
Dr Evan Crawford ecrawford@westernsydney.edu.au
COMP Operating Systems Programming
Practical Case Study C
This is the sample file
#include "logservice.h
int mainint argc,char argv
int id;
Check if arguments are present on command line
if argc
fprintfstderr "Usage: s message", argv;
exit;
connect to the log service
ifid logServiceInit
perrorConnecting to queue";
exit;
log the message supplied on the command line
if logMessageid argv
perrorSending Message";
exit;
return ;
logserverc
logserverc implementation of the log server
Dr Evan Crawford ecrawford@westernsydney.edu.au
COMP Operati
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
