File klibc-2.0.4-sleep.patch of Package klibc

diff -Nurp klibc-2.0.4/usr/utils/sleep.c klibc-2.0.4-sleep/usr/utils/sleep.c
--- klibc-2.0.4/usr/utils/sleep.c	2014-07-26 03:15:07.000000000 +0300
+++ klibc-2.0.4-sleep/usr/utils/sleep.c	2014-09-22 05:49:10.315413939 +0300
@@ -5,22 +5,56 @@
 
 int main(int argc, char *argv[])
 {
-	struct timespec ts;
-	char *p;
+	int i;
+	struct timespec ts[argc - 1];
 
-	if (argc != 2)
-		goto err;
+	if (argc < 2) {
+		fprintf(stderr, "%s: missing operand\n", argv[0]);
+		return 1;
+	}
+
+	argv++;
+	argc--;
+	for (i = 0; i < argc; i++) {
+		size_t l = strlen(argv[i]) - 1;
+		unsigned int f;
+
+		switch (argv[i][l]) {
+		case 'd':
+			f = 24 * 60 * 60;
+			break;
+		case 'h':
+			f = 60 * 60;
+			break;
+		case 'm':
+			f = 60;
+			break;
+		case 's':
+			f = 1;
+			break;
+		default:
+			f = 0;
+			break;
+		}
+		if (f)
+			argv[i][l] = '\0';
+		if (*strtotimespec(argv[i], &ts[i])) {
+			fprintf(stderr, "%s: invalid time interval '%s'\n", argv[0], argv[i]);
+			return 1;
+		}
+		if (f > 1) {
+			ts[i].tv_sec *= f;
+			if (ts[i].tv_nsec) {
+				unsigned long long n = (unsigned long long)ts[i].tv_nsec * f;
+
+				ts[i].tv_sec += n / 1000000000;
+				ts[i].tv_nsec *= n % 1000000000;
+			}
+		}
+	}
 
-	p = strtotimespec(argv[1], &ts);
-	if (*p)
-		goto err;
-
-	while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
-		;
+	for (i = 0; i < argc; i++)
+		while (nanosleep(&ts[i], &ts[i]) == -1 && errno == EINTR);
 
 	return 0;
-
-err:
-	fprintf(stderr, "Usage: %s seconds[.fraction]\n", argv[0]);
-	return 1;
 }
openSUSE Build Service is sponsored by