|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T s
Length: 5478 (0x1566) Types: TextFile Names: »submit_que.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« └─⟦e5a54fb17⟧ └─⟦this⟧ »pp-5.0/Src/submit/submit_que.c«
/* submit_que.c: store messages in the queue */ # ifndef lint static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Src/submit/RCS/submit_que.c,v 5.0 90/09/20 16:23:26 pp Exp Locker: pp $"; # endif /* * $Header: /cs/research/pp/hubris/pp-beta/Src/submit/RCS/submit_que.c,v 5.0 90/09/20 16:23:26 pp Exp Locker: pp $ * * $Log: submit_que.c,v $ * Revision 5.0 90/09/20 16:23:26 pp * rcsforce : 5.0 public release * */ #include "head.h" #include "prm.h" #include "q.h" #include "adr.h" #include <sys/file.h> #include <sys/time.h> extern CHAN *ch_all[]; extern UTC time_t2utc(); extern void err_abrt(); extern long msg_size; extern char *aquedir; /* Q/addr dir for control files */ extern char *bquedir; /* Q/msg/msg.XXX/base dir */ extern char *mquedir; /* Q/msg dir for msg body parts */ extern char *tquedir; /* Q/msg temporary dir */ /* -- globals -- */ char *msg_basedir; /* full pathname to bquedir */ char *msg_unique; /* unique-part of Q/msg file name */ char msg_fullpath[FILNSIZE]; /* full pathname to mquedir */ char *ad_unique; /* unique-part of aquedir file name */ /* -- static variables -- */ static FILE *ad_ffp; /* file pointer to address file */ static char ad_fullpath[FILNSIZE]; /* full pathname to aquedir */ /* -- local routines -- */ void clear_q(); void move_q(); void winit_q(); void write_q(); static int make_temp(); /* --------------------- Begin Routines -------------------------------- */ /* -- initialise system to write a message into the queue. -- */ void winit_q() { int tmp_fd = NOTOK; char buf[FILNSIZE]; PP_TRACE (("submit/winit_q()")); (void) strcpy (ad_fullpath, tquedir); ad_unique = ad_fullpath + strlen (ad_fullpath); (void) strcpy (msg_fullpath, tquedir); msg_unique = msg_fullpath + strlen (msg_fullpath); tmp_fd = make_temp (ad_unique, ad_fullpath); if (tmp_fd == NOTOK) err_abrt (RP_FCRT, "Can't create a unique Q file"); if ((ad_ffp = fdopen (tmp_fd, "w")) == NULL) err_abrt (RP_FOPN, "Can't access text Q file."); (void) strcpy (msg_unique, ad_unique); (void) strcat (msg_unique, "dir"); if (mkdir (msg_fullpath, 0777) < 0) err_abrt (RP_FIO, "Cannot create msg dir %s", msg_fullpath); (void) sprintf (buf, "%s/%s", msg_fullpath, bquedir); msg_basedir = strdup (buf); } void move_q () { int fd; char tfile[FILNSIZE]; char tunique[FILNSIZE]; PP_TRACE (("Original file='%s'", ad_unique)); (void) strcpy (tfile, aquedir); ad_unique = tfile + strlen (tfile); fd = make_temp (ad_unique, tfile); if (fd == NOTOK) err_abrt (RP_FCRT, "Can't link into queue"); PP_TRACE (("New file = %s", ad_unique)); PP_TRACE (("Renames %s to %s", ad_fullpath, tfile)); if (rename (ad_fullpath, tfile) == NOTOK) err_abrt (RP_FCRT, "Can't rename file %s to %s", ad_fullpath, tfile); (void) close (fd); (void) strcpy (ad_fullpath, tfile); /* -- now rename the message directory -- */ (void) strcpy (tunique, ad_unique); (void) strcpy (tfile, msg_fullpath); (void) strcpy (msg_fullpath, mquedir); msg_unique = msg_fullpath + strlen (msg_fullpath); (void) strcpy (msg_unique, tunique); PP_TRACE (("Renames %s to %s", tfile, msg_fullpath)); if (rename (tfile, msg_fullpath) == NOTOK) { (void) unlink (ad_fullpath); err_abrt (RP_FCRT, "Can't rename %s to %s", tfile, msg_fullpath); } } void write_q (qp, pr) register Q_struct *qp; register struct prm_vars *pr; { int retval; ADDR *ap; PP_TRACE (("submit/write_q (qp,pr)")); if (qp->msgsize == NULL) qp->msgsize = msg_size; if (qp->queuetime == 0) qp->queuetime = utcnow (); if (pr -> prm_opts) pr -> prm_opts = PRM_NONE; if (pr -> prm_passwd) { free (pr -> prm_passwd); pr -> prm_passwd = NULLCP; } retval = wr_prm (pr, ad_ffp); if (rp_isbad (retval)) goto bad; retval = wr_q (qp, ad_ffp); if (rp_isbad (retval)) goto bad; retval = wr_adr (qp->Oaddress, ad_ffp, AD_ORIGINATOR); if (rp_isbad (retval)) goto bad; for (ap = qp -> Raddress; ap; ap = ap -> ad_next) { retval = wr_adr (ap, ad_ffp, AD_RECIPIENT); if (rp_isbad (retval)) goto bad; } if(fclose (ad_ffp) == EOF) goto bad; ad_ffp = NULLFILE; return; bad: err_abrt (RP_FIO, "Error writing to q file"); } /* -- in case of error, zap all the work thats been done. -- */ void clear_q() { PP_TRACE (("clear_q ()")); txt_tend(); if (ad_ffp != NULLFILE) { /* address file */ (void) fclose (ad_ffp); ad_ffp = NULLFILE; (void) unlink (ad_fullpath); *ad_fullpath = '\0'; } } /* --------------------- Static Routines ------------------------------- */ /* * mktemp gives up too easily - this ones goes on forever * I think we'll run out of inodes long before this fails... */ static int make_temp (unique, base) char *base; char *unique; { static long tries = 0; static int mypid = 0; int fd = NOTOK; if (mypid == 0) mypid = getpid (); for (; tries < 32000; tries ++) { (void) sprintf (unique, "msg.%d-%d", mypid, tries); if ((fd = open (base, O_WRONLY | O_CREAT | O_EXCL, 0666)) != NOTOK) { if (flock (fd, LOCK_EX | LOCK_NB) == 0) break; /* we've now secured a safe queue place */ (void) close (fd); fd = NOTOK; } } return fd; }