summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshura <d.cirasino1@studenti.uniba.it>2019-02-24 18:09:47 +0100
committerFilipe Coelho <falktx@falktx.com>2019-02-24 18:09:47 +0100
commitbb3f5cb2963dc74ba045a1553e05f755af8623cc (patch)
treed768933a6e8dee6789f038bec3e6557c37986a3a
parent2bcacf66b4fa0140c16e5ec592e21884f9d4d8a3 (diff)
downloadjack2-bb3f5cb2963dc74ba045a1553e05f755af8623cc.tar.gz
Solving problems while compiling jack2 on macOS X with dbus support (#434)
* Solving problems while compiling jack2 on macOS X with dbus support * Using the right function name in uptime error
-rw-r--r--dbus/controller.c18
-rw-r--r--dbus/wscript6
-rw-r--r--linux/uptime.c12
-rw-r--r--linux/uptime.h27
-rw-r--r--macosx/uptime.c17
-rw-r--r--macosx/uptime.h27
6 files changed, 98 insertions, 9 deletions
diff --git a/dbus/controller.c b/dbus/controller.c
index f4ed8397..69180114 100644
--- a/dbus/controller.c
+++ b/dbus/controller.c
@@ -27,13 +27,13 @@
#include <dbus/dbus.h>
#include <assert.h>
#include <unistd.h>
-#include <sys/sysinfo.h>
#include <errno.h>
#include "controller.h"
#include "controller_internal.h"
#include "xml.h"
#include "reserve.h"
+#include "uptime.h"
struct jack_dbus_interface_descriptor * g_jackcontroller_interfaces[] =
{
@@ -787,18 +787,18 @@ void
jack_controller_run(
void * context)
{
- struct sysinfo si;
+ long ut;
if (controller_ptr->pending_save == 0)
{
return;
}
- if (sysinfo(&si) != 0)
+ if ((ut = uptime()) < 0)
{
- jack_error("sysinfo() failed with %d", errno);
+ jack_error(UPTIME_FUNCTION_NAME "() failed with %d", errno);
}
- else if (si.uptime < controller_ptr->pending_save + 2) /* delay save by two seconds */
+ else if (ut < controller_ptr->pending_save + 2) /* delay save by two seconds */
{
return;
}
@@ -813,15 +813,15 @@ void
jack_controller_pending_save(
struct jack_controller * controller_ptr)
{
- struct sysinfo si;
+ long ut;
- if (sysinfo(&si) != 0)
+ if ((ut = uptime()) < 0)
{
- jack_error("sysinfo() failed with %d.", errno);
+ jack_error(UPTIME_FUNCTION_NAME "() failed with %d.", errno);
controller_ptr->pending_save = 0;
jack_controller_settings_save_auto(controller_ptr);
return;
}
- controller_ptr->pending_save = si.uptime;
+ controller_ptr->pending_save = ut;
}
diff --git a/dbus/wscript b/dbus/wscript
index f1663d43..535d4121 100644
--- a/dbus/wscript
+++ b/dbus/wscript
@@ -63,8 +63,14 @@ def build(bld):
]
obj.use = ['serverlib']
if bld.env['IS_LINUX']:
+ obj.source += [
+ '../linux/uptime.c',
+ ]
obj.use += ['PTHREAD', 'DL', 'RT', 'DBUS-1', 'EXPAT', 'STDC++']
if bld.env['IS_MACOSX']:
+ obj.source += [
+ '../macosx/uptime.c',
+ ]
obj.use += ['PTHREAD', 'DL', 'DBUS-1', 'EXPAT']
obj.target = 'jackdbus'
diff --git a/linux/uptime.c b/linux/uptime.c
new file mode 100644
index 00000000..d6e6c9d5
--- /dev/null
+++ b/linux/uptime.c
@@ -0,0 +1,12 @@
+#include <sys/sysinfo.h>
+
+long uptime(void) {
+ struct sysinfo si;
+
+ if (sysinfo(&si) != 0)
+ {
+ return -1;
+ }
+
+ return si.uptime;
+}
diff --git a/linux/uptime.h b/linux/uptime.h
new file mode 100644
index 00000000..f0587bfd
--- /dev/null
+++ b/linux/uptime.h
@@ -0,0 +1,27 @@
+/*
+Copyright (C) 2004-2005 Grame
+
+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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef __uptime_LINUX__
+#define __uptime_LINUX__
+
+#define UPTIME_FUNCTION_NAME "sysinfo"
+
+long uptime(void);
+
+#endif
diff --git a/macosx/uptime.c b/macosx/uptime.c
new file mode 100644
index 00000000..7146fb52
--- /dev/null
+++ b/macosx/uptime.c
@@ -0,0 +1,17 @@
+#include <time.h>
+#include <errno.h>
+#include <sys/sysctl.h>
+
+long uptime(void)
+{
+ struct timeval boottime;
+ size_t len = sizeof(boottime);
+ int mib[2] = { CTL_KERN, KERN_BOOTTIME };
+ if (sysctl(mib, 2, &boottime, &len, NULL, 0) < 0)
+ {
+ return -1L;
+ }
+ time_t bsec = boottime.tv_sec, csec = time(NULL);
+
+ return (long) difftime(csec, bsec);
+}
diff --git a/macosx/uptime.h b/macosx/uptime.h
new file mode 100644
index 00000000..8fc5df11
--- /dev/null
+++ b/macosx/uptime.h
@@ -0,0 +1,27 @@
+/*
+Copyright (C) 2004-2005 Grame
+
+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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef __uptime_APPLE__
+#define __uptime_APPLE__
+
+#define UPTIME_FUNCTION_NAME "sysctl"
+
+long uptime(void);
+
+#endif