head 1.11; access; symbols new_system:1.8 old_system:1.7; locks alexis:1.11; strict; comment @ * @; 1.11 date 99.01.07.13.15.26; author alexis; state Exp; branches; next 1.10; 1.10 date 98.10.07.16.22.41; author alexis; state Exp; branches; next 1.9; 1.9 date 98.08.28.13.12.26; author alexis; state Exp; branches; next 1.8; 1.8 date 98.08.08.09.47.47; author alexis; state Exp; branches; next 1.7; 1.7 date 98.08.07.14.49.25; author alexis; state Exp; branches; next 1.6; 1.6 date 98.08.07.11.28.42; author alexis; state Exp; branches; next 1.5; 1.5 date 97.11.11.11.57.48; author alexis; state Exp; branches; next 1.4; 1.4 date 97.10.26.12.12.30; author alexis; state Exp; branches; next 1.3; 1.3 date 97.02.21.17.09.02; author alexis; state Exp; branches; next 1.2; 1.2 date 97.02.09.16.00.50; author alexis; state Exp; branches; next 1.1; 1.1 date 97.02.01.21.52.17; author alexis; state Exp; branches; next ; desc @MILEPOST - WORKS @ 1.11 log @symbol name changes @ 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 /* for getpwuid() */ #include /* for getgrgid() */ #include "ppplcd_msgids.h" #include "utils.h" #include "ppplcd_ipc.h" int key = 1234; int msqid; static char *ppplcd_ipc_c_rcs_id = "$Header: /diskb/home/alexis/dev/supported/ppplc/bin/RCS/ppplcd_ipc.c,v 1.10 1998/10/07 16:22:41 alexis Exp alexis $"; struct msgrec { long mtype; char mtext[MAX_MSG_SIZ]; }; int lookup_msginfo( struct msginfrec *msginfo_datap, int msgid) { int msgidx; debug(DBG_FUNCS, "lookup_msginfo: sof"); for (msgidx=0; (msginfo_datap+msgidx)->id != msgid && (msginfo_datap+msgidx)->id != MSGID_LAST; msgidx++) ; if ((msginfo_datap+msgidx)->id == MSGID_LAST) { internal("(%s:%d): failed to locate msgid %d in table", __FILE__, __LINE__, msgid); return(-1); } debug(DBG_FUNCS, "lookup_msginfo: eof"); return(msgidx); } int lookup_msgmhf( struct mhflkuprec *mhf_datap, int msgid) { int msgidx; debug(DBG_FUNCS, "lookup_msgmhf: sof"); for (msgidx=0; (mhf_datap+msgidx)->id != msgid && (mhf_datap+msgidx)->id != MHF_LAST; msgidx++) ; if ((mhf_datap+msgidx)->id == MHF_LAST) { internal("(%s,%d): failed to locate msgid %d in table", __FILE__, __LINE__, msgid); return(-1); } return(msgidx); } int ipc_queue_submit( struct msginfrec *msginfo_datap, int towhome, time_t dotime, int msgid, int *mp) { struct msgrec sbuf; int msgidx; int i; debug(DBG_FUNCS, "ipc_queue_submit: sof"); /* * Mark who the message is for, and put the message id in the message * text. */ sbuf.mtype = towhome; sprintf(sbuf.mtext, "%ld %d ", dotime, 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=lookup_msginfo(msginfo_datap, msgid)) < 0) return(1); for (i=0; i<(msginfo_datap+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)", (msginfo_datap+msgidx)->cmt); /* * Dispatch the message. */ debug(DBG_MSGQ, "ipc_queue_submit: sending to: %d msg: %s", towhome, sbuf.mtext); if (msgsnd(msqid, (struct msgbuf *) &sbuf, strlen(sbuf.mtext) + 1, 0) < 0) error("msgsnd: %s", strerror(errno)); /* * 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. */ debug(DBG_FUNCS, "ipc_queue_submit: eof"); return(0); } ppplcd_ipc_server_init( uid_t ipc_owner, gid_t ipc_group, int ipc_mode) { struct msqid_ds mspars; struct passwd *tpwp; struct group *tgrp; debug(DBG_FUNCS, "ppplcd_ipc_server_init: sof"); /* * Create the message queue */ if ((msqid=msgget(key, IPC_CREAT | ipc_mode)) < 0) { debug(DBG_MSGQ, "msgget(%d, IPC_CREAT | %o): %s", key, ipc_mode, strerror(errno)); return(-1); } /* * Read current owner and group */ if (msgctl(msqid, IPC_STAT, &mspars) < 0) { debug(DBG_MSGQ, "msgctl(%d, IPC_STAT, ): %s", msqid, strerror(errno)); return(-1); } tpwp = getpwuid(mspars.msg_perm.uid); tgrp = getgrgid(mspars.msg_perm.gid); debug(DBG_MSGQ, "queue has owner: %s, group %s", tpwp->pw_name, tgrp->gr_name); if (mspars.msg_perm.uid == ipc_owner && mspars.msg_perm.gid == ipc_group) { debug(DBG_MSGQ, "owner and group are ok already"); return(0); } /* * If necessary, set owner and group */ mspars.msg_perm.uid = ipc_owner; mspars.msg_perm.gid = ipc_group; if (msgctl(msqid, IPC_SET, &mspars) < 0) { debug(DBG_MSGQ, "msgctl(%d, IPC_SET, ): %d (%s)", msqid, errno, strerror(errno)); return(-1); } return(0); } ppplcd_ipc_client_init() { debug(DBG_FUNCS, "ppplcd_ipc_client_init: sof"); return(((msqid=msgget(key, 0666)) < 0) ? -1 : 0); } ppplcd_ipc_server_shutdown() { debug(DBG_FUNCS, "ppplcd_ipc_server_shutdown: sof"); msgctl(msgget(key, 0666), IPC_RMID, NULL); } int ipc_queue_process( struct msginfrec *msginfo_datap, int towhome, int (*c_queue_submit_fnc)()) { struct msgrec rbuf; int msgid; int rc; int parcnt; int *mp; int i; char *cp; int msgidx; time_t dotime; debug(DBG_FUNCS, "ipc_queue_process: sof"); debug(DBG_MSGQ, "ipc_queue_process: awaiting msg to %d", towhome); rc = msgrcv(msqid, (struct msgbuf *) &rbuf, MAX_MSG_SIZ, towhome, 0); if (rc < 0 && errno == EINTR) { debug(DBG_MSGQ, "ipc_queue_process: interrupted system call"); return(EINTR); } else if (rc < 0) error("msgrcv: %s", strerror(errno)); debug(DBG_MSGQ, "ipc_queue_process: to: %d, msg: %s", towhome, rbuf.mtext); /* * at this point we would parse the next word as a activation time */ dotime = atoi(strtok(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(NULL, " ")); parcnt = (msginfo_datap+lookup_msginfo(msginfo_datap, msgid))->argc; if ((mp=((int *) calloc(parcnt, sizeof(int)))) == NULL) error("calloc: ", strerror(errno)); for (i=0; (cp=strtok(NULL, " ")) != NULL && iid != msgid && (msginfo_datap+msgidx)->id != MSGID_LAST_MARKER; msgidx++) d37 1 a37 1 if ((msginfo_datap+msgidx)->id == MSGID_LAST_MARKER) { d54 1 a54 1 for (msgidx=0; (mhf_datap+msgidx)->id != msgid && (mhf_datap+msgidx)->id != MHF_LAST_MARKER; msgidx++) d56 1 a56 1 if ((mhf_datap+msgidx)->id == MHF_LAST_MARKER) { @ 1.9 log @milepost @ text @d19 1 a19 1 static char *rcs_id = "$Id: ppplcd_ipc.c,v 1.8 1998/08/08 09:47:47 alexis Exp alexis $"; d107 1 a107 1 error(exit, 1, "msgsnd: %s", strerror[errno]); d121 2 a122 2 int ipc_owner, int ipc_group, d136 1 a136 1 debug(DBG_MSGQ, "msgget(%d, IPC_CREAT | %o): %s", key, ipc_mode, strerror[errno]); d145 1 a145 1 debug(DBG_MSGQ, "msgctl(%d, IPC_STAT, ): %s", msqid, strerror[errno]); d163 1 a163 1 debug(DBG_MSGQ, "msgctl(%d, IPC_SET, ): %d (%s)", msqid, errno, strerror[errno]); d206 1 a206 1 error(exit, 1, "msgrcv: %s", strerror[errno]); d225 1 a225 1 error(exit, 1, "calloc: ", strerror[errno]); d229 1 a229 1 error(exit, 1, "superflous arguments to message %d", msgid); d233 1 a233 1 error(exit, 1, "insufficient arguments to message %d", msgid); @ 1.8 log @new system - heavily modified to use alarms @ text @a0 3 #define NEW_SYSTEM 1 #define OLD_SYSTEM (!(NEW_SYSTEM)) d9 2 d19 1 a19 1 static char *rcs_id = "$Id: ppplcd_ipc.c,v 1.7 1998/08/07 14:49:25 alexis Exp $"; d27 2 a28 2 int id2infidx( struct msginfrec *msginfdatp, d33 1 a33 1 debug(DBG_FUNCS, "id2infidx: sof"); d35 1 a35 1 for (msgidx=0; (msginfdatp+msgidx)->id != msgid && (msginfdatp+msgidx)->id != MSGID_LAST_MARKER; msgidx++) d37 1 a37 1 if ((msginfdatp+msgidx)->id == MSGID_LAST_MARKER) { d41 2 d46 2 a47 2 int id2mhfidx( struct mhflkuprec *mhflkupdatp, d52 1 a52 1 debug(DBG_FUNCS, "id2mhfidx: sof"); d54 1 a54 1 for (msgidx=0; (mhflkupdatp+msgidx)->id != msgid && (mhflkupdatp+msgidx)->id != MHF_LAST_MARKER; msgidx++) d56 1 a56 1 if ((mhflkupdatp+msgidx)->id == MHF_LAST_MARKER) { d63 2 a64 2 int ppplcd_ipc_send_msg( struct msginfrec *msginfdatp, d74 1 a74 1 debug(DBG_FUNCS, "ppplcd_ipc_send_msg: sof"); d89 1 a89 1 if ((msgidx=id2infidx(msginfdatp, msgid)) < 0) d91 1 a91 1 for (i=0; i<(msginfdatp+msgidx)->argc; i++) d99 1 a99 1 sprintf(sbuf.mtext+strlen(sbuf.mtext), "(%s)", (msginfdatp+msgidx)->cmt); d105 1 a105 1 debug(DBG_MSGQ, "ppplcd_ipc_send_msg: sending to: %d msg: %s", towhome, sbuf.mtext); d116 1 d123 1 a123 1 int ipc_perms) d126 2 d131 6 a136 1 if ((msqid=msgget(key, IPC_CREAT | ipc_perms)) < 0) d138 8 a145 1 if (msgctl(msqid, IPC_STAT, &mspars) < 0) d147 13 d162 2 a163 1 if (msgctl(msqid, IPC_SET, &mspars) < 0) d165 1 d184 2 a185 2 int ppplcd_ipc_read_msg( struct msginfrec *msginfdatp, d187 1 a187 1 int (*delayqueue_send_fnc)()) d199 7 a205 6 debug(DBG_FUNCS, "ppplcd_ipc_read_msg: sof"); debug(DBG_MSGQ, "ppplcd_ipc_read_msg: awaiting msg to %d", towhome); while ((rc=msgrcv(msqid, (struct msgbuf *) &rbuf, MAX_MSG_SIZ, towhome, 0)) < 0 && errno == 4) debug(DBG_MSGQ, "ppplcd_ipc_read_msg: ignoring interrupted system call"); if (rc < 0) a206 1 debug(DBG_MSGQ, "ppplcd_ipc_read_msg: to: %d, msg: %s", towhome, rbuf.mtext); d208 1 a208 1 #if NEW_SYSTEM a210 1 * NEW SYSTEM: a214 1 #endif d223 1 a223 1 parcnt = (msginfdatp+id2infidx(msginfdatp, msgid))->argc; a234 2 #if NEW_SYSTEM a235 1 * NEW SYSTEM: d245 1 a245 23 (*delayqueue_send_fnc)(dotime, msgid, mp); #else /* * Lookup the index of the function to be invoked on this message * in the table specified as a parameter. Invoke the function passing * it the address of the parameter block. Release the memory after. */ if ((msgidx=id2mhfidx(mhflkupdatp, msgid)) < 0) error(exit, 1, "no function associated with message %d in specified table"); /* * Call the appropriate function and destroy the parameter block since * it is used by the functions. */ ((mhflkupdatp+msgidx)->fnc)(mp); free(mp); #endif @ 1.7 log @milepost - really works - pre queue jiggle @ text @d1 3 d20 1 a20 1 static char *rcs_id = "$Id: ppplcd_ipc.c,v 1.6 1998/08/07 11:28:42 alexis Exp $"; d39 1 a39 1 internal("(%s,%d): failed to locate msgid %d in table", __FILE__, __LINE__, msgid); d65 1 d81 1 a81 1 sprintf(sbuf.mtext, "%d ", msgid); d104 1 a104 1 debug(DBG_MSGQ, "ppplcd_ipc_send_msg: sending %d to %s", towhome, sbuf.mtext); d156 1 a156 1 struct mhflkuprec *mhflkupdatp) d166 1 d169 1 a169 1 debug(DBG_MSGQ, "ppplcd_ipc_send_msg: awaiting msg to %d", towhome); d175 11 a185 1 debug(DBG_MSGQ, "ppplcd_ipc_read_msg: recd msg %s for %d", rbuf.mtext, towhome); d193 1 a193 7 msgid = atoi(strtok(rbuf.mtext, " ")); /* * NEW SYSTEM: * at this point we would parse the next word as a activation time */ d206 17 d232 5 a236 11 /* * NEW SYSTEM: * and here we would *not* call the function, but put the structured * message on the delay queue, sort the delay queue accordingly and * set the wake up time. Of course while we do this sorting we would * not want to be interupted so we would cancel pending alarms very * first thing. We would queue the structure in a function - and then * this function could be made available as a way of sending messages * internally. */ d239 2 @ 1.6 log @milepost - seems to work ok, though few messages seem wrong @ text @d17 1 a17 1 static char *rcs_id = "$Id: ppplcd_ipc.c,v 1.5 1997/11/11 11:57:48 alexis Exp alexis $"; d179 6 d205 12 @ 1.5 log @ppplcd_utils.h renamed @ text @d17 1 a17 1 static char *rcs_id = "$Id: ppplcd_ipc.c,v 1.4 1997/10/26 12:12:30 alexis Exp $"; d100 1 a100 1 debug(DBG_IPCMSG, "ppplcd_ipc_send_msg: sending to %d: %s", towhome, sbuf.mtext); d164 1 a164 1 debug(DBG_IPCMSG, "ppplcd_ipc_send_msg: awaiting msg to %d", towhome); d167 1 a167 1 debug(DBG_IPCMSG, "ppplcd_ipc_read_msg: ignoring interrupted system call"); d170 1 a170 1 debug(DBG_IPCMSG, "ppplcd_ipc_read_msg: recd msg for %d: %s", towhome, rbuf.mtext); @ 1.4 log @stamped for release 1.0.6 @ text @d11 1 a11 1 #include "ppplcd_utils.h" d17 1 a17 1 static char *rcs_id = "$Id: ppplcd_ipc.c,v 1.3 1997/02/21 17:09:02 alexis Exp alexis $"; @ 1.3 log @server init now takes perms, owner and group as params @ text @d17 1 a17 1 static char *rcs_id = "$Id: ppplcd_ipc.c,v 1.2 1997/02/09 16:00:50 alexis Exp alexis $"; @ 1.2 log @More changes ... now works. @ text @d17 1 a17 1 static char *rcs_id = "$Id: ppplcd_ipc.c,v 1.1 1997/02/01 21:52:17 alexis Exp alexis $"; d114 4 a117 1 ppplcd_ipc_server_init() d119 2 d123 10 a132 1 return(((msqid=msgget(key, IPC_CREAT | 0666)) < 0) ? -1 : 0); @ 1.1 log @Initial revision @ text @d17 1 a17 1 static char *rcs_id = "$Id: ppplcd_ipc.c,v 1.3 1997/01/31 14:43:34 alexis Exp alexis $"; d101 2 a102 4 if (msgsnd(msqid, (struct msgbuf *) &sbuf, strlen(sbuf.mtext) + 1, 0) < 0) { perror("msgsnd"); exit(1); } d155 1 a155 1 perror("msgrcv"); d166 2 a167 4 if ((mp=((int *) calloc(parcnt, sizeof(int)))) == NULL) { perror("calloc"); exit(1); } d171 1 a171 1 error("superflous arguments to message %d", msgid); d175 1 a175 1 error("insufficient arguments to message %d", msgid); d184 1 a184 1 error("no function associated with message %d in specified table"); @