[comp.sources.wanted] cron/at and uucp in minix

johnk@auscso.UUCP (John Knutson) (01/28/88)

Now that we have tty drivers out, has anyone ported a version of uupc or some
other uucp mechanism to work in minix?  
also, what about a cron mechanism to start it automatically at specified times
if we want? i'm sure that a simple at program could be made by some programmer,
but i'm not a C programmer myself. anyway, has anyone done this, and if not,
any guesses about how i might be able to do it myself?  One thing tho, i think
uupc needs to be compiled in large model.  i heard that minix' C compiler was
small model only.  is this true?
-- 
John Knutson   {ihnp4,allegra,ut-sally}!ut-emx!auscso!johnk
	Live long and slay me, brother!
	Communicating, like in the good ol' days.
Disclaimer:  Don't look at me, I don't even work here!

rmtodd@uokmax.UUCP (Richard Michael Todd) (01/30/88)

In article <2535@auscso.UUCP> johnk@auscso.UUCP (John Knutson) writes:
>Now that we have tty drivers out, has anyone ported a version of uupc or some
>other uucp mechanism to work in minix?  
As I recall, not too long after the posting of the serial driver, Jim Paradis
announced that he had gotten the uucp clone DCP to work on MINIX and talk back
and forth to 'encore'.  
>also, what about a cron mechanism to start it automatically at specified times
>if we want? i'm sure that a simple at program could be made by some programmer,
There was a PD cron program posted to either comp.sources.unix or
comp.sources.misc some time back by Paul Vixie.  I don't remember enough about
it to tell how hard the port to MINIX would be.  That might be a
good place to start.
>but i'm not a C programmer myself. anyway, has anyone done this, and if not,
>any guesses about how i might be able to do it myself?  One thing tho, i think
>uupc needs to be compiled in large model.  i heard that minix' C compiler was
>small model only.  is this true?
Yes, MINIX's C compiler is small-model only (assuming you mean by small model
at most a 64K code seg and a 64K data-stack seg.  The nomenclature for memory
models on the 8088 needs some work...).  It wouldn't matter if it did produce
other types of code, since the MINIX memory manager can't handle any other
sort of program besides "all in one 64K seg." and 64K split I&D ("small
model").
  Now as for uupc.  I'm not familiar with the uupc code per se, but uupc was
derived from the earlier DCP program, which I am familiar with and run on
my system.  The original version of DCP required large-code-large data
compilation, but only because the code's author was a bit sloppy; the code
and data requirements of DCP do not themselves exceed 64K, and a fairly
trivial change to one of the machine-code routines (it expected a far pointer
to a buffer; simply make it take the segment loc. of the buffer from DS)
makes it possible to compile in small-model.  I'd be surprised if those
working on uupc had added enough to push it over 64K, so it ought to compile
under small-model as well. 
  So, in conclusion, at least in principle it should be possible to port
uupc to MINIX.  You're probably gonna need to be fairly familiar with
DCP/uupc's innards as well as talking to serial ports under both DOS and
UNIX to figure out how to do it, however. 
--------------------------------------------------------------------------
Richard Todd					"OS/2? Just Say No"
USSnail:820 Annie Court,Norman OK 73069
UUCP: {allegra!cbosgd|ihnp4}!occrsh!uokmax!rmtodd

paul@vixie.UUCP (Paul Vixie Esq) (02/01/88)

In article <1024@uokmax.UUCP> rmtodd@uokmax.UUCP () writes:
>There was a PD cron program posted to either comp.sources.unix or
>comp.sources.misc some time back by Paul Vixie.  I don't remember enough about
>it to tell how hard the port to MINIX would be.  That might be a
>good place to start.
>--
>Richard Todd					"OS/2? Just Say No"

It was posted to comp.sources.misc, since it was only a beta version.  I've
since enhanced it considerably, and now that I have a few 386/SysV machines
around, I want to make it run on that as well.  Even in its present form,
though, it ought to run fine on V7 systems -- i.e., Minix.

I'm not in a huge hurry to get it posted, since Rich $alz is going to be
killed sometime during Uniforum, and it will be a while before we find
another person silly enough to moderate comp.sources.unix :-) :-)...
-- 
Paul A Vixie Esq
paul%vixie@uunet.uu.net
{uunet,ptsfa,hoptoad}!vixie!paul
San Francisco, (415) 647-7023

