⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toolkit.c

📁 openPBS的开放源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
    return (0);}/* * "Forget" about the file named by 'filename', or all files if 'filename' * is a NULL pointer.  Returns the number of files removed from the watch * list, or -1 if the file is not found (or the list was empty). */intschd_forget_file(char *filename){    /* char   *id = "schd_forget_file"; */    FileStatus *stats, *prev, *next;    int  count;    count = 0;    prev  = NULL;    /*     * Remove entries in the list of file stats being watched that match     * the supplied filename, or all entries if 'filename' is NULL.     */    for (stats = filestats; stats != NULL; stats = next) {	next = stats->next;	if (filename && (strcmp(filename, stats->filename) != 0)) {	    prev = stats;	    continue;	}	if (stats == filestats) {	    filestats = next;	} else {	    prev->next = next;	}	/* Free the schd_strdup()'d filename */	free(stats->filename);	free(stats);	count ++;    }    if (count)	return (count);    else	return (-1);}/* * Given a batch_status structure (bs), search the attributes for the  * requested attribute (at) and return it's value (v).  If the attribute  * contains a resource list, then search the resource list for the requested * resource (rs).  The function returns the value if found or a NULL if  * the search is not successful. */char *schd_getat(char *at, Batch_Status *bs, char *rs){    /* char   *id = "getat"; */    AttrList *a;    for (a = bs->attribs; a != NULL; a = a->next) {	/* Is this the attribute we are looking for? */	if (!strcmp(at, a->name)) {	    /*	     * If no resource specified, OR this resource matches the 	     * requested one, return a pointer to the attribute's value.	     */	    if ((rs == NULL) || (strcmp(rs, a->resource) == 0))		return (a->value);	}    }    return (NULL);	/* No matching attributes. */}/* * POSIX/ANSI does not provide a portable method for finding the system time  * of day at sub-second resolution.  gettimeofday() is not POSIX 1003.1  * compliant, so it cannot be used if _POSIX_SOURCE is defined. * * POSIX 1003.1 provides the times() library call, which returns the number * of ticks since some fixed time.  From this number of ticks, an elapsed  * time can be calculated to sub-second granularity.  Note that the system * must be asked how many ticks there are per second. */#ifndef HAVE_GETTIMEOFDAY#if (!defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)) || \	(defined(sgi) && (defined(_BSD_COMPAT) || defined(_BSD_TIME)))#define HAVE_GETTIMEOFDAY#endif /* ! _POSIX_SOURCE */#endif /* ! HAVE_GETTIMEOFDAY */voidschd_timestamp(char *msg){#ifdef DEBUG    char *id = "schd_timestamp";    static char  timestr[32];    time_t sec;    struct tms tms;    static clock_t oticks = 0;    clock_t ticks;    clock_t dsec, dmsec;    static int tickspersec = 0;#ifdef HAVE_GETTIMEOFDAY    struct timeval now;    if (gettimeofday(&now, NULL)) {	DBPRT(("%s: gettimeofday() failed.\n", id));	return;    }    sec = now.tv_sec;#else /* HAVE_GETTIMEOFDAY */    if (time(&sec) == (time_t)(-1)) {	DBPRT(("%s: gettimeofday() failed.\n", id));	return;    }#endif /* else HAVE_GETTIMEOFDAY */    strcpy(timestr, ctime(&sec));    timestr[19] = '\0';#ifdef HAVE_GETTIMEOFDAY    DBPRT(("%s: %-10s %s.%03ld ", id, (msg ? msg : "TIMESTAMP"), 	&timestr[11], now.tv_usec / 1000));#else /* HAVE_GETTIMEOFDAY */    DBPRT(("%s: %-10s %s ", id, (msg ? msg : "TIMESTAMP"), &timestr[11]));#endif /* else HAVE_GETTIMEOFDAY */    /* If not already known, find the number of ticks per second. */    if (tickspersec == 0) {	tickspersec = (int)sysconf(_SC_CLK_TCK);	if (tickspersec < 0) {	    DBPRT(("%s: sysconf(_SC_CLK_TCK) failed.\n", id));	    return;	}    }    ticks = times(&tms);    if (ticks == (clock_t)(-1)) {	DBPRT(("%s: times() failed.\n", id));	return;    }    if (oticks) {	dsec  = (ticks - oticks) / tickspersec;	dmsec = (((ticks - oticks) % tickspersec) * 1000) / tickspersec;	DBPRT(("elapsed %ld.%03ld\n", dsec, dmsec));    }    oticks = ticks;#endif /* DEBUG */    return;}/* * Free a set of QueueList structures that reference (through qptr->queue) * an existing set of Queue structs.  The Queues themselves are not affected. */intschd_free_qlist(QueueList *qlist){    QueueList *qptr, *next;    int   num = 0;    for (qptr = qlist; qptr != NULL; qptr = next) {	next = qptr->next;	free(qptr);	num++;    }    return (num);}/* * This function differs from the schd_free_qlist() function in that it * actually frees the Queue's themselves, while schd_free_qlist() simply * destroys the list structures that point to the Queue's. */int schd_destroy_qlist(QueueList *list){    int num_items = 0;    QueueList *qptr, *qnext;        for (qptr = list; qptr != NULL; qptr = qnext) {	qnext = qptr->next;	if (qptr->queue->qname)	    free(qptr->queue->qname);	/* Free strdup()'d storage. */	if (qptr->queue->useracl)	    schd_free_useracl(qptr->queue->useracl);	if (qptr->queue->exechost)	    free(qptr->queue->exechost);	free (qptr->queue);		/* Free the queue struct. */	free (qptr);			/* And the list that pointed to it. */	num_items++;			/* Count it. */    }    return (num_items);}/* * strdup(3) is not required for POSIX compliance, so we must provide a  * "lookalike". */char *schd_strdup(char *string){    size_t  length;    char   *copy;    /*     * Allocate new space for a copy of the string contents, and a      * trailing '\0'.     */    length = strlen(string) + 1;       copy = malloc(length);    if (copy == NULL)	return (NULL);    memcpy(copy, string, length);    return(copy);}/* * Convert characters of a string to lowercase.  Return a pointer to * the original string. */char *schd_lowercase(char *string){    char   *p;    for (p = string; *p != '\0'; p++) {	if (isupper(*p))	    *p = tolower(*p);    }    return (string);}/* * Return a pointer to a copy of the host part of the fqdn presented.  I.e. * if fqdn is "foo.bar.com", copy the host part and return a pointer to it, * with the contents "foo".  If it is already short, return a copy anyway. */char *schd_shorthost(char *fqdn){    char   *shorthost, *dotp;    size_t  length;    /* Check for bogus fqdn. */    if (*fqdn == '.')	return (NULL);    if ((dotp = strchr(fqdn, '.')) != NULL)	length = (size_t)(dotp - fqdn);    else	length = strlen(fqdn);    if ((shorthost = (char *)malloc(length + 1)) != NULL) {	memcpy(shorthost, fqdn, length);	shorthost[length] = '\0';    }    return (shorthost);}/* * Move the internal representation of the given job from the list on its * queue to the tail of the destination queue's list. * * If the destination queue is NULL, this is equivalent to deleting the job * from the per-queue lists. */intschd_move_job_to(Job *thisjob, Queue *destq){    Job    *prev, *tail;    Queue  *srcq;    srcq = thisjob->queue;    if (srcq == NULL) {	DBPRT(("move_job_to(Job %s, Queue %s) before job->queue init'd\n",	    thisjob->jobid, destq ? destq->qname : "[dead]"));	return (-1);    }    if (srcq->jobs == NULL) {	DBPRT(("job %s says queue %s is owner, but joblist is NULL.\n",	    thisjob->jobid, srcq->qname));	return (-1);    }    /*     * If the head of the source queue's job list is not the job in question,     * walk down the list until we find the element before the job (i.e.     * until the element's next pointer is equal to the job's pointer).     */    prev = NULL;    if (srcq->jobs != thisjob) {	for (prev = srcq->jobs; prev != NULL; prev = prev->next) {	    if (prev->next == thisjob)		break;	}	if (prev == NULL) {	    DBPRT(("job %s says queue %s is owner, but not on queue joblist.\n",		thisjob->jobid, srcq->qname));	    return (-1);	}    }    /*     * Account for the moved job.  Decrement the appropriate counters on the     * source queue, and increment them on the destination queue (if present)     */    switch (thisjob->state) {    case 'R':	srcq->running --;	if (destq)	    destq->running ++;	break;        case 'Q':	srcq->queued --;	if (destq)	    destq->queued ++;	break;    default:	/* Do nothing.  Present for completeness. */	break;    }    /*      * Remove the job from the source queue's list.  The previous pointer may     * be NULL -- this indicates that the job is the head of the source list.     * In that case, simply move the source queue's pointer forward and we're     * done.  Otherwise, point the previous job's next pointer to skip over     * this one.  Either way, the job is no longer a list, so set its next      * pointer to NULL.     */    if (prev == NULL)	srcq->jobs = srcq->jobs->next;    else	prev->next = thisjob->next;    thisjob->next = NULL;    if (destq) {	/*	 * Append the job to the destination queue job list.  Like the source	 * queue, a NULL pointer in queue->jobs indicates that the list is	 * empty.  In this case, the detached job becomes the head of the	 * list.  Otherwise, find the tail of the list and hook the new job	 * onto the end of the list.	 */	if (destq->jobs == NULL) {	    destq->jobs = thisjob;	} else {	    for (tail = destq->jobs; tail->next != NULL; tail = tail->next)		/* do nothing -- just walk the list */ 		;	    tail->next = thisjob;	}	/* Make the destination the owner of the job. */	thisjob->queue = destq;    } else {	/*	 * Moving to a NULL queue is a job deletion.  This job is no longer	 * referenced on the source, so will be lost.  Free it's resources.	 */	schd_free_jobs(thisjob);    }    return (0);}/* * It is important to be able to accurately determine when it is prime and  * non-prime time.  This is accomplished by reading the holidays file and  * creating a table of prime and non-prime times. * A quick search of the table can then determine whether we are in prime  * or non-prime time. */#define	SUNDAY   0#define SATURDAY 1	/* XXX Saturday is 6 in timeval */#define WEEKDAY  2#define	PRIME    0#define NONPRIME 1#define MAX_HOLIDAYS	256/* * Range of valid primetime times is 0 - 86399 (hr * 3600 + min * 60 + sec). * Valid times cannot be negative. */#define	ALL      -1#define NONE     -2static int Num_holidays;static int holidays[MAX_HOLIDAYS][2];static int weekdays[3][2];static int day_prime_time (int, int);void init_holidays (void);/* * Given a time_t, determine if it is prime or nonprime time then.  If * the 'when' argument is 0, find out if it is primetime *now*. * Return 1 for prime time, 0 for nonprime time */int schd_prime_time(time_t when){    struct tm *tmptr;    int     cur_time;	/* Now (decimal - 9:30AM == 930, 6:45PM == 1845) */    int     h_idx;    int     rcode;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -