[Pkg-sysvinit-commits] r1202 - in sysvinit/trunk/debian: . startpar

pere at alioth.debian.org pere at alioth.debian.org
Mon Jan 7 22:12:42 UTC 2008


Author: pere
Date: 2008-01-07 22:12:42 +0000 (Mon, 07 Jan 2008)
New Revision: 1202

Modified:
   sysvinit/trunk/debian/changelog
   sysvinit/trunk/debian/startpar/Makefile
   sysvinit/trunk/debian/startpar/makeboot.c
   sysvinit/trunk/debian/startpar/makeboot.h
   sysvinit/trunk/debian/startpar/proc.c
   sysvinit/trunk/debian/startpar/startpar.8
   sysvinit/trunk/debian/startpar/startpar.c
Log:
  * Updated the startpar source to version 0.50 from
    <URL:ftp://ftp.suse.com/pub/projects/init/>.

Modified: sysvinit/trunk/debian/changelog
===================================================================
--- sysvinit/trunk/debian/changelog	2008-01-06 18:21:45 UTC (rev 1201)
+++ sysvinit/trunk/debian/changelog	2008-01-07 22:12:42 UTC (rev 1202)
@@ -58,6 +58,8 @@
   * Improve content of initscripts README.Debian, and document the new
     sendsigs omitpid interface there (Closes: #459425).  Based on
     patch from Kel Modderman.
+  * Updated the startpar source to version 0.50 from
+    <URL:ftp://ftp.suse.com/pub/projects/init/>.
 
  -- Petter Reinholdtsen <pere at debian.org>  Mon, 31 Dec 2007 12:18:42 +0100
 

Modified: sysvinit/trunk/debian/startpar/Makefile
===================================================================
--- sysvinit/trunk/debian/startpar/Makefile	2008-01-06 18:21:45 UTC (rev 1201)
+++ sysvinit/trunk/debian/startpar/Makefile	2008-01-07 22:12:42 UTC (rev 1202)
@@ -1,4 +1,4 @@
-VERSION = 0.49
+VERSION = 0.50
 
 INSTALL		= install -m 755
 INSTALL_DATA	= install -m 644
@@ -21,7 +21,7 @@
 
 install: startpar
 	$(INSTALL) -d $(DESTDIR)$(sbindir) $(DESTDIR)$(man8dir)
-	$(INSTALL) -s startpar $(DESTDIR)$(sbindir)/.
+	$(INSTALL) startpar $(DESTDIR)$(sbindir)/.
 	$(INSTALL_DATA) startpar.8 $(DESTDIR)$(man8dir)/.
 
 clean:

Modified: sysvinit/trunk/debian/startpar/makeboot.c
===================================================================
--- sysvinit/trunk/debian/startpar/makeboot.c	2008-01-06 18:21:45 UTC (rev 1201)
+++ sysvinit/trunk/debian/startpar/makeboot.c	2008-01-07 22:12:42 UTC (rev 1202)
@@ -68,6 +68,18 @@
 }
 
 /*
+ * Set and propagate importance of a node to all depencies of this node
+ */
+static void add_importance(struct makenode *node, int importance)
+{
+	struct makelist *s = node->depend;
+
+	node->importance += importance;
+	for (s = node->depend; s; s = s->next)
+		add_importance(s->node, importance);
+}
+
+/*
  * create a dependecy/selection node
  */
 static struct makelist *new_list(struct makenode *node, struct makelist *next)
@@ -187,6 +199,19 @@
 		}
 	}
 	fclose(fp);
