Re: Temporaere erhoehung destTimeoutlimits in initskripten (openrc)

[email protected]
Newsgroups gmane.linux.gentoo.user.german
Message-ID <[email protected]>
On Tue, Feb 05, 2013 at 06:34:47PM +0100, Sandy Marko Knauer wrote:
> Am 05.02.2013 14:49, schrieb [email protected]:
> > hallo,
> >
> > hab jetzt ein wenig im openrc code geschmoekert. und ohne anpassung
> > daran laesst sich das vermutlich nich realisieren.
> >
> > gruss
> > martin
> >
> Hi,
> 
> könnte einige Interessieren die dieses Thema verfolgt haben.
> 
> http://dev.gentoo.org/~vapier/openrc/projects/openrc/ticket/125.html
> 
> Sandy
> 

geht glaub ich ein etwas andere richtung. zumindest scheint es mir so

sollte ausser mir noch jemand interesse an einem derartigen timeout
mechanismus haben, kann er den patch im anhang verwenden.
ich hoff das ist ok, dass ich den einfach so anhaeng.

dazu habe ich im depend bereich das schluesselwort 'mintime' definiert.
anschliessen wird die zeit in sekunden angegeben, um die der
timeoutmechansimus verzoegert wird.

gruss
martin
0001-Allow-to-specify-a-minimum-service-handling-time.patch (text/x-diff, 4.4 KB)
From b9b31ee3c746ef7b7b4260ee4816259b3950bb70 Mon Sep 17 00:00:00 2001
From: Hinterwaeldler <[email protected]>
Date: Fri, 8 Feb 2013 13:16:54 +0000
Subject: [PATCH] Allow to specify a minimum service handling time

When a service is started their could be warnings due to larger
processing time.
To avoid the usage of the complete deactivation of the timeout mechanism
a 'mintime' dependancy is introduced.

During the given time the regular timeout mechanism is deactived.
After the time expires the regular timeout is still able to kill the
process if necessary.
---
 man/runscript.8     |  5 +++++
 sh/gendepends.sh.in |  3 +++
 src/rc/runscript.c  | 51 +++++++++++++++++++++++++++++++++++++--------------
 3 files changed, 45 insertions(+), 14 deletions(-)

diff --git a/man/runscript.8 b/man/runscript.8
index 044bef7..25a818a 100644
--- a/man/runscript.8
+++ b/man/runscript.8
@@ -191,6 +191,11 @@ Same as -jail, but for Xen DOM0 systems.
 .It Dv -xenu
 Same as -jail, but for Xen DOMU systems.
 .El
+.It Ic mintime 
+Specify a minimum amount of time in seconds a service needs to complete.
+During this time no timeout can occure (e.g. need more than 60 seconds).
+After the given time expires, a timeout can occure.
+This values only influence the timeout mechanism i.e. the service handling may use less time.
 .El
 .Pp
 To see how to influence dependencies in configuration files, see the
diff --git a/sh/gendepends.sh.in b/sh/gendepends.sh.in
index f78f3d3..987ad4b 100644
--- a/sh/gendepends.sh.in
+++ b/sh/gendepends.sh.in
@@ -31,6 +31,9 @@ keyword() {
 depend() {
 	:
 }
+mintime(){
+	[ -n "$*" ] && echo "$RC_SVCNAME mintime $*" >&3
+}
 
 _done_dirs=
 for _dir in \
diff --git a/src/rc/runscript.c b/src/rc/runscript.c
index e504e4a..16f7207 100644
--- a/src/rc/runscript.c
+++ b/src/rc/runscript.c
@@ -488,8 +488,11 @@ svc_wait(const char *svc)
 	char file[PATH_MAX];
 	int fd;
 	bool forever = false;
-	RC_STRINGLIST *keywords;
-	struct timespec interval, timeout, warn;
+	RC_STRINGLIST *keywords, *mintime_list;
+	struct timespec interval, timeout, warn, mintime;
+	RC_STRING *mintime_element;
+	char *conf_value, *mintime_check;
+	int conf_value_length, mintime_value = 0;
 
 	/* Some services don't have a timeout, like fsck */
 	keywords = rc_deptree_depend(deptree, svc, "keyword");
@@ -498,6 +501,24 @@ svc_wait(const char *svc)
 		forever = true;
 	rc_stringlist_free(keywords);
 
+	/* Allow services to use a specified amount of time without warnings */
+	mintime_list = rc_deptree_depend(deptree, svc, "mintime");
+	if (mintime_list) {
+		mintime_element = TAILQ_FIRST(mintime_list);
+		if (mintime_element) {
+			conf_value = mintime_element->value;
+			conf_value_length = strlen(conf_value);
+			mintime_value = strtol(conf_value, &mintime_check, 10);
+			if (mintime_check != conf_value + conf_value_length ||
+			    mintime_value < 0) {
+				mintime_value = 0;
+				eerror("Invalid mintime definition: %s",
+				    conf_value);
+			}
+		}
+	}
+	rc_stringlist_free(mintime_list);
+
 	snprintf(file, sizeof(file), RC_SVCDIR "/exclusive/%s",
 	    basename_c(svc));
 
@@ -507,6 +528,8 @@ svc_wait(const char *svc)
 	timeout.tv_nsec = 0;
 	warn.tv_sec = WARN_TIMEOUT;
 	warn.tv_nsec = 0;
+	mintime.tv_sec = mintime_value;
+	mintime.tv_nsec = 0;
 	for (;;) {
 		fd = open(file, O_RDONLY | O_NONBLOCK);
 		if (fd != -1) {
@@ -526,15 +549,18 @@ svc_wait(const char *svc)
 				return false;
 		}
 		if (!forever) {
-			timespecsub(&timeout, &interval, &timeout);
-			if (timeout.tv_sec <= 0)
-				return false;
-			timespecsub(&warn, &interval, &warn);
-			if (warn.tv_sec <= 0) {
-				ewarn("%s: waiting for %s (%d seconds)",
-				    applet, svc, (int)timeout.tv_sec);
-				warn.tv_sec = WARN_TIMEOUT;
-				warn.tv_nsec = 0;
+			timespecsub(&mintime, &interval, &mintime);
+			if (mintime.tv_sec <= 0){
+				timespecsub(&timeout, &interval, &timeout);
+				if (timeout.tv_sec <= 0)
+					return false;
+				timespecsub(&warn, &interval, &warn);
+				if (warn.tv_sec <= 0) {
+					ewarn("%s: waiting for %s (%d seconds)",
+					    applet, svc, (int)timeout.tv_sec);
+					warn.tv_sec = WARN_TIMEOUT;
+					warn.tv_nsec = 0;
+				}
 			}
 		}
 	}
@@ -1348,9 +1374,6 @@ runscript(int argc, char **argv)
 			    applet_list,
 			    runlevel, depoptions);
 			rc_stringlist_free(tmplist);
-			TAILQ_FOREACH(svc, services, entries)
-			    printf("%s ", svc->value);
-			printf ("\n");
 			rc_stringlist_free(services);
 			services = NULL;
 		} else if (strcmp (optarg, "status") == 0) {
-- 
1.7.12.4
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.