Package init
This commit is contained in:
parent
e9ed51f1d8
commit
70b17fbffc
@ -1,131 +0,0 @@
|
|||||||
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");
|
|
||||||
|
|
||||||
Binary file not shown.
115
acpid.init
115
acpid.init
@ -1,115 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# /etc/rc.d/init.d/acpid
|
|
||||||
#
|
|
||||||
# Starts the acpi daemon
|
|
||||||
#
|
|
||||||
# chkconfig: 345 26 74
|
|
||||||
# description: Listen and dispatch ACPI events from the kernel
|
|
||||||
# processname: acpid
|
|
||||||
|
|
||||||
### BEGIN INIT INFO
|
|
||||||
# Provides: acpid
|
|
||||||
# Required-Start: $syslog $local_fs
|
|
||||||
# Required-Stop: $syslog $local_fs
|
|
||||||
# Default-Start: 2 3 4 5
|
|
||||||
# Default-Stop: 0 1 6
|
|
||||||
# Short-Description: start and stop acpid
|
|
||||||
# Description: Listen and dispatch ACPI events from the kernel
|
|
||||||
### END INIT INFO
|
|
||||||
|
|
||||||
# Source function library.
|
|
||||||
. /etc/rc.d/init.d/functions
|
|
||||||
|
|
||||||
# Source networking configuration.
|
|
||||||
. /etc/sysconfig/acpid
|
|
||||||
|
|
||||||
RETVAL=0
|
|
||||||
|
|
||||||
#
|
|
||||||
# See how we were called.
|
|
||||||
#
|
|
||||||
|
|
||||||
check() {
|
|
||||||
# Check that we're a privileged user
|
|
||||||
[ `id -u` = 0 ] || exit 4
|
|
||||||
|
|
||||||
# Check if acpid is executable
|
|
||||||
test -x /usr/sbin/acpid || exit 5
|
|
||||||
}
|
|
||||||
|
|
||||||
start() {
|
|
||||||
|
|
||||||
check
|
|
||||||
|
|
||||||
# Check if it is already running
|
|
||||||
if [ ! -f /var/lock/subsys/acpid ]; then
|
|
||||||
echo -n $"Starting acpi daemon: "
|
|
||||||
daemon /usr/sbin/acpid $OPTIONS
|
|
||||||
RETVAL=$?
|
|
||||||
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/acpid
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
return $RETVAL
|
|
||||||
}
|
|
||||||
|
|
||||||
stop() {
|
|
||||||
|
|
||||||
check
|
|
||||||
|
|
||||||
echo -n $"Stopping acpi daemon: "
|
|
||||||
killproc /usr/sbin/acpid
|
|
||||||
RETVAL=$?
|
|
||||||
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/acpid
|
|
||||||
echo
|
|
||||||
return $RETVAL
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
restart() {
|
|
||||||
stop
|
|
||||||
start
|
|
||||||
}
|
|
||||||
|
|
||||||
reload() {
|
|
||||||
|
|
||||||
check
|
|
||||||
|
|
||||||
trap "" SIGHUP
|
|
||||||
action $"Reloading acpi daemon:" killall -HUP acpid
|
|
||||||
RETVAL=$?
|
|
||||||
return $RETVAL
|
|
||||||
}
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
start)
|
|
||||||
start
|
|
||||||
;;
|
|
||||||
stop)
|
|
||||||
stop
|
|
||||||
;;
|
|
||||||
reload)
|
|
||||||
reload
|
|
||||||
;;
|
|
||||||
force-reload)
|
|
||||||
echo "$0: Unimplemented feature."
|
|
||||||
RETVAL=3
|
|
||||||
;;
|
|
||||||
restart)
|
|
||||||
restart
|
|
||||||
;;
|
|
||||||
condrestart)
|
|
||||||
if [ -f /var/lock/subsys/acpid ]; then
|
|
||||||
restart
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
status)
|
|
||||||
status acpid
|
|
||||||
RETVAL=$?
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload}"
|
|
||||||
RETVAL=2
|
|
||||||
esac
|
|
||||||
|
|
||||||
exit $RETVAL
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
# ACPID config to power down machine if powerbutton is pressed, but only if
|
|
||||||
# no gnome-power-manager is running
|
|
||||||
|
|
||||||
event=button/power.*
|
|
||||||
action=/etc/acpi/actions/power.sh
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
PATH=/usr/sbin:/usr/bin
|
|
||||||
|
|
||||||
# $1 = session number
|
|
||||||
function get_session_processes() {
|
|
||||||
local uid=$(loginctl show-session $1 | grep '^User=' | sed -r -e 's/^User=(.*)$/\1/')
|
|
||||||
systemd-cgls "/user.slice/user-${uid}.slice/session-${1}.scope"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check session status using systemd
|
|
||||||
session_ids=$(loginctl list-sessions 2>/dev/null | awk '{print $1}')
|
|
||||||
for session in ${session_ids} ; do
|
|
||||||
session_status=$(loginctl show-session ${session})
|
|
||||||
session_processes="$(get_session_processes ${session})"
|
|
||||||
echo "${session_status}" | grep -e 'Active=yes' &> /dev/null &&
|
|
||||||
echo "${session_processes}" | grep -e '\(gnome-settings-daemon\|cinnamon-settings-daemon\|kded[4-5]\|plasmashell\|xfce4-power-manager\|mate-power-manager\)' &> /dev/null && exit 0
|
|
||||||
done
|
|
||||||
|
|
||||||
# Get the ID of the first active X11 session: using ConsoleKit
|
|
||||||
uid_session=$(
|
|
||||||
ck-list-sessions 2>/dev/null | \
|
|
||||||
awk '
|
|
||||||
/^Session[0-9]+:$/ { uid = active = x11 = "" ; next }
|
|
||||||
{ gsub(/'\''/, "", $3) }
|
|
||||||
$1 == "unix-user" { uid = $3 }
|
|
||||||
$1 == "active" { active = $3 }
|
|
||||||
$1 == "x11-display" { x11 = $3 }
|
|
||||||
active == "TRUE" && x11 != "" {
|
|
||||||
print uid
|
|
||||||
exit
|
|
||||||
}')
|
|
||||||
|
|
||||||
# Check that there is a power manager, otherwise shut down.
|
|
||||||
[ "$uid_session" ] &&
|
|
||||||
ps axo uid,cmd | \
|
|
||||||
awk '
|
|
||||||
$1 == '$uid_session' &&
|
|
||||||
($2 ~ /gnome-power-manager/ || $2 ~ /kpowersave/ ||
|
|
||||||
$2 ~ /mate-power-manager/ || $2 ~ /xfce4-power-manager/ ||
|
|
||||||
$2 ~ /\/usr\/libexec\/gnome-settings-daemon/ ||
|
|
||||||
$2 ~ /\/usr\/libexec\/cinnamon-settings-daemon/ ||
|
|
||||||
$2 ~ /kded[4-5]/ || $2 ~ /guidance-power-manager/ ||
|
|
||||||
$2 ~ /plasmashell/) \
|
|
||||||
{ found = 1; exit }
|
|
||||||
END { exit !found }
|
|
||||||
' ||
|
|
||||||
shutdown -h now
|
|
||||||
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=ACPI Event Daemon
|
|
||||||
Documentation=man:acpid(8)
|
|
||||||
Requires=acpid.socket
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
StandardInput=socket
|
|
||||||
EnvironmentFile=/etc/sysconfig/acpid
|
|
||||||
ExecStart=/usr/sbin/acpid $OPTIONS
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
Also=acpid.socket
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=ACPID Listen Socket
|
|
||||||
Documentation=man:acpid(8)
|
|
||||||
|
|
||||||
[Socket]
|
|
||||||
ListenStream=/var/run/acpid.socket
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=sockets.target
|
|
||||||
85
acpid.spec
85
acpid.spec
@ -1,85 +0,0 @@
|
|||||||
Name: acpid
|
|
||||||
Version: 2.0.30
|
|
||||||
Release: 2
|
|
||||||
Summary: Advanced Configuration and Power Interface event daemon
|
|
||||||
License: GPLv2+
|
|
||||||
URL: http://sourceforge.net/projects/acpid2/
|
|
||||||
Source0: http://downloads.sourceforge.net/acpid2/%{name}-%{version}.tar.xz
|
|
||||||
Source1: acpid.init
|
|
||||||
Source2: acpid.video.conf
|
|
||||||
Source3: acpid.power.conf
|
|
||||||
Source4: acpid.power.sh
|
|
||||||
Source5: acpid.service
|
|
||||||
Source6: acpid.sysconfig
|
|
||||||
Source7: acpid.socket
|
|
||||||
|
|
||||||
Patch1: acpid-2.0.28-kacpimon-dynamic-connections.patch
|
|
||||||
ExclusiveArch: aarch64 x86_64 %{ix86}
|
|
||||||
|
|
||||||
BuildRequires: systemd, gcc
|
|
||||||
Requires: systemd
|
|
||||||
|
|
||||||
%description
|
|
||||||
acpid is designed to notify user-space programs of ACPI events.
|
|
||||||
|
|
||||||
%package help
|
|
||||||
Summary: Development documents for ACPI library
|
|
||||||
Requires: %{name} = %{version}-%{release}
|
|
||||||
|
|
||||||
%description help
|
|
||||||
Development document for ACPI library.
|
|
||||||
|
|
||||||
%prep
|
|
||||||
%autosetup -n %{name}-%{version} -p1
|
|
||||||
|
|
||||||
|
|
||||||
%build
|
|
||||||
%configure
|
|
||||||
%make_build CFLAGS="%{optflags} -pie -Wl,-z,relro,-z,now"
|
|
||||||
|
|
||||||
%install
|
|
||||||
rm -rf %{buildroot}/*
|
|
||||||
mkdir -p -m 755 %{buildroot}%{_sysconfdir}/acpi/events
|
|
||||||
mkdir -p -m 755 %{buildroot}%{_sysconfdir}/acpi/actions
|
|
||||||
mkdir -p -m 755 %{buildroot}%{_unitdir}
|
|
||||||
mkdir -p -m 755 %{buildroot}%{_sysconfdir}/sysconfig/acpid
|
|
||||||
%make_install docdir=%{_docdir}/%{name}
|
|
||||||
install -p -m 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/acpi/events/videoconf
|
|
||||||
install -p -m 644 %{SOURCE3} %{buildroot}%{_sysconfdir}/acpi/events/powerconf
|
|
||||||
install -p -m 755 %{SOURCE4} %{buildroot}%{_sysconfdir}/acpi/actions/power.sh
|
|
||||||
install -p -m 644 %{SOURCE5} %{SOURCE7} %{buildroot}%{_unitdir}
|
|
||||||
install -p -m 644 %{SOURCE6} %{buildroot}%{_sysconfdir}/sysconfig/acpid
|
|
||||||
|
|
||||||
%files
|
|
||||||
%{_unitdir}/%{name}.service
|
|
||||||
%{_unitdir}/%{name}.socket
|
|
||||||
%dir %{_sysconfdir}/acpi
|
|
||||||
%dir %{_sysconfdir}/acpi/events
|
|
||||||
%dir %{_sysconfdir}/acpi/actions
|
|
||||||
%config %attr(0644,root,root) %{_sysconfdir}/acpi/events/videoconf
|
|
||||||
%config %attr(0644,root,root) %{_sysconfdir}/acpi/events/powerconf
|
|
||||||
%config %attr(0755,root,root) %{_sysconfdir}/acpi/actions/power.sh
|
|
||||||
%config %attr(0644,root,root) %{_sysconfdir}/sysconfig/acpid
|
|
||||||
%{_bindir}/acpi_listen
|
|
||||||
%{_sbindir}/acpid
|
|
||||||
%{_sbindir}/kacpimon
|
|
||||||
|
|
||||||
%files help
|
|
||||||
%doc %{_docdir}/%{name}
|
|
||||||
%{_mandir}/man8/acpid.8.gz
|
|
||||||
%{_mandir}/man8/acpi_listen.8.gz
|
|
||||||
%{_mandir}/man8/kacpimon.8.gz
|
|
||||||
|
|
||||||
%post
|
|
||||||
%systemd_post %{name}.socket %{name}.service
|
|
||||||
|
|
||||||
%preun
|
|
||||||
%systemd_preun %{name}.socket %{name}.service
|
|
||||||
|
|
||||||
%postun
|
|
||||||
%systemd_postun_with_restart %{name}.socket %{name}.service
|
|
||||||
|
|
||||||
%changelog
|
|
||||||
* Thu Aug 29 2019 openEuler Buildteam <buildteam@openeuler.org> - 2.0.31
|
|
||||||
- Package init
|
|
||||||
|
|
||||||
@ -1 +0,0 @@
|
|||||||
OPTIONS=
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
# Configuration to turn on DPMS again on video activity, needed for some
|
|
||||||
# laptops. Disabled by default, uncomment if your laptop display stays blank
|
|
||||||
# after you close and open the lid.
|
|
||||||
|
|
||||||
#event=video.*
|
|
||||||
#action=/usr/sbin/vbetool dpms on
|
|
||||||
Loading…
x
Reference in New Issue
Block a user