+
+	for (node = tree_list; node; node = node->next) {
+		int importance = 0;
+
+		if (! strcmp(node->name, "xdm"))
+			importance = 100;
+
+		if (! strncmp(node->name, "early", 5))
+			importance = 8000;
+
+		if (importance)
+			add_importance(node, importance);
+	}
 }
 
 /*
@@ -306,16 +331,15 @@
  */
 struct makenode *pickup_task(void)
 {
-	struct makenode *node;
+	struct makenode *node, *best = (struct makenode*)0;
 
 	for (node = tree_list; node; node = node->next) {
-		if (! node->status && ! node->num_deps) {
-			node->status = T_RUNNING;
-			blogger("service %s", node->name);
-			return node;
+		if ((! node->status) && (! node->num_deps) &&
+		    ((! best) || (node->importance > best->importance))) {
+			best = node;
 		}
 	}
-	return NULL;
+	return best;
 }
 
 /*
@@ -378,12 +402,13 @@
 	printf("\"\n");
 }
 
-#if 0
+#if DEBUG
 void dump_status(void)
 {
 	struct makenode *node;
 
 	for (node = tree_list; node; node = node->next)
-		fprintf(stderr, "XXX %s: status = %d, dep = %d, int = %d\n", node->name, node->status, node->num_deps, node->interactive);
+		fprintf(stderr, "XXX %s: status = %d, dep = %d, int = %d, imp = %d\n",
+			node->name, node->status, node->num_deps, node->interactive, node->importance);
 }
 #endif

Modified: sysvinit/trunk/debian/startpar/makeboot.h
===================================================================
--- sysvinit/trunk/debian/startpar/makeboot.h	2008-01-06 18:21:45 UTC (rev 1201)
+++ sysvinit/trunk/debian/startpar/makeboot.h	2008-01-07 22:12:42 UTC (rev 1202)
@@ -15,6 +15,7 @@
 	int status;
 	struct makenode *next;
 	int interactive;
+	int importance;
 };
 
 /* dependency and selection list nodes */
@@ -25,18 +26,10 @@
 
 extern int tree_entries;
 extern struct makenode *tree_list;
-extern char *run_action;
 
-void parse_makefile(const char *path);
-void check_run_files(const char *action, const char *prev, const char *run);
-
-struct makenode *pickup_task(void);
-void finish_task(struct makenode *n);
-
-extern int do_splash;
-extern int progress;
-void init_splash(char *action);
-
-void *xcalloc(size_t nmemb, size_t size);
-
-void print_run_result(int *resvec, struct makenode **nodevec, const char *action);
+extern void parse_makefile(const char *path);
+extern void check_run_files(const char *action, const char *prev, const char *run);
+extern struct makenode *pickup_task(void);
+extern void finish_task(struct makenode *n);
+extern void *xcalloc(size_t nmemb, size_t size);
+extern void print_run_result(int *resvec, struct makenode **nodevec, const char *action);

Modified: sysvinit/trunk/debian/startpar/proc.c
===================================================================
--- sysvinit/trunk/debian/startpar/proc.c	2008-01-06 18:21:45 UTC (rev 1201)
+++ sysvinit/trunk/debian/startpar/proc.c	2008-01-07 22:12:42 UTC (rev 1202)
@@ -45,30 +45,29 @@
 
 int read_proc(unsigned long int * const prcs_run, unsigned long int * const prcs_blked)
 {
-    static char StatBuf[32*1024];
+    char StatBuf[2048], *ptr = &StatBuf[0];
     unsigned long int running, blocked;
-    ssize_t n;
-    int fd;
+    ssize_t len;
+    size_t skip;
+    FILE *stat;
 
     *prcs_run = 0;
     *prcs_blked = 0;
 
-    if ((fd = open( "/proc/stat", O_RDONLY )) < 0) {
+    if ((stat = fopen("/proc/stat", "r")) == (FILE*)0) {
 	fprintf(stderr, "ERROR: could not open /proc/stat: %s\n", strerror(errno));
 	return 1;
     }
 
-    n = read( fd, StatBuf, (sizeof(StatBuf) - 1));
-    close(fd);
-    if (n < 40) {
-	if (n < 0) {
-	    fprintf(stderr, "ERROR: could not read /proc/stat: %s\n", strerror(errno));
-	    return 1;
-	}
-	fprintf(stderr, "ERROR: no enough data in /proc/stat?\n");
-	return 1;
+    len = sizeof(StatBuf);
+    while ((len > 0) && (fgets(ptr, len, stat))) {
+	if (ptr[0] != 'p')
+	    continue;
+	skip = strlen(ptr);
+	len -= skip;
+	ptr += skip;
     }
-    StatBuf[n] = 0;
+    fclose(stat);
     
     /* These fields are not present in /proc/stat for 2.4 kernels */
     running = scan_one(StatBuf, "procs_running");

Modified: sysvinit/trunk/debian/startpar/startpar.8
===================================================================
--- sysvinit/trunk/debian/startpar/startpar.8	2008-01-06 18:21:45 UTC (rev 1201)
+++ sysvinit/trunk/debian/startpar/startpar.8	2008-01-07 22:12:42 UTC (rev 1202)
@@ -11,52 +11,63 @@
 
 .SH SYNOPSIS
 .B startpar
-.RB [ -p
+.RB [ \-p
 .IR par ]
-.RB [ -t
+.RB [ \-i
+.IR iorate ]
+.RB [ \-t
 .IR timeout ]
-.RB [ -T
+.RB [ \-T
 .IR global_timeout ]
-.RB [ -a
+.RB [ \-a
 .IR arg ]
 .B prg1
 .B prg2
 .B ...
 .br
 .B startpar
-.RB [ -p
+.RB [ \-p
 .IR par ]
-.RB [ -t
+.RB [ \-i
+.IR iorate ]
+.RB [ \-t
 .IR timeout ]
-.RB [ -T
+.RB [ \-T
 .IR global_timeout ]
-.B -M [
+.B \-M [
 .IR boot | start | stop ]
 
 .SH DESCRIPTION
-startpar is used to run multiple run-level scripts in parallel.
+startpar is used to run multiple run\-level scripts in parallel.
 The degree of parallelism on one
 .B CPU
 can be set with the
-.B -p
+.B \-p
 option, the default is full parallelism. An argument to all of
 the scripts can be provided with the
-.B -a
+.B \-a
 option.
+Processes block by pending
+.B I/O
+will weighting by the factor
+.IR 800 .
+To change this factor the option
+.B \-i
+can be used to specify an other value.
 
 The output of each script is buffered and written when the script
 exits, so output lines of different scripts won't mix. You can
 modify this behaviour by setting a timeout.
 
 The timeout set with the
-.B -t
+.B \-t
 option is used as buffer timeout. If the output buffer of a
 script is not empty and the last output was
 .I timeout
 seconds ago, startpar will flush the buffer.
 
 The
-.B -T
+.B \-T
 option timeout works more globally. If no output is printed for
 more than
 .I global_timeout
@@ -65,7 +76,7 @@
 script until it is finished.
 
 The
-.B -M
+.B \-M
 option switches
 .B startpar
 into a
@@ -94,6 +105,8 @@
 
 .SH COPYRIGHT
 2003,2004 SuSE Linux AG, Nuernberg, Germany.
+.br
+2007 SuSE LINUX Products GmbH, Nuernberg, Germany.
 
 .SH AUTHOR
 Michael Schroeder <mls at suse.de>

Modified: sysvinit/trunk/debian/startpar/startpar.c
===================================================================
--- sysvinit/trunk/debian/startpar/startpar.c	2008-01-06 18:21:45 UTC (rev 1201)
+++ sysvinit/trunk/debian/startpar/startpar.c	2008-01-07 22:12:42 UTC (rev 1202)
@@ -72,6 +72,7 @@
 static struct prg *prgs;
 static int inpar, par;
 static int pidpipe[2];
+static int iorate = 800;
 
 void *xcalloc(size_t nmemb, size_t size)
 {
@@ -127,6 +128,19 @@
   splashpid = 0;
 }
 
+void closeall(void)
+{
+  int s;
+
+  if (!prgs)
+    return;
+  for (s = 0; s < par; s++)
+    if (prgs[s].fd)
+      close(prgs[s].fd);
+  close(pidpipe[0]);
+  close(pidpipe[1]);
+}
+
 void callsplash(int n, char *path, char *action)
 {
   char *p;
@@ -169,24 +183,11 @@
     }
   close(1);
   dup(2);
+  closeall();
   execl("/sbin/splash", "splash", "-p", sbuf, "-t", tbuf, splashcfg, (char *)0);
   _exit(1);
 }
 
-
-void closeall(void)
-{
-  int s;
-
-  if (!prgs)
-    return;
-  for (s = 0; s < par; s++)
-    if (prgs[s].fd)
-      close(prgs[s].fd);
-  close(pidpipe[0]);
-  close(pidpipe[1]);
-}
-
 void writebuf(struct prg *p)
 {
   char *b = p->buf;
@@ -240,10 +241,11 @@
     return par;
 
   newpar = (par*numcpu) - prcs_run + 1; /* +1 for startpar its self */
-  newpar -= (prcs_blked>>2);		/* I/O load reduction */
+  newpar -= (prcs_blked * iorate);	/* I/O load reduction */
 
 #if DEBUG
   fprintf(stderr, "checksystem par=%d newpar=%d (prcs_run=%u) %ld\n", par, newpar, prcs_run, time(0));
+  dump_status();
 #endif
   if (newpar <= 0)
     return 1;
@@ -360,6 +362,7 @@
 
       close(1);
       dup(2);
+      closeall();
       if (run_mode)
 	{
 	  char path[128];
@@ -510,6 +513,7 @@
 
 int main(int argc, char **argv)
 {
+  volatile int broken;
   int timo = -1;
   int gtimo = -1;
   int r, c, i, s, last, num;
@@ -531,7 +535,7 @@
   numcpu = sysconf(_SC_NPROCESSORS_ONLN);
   myname = argv[0];
 
-  while ((c = getopt(argc, argv, "fhp:t:T:a:M:P:R:S:v")) != EOF)
+  while ((c = getopt(argc, argv, "fhp:t:T:a:M:P:R:S:vi:")) != EOF)
     {
       switch(c)
         {
@@ -568,6 +572,11 @@
 	case 'h':
 	  usage(0);
 	  break;
+	case 'i':
+	  iorate = atoi(optarg);
+	  if (iorate <= 0)
+	    iorate = 800;
+	  break;
 	default:
 	  usage(1);
 	  break;
@@ -706,6 +715,7 @@
       exit(1);
     }
 
+  broken = 0;					/* Detect broken hardware */
   gettimeofday(&glastio, 0);
   limit = checklimit(inpar, (run_mode) ? run_mode : "stop");
   lastlim.tv_sec  = glastio.tv_sec;
@@ -721,6 +731,7 @@
       last = -1;
       maxfd = -1;
       active = 0;
+      pid = 0;
 
       diff = ((now.tv_sec  - lastlim.tv_sec) * 1000) +
 	     ((now.tv_usec - lastlim.tv_usec)/ 1000);
@@ -795,8 +806,7 @@
 
 	} /* for (s = 0; s < par; s++) */
 
-      if (s < limit && num < argc)
-	continue;				/* start new processes */
+      broken++;					/* no endless loops due broken systems */
 
       if (interactive_task)
 	{
@@ -809,9 +819,14 @@
 	      p->pid = 0;
 	      p->fd = 0;
 	      interactive_task = NULL;
+	      broken = 0;			/* run_single() uses waitpid() */
 	      continue;
 	    }
 	}
+
+      if ((active < limit) && (num < argc) && (broken < argc))
+	continue;				/* try to start new processes */
+
       if (active == 0)
 	{
 	  if (num < argc)
@@ -828,16 +843,25 @@
       if (active == 1 && last >= 0)
 	{
 	  p = prgs + last;
-	  writebuf(p);
-	  continue;
+	  if ((pid = waitpid(p->pid, &r, maxfd < 0 ? 0 : WNOHANG)) == 0)
+	    {
+	      writebuf(p);
+	      continue;
+	    }
+          broken = 0;
 	}
 
       FD_SET(pidpipe[0], &rset);
       /* drain the pidpipe */
-      while ((r = read(pidpipe[0], pipebuf, sizeof pipebuf)) > 0)
+      while ((c = read(pidpipe[0], pipebuf, sizeof pipebuf)) > 0)
 	;
 
-      pid = waitpid(-1, &r, maxfd < 0 ? 0 : WNOHANG);
+      if (pid == 0)
+	{
+	  pid = waitpid(-1, &r, maxfd < 0 ? 0 : WNOHANG);
+	  broken = 0;
+	}
+
       if (pid > 0)
 	{
 	  if (pid == splashpid)
@@ -874,7 +898,7 @@
 		    }
 		  break;
 		}
-	    }
+	    } /* for (s = 0; s < par; s++) */
 	  continue;
 	}
 
@@ -993,9 +1017,9 @@
 		}
 	      p->lastio.tv_sec  = now.tv_sec;
 	      p->lastio.tv_usec = now.tv_usec;
-	    }
+	    } /* for (s = 0; s < par; s++) */
 	}
-    }
+    } /* for (;;) */
 
  finished:
   waitsplash();




More information about the Pkg-sysvinit-commits mailing list