DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T q

⟦ea4217648⟧ TextFile

    Length: 5503 (0x157f)
    Types: TextFile
    Names: »qmgr-load.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« 
        └─⟦e5a54fb17⟧ 
            └─⟦this⟧ »pp-5.0/Chans/qmgr-load/qmgr-load.c« 

TextFile

/* qmgr-load.c: load the queue manager via readqueue */

# ifndef lint
static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Chans/qmgr-load/RCS/qmgr-load.c,v 5.0 90/09/20 15:53:07 pp Exp Locker: pp $";
# endif

/*
 * $Header: /cs/research/pp/hubris/pp-beta/Chans/qmgr-load/RCS/qmgr-load.c,v 5.0 90/09/20 15:53:07 pp Exp Locker: pp $
 *
 * $Log:	qmgr-load.c,v $
 * Revision 5.0  90/09/20  15:53:07  pp
 * rcsforce : 5.0 public release
 * 
 */



#include "util.h"
#include <pwd.h>
#include "retcode.h"
#include <isode/usr.dirent.h>
#include "ryresponder.h"                /* for generic idempotent responders */
#include "Qmgr-ops.h"                   /* operation definitions */
#include "Qmgr-types.h"                 /* type definitions */

/* Sumbit types */
#include "q.h"
#include "prm.h"


/* Outside routines */
int                             rd_msg();
struct type_Qmgr_MsgStruct      *qstruct2qmgr();
void                            qinit();

extern char     *quedfldir;
extern void	rd_end(), sys_init(), err_abrt(), getfpath();
static char *myservice = "qmgr-load";

/* OPERATIONS */
static int     op_readqueue();

static struct server_dispatch dispatches[] = {
	"readqueue", operation_Qmgr_readqueue, op_readqueue,
	NULL
	};

static int get_msg_list();
static struct type_Qmgr_MsgStructList *get_all_messages();
static int isMsgFile();
static void dirinit ();
static struct type_Qmgr_MsgStruct *readInMsg();

/* \f

 MAIN */

/* ARGSUSED */
main (argc, argv, envp)
int     argc;
char    **argv,
	**envp;
{
	sys_init (argv[0]);
	dirinit ();
#ifdef PP_DEBUG
	if (argc>1 && (strcmp(argv[1],"debug") == 0))
		get_all_messages();
	else
#endif
	ryresponder (argc, argv, PLocalHostName(), myservice, dispatches,
		     table_Qmgr_Operations, NULLIFP, NULLIFP); 
	exit (0);       /* NOT REACHED */
}

/* routine to move to correct place in file system */

static void dirinit ()
{
	if (chdir (quedfldir) < 0)
		err_abrt (RP_LIO, " Unable to change directory to '%s'",
			  quedfldir);
}

/* \f

 OPERATIONS */

/* ARGSUSED */
static int op_readqueue (ad, ryo, rox, in, roi)
int                     ad;
struct RyOperation      *ryo;
struct RoSAPinvoke      *rox;
caddr_t                 in;
struct RoSAPindication  *roi;
{
	if (rox->rox_nolinked == 0) {
		PP_LOG (LLOG_NOTICE,
			("RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",
			ad, ryo->ryo_name, rox->rox_linkid));
		return ureject (ad, ROS_IP_LINKED, rox, roi);
	}
	PP_LOG (LLOG_NOTICE,
		("RO-INVOKE.INDICATION/%d: %s",ad, ryo -> ryo_name));
	return get_msg_list(ad, rox, roi);
}

static int get_msg_list(ad, rox, roi)
int                     ad;
struct RoSAPinvoke      *rox;
struct RoSAPindication  *roi;
{
	struct type_Qmgr_MsgList *base;

	PP_TRACE(("get_msg_list ()"));

	if ((base = (struct type_Qmgr_MsgList *) calloc (1, sizeof(*base)))
	     == NULL)
		return error (ad, error_Qmgr_congested, (caddr_t) NULL,
			      rox, roi);

	/* now make list */
	base->msgs = get_all_messages();

	if (RyDsResult (ad, rox->rox_id, (caddr_t) base, ROS_NOPRIO, roi)
	    == NOTOK)
		ros_adios(&roi->roi_preject,"RESULT");

	return OK;
}

static struct type_Qmgr_MsgStructList *get_all_messages()
{
	struct type_Qmgr_MsgStructList *head, *tail, *temp;
	struct type_Qmgr_MsgStruct *msg;
	struct dirent **namelist, **ix;
	char real_aquedir[FILNSIZE];
	extern char *quedfldir;
	extern char *aquedir;
	int noEntries, i;
	head = tail = NULL;

	namelist = NULL;
	/* get addr directory name */
	getfpath (quedfldir, aquedir, real_aquedir);

	noEntries = _scandir(real_aquedir, &namelist, isMsgFile, NULLIFP);
	i = 0;
	ix = namelist;
	while ((i++ < noEntries) && (*ix != NULL)) {
		PP_TRACE (("reading message %s", (*ix) -> d_name));
		if ((msg = readInMsg((*ix)->d_name)) != NULL) {
			/* add to list */
			temp = (struct type_Qmgr_MsgStructList *) 
				calloc(1,sizeof(*temp));
			temp->MsgStruct = msg;
			if (head == NULL)
				head = tail = temp;
			else {
				tail->next = temp;
				tail = temp;
			}
		}
		ix++;
	}

	free((char *)namelist);
	return head;
}

static int isMsgFile (entry)
struct dirent *entry;
{
	if (strncmp(entry->d_name, "msg.", 4) == 0)
		return 1;
	else
		return 0;
}

static struct type_Qmgr_MsgStruct *readInMsg(name)
char *name;
{
	struct type_Qmgr_MsgStruct *arg = NULL;
	struct prm_vars prm;
	Q_struct        que;
	ADDR            *sender = NULL;
	ADDR            *recips = NULL;
	int             rcount, result;

	result = OK;

	prm_init (&prm);
	q_init (&que);
	qinit (&que);

	if ((result == OK)
	    && (rp_isbad(rd_msg(name,&prm,&que,&sender,&recips,&rcount)))) {
		PP_LOG(LLOG_EXCEPTIONS,
		       ("Chans/qmgr-load rd_msg err: '%s'",name));
		result = NOTOK;
	}
	/* unlock message */
	rd_end();

	if ((result == OK)
	    && ((arg = qstruct2qmgr(name,&prm,&que,sender,recips,rcount)) == NULL)) {
		PP_LOG(LLOG_EXCEPTIONS,
		       ("Chans/qmgr-load qstruct2qmgr err: '%s'",name));
		result = NOTOK;
	}

	/* free all storage */
	q_free (&que);

	return result == NOTOK ? NULL : arg;
}


/*    ERROR */

int  error (sd, err, param, rox, roi)
int     sd,
	err;
caddr_t param;
struct RoSAPinvoke *rox;
struct RoSAPindication *roi;
{
	if (RyDsError (sd, rox -> rox_id, err, param, ROS_NOPRIO, roi) == NOTOK)
		ros_adios (&roi -> roi_preject, "ERROR");

	return OK;
}

int ureject (sd, reason, rox, roi)
int     sd, reason;
struct RoSAPinvoke *rox;
struct RoSAPindication *roi;
{
	if ( RyDsUReject (sd, rox -> rox_id, reason, ROS_NOPRIO, roi) == NOTOK)
		ros_adios (&roi -> roi_preject, "U-REJECT");
	return OK;
}