[Go to Google Groups Home] Advanced Groups Search Groups Help Groups Groups search result 1 for jdtcom group:comp.os.vms From: LBohan@dbc.spam_less..com (LBohan@dbc.spam_less..com) Search Result 1 Subject: Re: Basic VMS Question Newsgroups: comp.os.vms Date: 2001-07-23 View: Complete Thread (9 articles) | Original Format 04:24:36 PST On Mon, 23 Jul 2001 09:37:37 +0100, Andrew Robinson wrote: >Please could anyone help with the following: > >I have a procedure running on one of my VMS boxes which is constantly >checking a directory for a file which can be FTPed into it. If the file >appears it then runs another routine to process and remove the file ready >for the next one. I have a simple routine at the moment written in Diabold >which runs as a detached process. >The problem I have is that to make this process work, it is a simple looping >check, which eats CPU and slaughters the disk IO. >Is there anything in VMS which you can utilize which you can use to trigger >an event if a file appears in a specific location. >I using an Alpha 1200 running OVMS 7.2-1 + patches > >Thank you in advance > >Andrew Robinson ran across this a few years back; (tip of the hat/thanks to James Duff) may need some fixups due to line wraps, /* **++ ** ** MODULE DESCRIPTION: ** ** Did you ever write a program that would periodically poll a directory ** to see if there are files to process and wonder if there was a better ** way? Well, this is it! This program demonstrates how to take out ** what is known as the "Serialization lock" for a file. This lock is ** described in the "VMS File System Interals" manual. This lock is taken ** out before the file system attempts to write to the directory file, ** and, as this program has already taken it out in exclusive mode, ** a blocking ast fires which drops the lock (allowing the file system ** to get it) and awakens the main module. ** ** AUTHORS: ** ** James F. Duff ** JDT Computer Systems Pty Limited ** P.O. Box R1561 Royal Exchange NSW 2000 Australia ** JDTCOM@DECUS.ORG.AU ** Phone: +61 (0) 419 802 714 ** ** CREATION DATE: ** ** 05-Sep-1994 ** ** ** ENVIRONMENT: ** ** User and Kernel modes. SYSLCK and CMKRNL privileges required. ** ** ** MODIFICATION HISTORY: ** ** X01-00 Jim Duff 05-Sep-1994 ** Original version of module ** **-- */ #include #include #include #include #include #include #include #include #include #define EFN 20 /* ** Declare a global structure to hold vaiables that the kernel mode ** routines use. */ static struct { struct { short int status; short int unused; long int lock_id; } plock_sb; struct { short int status; short int unused; long int lock_id; } clock_sb; char logname[12]; short int fid[3]; } kmp; /******************************************************************************/ void drop_lock (void) { /* ** This routine is called as an AST in kernel mode. */ static long int r0_status; /* ** Drop the serialization lock */ r0_status = sys$deq (kmp.clock_sb.lock_id, 0, 0, 0); if (!($VMS_STATUS_SUCCESS (r0_status))) { lib$signal (r0_status); } /* ** Drop the volume lock */ r0_status = sys$deq (kmp.plock_sb.lock_id, 0, 0, 0); if (!($VMS_STATUS_SUCCESS (r0_status))) { lib$signal (r0_status); } /* ** Set the event flag the main routine is waiting on. */ r0_status = sys$setef (EFN); if (!($VMS_STATUS_SUCCESS (r0_status))) { lib$signal (r0_status); } } /******************************************************************************/ void get_lock (void) { /* ** This routine is executed in kernel mode */ static long int r0_status; static struct { char prefix[6]; char logname[12]; } parent_resource = { "F11B$v" }; static struct { char prefix[6]; short int fid; char unused; char rvn; } child_resource = { "F11B$s" }; static struct dsc$descriptor parent_resource_d = { sizeof (parent_resource), DSC$K_DTYPE_T, DSC$K_CLASS_S, &parent_resource }; static struct dsc$descriptor child_resource_d = { sizeof (child_resource), DSC$K_DTYPE_T, DSC$K_CLASS_S, &child_resource }; /* ** Construct the parent and child resources. */ memcpy (parent_resource.logname, kmp.logname, 12); child_resource.fid = kmp.fid[0]; child_resource.rvn = kmp.fid[2]; /* ** Obtain a null mode lock on the volume resource. */ r0_status = sys$enqw (0, LCK$K_NLMODE, &kmp.plock_sb, LCK$M_SYSTEM, &parent_resource_d, 0, 0, 0, 0, 0, 0); if (!($VMS_STATUS_SUCCESS (r0_status))) { lib$signal (r0_status); } /* ** Obtain the serialization lock for the file in exclusive mode. Note we ** specify the blocking ast parameter as our drop_lock routine. */ r0_status = sys$enqw (0, LCK$K_EXMODE, &kmp.clock_sb, LCK$M_SYSTEM, &child_resource_d, kmp.plock_sb.lock_id, 0, 0, &drop_lock, 0, 0); if (!($VMS_STATUS_SUCCESS (r0_status))) { lib$signal (r0_status); } } /******************************************************************************/ main (void) { /* ** Main routine. Obtain the name of the directory the user wants to watch. ** Find the label of the device the file is on, and the FID of the file. These ** pieces of info are required to format the resource names for the locks. ** Get to kernel to obtain the locks and then wait for the AST to fire to ** tell us to go ahead. */ static struct FAB fab; static struct NAM nam; static long int r0_status; static long int i; static char file[255]; static char es[255]; static char rs[255]; static char lockname[13]; static struct { short int length; short int code; void *bufadr; void *retlen; long int end_list; } dviitms = { 12, DVI$_VOLNAM, kmp.logname, NULL, 0 }; static struct { long int status; long int unused; } iosb; static struct dsc$descriptor file_d = { sizeof (file), DSC$K_DTYPE_T, DSC$K_CLASS_S, file }; static $DESCRIPTOR (prompt_d, "Directory to watch: "); /* ** Get the name of the directory the user wants to watch */ r0_status = lib$get_input (&file_d, &prompt_d, &file_d); if (!($VMS_STATUS_SUCCESS (r0_status))) { lib$signal (r0_status); } /* ** Set up a RMS file access block specifying the file name. Attach a ** Name attributes block. */ fab = cc$rms_fab; fab.fab$l_nam = &nam; fab.fab$l_fop = FAB$M_NAM; fab.fab$l_fna = file; fab.fab$b_fns = file_d.dsc$w_length; /* ** Set up a name attributes block */ nam = cc$rms_nam; nam.nam$l_esa = es; nam.nam$b_ess = sizeof(es); nam.nam$l_rsa = rs; nam.nam$b_rss = sizeof(rs); /* ** Use RMS to parse the file to pick up any fields in the filename ** the user failed to specify. */ r0_status = sys$parse (&fab); if (!($VMS_STATUS_SUCCESS(r0_status))) { lib$signal (r0_status); } /* ** Use RMS to search for the file. This fills in the NAM block, including ** the file id. */ r0_status = sys$search (&fab); if (!($VMS_STATUS_SUCCESS(r0_status))) { lib$signal (r0_status); } /* ** Reuse our filename string descriptor */ strcpy (file, rs); file_d.dsc$w_length = strlen (file); /* ** Call SYS$GETDVI to obtain the 12 character volume label. This is used ** to construct the resource for the volume lock, which is the parent ** of all serialization locks. */ r0_status = sys$getdviw (0, 0, &file_d, &dviitms, &iosb, 0, 0, 0); if (!($VMS_STATUS_SUCCESS (r0_status))) { lib$signal (r0_status); } if (!($VMS_STATUS_SUCCESS (iosb.status))) { lib$signal (iosb.status); } /* ** SYS$GETJPI returns a null filled string in the last call, but we need ** space filled, so loop through the string replacing nulls with spaces. */ for (i = 11; i >= 0; i--) { if (kmp.logname[i] != '\0') { break; } else { kmp.logname[i] = ' '; } } /* ** Store the file id in the global structure. */ kmp.fid[0] = nam.nam$w_fid[0]; kmp.fid[1] = nam.nam$w_fid[1]; kmp.fid[2] = nam.nam$w_fid[2]; /* ** Get to kernel and lock the resources. */ r0_status = sys$cmkrnl (&get_lock, 0); if (!($VMS_STATUS_SUCCESS (r0_status))) { lib$signal (r0_status); } /* ** Wait on an event flag. The blocking AST which drops the locks will ** set this flag so the program exits. */ r0_status = sys$clref (EFN); if (!($VMS_STATUS_SUCCESS (r0_status))) { lib$signal (r0_status); } r0_status = sys$waitfr (EFN); if (!($VMS_STATUS_SUCCESS (r0_status))) { lib$signal (r0_status); } } --------------------------------------------------------------------------- Google Home - Advertise with Us - Search Solutions - News and Resources - Language Tools - Jobs, Press, Cool Stuff... ©2002 Google