aboutsummaryrefslogtreecommitdiffstats
path: root/x11
diff options
context:
space:
mode:
authormarcus <marcus@FreeBSD.org>2005-07-04 04:31:43 +0800
committermarcus <marcus@FreeBSD.org>2005-07-04 04:31:43 +0800
commite897ee1af4c3459d9539264be73793276aacf2c6 (patch)
treefd79f99582821cf7985c54631d6b21bfa5470603 /x11
parent925ac4070bc5bbcf196d01007ea524f3cb2c56da (diff)
downloadfreebsd-ports-gnome-e897ee1af4c3459d9539264be73793276aacf2c6.tar.gz
freebsd-ports-gnome-e897ee1af4c3459d9539264be73793276aacf2c6.tar.zst
freebsd-ports-gnome-e897ee1af4c3459d9539264be73793276aacf2c6.zip
Check to make sure we were able to open /var/run/devd.pipe successfully
once before continually trying to reopen it. Because of this, some users not using the devd patch to process dynamic ACPI updates were bitten by the file descriptor leak. Thus, I am bumping PORTREVISION for this commit.
Diffstat (limited to 'x11')
-rw-r--r--x11/gnome-applets/Makefile2
-rw-r--r--x11/gnome-applets/files/patch-battstat-acpi438
-rw-r--r--x11/gnomeapplets2/Makefile2
-rw-r--r--x11/gnomeapplets2/files/patch-battstat-acpi438
4 files changed, 456 insertions, 424 deletions
diff --git a/x11/gnome-applets/Makefile b/x11/gnome-applets/Makefile
index cc7bbb080f7d..79b2c9131064 100644
--- a/x11/gnome-applets/Makefile
+++ b/x11/gnome-applets/Makefile
@@ -7,7 +7,7 @@
PORTNAME= gnomeapplets2
PORTVERSION= 2.10.1
-PORTREVISION= 2
+PORTREVISION= 3
CATEGORIES= x11 gnome
MASTER_SITES= ${MASTER_SITE_GNOME}
MASTER_SITE_SUBDIR= sources/gnome-applets/2.10
diff --git a/x11/gnome-applets/files/patch-battstat-acpi b/x11/gnome-applets/files/patch-battstat-acpi
index 86008cf35bd1..903e8b951d11 100644
--- a/x11/gnome-applets/files/patch-battstat-acpi
+++ b/x11/gnome-applets/files/patch-battstat-acpi
@@ -78,217 +78,9 @@
#include "battstat.h"
#ifndef gettext_noop
---- battstat/acpi-freebsd.h.orig Tue Jun 28 23:40:48 2005
-+++ battstat/acpi-freebsd.h Wed Jun 29 00:53:36 2005
-@@ -0,0 +1,58 @@
-+/*
-+ * Copyright (C) 2004 by Joe Marcus Clarke <marcus@FreeBSD.org>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
-+ */
-+
-+#ifndef __ACPI_FREEBSD_H__
-+#define __ACPI_FREEBSD_H__
-+
-+#define ACPIDEV "/dev/acpi"
-+
-+#define BATT_MIN 0
-+#define BATT_MAX 64
-+
-+#define ACPI_ACLINE "hw.acpi.acline"
-+#define ACPI_TIME "hw.acpi.battery.time"
-+#define ACPI_LIFE "hw.acpi.battery.life"
-+#define ACPI_STATE "hw.acpi.battery.state"
-+
-+/* XXX: AMD64 does not have machine/apm_bios.h. */
-+#if !defined(__i386__)
-+struct apm_info {
-+ guint ai_acline;
-+ guint ai_batt_stat;
-+ guint ai_batt_life;
-+ int ai_batt_time;
-+ guint ai_status;
-+};
-+#endif
-+
-+struct acpi_info {
-+ gboolean ac_online;
-+ int acpifd;
-+ int event_fd;
-+ int max_capacity;
-+ int low_capacity;
-+ int critical_capacity;
-+ GIOChannel * channel;
-+};
-+
-+gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info * acpiinfo);
-+gboolean acpi_process_event(struct acpi_info * acpiinfo, gboolean *read_error);
-+gboolean acpi_freebsd_init(struct acpi_info * acpiinfo);
-+void acpi_freebsd_cleanup(struct acpi_info * acpiinfo);
-+
-+#endif /* __ACPI_FREEBSD_H__ */
---- battstat/power-management.c.orig Sun Mar 20 05:20:55 2005
-+++ battstat/power-management.c Thu Jun 30 15:54:39 2005
-@@ -73,12 +73,42 @@ static int pm_initialised;
- * the problem might be. This error message is not to be freed.
- */
-
--#ifdef __FreeBSD__
--
-+#if defined(__FreeBSD__)
-+#if defined(__i386__)
- #include <machine/apm_bios.h>
-+#endif
-+#include "acpi-freebsd.h"
-+
-+static struct acpi_info acpiinfo;
-+static gboolean using_acpi;
-+static int acpi_count;
-+static int acpiwatch;
-+static struct apm_info apminfo;
-+
-+gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info *acpiinfo);
-
- #define APMDEVICE "/dev/apm"
-
-+static gboolean acpi_callback (GIOChannel * chan, GIOCondition cond, gpointer data)
-+{
-+ gboolean read_error;
-+
-+ if (cond & (G_IO_ERR | G_IO_HUP)) {
-+ acpi_freebsd_cleanup(&acpiinfo);
-+ return FALSE;
-+ }
-+
-+ if (acpi_process_event(&acpiinfo, &read_error)) {
-+ acpi_freebsd_read(&apminfo, &acpiinfo);
-+ }
-+ else if (read_error) {
-+ acpi_freebsd_cleanup(&acpiinfo);
-+ return FALSE;
-+ }
-+
-+ return TRUE;
-+}
-+
- static const char *
- apm_readinfo (BatteryStatus *status)
- {
-@@ -86,32 +116,53 @@ apm_readinfo (BatteryStatus *status)
- FreeBSD. Each time this functions is called (once every second)
- the APM device is opened, read from and then closed.
- */
-- struct apm_info apminfo;
- int fd;
-
- if (DEBUG) g_print("apm_readinfo() (FreeBSD)\n");
-
-- fd = open(APMDEVICE, O_RDONLY);
-- if (fd == -1)
-- {
-- pm_initialised = 0;
-- return ERR_OPEN_APMDEV;
-+ if (using_acpi && acpiinfo.event_fd >= 0) {
-+ if (acpi_count <= 0) {
-+ acpi_count = 30;
-+ acpi_freebsd_read(&apminfo, &acpiinfo);
-+ }
-+ acpi_count--;
- }
-+ else if (using_acpi) {
-+ if (acpi_freebsd_init(&acpiinfo)) {
-+ acpiwatch = g_io_add_watch (acpiinfo.channel,
-+ G_IO_IN | G_IO_ERR | G_IO_HUP,
-+ acpi_callback, NULL);
-+ acpi_freebsd_read(&apminfo, &acpiinfo);
-+ }
-+ }
-+ else {
-+#if defined(__i386__)
-+ fd = open(APMDEVICE, O_RDONLY);
-+ if (fd == -1) {
-+ return ERR_OPEN_APMDEV;
-+ }
-
-- if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1)
-- err(1, "ioctl(APMIO_GETINFO)");
-+ if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1)
-+ err(1, "ioctl(APMIO_GETINFO)");
-
-- close(fd);
-+ close(fd);
-
-- if(apminfo.ai_status == 0)
-- return ERR_APM_E;
-+ if(apminfo.ai_status == 0)
-+ return ERR_APM_E;
-+#else
-+ return ERR_OPEN_APMDEV;
-+#endif
-+ }
-
- status->present = TRUE;
- status->on_ac_power = apminfo.ai_acline ? 1 : 0;
- status->state = apminfo.ai_batt_stat;
- status->percent = apminfo.ai_batt_life;
- status->charging = (status->state == 3) ? TRUE : FALSE;
-- status->minutes = apminfo.ai_batt_time;
-+ if (using_acpi)
-+ status->minutes = apminfo.ai_batt_time;
-+ else
-+ status->minutes = (int) (apminfo.ai_batt_time/60.0);
-
- return NULL;
- }
-@@ -339,6 +390,19 @@ power_management_initialise( void )
- G_IO_IN | G_IO_ERR | G_IO_HUP,
- acpi_callback, NULL);
- }
-+#elif defined(__FreeBSD__)
-+ if (acpi_freebsd_init(&acpiinfo)) {
-+ using_acpi = TRUE;
-+ acpi_count = 0;
-+ }
-+ else
-+ using_acpi = FALSE;
-+
-+ if (using_acpi && acpiinfo.event_fd >= 0) {
-+ acpiwatch = g_io_add_watch (acpiinfo.channel,
-+ G_IO_IN | G_IO_ERR | G_IO_HUP,
-+ acpi_callback, NULL);
-+ }
- #endif
- pm_initialised = 1;
-
-@@ -360,6 +424,13 @@ power_management_cleanup( void )
- g_source_remove(acpiwatch);
- acpiwatch = 0;
- acpi_linux_cleanup(&acpiinfo);
-+ }
-+#elif defined(__FreeBSD__)
-+ if (using_acpi) {
-+ if (acpiwatch != 0)
-+ g_source_remove(acpiwatch);
-+ acpiwatch = 0;
-+ acpi_freebsd_cleanup(&acpiinfo);
- }
- #endif
-
---- battstat/acpi-freebsd.c.orig Thu Jun 30 15:51:37 2005
-+++ battstat/acpi-freebsd.c Sat Jul 2 00:41:51 2005
-@@ -0,0 +1,269 @@
+--- battstat/acpi-freebsd.c.orig Sun Jul 3 16:00:01 2005
++++ battstat/acpi-freebsd.c Sun Jul 3 16:23:26 2005
+@@ -0,0 +1,280 @@
+/* battstat A GNOME battery meter for laptops.
+ * Copyright (C) 2000 by Jörgen Pehrson <jp@spektr.eu.org>
+ *
@@ -407,11 +199,13 @@
+ strcpy(addr.sun_path, "/var/run/devd.pipe");
+ if (connect(event_fd, (struct sockaddr *) &addr, sizeof(addr)) == 0) {
+ acpiinfo->event_fd = event_fd;
++ acpiinfo->event_inited = TRUE;
+ acpiinfo->channel = g_io_channel_unix_new(event_fd);
+ }
+ else {
+ close(event_fd);
+ acpiinfo->event_fd = -1;
++ acpiinfo->event_inited = FALSE;
+ }
+ }
+
@@ -437,6 +231,15 @@
+ return ACPI_EVENT_IGNORE;
+}
+
++void acpi_freebsd_update(struct acpi_info *acpiinfo)
++{
++ /* XXX This is needed for systems where devd does not have permissions
++ * to allow for event-driven updates.
++ */
++ update_ac_info(acpiinfo);
++ update_battery_info(acpiinfo);
++}
++
+gboolean acpi_process_event(struct acpi_info *acpiinfo, gboolean *read_error)
+{
+ gsize i;
@@ -558,3 +361,216 @@
+ return TRUE;
+}
+#endif
+--- battstat/acpi-freebsd.h.orig Sun Jul 3 16:00:01 2005
++++ battstat/acpi-freebsd.h Sun Jul 3 16:23:56 2005
+@@ -0,0 +1,60 @@
++/*
++ * Copyright (C) 2004 by Joe Marcus Clarke <marcus@FreeBSD.org>
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
++ */
++
++#ifndef __ACPI_FREEBSD_H__
++#define __ACPI_FREEBSD_H__
++
++#define ACPIDEV "/dev/acpi"
++
++#define BATT_MIN 0
++#define BATT_MAX 64
++
++#define ACPI_ACLINE "hw.acpi.acline"
++#define ACPI_TIME "hw.acpi.battery.time"
++#define ACPI_LIFE "hw.acpi.battery.life"
++#define ACPI_STATE "hw.acpi.battery.state"
++
++/* XXX: AMD64 does not have machine/apm_bios.h. */
++#if !defined(__i386__)
++struct apm_info {
++ guint ai_acline;
++ guint ai_batt_stat;
++ guint ai_batt_life;
++ int ai_batt_time;
++ guint ai_status;
++};
++#endif
++
++struct acpi_info {
++ gboolean ac_online;
++ gboolean event_inited;
++ int acpifd;
++ int event_fd;
++ int max_capacity;
++ int low_capacity;
++ int critical_capacity;
++ GIOChannel * channel;
++};
++
++gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info * acpiinfo);
++void acpi_freebsd_update(struct acpi_info * acpiinfo);
++gboolean acpi_process_event(struct acpi_info * acpiinfo, gboolean *read_error);
++gboolean acpi_freebsd_init(struct acpi_info * acpiinfo);
++void acpi_freebsd_cleanup(struct acpi_info * acpiinfo);
++
++#endif /* __ACPI_FREEBSD_H__ */
+--- battstat/power-management.c.orig Sun Mar 20 05:20:55 2005
++++ battstat/power-management.c Sun Jul 3 16:21:42 2005
+@@ -73,12 +73,42 @@ static int pm_initialised;
+ * the problem might be. This error message is not to be freed.
+ */
+
+-#ifdef __FreeBSD__
+-
++#if defined(__FreeBSD__)
++#if defined(__i386__)
+ #include <machine/apm_bios.h>
++#endif
++#include "acpi-freebsd.h"
++
++static struct acpi_info acpiinfo;
++static gboolean using_acpi;
++static int acpi_count;
++static int acpiwatch;
++static struct apm_info apminfo;
++
++gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info *acpiinfo);
+
+ #define APMDEVICE "/dev/apm"
+
++static gboolean acpi_callback (GIOChannel * chan, GIOCondition cond, gpointer data)
++{
++ gboolean read_error;
++
++ if (cond & (G_IO_ERR | G_IO_HUP)) {
++ acpi_freebsd_cleanup(&acpiinfo);
++ return FALSE;
++ }
++
++ if (acpi_process_event(&acpiinfo, &read_error)) {
++ acpi_freebsd_read(&apminfo, &acpiinfo);
++ }
++ else if (read_error) {
++ acpi_freebsd_cleanup(&acpiinfo);
++ return FALSE;
++ }
++
++ return TRUE;
++}
++
+ static const char *
+ apm_readinfo (BatteryStatus *status)
+ {
+@@ -86,32 +116,56 @@ apm_readinfo (BatteryStatus *status)
+ FreeBSD. Each time this functions is called (once every second)
+ the APM device is opened, read from and then closed.
+ */
+- struct apm_info apminfo;
+ int fd;
+
+ if (DEBUG) g_print("apm_readinfo() (FreeBSD)\n");
+
+- fd = open(APMDEVICE, O_RDONLY);
+- if (fd == -1)
+- {
+- pm_initialised = 0;
+- return ERR_OPEN_APMDEV;
++ if (using_acpi && (!acpiinfo.event_inited || acpiinfo.event_fd >= 0)) {
++ if (acpi_count <= 0) {
++ acpi_count = 30;
++ if (!acpiinfo.event_inited) {
++ acpi_freebsd_update(&acpiinfo);
++ }
++ acpi_freebsd_read(&apminfo, &acpiinfo);
++ }
++ acpi_count--;
++ }
++ else if (using_acpi && acpiinfo.event_inited) {
++ if (acpi_freebsd_init(&acpiinfo)) {
++ acpiwatch = g_io_add_watch (acpiinfo.channel,
++ G_IO_IN | G_IO_ERR | G_IO_HUP,
++ acpi_callback, NULL);
++ acpi_freebsd_read(&apminfo, &acpiinfo);
++ }
+ }
++ else {
++#if defined(__i386__)
++ fd = open(APMDEVICE, O_RDONLY);
++ if (fd == -1) {
++ return ERR_OPEN_APMDEV;
++ }
+
+- if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1)
+- err(1, "ioctl(APMIO_GETINFO)");
++ if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1)
++ err(1, "ioctl(APMIO_GETINFO)");
+
+- close(fd);
++ close(fd);
+
+- if(apminfo.ai_status == 0)
+- return ERR_APM_E;
++ if(apminfo.ai_status == 0)
++ return ERR_APM_E;
++#else
++ return ERR_OPEN_APMDEV;
++#endif
++ }
+
+ status->present = TRUE;
+ status->on_ac_power = apminfo.ai_acline ? 1 : 0;
+ status->state = apminfo.ai_batt_stat;
+ status->percent = apminfo.ai_batt_life;
+ status->charging = (status->state == 3) ? TRUE : FALSE;
+- status->minutes = apminfo.ai_batt_time;
++ if (using_acpi)
++ status->minutes = apminfo.ai_batt_time;
++ else
++ status->minutes = (int) (apminfo.ai_batt_time/60.0);
+
+ return NULL;
+ }
+@@ -339,6 +393,19 @@ power_management_initialise( void )
+ G_IO_IN | G_IO_ERR | G_IO_HUP,
+ acpi_callback, NULL);
+ }
++#elif defined(__FreeBSD__)
++ if (acpi_freebsd_init(&acpiinfo)) {
++ using_acpi = TRUE;
++ acpi_count = 0;
++ }
++ else
++ using_acpi = FALSE;
++
++ if (using_acpi && acpiinfo.event_fd >= 0) {
++ acpiwatch = g_io_add_watch (acpiinfo.channel,
++ G_IO_IN | G_IO_ERR | G_IO_HUP,
++ acpi_callback, NULL);
++ }
+ #endif
+ pm_initialised = 1;
+
+@@ -360,6 +427,13 @@ power_management_cleanup( void )
+ g_source_remove(acpiwatch);
+ acpiwatch = 0;
+ acpi_linux_cleanup(&acpiinfo);
++ }
++#elif defined(__FreeBSD__)
++ if (using_acpi) {
++ if (acpiwatch != 0)
++ g_source_remove(acpiwatch);
++ acpiwatch = 0;
++ acpi_freebsd_cleanup(&acpiinfo);
+ }
+ #endif
+
diff --git a/x11/gnomeapplets2/Makefile b/x11/gnomeapplets2/Makefile
index cc7bbb080f7d..79b2c9131064 100644
--- a/x11/gnomeapplets2/Makefile
+++ b/x11/gnomeapplets2/Makefile
@@ -7,7 +7,7 @@
PORTNAME= gnomeapplets2
PORTVERSION= 2.10.1
-PORTREVISION= 2
+PORTREVISION= 3
CATEGORIES= x11 gnome
MASTER_SITES= ${MASTER_SITE_GNOME}
MASTER_SITE_SUBDIR= sources/gnome-applets/2.10
diff --git a/x11/gnomeapplets2/files/patch-battstat-acpi b/x11/gnomeapplets2/files/patch-battstat-acpi
index 86008cf35bd1..903e8b951d11 100644
--- a/x11/gnomeapplets2/files/patch-battstat-acpi
+++ b/x11/gnomeapplets2/files/patch-battstat-acpi
@@ -78,217 +78,9 @@
#include "battstat.h"
#ifndef gettext_noop
---- battstat/acpi-freebsd.h.orig Tue Jun 28 23:40:48 2005
-+++ battstat/acpi-freebsd.h Wed Jun 29 00:53:36 2005
-@@ -0,0 +1,58 @@
-+/*
-+ * Copyright (C) 2004 by Joe Marcus Clarke <marcus@FreeBSD.org>
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, write to the Free Software
-+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
-+ */
-+
-+#ifndef __ACPI_FREEBSD_H__
-+#define __ACPI_FREEBSD_H__
-+
-+#define ACPIDEV "/dev/acpi"
-+
-+#define BATT_MIN 0
-+#define BATT_MAX 64
-+
-+#define ACPI_ACLINE "hw.acpi.acline"
-+#define ACPI_TIME "hw.acpi.battery.time"
-+#define ACPI_LIFE "hw.acpi.battery.life"
-+#define ACPI_STATE "hw.acpi.battery.state"
-+
-+/* XXX: AMD64 does not have machine/apm_bios.h. */
-+#if !defined(__i386__)
-+struct apm_info {
-+ guint ai_acline;
-+ guint ai_batt_stat;
-+ guint ai_batt_life;
-+ int ai_batt_time;
-+ guint ai_status;
-+};
-+#endif
-+
-+struct acpi_info {
-+ gboolean ac_online;
-+ int acpifd;
-+ int event_fd;
-+ int max_capacity;
-+ int low_capacity;
-+ int critical_capacity;
-+ GIOChannel * channel;
-+};
-+
-+gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info * acpiinfo);
-+gboolean acpi_process_event(struct acpi_info * acpiinfo, gboolean *read_error);
-+gboolean acpi_freebsd_init(struct acpi_info * acpiinfo);
-+void acpi_freebsd_cleanup(struct acpi_info * acpiinfo);
-+
-+#endif /* __ACPI_FREEBSD_H__ */
---- battstat/power-management.c.orig Sun Mar 20 05:20:55 2005
-+++ battstat/power-management.c Thu Jun 30 15:54:39 2005
-@@ -73,12 +73,42 @@ static int pm_initialised;
- * the problem might be. This error message is not to be freed.
- */
-
--#ifdef __FreeBSD__
--
-+#if defined(__FreeBSD__)
-+#if defined(__i386__)
- #include <machine/apm_bios.h>
-+#endif
-+#include "acpi-freebsd.h"
-+
-+static struct acpi_info acpiinfo;
-+static gboolean using_acpi;
-+static int acpi_count;
-+static int acpiwatch;
-+static struct apm_info apminfo;
-+
-+gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info *acpiinfo);
-
- #define APMDEVICE "/dev/apm"
-
-+static gboolean acpi_callback (GIOChannel * chan, GIOCondition cond, gpointer data)
-+{
-+ gboolean read_error;
-+
-+ if (cond & (G_IO_ERR | G_IO_HUP)) {
-+ acpi_freebsd_cleanup(&acpiinfo);
-+ return FALSE;
-+ }
-+
-+ if (acpi_process_event(&acpiinfo, &read_error)) {
-+ acpi_freebsd_read(&apminfo, &acpiinfo);
-+ }
-+ else if (read_error) {
-+ acpi_freebsd_cleanup(&acpiinfo);
-+ return FALSE;
-+ }
-+
-+ return TRUE;
-+}
-+
- static const char *
- apm_readinfo (BatteryStatus *status)
- {
-@@ -86,32 +116,53 @@ apm_readinfo (BatteryStatus *status)
- FreeBSD. Each time this functions is called (once every second)
- the APM device is opened, read from and then closed.
- */
-- struct apm_info apminfo;
- int fd;
-
- if (DEBUG) g_print("apm_readinfo() (FreeBSD)\n");
-
-- fd = open(APMDEVICE, O_RDONLY);
-- if (fd == -1)
-- {
-- pm_initialised = 0;
-- return ERR_OPEN_APMDEV;
-+ if (using_acpi && acpiinfo.event_fd >= 0) {
-+ if (acpi_count <= 0) {
-+ acpi_count = 30;
-+ acpi_freebsd_read(&apminfo, &acpiinfo);
-+ }
-+ acpi_count--;
- }
-+ else if (using_acpi) {
-+ if (acpi_freebsd_init(&acpiinfo)) {
-+ acpiwatch = g_io_add_watch (acpiinfo.channel,
-+ G_IO_IN | G_IO_ERR | G_IO_HUP,
-+ acpi_callback, NULL);
-+ acpi_freebsd_read(&apminfo, &acpiinfo);
-+ }
-+ }
-+ else {
-+#if defined(__i386__)
-+ fd = open(APMDEVICE, O_RDONLY);
-+ if (fd == -1) {
-+ return ERR_OPEN_APMDEV;
-+ }
-
-- if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1)
-- err(1, "ioctl(APMIO_GETINFO)");
-+ if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1)
-+ err(1, "ioctl(APMIO_GETINFO)");
-
-- close(fd);
-+ close(fd);
-
-- if(apminfo.ai_status == 0)
-- return ERR_APM_E;
-+ if(apminfo.ai_status == 0)
-+ return ERR_APM_E;
-+#else
-+ return ERR_OPEN_APMDEV;
-+#endif
-+ }
-
- status->present = TRUE;
- status->on_ac_power = apminfo.ai_acline ? 1 : 0;
- status->state = apminfo.ai_batt_stat;
- status->percent = apminfo.ai_batt_life;
- status->charging = (status->state == 3) ? TRUE : FALSE;
-- status->minutes = apminfo.ai_batt_time;
-+ if (using_acpi)
-+ status->minutes = apminfo.ai_batt_time;
-+ else
-+ status->minutes = (int) (apminfo.ai_batt_time/60.0);
-
- return NULL;
- }
-@@ -339,6 +390,19 @@ power_management_initialise( void )
- G_IO_IN | G_IO_ERR | G_IO_HUP,
- acpi_callback, NULL);
- }
-+#elif defined(__FreeBSD__)
-+ if (acpi_freebsd_init(&acpiinfo)) {
-+ using_acpi = TRUE;
-+ acpi_count = 0;
-+ }
-+ else
-+ using_acpi = FALSE;
-+
-+ if (using_acpi && acpiinfo.event_fd >= 0) {
-+ acpiwatch = g_io_add_watch (acpiinfo.channel,
-+ G_IO_IN | G_IO_ERR | G_IO_HUP,
-+ acpi_callback, NULL);
-+ }
- #endif
- pm_initialised = 1;
-
-@@ -360,6 +424,13 @@ power_management_cleanup( void )
- g_source_remove(acpiwatch);
- acpiwatch = 0;
- acpi_linux_cleanup(&acpiinfo);
-+ }
-+#elif defined(__FreeBSD__)
-+ if (using_acpi) {
-+ if (acpiwatch != 0)
-+ g_source_remove(acpiwatch);
-+ acpiwatch = 0;
-+ acpi_freebsd_cleanup(&acpiinfo);
- }
- #endif
-
---- battstat/acpi-freebsd.c.orig Thu Jun 30 15:51:37 2005
-+++ battstat/acpi-freebsd.c Sat Jul 2 00:41:51 2005
-@@ -0,0 +1,269 @@
+--- battstat/acpi-freebsd.c.orig Sun Jul 3 16:00:01 2005
++++ battstat/acpi-freebsd.c Sun Jul 3 16:23:26 2005
+@@ -0,0 +1,280 @@
+/* battstat A GNOME battery meter for laptops.
+ * Copyright (C) 2000 by Jörgen Pehrson <jp@spektr.eu.org>
+ *
@@ -407,11 +199,13 @@
+ strcpy(addr.sun_path, "/var/run/devd.pipe");
+ if (connect(event_fd, (struct sockaddr *) &addr, sizeof(addr)) == 0) {
+ acpiinfo->event_fd = event_fd;
++ acpiinfo->event_inited = TRUE;
+ acpiinfo->channel = g_io_channel_unix_new(event_fd);
+ }
+ else {
+ close(event_fd);
+ acpiinfo->event_fd = -1;
++ acpiinfo->event_inited = FALSE;
+ }
+ }
+
@@ -437,6 +231,15 @@
+ return ACPI_EVENT_IGNORE;
+}
+
++void acpi_freebsd_update(struct acpi_info *acpiinfo)
++{
++ /* XXX This is needed for systems where devd does not have permissions
++ * to allow for event-driven updates.
++ */
++ update_ac_info(acpiinfo);
++ update_battery_info(acpiinfo);
++}
++
+gboolean acpi_process_event(struct acpi_info *acpiinfo, gboolean *read_error)
+{
+ gsize i;
@@ -558,3 +361,216 @@
+ return TRUE;
+}
+#endif
+--- battstat/acpi-freebsd.h.orig Sun Jul 3 16:00:01 2005
++++ battstat/acpi-freebsd.h Sun Jul 3 16:23:56 2005
+@@ -0,0 +1,60 @@
++/*
++ * Copyright (C) 2004 by Joe Marcus Clarke <marcus@FreeBSD.org>
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
++ */
++
++#ifndef __ACPI_FREEBSD_H__
++#define __ACPI_FREEBSD_H__
++
++#define ACPIDEV "/dev/acpi"
++
++#define BATT_MIN 0
++#define BATT_MAX 64
++
++#define ACPI_ACLINE "hw.acpi.acline"
++#define ACPI_TIME "hw.acpi.battery.time"
++#define ACPI_LIFE "hw.acpi.battery.life"
++#define ACPI_STATE "hw.acpi.battery.state"
++
++/* XXX: AMD64 does not have machine/apm_bios.h. */
++#if !defined(__i386__)
++struct apm_info {
++ guint ai_acline;
++ guint ai_batt_stat;
++ guint ai_batt_life;
++ int ai_batt_time;
++ guint ai_status;
++};
++#endif
++
++struct acpi_info {
++ gboolean ac_online;
++ gboolean event_inited;
++ int acpifd;
++ int event_fd;
++ int max_capacity;
++ int low_capacity;
++ int critical_capacity;
++ GIOChannel * channel;
++};
++
++gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info * acpiinfo);
++void acpi_freebsd_update(struct acpi_info * acpiinfo);
++gboolean acpi_process_event(struct acpi_info * acpiinfo, gboolean *read_error);
++gboolean acpi_freebsd_init(struct acpi_info * acpiinfo);
++void acpi_freebsd_cleanup(struct acpi_info * acpiinfo);
++
++#endif /* __ACPI_FREEBSD_H__ */
+--- battstat/power-management.c.orig Sun Mar 20 05:20:55 2005
++++ battstat/power-management.c Sun Jul 3 16:21:42 2005
+@@ -73,12 +73,42 @@ static int pm_initialised;
+ * the problem might be. This error message is not to be freed.
+ */
+
+-#ifdef __FreeBSD__
+-
++#if defined(__FreeBSD__)
++#if defined(__i386__)
+ #include <machine/apm_bios.h>
++#endif
++#include "acpi-freebsd.h"
++
++static struct acpi_info acpiinfo;
++static gboolean using_acpi;
++static int acpi_count;
++static int acpiwatch;
++static struct apm_info apminfo;
++
++gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info *acpiinfo);
+
+ #define APMDEVICE "/dev/apm"
+
++static gboolean acpi_callback (GIOChannel * chan, GIOCondition cond, gpointer data)
++{
++ gboolean read_error;
++
++ if (cond & (G_IO_ERR | G_IO_HUP)) {
++ acpi_freebsd_cleanup(&acpiinfo);
++ return FALSE;
++ }
++
++ if (acpi_process_event(&acpiinfo, &read_error)) {
++ acpi_freebsd_read(&apminfo, &acpiinfo);
++ }
++ else if (read_error) {
++ acpi_freebsd_cleanup(&acpiinfo);
++ return FALSE;
++ }
++
++ return TRUE;
++}
++
+ static const char *
+ apm_readinfo (BatteryStatus *status)
+ {
+@@ -86,32 +116,56 @@ apm_readinfo (BatteryStatus *status)
+ FreeBSD. Each time this functions is called (once every second)
+ the APM device is opened, read from and then closed.
+ */
+- struct apm_info apminfo;
+ int fd;
+
+ if (DEBUG) g_print("apm_readinfo() (FreeBSD)\n");
+
+- fd = open(APMDEVICE, O_RDONLY);
+- if (fd == -1)
+- {
+- pm_initialised = 0;
+- return ERR_OPEN_APMDEV;
++ if (using_acpi && (!acpiinfo.event_inited || acpiinfo.event_fd >= 0)) {
++ if (acpi_count <= 0) {
++ acpi_count = 30;
++ if (!acpiinfo.event_inited) {
++ acpi_freebsd_update(&acpiinfo);
++ }
++ acpi_freebsd_read(&apminfo, &acpiinfo);
++ }
++ acpi_count--;
++ }
++ else if (using_acpi && acpiinfo.event_inited) {
++ if (acpi_freebsd_init(&acpiinfo)) {
++ acpiwatch = g_io_add_watch (acpiinfo.channel,
++ G_IO_IN | G_IO_ERR | G_IO_HUP,
++ acpi_callback, NULL);
++ acpi_freebsd_read(&apminfo, &acpiinfo);
++ }
+ }
++ else {
++#if defined(__i386__)
++ fd = open(APMDEVICE, O_RDONLY);
++ if (fd == -1) {
++ return ERR_OPEN_APMDEV;
++ }
+
+- if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1)
+- err(1, "ioctl(APMIO_GETINFO)");
++ if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1)
++ err(1, "ioctl(APMIO_GETINFO)");
+
+- close(fd);
++ close(fd);
+
+- if(apminfo.ai_status == 0)
+- return ERR_APM_E;
++ if(apminfo.ai_status == 0)
++ return ERR_APM_E;
++#else
++ return ERR_OPEN_APMDEV;
++#endif
++ }
+
+ status->present = TRUE;
+ status->on_ac_power = apminfo.ai_acline ? 1 : 0;
+ status->state = apminfo.ai_batt_stat;
+ status->percent = apminfo.ai_batt_life;
+ status->charging = (status->state == 3) ? TRUE : FALSE;
+- status->minutes = apminfo.ai_batt_time;
++ if (using_acpi)
++ status->minutes = apminfo.ai_batt_time;
++ else
++ status->minutes = (int) (apminfo.ai_batt_time/60.0);
+
+ return NULL;
+ }
+@@ -339,6 +393,19 @@ power_management_initialise( void )
+ G_IO_IN | G_IO_ERR | G_IO_HUP,
+ acpi_callback, NULL);
+ }
++#elif defined(__FreeBSD__)
++ if (acpi_freebsd_init(&acpiinfo)) {
++ using_acpi = TRUE;
++ acpi_count = 0;
++ }
++ else
++ using_acpi = FALSE;
++
++ if (using_acpi && acpiinfo.event_fd >= 0) {
++ acpiwatch = g_io_add_watch (acpiinfo.channel,
++ G_IO_IN | G_IO_ERR | G_IO_HUP,
++ acpi_callback, NULL);
++ }
+ #endif
+ pm_initialised = 1;
+
+@@ -360,6 +427,13 @@ power_management_cleanup( void )
+ g_source_remove(acpiwatch);
+ acpiwatch = 0;
+ acpi_linux_cleanup(&acpiinfo);
++ }
++#elif defined(__FreeBSD__)
++ if (using_acpi) {
++ if (acpiwatch != 0)
++ g_source_remove(acpiwatch);
++ acpiwatch = 0;
++ acpi_freebsd_cleanup(&acpiinfo);
+ }
+ #endif
+