File: agenda.c

package info (click to toggle)
zmailer 2.99.55-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 19,516 kB
  • ctags: 9,694
  • sloc: ansic: 120,953; sh: 3,862; makefile: 3,166; perl: 2,695; python: 115; awk: 22
file content (96 lines) | stat: -rw-r--r-- 2,435 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 *	Copyright 1990 by Rayan S. Zachariassen, all rights reserved.
 *	This will be free software, but only when it is finished.
 */
/*
 *	Lots of modifications (new guts, more or less..) by
 *	Matti Aarnio <mea@nic.funet.fi>  (copyright) 1992-1995
 */

#include "hostenv.h"
#include <sfio.h>
#include "scheduler.h"
#include "prototypes.h"

int	/* return non-zero when there are some childs
	   available for start				*/
doagenda()
{
	struct thread *ncuritem, *nncuritem;
	int didsomething = 0;

	mytime(&now);

	ncuritem = thread_head;

	if (verbose)
	  sfprintf(sfstdout,"curitem %p curitem->wakeup %lu now %d\n",
		   ncuritem, ncuritem ? ncuritem->wakeup : 0, (int)now);

	/* thread_head -chain should be in time order, thus the while-loop
	   should be traversed only once, because  thread_start kicks
	   right away (or reschedules) */

	while (ncuritem  && ncuritem->wakeup <= now  ) {
	  /* Object pointed by  ncuritem  may disappear due to
	     expiration at thread_start() .. */
	  nncuritem = ncuritem->nexttr;
	  /* Not running, and wakeup in past ? */
	  if (ncuritem->proc == NULL && ncuritem->wakeup <= now)
	    /* Try to start it! */
	    while (thread_start(ncuritem, 0))
	      ++ didsomething;

	  ncuritem = nncuritem;

	  queryipccheck();
	}

	mytime(&now);

	/* if (verbose)
	   printf("alarmed %d\n", now);  */

	return (didsomething);
}

/* Do immediate scheduling of given host-indentifier. */
int
turnme(turnarg)
const char *turnarg;
{
	struct spblk *spl;
	struct web *wp;
	char *cp = strchr(turnarg,' ');
	struct thread *ncuritem, *nncuritem;
	spkey_t spk;
	int rc = 0;

	/* caller has done 'strlower()' to our input.. */
	if (cp) *cp = 0;  /* Chop at the first SPACE or TAB */
	cp = strchr(turnarg,'\t');
	if (cp) *cp = 0;

	spk = symbol_lookup_db((void*)turnarg, spt_mesh[L_HOST]->symbols);
	spl = sp_lookup(spk, spt_mesh[L_HOST]);
	if (spl == NULL || spl->data == NULL) {
	  /* Not found, nothing to do.. */
	  return 0;
	}
	wp = (struct web *)spl->data;
	
	ncuritem = thread_head;
	while (ncuritem != NULL) {
	  /* Object pointed by  ncuritem  may disappear due to
	     expiration at thread_start()	 */
	  nncuritem = ncuritem->nexttr;

	  if (wp == ncuritem->whost && ncuritem->proc == NULL) {
	    ncuritem->wakeup = 0; /* Force its starttime! */
	    rc += thread_start(ncuritem, 1);
	    /* We MAY get multiple matches, though it is unlikely.. */
	  }
	  ncuritem = nncuritem;
	}
	return rc;
}