From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 31-JAN-1991 14:00:41.93
To:	MRGATE::"ARISIA::EVERHART"
CC:	
Subj:	RE: Stopping a Queue using SYS$SNDJBC

Received:  by crdgw1.ge.com (5.57/GE 1.80)
	 id AA26910; Thu, 31 Jan 91 13:47:41 EST
Received: From CRDGW1.GE.COM by CRVAX.SRI.COM with TCP; Thu, 31 JAN 91 07:37:38 PST
Received:  by crdgw1.ge.com (5.57/GE 1.80)
	 id AA18176; Thu, 31 Jan 91 10:36:57 EST
Date:  Thu, 31 Jan 91 10:36:57 EST
Message-Id:  <9101311536.AA18176@crdgw1.ge.com>
From: sessions%sparev.DECNET@crdgw1 (Zack Sessions 8*292-5517)
To: info-vax@sparev.DECNET
Subject: RE: Stopping a Queue using SYS$SNDJBC

Glenn Tarcea <tarcea@argo.acs.oakland.edu> writes:
>  I'm working on a piece of software to aid in the management of the (millions)
>of queues we have on our various VMS systems. Some of this involves starting
>and stopping queues. I have been trying to use the SYS$SNDJBCW system call
>to stop a print queue (First I tried it on a generic queue, then on a execution
>queue), but for some reason it doesn't seem to work. Could somebody please
>either post or mail me some working code (I am writing the software in C so
>I would prefer the example in C, but I'll accept it in just about any language
>except LISP ;-)  ). Please note, I do not wish to get into a discussion over
>the merits of calling SYS$SNDJBC(W) vs. spawning a subprocess and writing
>the appropriate DCL commands to it. 

Here's the source of a little dittie I once whipped up which should lead
you in the right direction:

/*
	queform.c

	change the form number on a queue. intended to be installed with
	OPER priv to allow users to do this.

	define the foreign command queform to run the image. then the
	command line would be:

$ queform quename formnumber

*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ssdef.h>
#include <descrip.h>
#include <opcdef.h>
#include <iodef.h>
#include <quidef.h>
#include "sjcdef.h"
#include "jbcdef.h"

typedef struct {
	variant_union udef {
		variant_struct entrydef {
			short	buflen;
			short	itmcod;
			char	*bufadr;
			char	*retadr;
		} entry;
		int	end_list;
	} uent;
} LIST;
struct iosbdef {
	variant_union udef {
		int l_iosb[2];
		variant_struct mbdef {
			short	s1_iosb[2];
			int	s2_iosb;
		} s;
	} u;
} iosb;

LIST qlist[5];
LIST jlist[4];
LIST sjclist[4];
LIST flist[3];
int qlen;
int jlen;
int ulen;
int flen;
int currform;
char form_name[32];
char job_name[40];
char username[13];
int search_flags;
int que_status;
int job_status;
int status_q;
int status_j;
int status_f;
int was_running = FALSE;

char quename[32];
int formnum;
suqlist() 
{
	qlist[0].buflen = strlen(quename);
	qlist[0].itmcod = QUI$_SEARCH_NAME;
	qlist[0].bufadr = quename;
	qlist[0].retadr = NULL;
	qlist[1].buflen = 4;
	qlist[1].itmcod = QUI$_SEARCH_FLAGS;
	qlist[1].bufadr = &search_flags;
	qlist[1].retadr = NULL;
	qlist[2].buflen = 31;
	qlist[2].itmcod = QUI$_FORM_NAME;
	qlist[2].bufadr = form_name;
	qlist[2].retadr = &flen;
	qlist[3].buflen = 4;
	qlist[3].itmcod = QUI$_QUEUE_STATUS;
	qlist[3].bufadr = &que_status;
	qlist[3].retadr = NULL;
	qlist[4].end_list = 0;
}
suflist() 
{
	flist[0].buflen = strlen(form_name);
	flist[0].itmcod = QUI$_SEARCH_NAME;
	flist[0].bufadr = form_name;
	flist[0].retadr = NULL;
	flist[1].buflen = 4;
	flist[1].itmcod = QUI$_FORM_NUMBER;
	flist[1].bufadr = &currform;
	flist[1].retadr = NULL;
	flist[2].end_list = 0;
}
main(argc,argv)
 int argc;
 int *argv[];
{
	char cform[5];
	char response[2];
	int end_loop = FALSE;
	int still_running;
	int rval;
        cform[0] = '\0';
	response[0] = '\0';
	if(argc <= 1) {
		fprintf(stderr,"Insufficient parameters specified.");
		exit(0);
	}
	while(argc > 1) {
		--argc;
		++argv;
		if(strlen(quename) == 0)
			strcpy(quename,*argv);
		else
			if(strlen(cform) == 0)
				strcpy(cform,*argv);
	}
	if((strlen(quename) == 0) || (strlen(cform) == 0)) {
		fprintf(stderr,"Insufficient parameters specified.");
		exit(0);
	}
	formnum = atoi(cform);
	suqlist();
	search_flags = QUI$M_SEARCH_SYMBIONT;
	status_q = sys$getquiw(0,QUI$_CANCEL_OPERATION,0,0,0,0,0);
	status_q = sys$getquiw(0,QUI$_DISPLAY_QUEUE,0,qlist,&iosb,0,0);
	if(status_q == SS$_NORMAL)
		status_q = iosb.l_iosb[0];
	if(status_q == JBC$_NORMAL) {
		form_name[flen] = '\0';
		suflist();
		status_f = sys$getquiw(0,QUI$_DISPLAY_FORM,0,flist,&iosb,0,0);
		if(status_q == SS$_NORMAL)
			status_q = iosb.l_iosb[0];
		if(status_q == JBC$_NORMAL) {
			if(currform == formnum) {
				fprintf(stderr,"QUEUE IS ALREADY SET TO FORM %d\n",formnum);
				exit(0);
			}
			if(!(que_status & QUI$M_QUEUE_STOPPED)) {
				was_running = TRUE;
				sjclist[0].buflen = strlen(quename);
				sjclist[0].itmcod = SJC$_QUEUE;
				sjclist[0].bufadr = quename;
				sjclist[0].retadr = NULL;
				sjclist[1].end_list = 0;
				rval = sys$sndjbcw(0,SJC$_STOP_QUEUE,0,&sjclist,&iosb,0,0);
				if(rval != SS$_NORMAL) {
					fprintf(stderr,"Abnormal return code received!");
					sys$exit(rval);
				}
				if(iosb.l_iosb[0] != JBC$_NORMAL) {
					fprintf(stderr,"Abnormal return code received!");
					sys$exit(iosb.l_iosb[0]);
				}
			}
			still_running = TRUE;
			while(still_running) {
				suqlist();
				search_flags = QUI$M_SEARCH_SYMBIONT;
				status_q = sys$getquiw(0,QUI$_DISPLAY_QUEUE,0,qlist,&iosb,0,0);
				if(status_q == SS$_NORMAL)
					status_q = iosb.l_iosb[0];
				if(status_q == JBC$_NORMAL)
					if(que_status & QUI$M_QUEUE_STOPPED)
						still_running = FALSE;
					else {
						printf("Waiting for Queue to stop!\n");
						sleep(10);
					}
			}
			sjclist[0].buflen = strlen(quename);
			sjclist[0].itmcod = SJC$_QUEUE;
			sjclist[0].bufadr = quename;
			sjclist[0].retadr = NULL;
			sjclist[1].buflen = 4;
			sjclist[1].itmcod = SJC$_FORM_NUMBER;
			sjclist[1].bufadr = &formnum;
			sjclist[1].retadr = NULL;
			sjclist[2].end_list = 0;
			rval = sys$sndjbcw(0,SJC$_ALTER_QUEUE,0,&sjclist,&iosb,0,0);
			if(rval != SS$_NORMAL) {
				fprintf(stderr,"Abnormal return code received!");
				sys$exit(rval);
			}
			if(iosb.l_iosb[0] != JBC$_NORMAL) {
				fprintf(stderr,"Abnormal return code received!");
				sys$exit(iosb.l_iosb[0]);
			}
			while(!end_loop) {
				suqlist();
				search_flags = QUI$M_SEARCH_SYMBIONT;
				status_q = sys$getquiw(0,QUI$_DISPLAY_QUEUE,0,qlist,&iosb,0,0);
				if(status_q == SS$_NORMAL)
					status_q = iosb.l_iosb[0];
				if(status_q == JBC$_NORMAL) {
					suflist();
					status_f = sys$getquiw(0,QUI$_DISPLAY_FORM,0,flist,&iosb,0,0);
					if(status_q == SS$_NORMAL)
						status_q = iosb.l_iosb[0];
					if(status_q == JBC$_NORMAL)
						if(currform == formnum)
							end_loop = TRUE;
				}
			}
			if(was_running) {
				sjclist[0].buflen = strlen(quename);
				sjclist[0].itmcod = SJC$_QUEUE;
				sjclist[0].bufadr = quename;
				sjclist[0].retadr = NULL;
				sjclist[1].end_list = 0;
				rval = sys$sndjbcw(0,SJC$_START_QUEUE,0,&sjclist,&iosb,0,0);
				if(rval != SS$_NORMAL) {
					fprintf(stderr,"Abnormal return code received!");
					sys$exit(rval);
				}
				if(iosb.l_iosb[0] != JBC$_NORMAL) {
					fprintf(stderr,"Abnormal return code received!");
					sys$exit(iosb.l_iosb[0]);
				}
			}
		}
		else
			sys$exit(iosb.l_iosb[0]);
	}
	else
		sys$exit(iosb.l_iosb[0]);
}

ps, in case you can't tell this was one of my first VAX C system time programs!

Zack C. Sessions
Sessions@Sparev.dnet.ge.com (Internet)
Sessions%Sparev.dnet.ge.com@crdgw1.ge.com (Alternate Internet)

