X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=listati%2FMQFortuneServer.c;h=aec0e1eb713d6bf40d555e01ea9966909c0096e8;hp=cd0dd1ee430bc203193ec9a3bdfa15cfd77e9f0f;hb=d47f15496fa85c8ec22edcde608f2665ec5b95ae;hpb=b324b7a09e071b2f84a1849d109d4d14f27f44cd diff --git a/listati/MQFortuneServer.c b/listati/MQFortuneServer.c index cd0dd1e..aec0e1e 100644 --- a/listati/MQFortuneServer.c +++ b/listati/MQFortuneServer.c @@ -1,26 +1,26 @@ -int msgid; /* Message queue identifier */ +int msgid; /* Message queue identifier */ int main(int argc, char *argv[]) { /* Variables definition */ int i, n = 0; - char **fortune; /* array of fortune message string */ - char *fortunefilename = "/usr/share/games/fortunes/linux"; /* file name */ - struct msgbuf_read { /* message struct to read request from clients */ - long mtype; /* message type, must be 1 */ - long pid; /* message data, must be the pid of the client */ + char **fortune; /* array of fortune message string */ + char *fortunefilename = "/usr/share/games/fortunes/linux"; /* file name */ + struct msgbuf_read { /* message struct to read request from clients */ + long mtype; /* message type, must be 1 */ + long pid; /* message data, must be the pid of the client */ } msg_read; - struct msgbuf_write { /* message struct to write result to clients */ - long mtype; /* message type, will be the pid of the client*/ - char mtext[MSGMAX]; /* message data, will be the fortune */ + struct msgbuf_write { /* message struct to write result to clients */ + long mtype; /* message type, will be the pid of the client*/ + char mtext[MSGMAX]; /* message data, will be the fortune */ } msg_write; - key_t key; /* Message queue key */ - int size; /* message size */ + key_t key; /* Message queue key */ + int size; /* message size */ ... - Signal(SIGTERM, HandSIGTERM); /* set handlers for termination */ + Signal(SIGTERM, HandSIGTERM); /* set handlers for termination */ Signal(SIGINT, HandSIGTERM); Signal(SIGQUIT, HandSIGTERM); - if (n==0) usage(); /* if no pool depth exit printing usage info */ - i = FortuneParse(fortunefilename, fortune, n); /* parse phrases */ + if (n==0) usage(); /* if no pool depth exit printing usage info */ + i = FortuneParse(fortunefilename, fortune, n); /* parse phrases */ /* Create the queue */ key = ftok("./MQFortuneServer.c", 1); msgid = msgget(key, IPC_CREAT|0666); @@ -32,10 +32,10 @@ int main(int argc, char *argv[]) daemon(0, 0); while (1) { msgrcv(msgid, &msg_read, sizeof(int), 1, MSG_NOERROR); - n = random() % i; /* select random value */ + n = random() % i; /* select random value */ strncpy(msg_write.mtext, fortune[n], MSGMAX); size = min(strlen(fortune[n])+1, MSGMAX); - msg_write.mtype=msg_read.pid; /* use request pid as type */ + msg_write.mtype=msg_read.pid; /* use request pid as type */ msgsnd(msgid, &msg_write, size, 0); } } @@ -43,6 +43,6 @@ int main(int argc, char *argv[]) * Signal Handler to manage termination */ void HandSIGTERM(int signo) { - msgctl(msgid, IPC_RMID, NULL); /* remove message queue */ + msgctl(msgid, IPC_RMID, NULL); /* remove message queue */ exit(0); }