Switched kacpimon to dynamic connections (increased max connections

from 20 to 1024)
  Resolves: rhbz#1450980
Consolidated new line delimiters
This commit is contained in:
Jaroslav Škarvada 2017-08-31 13:48:39 +02:00
parent 069fd7bde6
commit 72d5fa1fe1
2 changed files with 141 additions and 7 deletions

View File

@ -0,0 +1,131 @@
diff --git a/kacpimon/connection_list.c b/kacpimon/connection_list.c
index 9b0b0a8..f228186 100644
--- a/kacpimon/connection_list.c
+++ b/kacpimon/connection_list.c
@@ -22,6 +22,7 @@
#include <unistd.h>
#include <stdio.h>
+#include <stdlib.h>
#include "connection_list.h"
@@ -30,9 +31,9 @@
/*---------------------------------------------------------------*/
/* private objects */
-#define MAX_CONNECTIONS 20
+static int capacity = 0;
-static struct connection connection_list[MAX_CONNECTIONS];
+static struct connection *connection_list = NULL;
static int nconnections = 0;
@@ -51,9 +52,19 @@ add_connection(struct connection *p)
{
if (nconnections < 0)
return;
- if (nconnections >= MAX_CONNECTIONS) {
- printf("add_connection(): Too many connections.\n");
- return;
+
+ /* if the list is full, allocate more space */
+ if (nconnections >= capacity) {
+ /* no more than 1024 */
+ if (capacity > 1024) {
+ printf("add_connection(): Too many connections.\n");
+ return;
+ }
+
+ /* another 20 */
+ capacity += 20;
+ connection_list =
+ realloc(connection_list, sizeof(struct connection) * capacity);
}
if (nconnections == 0)
@@ -70,6 +81,30 @@ add_connection(struct connection *p)
/*---------------------------------------------------------------*/
+void
+delete_all_connections(void)
+{
+ int i = 0;
+
+ /* For each connection */
+ for (i = 0; i <= get_number_of_connections(); ++i)
+ {
+ struct connection *p;
+
+ p = get_connection(i);
+
+ /* If this connection is invalid, try the next. */
+ if (p == 0)
+ continue;
+
+ close(p -> fd);
+ }
+ free(connection_list);
+ connection_list = NULL;
+}
+
+/*---------------------------------------------------------------*/
+
struct connection *
find_connection(int fd)
{
diff --git a/kacpimon/connection_list.h b/kacpimon/connection_list.h
index 1d037cf..a787637 100644
--- a/kacpimon/connection_list.h
+++ b/kacpimon/connection_list.h
@@ -56,4 +56,7 @@ extern const fd_set *get_fdset(void);
/* get the highest fd that was added to the list */
extern int get_highestfd(void);
+/* delete all connections, closing the fds */
+extern void delete_all_connections(void);
+
#endif /* CONNECTION_LIST_H__ */
diff --git a/kacpimon/kacpimon.c b/kacpimon/kacpimon.c
index 1ddb9aa..253d270 100644
--- a/kacpimon/kacpimon.c
+++ b/kacpimon/kacpimon.c
@@ -164,27 +164,6 @@ static void monitor(void)
// ---------------------------------------------------------------
-static void close_all(void)
-{
- int i = 0;
-
- /* For each connection */
- for (i = 0; i <= get_number_of_connections(); ++i)
- {
- struct connection *p;
-
- p = get_connection(i);
-
- /* If this connection is invalid, try the next. */
- if (p == 0)
- continue;
-
- close(p -> fd);
- }
-}
-
-// ---------------------------------------------------------------
-
int main(void)
{
printf("Kernel ACPI Event Monitor...\n");
@@ -199,7 +178,7 @@ int main(void)
printf("Closing files...\n");
- close_all();
+ delete_all_connections();
printf("Goodbye\n");

View File

@ -8,7 +8,7 @@
Summary: ACPI Event Daemon
Name: acpid
Version: 2.0.28
Release: 5%{?dist}
Release: 6%{?dist}
License: GPLv2+
Group: System Environment/Daemons
Source: http://downloads.sourceforge.net/acpid2/%{name}-%{version}.tar.xz
@ -19,6 +19,8 @@ Source4: acpid.power.sh
Source5: acpid.service
Source6: acpid.sysconfig
Source7: acpid.socket
# https://sourceforge.net/p/acpid2/tickets/14/
Patch0: acpid-2.0.28-kacpimon-dynamic-connections.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
ExclusiveArch: ia64 x86_64 %{ix86} %{arm} aarch64
URL: http://sourceforge.net/projects/acpid2/
@ -28,7 +30,6 @@ Requires(preun): systemd
Requires(postun): systemd
Requires: systemd
%description
acpid is a daemon that dispatches ACPI events to user-space programs.
@ -45,13 +46,12 @@ The acpid-sysvinit contains SysV initscript.
%prep
%setup -q
%patch0 -p1 -b .kacpimon-dynamic-connections
%build
%configure
make %{?_smp_mflags} CFLAGS="%{optflags} %{?harden}"
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}
@ -74,11 +74,9 @@ mkdir -p %{buildroot}%{_sysconfdir}/rc.d/init.d
install -p -m 755 %{SOURCE1} %{buildroot}%{_sysconfdir}/rc.d/init.d/acpid
%endif
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root)
%doc %{_docdir}/%{name}
@ -133,8 +131,13 @@ fi
/sbin/chkconfig --add acpid >/dev/null 2>&1 || :
%endif
%changelog
* Thu Aug 31 2017 Jaroslav Škarvada <jskarvad@redhat.com> - 2.0.28-6
- Switched kacpimon to dynamic connections (increased max connections
from 20 to 1024)
Resolves: rhbz#1450980
- Consolidated new line delimiters
* Wed Aug 02 2017 Fedora Release Engineering <releng@fedoraproject.org> - 2.0.28-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild