예제 #1
0
파일: cron.c 프로젝트: AjeyBohare/minix
static void load_crontabs(void)
/* Load all the crontabs we like to run.  We didn't bother to make a list in
 * an array or something, this is too system specific to make nice.
 */
{
	DIR *spool;
#if __minix_vmd
	FILE *pkgs;
#endif

	tab_parse("/usr/lib/crontab", nil);
	tab_parse("/usr/local/lib/crontab", nil);
	tab_parse("/var/lib/crontab", nil);

#if __minix_vmd
	if ((pkgs= fopen("/usr/lib/packages", "r")) != nil) {
		char name[NAME_MAX+1];
		char *np;
		int c;
		char tab[sizeof("/var/opt//lib/crontab") + NAME_MAX];

		while ((c= fgetc(pkgs)) != EOF) {
			np= name;
			while (c != EOF && c != '/' && c != '\n') {
				if (np < name+NAME_MAX) *np++ = c;
				c= fgetc(pkgs);
			}
			*np= 0;
			while (c != EOF && c != '\n') c= fgetc(pkgs);

			if (name[0] == 0) continue;	/* ? */

			strcpy(tab, "/var/opt/");
			strcat(tab, name);
			strcat(tab, "/lib/crontab");
			tab_parse(tab, nil);
		}
		if (ferror(pkgs)) {
			log(LOG_CRIT, "/usr/lib/packages: %s\n",
							strerror(errno));
		}
		fclose(pkgs);
	} else {
		if (errno != ENOENT) {
			log(LOG_ERR, "/usr/lib/packages: %s\n",
							strerror(errno));
		}
	}
#endif /* Minix-vmd */

	if ((spool= opendir("/usr/spool/crontabs")) != nil) {
		struct dirent *entry;
		char tab[sizeof("/usr/spool/crontabs/") + NAME_MAX];

		while ((entry= readdir(spool)) != nil) {
			if (entry->d_name[0] == '.') continue;

			strcpy(tab, "/usr/spool/crontabs/");
			strcat(tab, entry->d_name);
			tab_parse(tab, entry->d_name);
		}
		closedir(spool);
	}

	/* Find the first to be executed AT job. */
	tab_find_atjob("/usr/spool/at");

	tab_purge();
	if (debug >= 2) {
		tab_print(stderr);
		fprintf(stderr, "%lu memory chunks in use\n",
			(unsigned long) alloc_count);
	}
}
예제 #2
0
파일: odftread.c 프로젝트: andreiw/polaris
int
odftread()
{
    if (Already_read)
	return(0);
    Already_read = TRUE;
    if (!Vflag) {
	/*
	 * table is hard-coded for "FACE" FMLI 
	 */
	register int i;

	for (i = 0; i < MAXODFT && FMLI_detab[i].objtype[0] != '\0';i++)
	    Detab[i] = FMLI_detab[i];
	Detab[i].objtype[0] = '\0';
    }
    else {
	register int i, moffset;
	char *p, *q, buf[PATHSIZ];
	char *b;
	char	*tmpstr;
	FILE *fp;
	int offset = 0, magic;
	long magic_offset[MAXMAGIC+1];
	char magic_bytes[MAXMAGIC];
	char	*get_skip();
	char	*tab_parse();
	long	tab_long();

	p = expand("$OASYS/info/OH/externals/detect.tab");
	fp = fopen(p, "r");
	free(p);
	if (fp == NULL)
	    fatal(MISSING, "detect.tab");
	tmpstr = NULL;
	while (get_skip(buf, PATHSIZ, fp) != NULL) {
	    /* flush optional line number */
	    for (b = buf; *b == '\t' || isdigit(*b); b++)
		;
	    b = tab_parse(&tmpstr, b);
	    strncpy(Detab[offset].objtype, tmpstr, OTYPESIZ);
	    if (b) {
		char	*unbackslash();

		b = tab_parse(&Detab[offset].defodi, b);
		p = unbackslash(Detab[offset].defodi);
		if (p[0] == '"')
		    memshift(p, p + 1, strlen(p));
		p += strlen(p) - 1;
		if (p[0] == '"')
		    p[0] = '\0';
	    }
	    Detab[offset].defmask = tab_long(&b, 16);
	    if (b && *b)
		Detab[offset].func_type = tab_long(&b, 16);
	    else {
#ifdef _DEBUG
		_debug(stderr, "BAD ODFT '%s'\n", Detab[offset].objtype);
#endif
		error(MUNGED, "heuristics table");
		continue;
	    }
	    switch (Detab[offset].func_type) {
	    case F_INT:
		Detab[offset].intern_func = tab_long(&b, 0);
		break;
	    case F_SHELL:
	    case F_EXEC:
		b = tab_parse(&tmpstr, b);
		Detab[offset].extern_func = tmpstr;
		tmpstr = NULL;
		break;
	    case F_PARTS:
	    case F_DPARTS:
		break;
	    case F_MAGIC:
		p = b;
		magic = 0;
		while (*p && magic < MAXMAGIC) {
		    moffset = strtol(p, &q, 0);
		    if (p == q)	/* strtol failed */
			break;
		    p = q;
		    while (*q && isspace(*q))
			q++;
		    if (*q == '"') {
			q++;
			while (*q && *q != '"' && magic < MAXMAGIC-1) {
			    magic_bytes[magic] = *q;
			    magic_offset[magic] = moffset++;
			    magic++;
			    q++;
			}
			if (*q)
			    q++;
		    } else {
			magic_offset[magic] = moffset;
			magic_bytes[magic] = (char) strtol(p,&q,0);
			if (p == q) {
			    p = '\0';
			    break;
			} else
			    p = q;
			magic++;
		    }
		}
		if (magic == 0) {
#ifdef _DEBUG
		    _debug(stderr, "BAD ODFT '%s' MAGIC: %s\n", Detab[offset].objtype, q);
#endif
		    error(MUNGED, "heuristics magic number");
		    continue;
		}
		magic_offset[magic] = -1L;

		/* for efficiency, the most common magic number
		 * case, 0, 1, -1, is coded up.
		 */

		if (magic == 2 && magic_offset[0] == 0L &&
		    magic_offset[1] == 1L) {
		    Detab[offset].magic_offset = &(Normal_mag_offset[0]);
		}
		else {
		    Detab[offset].magic_offset = (long *)calloc(magic+1, sizeof(long));
		    for (i = 0; i < magic+1; i++)
			Detab[offset].magic_offset[i] = magic_offset[i];
		}
		Detab[offset].magic_bytes = calloc(magic, sizeof(char));
		for (i = 0; i < magic; i++)
		    Detab[offset].magic_bytes[i] = magic_bytes[i];
		break;
	    default:
#ifdef _DEBUG
		_debug(stderr, "ODFT '%s' BAD FUNCTION: %d\n", Detab[offset].objtype, Detab[offset].func_type);
#endif
		error(MUNGED, "heuristics table function");
		continue;
	    }
	    offset++;
	}
	fclose(fp);
	Detab[offset].objtype[0] = '\0';
	if (tmpstr)
	    free(tmpstr);
    }
    return(0);
}