head 1.3; access; symbols; locks alexis:1.3; strict; comment @ * @; 1.3 date 97.01.31.14.43.34; author alexis; state Exp; branches; next 1.2; 1.2 date 97.01.31.10.22.48; author alexis; state Exp; branches; next 1.1; 1.1 date 97.01.22.10.34.43; author alexis; state Exp; branches; next ; desc @@ 1.3 log @MILEPOST - MAY NOT WORK @ text @#include /* for NULL */ #include /* for IPC support */ #include /* for IPC */ #include /* for IPC/MSG */ #include /* for errno */ #include /* for va_lists */ #include /* for calloc(), atoi() */ #include /* for strtok() */ #include "pppld_msgids.h" #include "pppld_utils.h" #include "pppld_ipc.h" int key = 1234; int msqid; static char *rcs_id = "$Id$"; struct msgrec { long mtype; char mtext[MAX_MSG_SIZ]; }; int id2infidx( struct msginfrec *msginfdatp, int msgid) { int msgidx; debug(DBG_FUNCS, "id2infidx: sof"); for (msgidx=0; (msginfdatp+msgidx)->id != msgid && (msginfdatp+msgidx)->id != MSGID_LAST_MARKER; msgidx++) ; if ((msginfdatp+msgidx)->id == MSGID_LAST_MARKER) { internal("(%s,%d): failed to locate msgid %d in table", __FILE__, __LINE__, msgid); return(-1); } return(msgidx); } int id2mhfidx( struct mhflkuprec *mhflkupdatp, int msgid) { int msgidx; debug(DBG_FUNCS, "id2mhfidx: sof"); for (msgidx=0; (mhflkupdatp+msgidx)->id != msgid && (mhflkupdatp+msgidx)->id != MHF_LAST_MARKER; msgidx++) ; if ((mhflkupdatp+msgidx)->id == MHF_LAST_MARKER) { internal("(%s,%d): failed to locate msgid %d in table", __FILE__, __LINE__, msgid); return(-1); } return(msgidx); } int pppld_ipc_send_msg( struct msginfrec *msginfdatp, int towhome, int msgid, int *mp) { struct msgrec sbuf; int msgidx; int i; debug(DBG_FUNCS, "pppld_ipc_send_msg: sof"); /* * Mark who the message is for, and put the message id in the message * text. */ sbuf.mtype = towhome; sprintf(sbuf.mtext, "%d ", msgid); /* * Look up how many parameters this message type has and copy them out * of the passed memory block into the message text. */ if ((msgidx=id2infidx(msginfdatp, msgid)) < 0) return(1); for (i=0; i<(msginfdatp+msgidx)->argc; i++) sprintf(sbuf.mtext+strlen(sbuf.mtext), "%d ", *(mp+i)); /* * Append the message text (not important for programs, but looks nice * if we ever get to making this use AF_INET sockets instead of IPC. */ sprintf(sbuf.mtext+strlen(sbuf.mtext), "(%s)", (msginfdatp+msgidx)->cmt); /* * Dispatch the message. */ debug(DBG_IPCMSG, "pppld_ipc_send_msg: sending to %d: %s", towhome, sbuf.mtext); if (msgsnd(msqid, (struct msgbuf *) &sbuf, strlen(sbuf.mtext) + 1, 0) < 0) { perror("msgsnd"); exit(1); } /* * It's up to the caller to free the memory block if it wants. * Though if this is being called by the delayed message queue then it * will free it up after this function gets called, having taken a * copy when it itself was called. */ return(0); } pppld_ipc_server_init() { debug(DBG_FUNCS, "pppld_ipc_server_init: sof"); return(((msqid=msgget(key, IPC_CREAT | 0666)) < 0) ? -1 : 0); } pppld_ipc_client_init() { debug(DBG_FUNCS, "pppld_ipc_client_init: sof"); return(((msqid=msgget(key, 0666)) < 0) ? -1 : 0); } pppld_ipc_server_shutdown() { debug(DBG_FUNCS, "pppld_ipc_server_shutdown: sof"); msgctl(msgget(key, 0666), IPC_RMID, NULL); } int pppld_ipc_read_msg( struct msginfrec *msginfdatp, int towhome, struct mhflkuprec *mhflkupdatp) { struct msgrec rbuf; int msgid; int rc; int parcnt; int *mp; int i; char *cp; int msgidx; debug(DBG_FUNCS, "pppld_ipc_read_msg: sof"); debug(DBG_IPCMSG, "pppld_ipc_send_msg: awaiting msg to %d", towhome); while ((rc=msgrcv(msqid, (struct msgbuf *) &rbuf, MAX_MSG_SIZ, towhome, 0)) < 0 && errno == 4) debug(DBG_IPCMSG, "pppld_ipc_read_msg: ignoring interrupted system call"); if (rc < 0) perror("msgrcv"); debug(DBG_IPCMSG, "pppld_ipc_read_msg: recd msg for %d: %s", towhome, rbuf.mtext); /* * Get the message id, and allocate enough memory for the number of * parameters that this message should have. Then read the parameters * checking that there are the right number. */ msgid = atoi(strtok(rbuf.mtext, " ")); parcnt = (msginfdatp+id2infidx(msginfdatp, msgid))->argc; if ((mp=((int *) calloc(parcnt, sizeof(int)))) == NULL) { perror("calloc"); exit(1); } for (i=0; (cp=strtok(NULL, " ")) != NULL && ifnc)(mp); free(mp); return(0); } @ 1.2 log @WORKING MILESTONE @ text @d17 2 d31 2 d48 2 d69 15 a85 2 sprintf(sbuf.mtext, "%d ", msgid); d88 6 a94 1 sbuf.mtype = towhome; d96 5 d105 7 a111 1 debug(DBG_MSGMAJ, "pppld_ipc_send_msg: sent to %d: %s", towhome, sbuf.mtext); d118 2 d125 2 d132 2 d151 2 a152 1 debug(DBG_MSGMIN, "pppld_ipc_send_msg: awaiting msg to %d", towhome); d155 1 a155 1 debug(DBG_MSGMIN, "pppld_ipc_read_msg: ignoring interrupted system call, waiting again"); d158 1 d160 5 a164 1 debug(DBG_MSGMAJ, "pppld_ipc_read_msg: recd in %d: %s", towhome, rbuf.mtext); d177 1 a177 1 info("comments on message %d", msgid); d181 6 a188 1 @ 1.1 log @Initial revision @ text @d6 3 d12 1 d23 2 a24 1 char *msgid2txt( d29 3 a31 4 for (msgidx=0; msgid2txtdat[msgidx].id!=MSGID_LAST_MARKER; msgidx++) if(msgid2txtdat[msgidx].id == msgid) break; if (msgid2txtdat[msgidx].id == MSGID_LAST_MARKER) d33 3 a35 3 debug(DBG_MSGMIN, "msgid2txt: converted %d to %s", msgid, msgid2txtdat[msgidx].txt); return(msgid2txtdat[msgidx].txt); d38 3 a40 2 int msgtxt2id( char *buf) d44 7 a50 9 for (msgidx=0; msgid2txtdat[msgidx].id!=MSGID_LAST_MARKER; msgidx++) if (strcmp(buf, msgid2txtdat[msgidx].txt) == 0) break; if (msgid2txtdat[msgidx].id == MSGID_LAST_MARKER) internal("(%s,%d): failed to locate msgtxt %s in table", __FILE__, __LINE__, buf); debug(DBG_MSGMIN, "msgtxt2id: converted %s to %d", buf, msgid2txtdat[msgidx].id); return(msgid2txtdat[msgidx].id); d54 1 d56 2 a57 1 char *buf) d60 2 d63 2 d66 4 a69 1 strcpy(sbuf.mtext, buf); d76 1 a76 1 debug(DBG_MSGMAJ, "pppld_ipc_send_msg: sent msg to %d: %s", towhome, buf); d93 1 a93 1 msgctl(msqid, IPC_RMID, NULL); a95 1 d97 1 d99 1 a99 1 char *buf) d102 1 d104 5 d110 1 a110 1 debug(DBG_MSGMAJ, "pppld_ipc_send_msg: awaiting msg to %d", towhome); d117 23 a139 2 strcpy(buf, rbuf.mtext); debug(DBG_MSGMAJ, "pppld_ipc_read_msg: recd msg to %d: %s", towhome, buf); @