paradis@encore.UUCP (Jim Paradis) (02/01/88)

In article <1024@uokmax.UUCP> rmtodd@uokmax.UUCP () writes:
>As I recall, not too long after the posting of the serial driver, Jim Paradis
>announced that he had gotten the uucp clone DCP to work on MINIX and talk back
>and forth to 'encore'.  

Well, uh, yeah, I got it "working".  However, it kinda breaks down on long
file transfers (i.e. above about 2K or so...).  I've since put in a request
to John Gilmore for a beta test copy of "gnuucp", but I haven't heard back
from him yet.  I think the problem is down in the "g" protocol handler...
since the only documentation for this protocol is sketchy at best, it's VERY
easy to mess it up, and that's PART of what I think is happening with both of
my versions of DCP.  Watch this space for further details.

   +----------------+  Jim Paradis                  linus--+
+--+-------------+  |  Encore Computer Corp.       necntc--|
|  | E N C O R E |  |  257 Cedar Hill St.           ihnp4--+-encore!paradis
|  +-------------+--+  Marlboro MA 01752           decvax--|
+----------------+     (617) 460-0500             talcott--+
...coated with sesame seeds, and garnished with lark's vomit!

sampson@killer.UUCP (Steve Sampson) (02/02/88)

[]
Concerning cron, I sent a copy to iscuva!ricks of my simple cron, but I don't
think he ever ported it to minix.  I know this ain't the place for sources but
if I put it in comp.os.minix someone will start complaining that it don't work.
It's short, lacks bells and whistles, and ain't ported:

/*
 *	cron.c
 *
 *	Public Domain (p) No Rights Reserved
 *
 *	This program operates as a daemon, waking up every minute
 *	to execute the CRONTAB table.  Logging errors to CRONERR.
 *
 *	Put in UniFLEX 68020 startup as: cron&
 *
 *	Some notes are included below concerning the cron table
 *	file format.  In this version the cron table file is left
 *	on disk and not moved to core, and  the command character
 *	to signify a newline '%' is not used.
 *
 *	Some cron table entry examples:
 *
 *	Print the date on console every minute:
 *		* * * * * date >/dev/tty00
 *
 *	Print the date on console on the hour, every hour:
 *		0 * * * * date >/dev/tty00
 *
 *	Backup the files at 4:30 am every day except Sat and Sun:
 *		30 4 * * 1-5 backup /dev/st0 / +BdNqV=CronBackup
 *
 *	Backup the files every other day at 7:30 pm:
 *		30 19 * * 1,3,5 backup /dev/st0 / +BdNqV=CronBackup
 *
 */

#include <stdio.h>
#include <time.h>
#include <string.h>
#include <signal.h>
#include <errno.h>

#define CRONTAB "/act/crontab"
#define CRONERR "/act/cronerr"

#define MAXLINE	132
#define SIZE	64

#ifndef	_READ
#define	_READ	1
#endif

extern	int	errno;

int	eof;
char	min[SIZE], hour[SIZE], day[SIZE],
	month[SIZE], wday[SIZE], command[SIZE];
char	*tokv[] = { min, hour, day, month, wday };
FILE	*fd, *err;


/*
 *	This is the basics, ready for bells and whistles
 *
 */

void main()
{
	void wakeup(), killer();

	/*
	 *	fopen() will create the file if it does not exist.
	 *	Any other errors will be output to stderr at startup.
	 */
        
	if ((err = fopen(CRONERR, "a")) == (FILE *)NULL)  {
		perror("cron");
		exit(1);
	}

	setbuf(err, (char *)NULL);	/* error I/O is now unbuffered */

	close(0); close(1); close(2);	/* close all I/O paths */

	for (;;)  {
		signal(SIGALRM, wakeup);
		alarm(59);
		pause();		/* check for work every minute */

		signal(SIGALRM, killer);
		alarm(1);
		wait((int *)NULL);	/* clean up zombie children */
	}
}


/*
 *	Cron does not wait() for child to die.  Therefore children
 *	become zombies when they complete.  In order to clear out the
 *	"floating dead babies" the parent must execute wait() every
 *	now and then.  (Thanks to Fred Buck for enlightenment
 *	See Doctor Dobbs #126 April 87, p. 152)
 */

void killer()
{
}


void wakeup()
{
	register struct tm *tm;
	struct tm *localtime();
	char *ctime();
	long cur_time;

	time(&cur_time);		/* get the current time */
	tm = localtime(&cur_time);	/* break it down */

	if (access(CRONTAB, _READ) == -1)  {
	  fprintf(err,"%s has no read permission %s",CRONTAB,ctime(&cur_time));
	  return;
	}
	else
	  fd = fopen(CRONTAB, "r");

	eof = FALSE;

	while (!eof)  {
		if (getline() && match(min,tm->tm_min) &&
		   match(hour,tm->tm_hour) && match(day,tm->tm_mday) &&
		   match(month,tm->tm_mon) && match(wday,tm->tm_wday))  {

		   /*
		    *  Execute command in the shell
		    */

		   if (fork() == 0)  {
			execl("/bin/shell", "shell", "+bcx", command, 0);
			fprintf(err,"Can't access shell %s", ctime(&cur_time));

			fclose(err);
			fclose(fd);

			exit(1);
		   }

		}
	}

	fclose(fd);
}


/*
 *	A line consists of six fields.  The first five are:
 *
 *		minute:         0-59
 *		hour:           0-23
 *		day:            1-31
 *		month:          1-12
 *		weekday:        0-6 (Sunday = 0)
 *
 *	The fields are seperated by spaces or tabs, with the
 *	first field left justified (no leading spaces or tabs).
 *	See below for optional field syntax.
 *
 *	The last field is the command field.  This command will
 *	be executed by the shell just as if typed from a console.
 */

int getline()
{
	register char *p;
	register int   i;
	char    buffer[MAXLINE], *scanner();

	if (fgets(buffer, sizeof buffer, fd) == (char *)NULL)  {
		eof = TRUE;
		return(FALSE);
	}

	for (p = buffer, i = 0; i < 5; i++)  {
		if ((p = scanner(tokv[i], p)) == (char *)NULL)
			return(FALSE);
	}

	strcpy(command, p);     /* scoop the command */
	return(TRUE);
}


char *scanner(token, offset)
register char   *token;		/* target buffer to receive scanned token */
register char   *offset;	/* place holder into source buffer */
{
	while ((*offset != ' ') && (*offset != '\t') && *offset)
		*token++ = *offset++;

	/*
	 *      Check for possible error condition
	 */
         
	if (!*offset)
		return ((char *)NULL);

	*token = '\0';
        
	while ((*offset == ' ') || (*offset == '\t'))
		offset++;

	return (offset);
}


/*
 *	This routine will match the left string with the right number.
 *
 *	The string can contain the following syntax:
 *
 *	*		This will return TRUE for any number
 *	x,y [,z, ...]	This will return TRUE for any number given.
 *	x-y		This will return TRUE for any number within
 *			the range of x thru y.
 */

int match(left, right)
register char   *left;
register int    right;
{
	register int	n;	register char	c;

	n = 0;
	if (!strcmp(left, "*"))
		return(TRUE);

	while ((c = *left++) && (c >= '0') && (c <= '9'))
		n  =  (n * 10) + c - '0';

	switch (c)  {
		case '\0':
			return (right == n);

		case ',':
			if (right == n)
				return(TRUE);
			do {
			      n = 0;
			      while ((c = *left++) && (c >= '0') && (c <= '9'))
					n = (n * 10) + c - '0';
			      if (right == n)
					return(TRUE);
			} while (c == ',');
			return(FALSE);

		case '-':
			if (right < n)
				return(FALSE);

			n = 0;
			while ((c = *left++) && (c >= '0') && (c <= '9'))
				n = (n * 10) + c - '0';

			return(right <= n);
	}
}

/* EOF */
-------------------
S. R. Sampson, Nicaragua Freedom Air, ihnp4!killer!sampson
"We help you find your God"
-------------------

dhesi@bsu-cs.UUCP (Rahul Dhesi) (02/02/88)

In article <797@vixie.UUCP> paul@vixie.UUCP (Paul Vixie Esq) writes:
[re Vixie's Cron]
>It was posted to comp.sources.misc, since it was only a beta version.

Vixie's Cron has been running on bsu-cs, a VAX-11/785, for several
months now, and handling everything previously done by the standard
cron.  Haven't found a single bug yet!  Thanks, Paul.
-- 
Rahul Dhesi         UUCP:  <backbones>!{iuvax,pur-ee,uunet}!bsu-cs!dhesi