summaryrefslogtreecommitdiffstats
path: root/meta/recipes-bsp/apmd/apmd/legacy.patch
blob: 88713118057782d779fe8712bb5c174fe1c43949 (plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
From 3595933d221f0ba836917debc0776b8723972ec9 Mon Sep 17 00:00:00 2001
From: Alexander Kanavin <alex.kanavin@gmail.com>
Date: Tue, 11 Aug 2015 17:40:50 +0300
Subject: [PATCH 1/3] Patch with fixes provided by Debian.

This patch is taken from
ftp://ftp.debian.org/debian/pool/main/a/apmd/apmd_3.2.2-15.debian.tar.xz

Upstream-Status: Inappropriate [upstream is dead]
Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>

---
 Makefile |  2 +-
 apm.c    |  3 ++-
 apm.h    |  9 +++++++++
 apmd.c   | 15 ++++++++-------
 4 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile
index bf346d9..92fc0fd 100644
--- a/Makefile
+++ b/Makefile
@@ -43,7 +43,7 @@ DESTDIR=
 
 CC=gcc
 CFLAGS=-O -g
-XTRACFLAGS=-Wall -pipe -I. -I/usr/src/linux/include \
+XTRACFLAGS=-Wall -pipe -I. -I/usr/src/linux/include -I/usr/X11R6/include \
 		-I/usr/src/linux-2.2/include -I /usr/src/linux-2.0/include \
 		-DVERSION=\"$(VERSION)\" \
 		-DDEFAULT_PROXY_NAME=\"$(PROXY_DIR)/apmd_proxy\"
diff --git a/apm.c b/apm.c
index b21c057..0359b1c 100644
--- a/apm.c
+++ b/apm.c
@@ -219,12 +219,13 @@ int main(int argc, char **argv)
 		}
 	}
 													    
-
+#if 0
     if (!(i.apm_flags & APM_32_BIT_SUPPORT))
     {
 	fprintf(stderr, "32-bit APM interface not supported\n");
 	exit(1);
     }
+#endif
 
     if (verbose && (i.apm_flags & 0x10))
 	printf("APM BIOS Power Management is currently disabled\n");
diff --git a/apm.h b/apm.h
index fb24dfd..824cc06 100644
--- a/apm.h
+++ b/apm.h
@@ -20,6 +20,13 @@
  * $Id: apm.h,v 1.7 1999/07/05 22:31:11 apenwarr Exp $
  * 
  */
+#ifndef _APM_H
+#define _APM_H 1
+
+#ifndef __KERNEL_STRICT_NAMES
+#define __KERNEL_STRICT_NAMES
+#endif
+
 #include <linux/apm_bios.h>
 #include <sys/types.h>
 
@@ -93,3 +100,5 @@ extern int apm_reject(int fd);
 #else
 #define apm_reject(fd)   (-EINVAL)
 #endif
+
+#endif
diff --git a/apmd.c b/apmd.c
index 49ed3a1..560f536 100644
--- a/apmd.c
+++ b/apmd.c
@@ -343,7 +343,7 @@ static int call_proxy(apm_event_t event)
 		/* parent */
 		int status, retval;
 		ssize_t len;
-		time_t time_limit;
+		time_t countdown;
 
 		if (pid < 0) {
 			/* Couldn't fork */
@@ -356,8 +356,9 @@ static int call_proxy(apm_event_t event)
 		/* Capture the child's output, if any, but only until it terminates */
 		close(fds[1]);
 		fcntl(fds[0], F_SETFL, O_RDONLY|O_NONBLOCK);
-		time_limit = time(0) + proxy_timeout;
+		countdown = proxy_timeout;
 		do {
+			countdown -= 1;
 			while ((len = read(fds[0], line, sizeof(line)-1)) > 0) {
 				line[len] = 0;
 				APMD_SYSLOG(LOG_INFO, "+ %s", line);
@@ -372,16 +373,16 @@ static int call_proxy(apm_event_t event)
 				goto proxy_done;
 			}
 				
-			sleep(1);
+			while (sleep(1) > 0) ;
 		} while (
-			(time(0) < time_limit)
+			(countdown >= 0)
 			|| (proxy_timeout < 0)
 		);
 
 		APMD_SYSLOG(LOG_NOTICE, "Proxy has been running more than %d seconds; killing it", proxy_timeout);
 
 		kill(pid, SIGTERM);
-		time_limit = time(0) + 5;
+		countdown = 5;
 		do {
 			retval = waitpid(pid, &status, WNOHANG);
 			if (retval == pid)
@@ -392,9 +393,9 @@ static int call_proxy(apm_event_t event)
 				goto proxy_done;
 			}
 
-			sleep(1);
+			while (sleep(1) > 0) ;
 
-		} while (time(0) < time_limit);
+		} while (countdown >= 0);
 
 		kill(pid, SIGKILL);
 		status = __W_EXITCODE(0, SIGKILL);
-- 
2.1.4