Signed-off-by: Radek Novacek <rnovacek(a)redhat.com>
---
src/host/host-dbus.c | 309 ++++++++++----------
src/host/host-qmf.cpp | 12 +-
src/include/matahari.h.in | 4 +-
src/include/matahari/host.h | 4 +-
src/include/matahari/logging.h | 159 ++++++-----
src/include/matahari/mainloop.h | 64 +++--
src/include/matahari/mh_agent.h | 17 +-
src/include/matahari/mh_dbus_common.h | 21 +-
src/include/matahari/mh_gobject_class.h | 25 +-
src/include/matahari/services.h | 43 ++-
src/include/matahari/utilities.h | 28 +-
src/lib/doxygen.h | 6 +-
src/lib/host.c | 75 +++--
src/lib/host_linux.c | 13 +-
src/lib/host_private.h | 15 +-
src/lib/host_windows.c | 14 +-
src/lib/mainloop.c | 83 +++---
src/lib/mh_agent.cpp | 90 ++++---
src/lib/mh_dbus_common.c | 410 +++++++++++++--------------
src/lib/network.c | 24 +-
src/lib/network_linux.c | 10 +-
src/lib/network_private.h | 6 +-
src/lib/network_windows.c | 6 +-
src/lib/services.c | 65 +++--
src/lib/services_linux.c | 233 ++++++++-------
src/lib/services_private.h | 27 +-
src/lib/services_windows.c | 389 +++++++++++++------------
src/lib/utilities.c | 472 ++++++++++++++++---------------
src/network/network-dbus.c | 242 ++++++++--------
src/network/network-qmf.cpp | 38 ++-
src/service/service-dbus.c | 288 ++++++++++----------
src/service/service-qmf.cpp | 75 +++---
src/tests/t_dnssrv.c | 6 +-
33 files changed, 1701 insertions(+), 1572 deletions(-)
diff --git a/src/host/host-dbus.c b/src/host/host-dbus.c
index ead877e..612b457 100644
--- a/src/host/host-dbus.c
+++ b/src/host/host-dbus.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2010 Red Hat, Inc.
* Written by Roman Rakus <rrakus(a)redhat.com>
- *
+ *
* 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
@@ -39,7 +39,7 @@
struct Private
{
- guint update_interval;
+ guint update_interval;
};
struct Private priv;
@@ -48,44 +48,42 @@ struct Private priv;
gboolean
Host_identify(Matahari* matahari, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(HOST_BUS_NAME ".identify", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- // TODO: Implement when implemented in backend
- error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED, "Action identify is
not implemented yet!");
- dbus_g_method_return(context, TRUE);
- return TRUE;
+ GError* error = NULL;
+ if (!check_authorization(HOST_BUS_NAME ".identify", &error, context))
{
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ // TODO: Implement when implemented in backend
+ error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED,
+ "Action identify is not implemented yet!");
+ dbus_g_method_return(context, TRUE);
+ return TRUE;
}
gboolean
Host_shutdown(Matahari* matahari, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(HOST_BUS_NAME ".shutdown", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- mh_host_shutdown();
- dbus_g_method_return(context, TRUE);
- return TRUE;
+ GError* error = NULL;
+ if (!check_authorization(HOST_BUS_NAME ".shutdown", &error, context))
{
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ mh_host_shutdown();
+ dbus_g_method_return(context, TRUE);
+ return TRUE;
}
gboolean
Host_reboot(Matahari* matahari, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(HOST_BUS_NAME ".reboot", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- mh_host_reboot();
- dbus_g_method_return(context, TRUE);
- return TRUE;
+ GError* error = NULL;
+ if (!check_authorization(HOST_BUS_NAME ".reboot", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ mh_host_reboot();
+ dbus_g_method_return(context, TRUE);
+ return TRUE;
}
/* Generated dbus stuff for host
@@ -95,149 +93,148 @@ Host_reboot(Matahari* matahari, DBusGMethodInvocation *context)
void
matahari_set_property(GObject *object, guint property_id, const GValue *value,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
- switch (property_id)
- {
- case PROP_UPDATE_INTERVAL:
- priv.update_interval = g_value_get_uint (value);
- break;
- default:
- /* We don't have any other property... */
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
+ switch (property_id) {
+ case PROP_UPDATE_INTERVAL:
+ priv.update_interval = g_value_get_uint (value);
+ break;
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
void
matahari_get_property(GObject *object, guint property_id, GValue *value,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
- sigar_proc_stat_t procs;
- sigar_loadavg_t avg;
- Dict *dict;
- GValue value_value = {0, };
-
- switch (property_id)
- {
- case PROP_UUID:
- g_value_set_string (value, mh_host_get_uuid());
- break;
- case PROP_HOSTNAME:
- g_value_set_string (value, mh_host_get_hostname());
- break;
- case PROP_OS:
- g_value_set_string (value, mh_host_get_operating_system());
- break;
- case PROP_ARCH:
- g_value_set_string (value, mh_host_get_architecture());
- break;
- case PROP_WORDSIZE:
- g_value_set_uint (value, mh_host_get_cpu_wordsize());
- break;
- case PROP_MEMORY:
- g_value_set_uint64 (value, mh_host_get_memory());
- break;
- case PROP_SWAP:
- g_value_set_uint64 (value, mh_host_get_swap());
- break;
- case PROP_CPU_COUNT:
- g_value_set_uint (value, mh_host_get_cpu_count());
- break;
- case PROP_CPU_CORES:
- g_value_set_uint (value, mh_host_get_cpu_number_of_cores());
- break;
- case PROP_CPU_MODEL:
- g_value_set_string (value, mh_host_get_cpu_model());
- break;
- case PROP_CPU_FLAGS:
- g_value_set_string (value, mh_host_get_cpu_flags());
- break;
- case PROP_UPDATE_INTERVAL:
- g_value_set_uint (value, priv.update_interval);
- break;
- case PROP_LAST_UPDATED:
- // Not used in DBus module
- break;
- case PROP_SEQUENCE:
- // Not used in DBus module
- break;
- case PROP_FREE_MEM:
- g_value_set_uint64 (value, mh_host_get_mem_free());
- break;
- case PROP_FREE_SWAP:
- g_value_set_uint64 (value, mh_host_get_swap_free());
- break;
- case PROP_LOAD:
- // 1/5/15 minute load average - map
- mh_host_get_load_averages(&avg);
-
- dict = dict_new(value);
- g_value_init (&value_value, G_TYPE_DOUBLE);
-
- g_value_set_double(&value_value, avg.loadavg[0]);
- dict_add(dict, "1", &value_value);
-
- g_value_set_double(&value_value, avg.loadavg[1]);
- dict_add(dict, "5", &value_value);
-
- g_value_set_double(&value_value, avg.loadavg[2]);
- dict_add(dict, "15", &value_value);
- dict_free(dict);
- break;
- case PROP_PROCESS_STATISTICS:
- // Process statistics is type map string -> int
- mh_host_get_processes(&procs);
-
- dict = dict_new(value);
- g_value_init (&value_value, G_TYPE_INT);
-
- g_value_set_int(&value_value, procs.total);
- dict_add(dict, "total", &value_value);
-
- g_value_set_int(&value_value, procs.idle);
- dict_add(dict, "idle", &value_value);
-
- g_value_set_int(&value_value, procs.zombie);
- dict_add(dict, "zombie", &value_value);
-
- g_value_set_int(&value_value, procs.running);
- dict_add(dict, "running", &value_value);
-
- g_value_set_int(&value_value, procs.stopped);
- dict_add(dict, "stopped", &value_value);
-
- g_value_set_int(&value_value, procs.sleeping);
- dict_add(dict, "sleeping", &value_value);
- dict_free(dict);
- break;
- default:
- /* We don't have any other property... */
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
+ sigar_proc_stat_t procs;
+ sigar_loadavg_t avg;
+ Dict *dict;
+ GValue value_value = {0, };
+
+ switch (property_id) {
+ case PROP_UUID:
+ g_value_set_string (value, mh_host_get_uuid());
+ break;
+ case PROP_HOSTNAME:
+ g_value_set_string (value, mh_host_get_hostname());
+ break;
+ case PROP_OS:
+ g_value_set_string (value, mh_host_get_operating_system());
+ break;
+ case PROP_ARCH:
+ g_value_set_string (value, mh_host_get_architecture());
+ break;
+ case PROP_WORDSIZE:
+ g_value_set_uint (value, mh_host_get_cpu_wordsize());
+ break;
+ case PROP_MEMORY:
+ g_value_set_uint64 (value, mh_host_get_memory());
+ break;
+ case PROP_SWAP:
+ g_value_set_uint64 (value, mh_host_get_swap());
+ break;
+ case PROP_CPU_COUNT:
+ g_value_set_uint (value, mh_host_get_cpu_count());
+ break;
+ case PROP_CPU_CORES:
+ g_value_set_uint (value, mh_host_get_cpu_number_of_cores());
+ break;
+ case PROP_CPU_MODEL:
+ g_value_set_string (value, mh_host_get_cpu_model());
+ break;
+ case PROP_CPU_FLAGS:
+ g_value_set_string (value, mh_host_get_cpu_flags());
+ break;
+ case PROP_UPDATE_INTERVAL:
+ g_value_set_uint (value, priv.update_interval);
+ break;
+ case PROP_LAST_UPDATED:
+ // Not used in DBus module
+ break;
+ case PROP_SEQUENCE:
+ // Not used in DBus module
+ break;
+ case PROP_FREE_MEM:
+ g_value_set_uint64 (value, mh_host_get_mem_free());
+ break;
+ case PROP_FREE_SWAP:
+ g_value_set_uint64 (value, mh_host_get_swap_free());
+ break;
+ case PROP_LOAD:
+ // 1/5/15 minute load average - map
+ mh_host_get_load_averages(&avg);
+
+ dict = dict_new(value);
+ g_value_init (&value_value, G_TYPE_DOUBLE);
+
+ g_value_set_double(&value_value, avg.loadavg[0]);
+ dict_add(dict, "1", &value_value);
+
+ g_value_set_double(&value_value, avg.loadavg[1]);
+ dict_add(dict, "5", &value_value);
+
+ g_value_set_double(&value_value, avg.loadavg[2]);
+ dict_add(dict, "15", &value_value);
+ dict_free(dict);
+ break;
+ case PROP_PROCESS_STATISTICS:
+ // Process statistics is type map string -> int
+ mh_host_get_processes(&procs);
+
+ dict = dict_new(value);
+ g_value_init (&value_value, G_TYPE_INT);
+
+ g_value_set_int(&value_value, procs.total);
+ dict_add(dict, "total", &value_value);
+
+ g_value_set_int(&value_value, procs.idle);
+ dict_add(dict, "idle", &value_value);
+
+ g_value_set_int(&value_value, procs.zombie);
+ dict_add(dict, "zombie", &value_value);
+
+ g_value_set_int(&value_value, procs.running);
+ dict_add(dict, "running", &value_value);
+
+ g_value_set_int(&value_value, procs.stopped);
+ dict_add(dict, "stopped", &value_value);
+
+ g_value_set_int(&value_value, procs.sleeping);
+ dict_add(dict, "sleeping", &value_value);
+ dict_free(dict);
+ break;
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
-GType matahari_dict_type(int prop)
+GType
+matahari_dict_type(int prop)
{
- switch (prop)
- {
+ switch (prop) {
case PROP_LOAD:
- return G_TYPE_DOUBLE;
- break;
+ return G_TYPE_DOUBLE;
+ break;
case PROP_PROCESS_STATISTICS:
- return G_TYPE_INT;
- break;
+ return G_TYPE_INT;
+ break;
default:
- g_printerr("Type of property %s is map of unknown types\n",
properties[prop].name);
- return G_TYPE_VALUE;
- }
+ g_printerr("Type of property %s is map of unknown types\n",
+ properties[prop].name);
+ return G_TYPE_VALUE;
+ }
}
int
main(int argc, char** argv)
{
- g_type_init();
- priv.update_interval = 5;
- return run_dbus_server(HOST_BUS_NAME, HOST_OBJECT_PATH);
+ g_type_init();
+ priv.update_interval = 5;
+ return run_dbus_server(HOST_BUS_NAME, HOST_OBJECT_PATH);
}
diff --git a/src/host/host-qmf.cpp b/src/host/host-qmf.cpp
index bbac480..7547daf 100644
--- a/src/host/host-qmf.cpp
+++ b/src/host/host-qmf.cpp
@@ -41,10 +41,11 @@ public:
int heartbeat();
virtual int setup(qmf::AgentSession session);
virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
- gpointer user_data);
+ gpointer user_data);
};
-static gboolean heartbeat_timer(gpointer data)
+static gboolean
+heartbeat_timer(gpointer data)
{
HostAgent *agent = (HostAgent *)data;
g_timeout_add(agent->heartbeat(), heartbeat_timer, data);
@@ -65,7 +66,8 @@ main(int argc, char **argv)
}
gboolean
-HostAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data)
+HostAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data)
{
if (event.getType() != qmf::AGENT_METHOD) {
session.methodSuccess(event);
@@ -124,9 +126,9 @@ HostAgent::heartbeat()
_heartbeat_sequence++;
mh_trace("Updating stats: %d %d", _heartbeat_sequence, interval);
- if(interval == 0) {
+ if (interval == 0) {
/* Updates disabled, check again in 5min */
- return 5*60*1000;
+ return 5 * 60 * 1000;
}
#ifndef MSVC
diff --git a/src/include/matahari.h.in b/src/include/matahari.h.in
index 3eef272..4899e0c 100644
--- a/src/include/matahari.h.in
+++ b/src/include/matahari.h.in
@@ -6,12 +6,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
diff --git a/src/include/matahari/host.h b/src/include/matahari/host.h
index 5f78564..d8d3acd 100644
--- a/src/include/matahari/host.h
+++ b/src/include/matahari/host.h
@@ -5,12 +5,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
diff --git a/src/include/matahari/logging.h b/src/include/matahari/logging.h
index f09ea44..8d0078a 100644
--- a/src/include/matahari/logging.h
+++ b/src/include/matahari/logging.h
@@ -6,12 +6,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -28,15 +28,15 @@
#ifdef __linux__
# include <syslog.h>
-#else
-# define LOG_EMERG 0 /* system is unusable */
-# define LOG_ALERT 1 /* action must be taken immediately */
-# define LOG_CRIT 2 /* critical conditions */
-# define LOG_ERR 3 /* error conditions */
-# define LOG_WARNING 4 /* warning conditions */
-# define LOG_NOTICE 5 /* normal but significant condition */
-# define LOG_INFO 6 /* informational */
-# define LOG_DEBUG 7 /* debug-level messages */
+#else
+# define LOG_EMERG 0 /* system is unusable */
+# define LOG_ALERT 1 /* action must be taken immediately */
+# define LOG_CRIT 2 /* critical conditions */
+# define LOG_ERR 3 /* error conditions */
+# define LOG_WARNING 4 /* warning conditions */
+# define LOG_NOTICE 5 /* normal but significant condition */
+# define LOG_INFO 6 /* informational */
+# define LOG_DEBUG 7 /* debug-level messages */
#endif
#include <stdio.h>
@@ -55,11 +55,11 @@ extern void mh_enable_stderr(gboolean to_stderr);
/* Linux with trace logging */
struct _mh_ddebug_query {
- const char *files;
- const char *formats;
- const char *functions;
- unsigned long long total;
- unsigned long long matches;
+ const char *files;
+ const char *formats;
+ const char *functions;
+ unsigned long long total;
+ unsigned long long matches;
};
/*
@@ -88,92 +88,97 @@ struct _mh_ddebug {
extern struct _mh_ddebug __start___verbose[];
extern struct _mh_ddebug __stop___verbose[];
-# define MH_TRACE_INIT_DATA(name) \
- void name(void); \
+# define MH_TRACE_INIT_DATA(name) \
+ void name(void); \
void name(void) { MH_ASSERT(__start___verbose != __stop___verbose); } \
void __attribute__ ((constructor)) name(void);
-# define MH_CHECK(expr, failure_action) do { \
- static struct _mh_ddebug descriptor \
- __attribute__((section("__verbose"), aligned(8))) = \
- { __func__, __FILE__, #expr, __LINE__, LOG_TRACE}; \
- \
- if(__unlikely((expr) == 0)) { \
- mh_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, \
- descriptor.bump != LOG_TRACE, 1); \
- failure_action; \
- } \
+# define MH_CHECK(expr, failure_action) do { \
+ static struct _mh_ddebug descriptor \
+ __attribute__((section("__verbose"), aligned(8))) = \
+ { __func__, __FILE__, #expr, __LINE__, LOG_TRACE}; \
+ \
+ if (__unlikely((expr) == 0)) { \
+ mh_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, \
+ descriptor.bump != LOG_TRACE, 1); \
+ failure_action; \
+ } \
} while(0)
/*
* Throughout the macros below, note the leading, pre-comma, space in the
* various ' , ##args' occurences to aid portability across versions of
'gcc'.
- *
http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html#Variadic-Macros
+ *
http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html#Variadic-Macros
*/
-# define mh_log(level, fmt, args...) do { \
- static struct _mh_ddebug descriptor \
- __attribute__((section("__verbose"), aligned(8))) = \
- { __func__, __FILE__, fmt, __LINE__, LOG_TRACE}; \
- \
- if(__likely((level) <= mh_log_level)) { \
- mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
- \
- } else if(__unlikely(descriptor.bump != LOG_TRACE)) { \
- mh_log_fn(descriptor.bump, "TRACE: %s: %s:%d " fmt, __PRETTY_FUNCTION__ ,
__FILE__, __LINE__, ##args); \
- } \
+# define mh_log(level, fmt, args...) do { \
+ static struct _mh_ddebug descriptor \
+ __attribute__((section("__verbose"), aligned(8))) = \
+ { __func__, __FILE__, fmt, __LINE__, LOG_TRACE}; \
+ \
+ if (__likely((level) <= mh_log_level)) { \
+ mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
+ \
+ } else if (__unlikely(descriptor.bump != LOG_TRACE)) { \
+ mh_log_fn(descriptor.bump, "TRACE: %s: %s:%d " fmt, \
+ __PRETTY_FUNCTION__ , __FILE__, __LINE__, ##args); \
+ } \
} while(0)
-# define mh_log_unlikely(level, fmt, args...) do { \
- static struct _mh_ddebug descriptor \
- __attribute__((section("__verbose"), aligned(8))) = \
- { __func__, __FILE__, fmt, __LINE__, LOG_TRACE }; \
- \
- if(__unlikely((level) <= mh_log_level)) { \
- mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
- \
- } else if(__unlikely(descriptor.bump != LOG_TRACE)) { \
- mh_log_fn(descriptor.bump, "TRACE: %s: %s:%d " fmt, __PRETTY_FUNCTION__ ,
__FILE__, __LINE__, ##args); \
- } \
+# define mh_log_unlikely(level, fmt, args...) do { \
+ static struct _mh_ddebug descriptor \
+ __attribute__((section("__verbose"), aligned(8))) = \
+ { __func__, __FILE__, fmt, __LINE__, LOG_TRACE }; \
+ \
+ if (__unlikely((level) <= mh_log_level)) { \
+ mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
+ \
+ } else if (__unlikely(descriptor.bump != LOG_TRACE)) { \
+ mh_log_fn(descriptor.bump, "TRACE: %s: %s:%d " fmt, \
+ __PRETTY_FUNCTION__ , __FILE__, __LINE__, ##args); \
+ } \
} while(0)
-# define mh_log_alias(level, file, function, line, fmt, args...) do { \
- if(line) { \
- mh_log_fn(level, "TRACE: %s %s:%d "fmt, function, file, line, ##args); \
- } else { \
- mh_log_fn(level, "%s "fmt, function, ##args); \
- } \
+# define mh_log_alias(level, file, function, line, fmt, args...) do { \
+ if (line) { \
+ mh_log_fn(level, "TRACE: %s %s:%d "fmt, function, file, line, \
+ ##args); \
+ } else { \
+ mh_log_fn(level, "%s "fmt, function, ##args); \
+ } \
} while(0)
#else
# define MH_TRACE_INIT_DATA(name)
-# define MH_CHECK(expr, failure_action) do { \
- if(__unlikely((expr) == 0)) { \
- mh_abort(__FILE__,__PRETTY_FUNCTION__,__LINE__, #expr, 0, 1); \
- failure_action; \
- } \
+# define MH_CHECK(expr, failure_action) do { \
+ if (__unlikely((expr) == 0)) { \
+ mh_abort(__FILE__,__PRETTY_FUNCTION__,__LINE__, #expr, 0, 1); \
+ failure_action; \
+ } \
} while(0)
-# define mh_log(level, fmt, args...) do { \
- if(__likely((level) <= mh_log_level)) { \
- mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
- } \
+# define mh_log(level, fmt, args...) do { \
+ if (__likely((level) <= mh_log_level)) { \
+ mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
+ } \
} while(0)
-# define mh_log_unlikely(level, fmt, args...) do { \
- if(__unlikely((level) <= mh_log_level)) { \
- mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
- } \
+# define mh_log_unlikely(level, fmt, args...) do { \
+ if (__unlikely((level) <= mh_log_level)) { \
+ mh_log_fn((level), "%s: " fmt, __PRETTY_FUNCTION__ , ##args); \
+ } \
} while(0)
-# define mh_log_alias(level, file, function, line, fmt, args...) do { \
- mh_log_fn(level, "%s"fmt, function, ##args); \
+# define mh_log_alias(level, file, function, line, fmt, args...) do { \
+ mh_log_fn(level, "%s"fmt, function, ##args); \
} while(0)
#endif
-#define mh_log_always(level, fmt, args...) mh_log_fn(level, "%s: " fmt,
__PRETTY_FUNCTION__ , ##args)
+#define mh_log_always(level, fmt, args...) mh_log_fn(level, "%s: " fmt, \
+ __PRETTY_FUNCTION__ ,\
+ ##args)
#define mh_crit(fmt, args...) mh_log(LOG_CRIT, fmt , ##args)
#define mh_err(fmt, args...) mh_log(LOG_ERR, fmt , ##args)
#define mh_warn(fmt, args...) mh_log(LOG_WARNING, fmt , ##args)
@@ -182,9 +187,9 @@ extern struct _mh_ddebug __stop___verbose[];
#define mh_debug(fmt, args...) mh_log_unlikely(LOG_DEBUG, fmt , ##args)
#define mh_trace(fmt, args...) mh_log_unlikely(LOG_TRACE, fmt , ##args)
-#define mh_perror(level, fmt, args...) do { \
- const char *err = strerror(errno); \
- fprintf(stderr, fmt ": %s (%d)\n", ##args, err, errno); \
- mh_log(level, fmt ": %s (%d)", ##args, err, errno); \
+#define mh_perror(level, fmt, args...) do { \
+ const char *err = strerror(errno); \
+ fprintf(stderr, fmt ": %s (%d)\n", ##args, err, errno); \
+ mh_log(level, fmt ": %s (%d)", ##args, err, errno); \
} while(0)
#endif
diff --git a/src/include/matahari/mainloop.h b/src/include/matahari/mainloop.h
index 2bd3f7b..43a7a20 100644
--- a/src/include/matahari/mainloop.h
+++ b/src/include/matahari/mainloop.h
@@ -1,16 +1,16 @@
-/*
+/*
* Copyright (C) 2009 Andrew Beekhof <andrew(a)beekhof.net>
- *
+ *
* 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.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -35,39 +35,39 @@ extern gboolean mainloop_add_signal(int sig, void (*dispatch)(int
sig));
extern gboolean mainloop_destroy_signal(int sig);
-typedef struct trigger_s
+typedef struct trigger_s
{
- GSource source;
- GDestroyNotify dnotify;
- gboolean trigger;
- void *user_data;
- guint id;
+ GSource source;
+ GDestroyNotify dnotify;
+ gboolean trigger;
+ void *user_data;
+ guint id;
} mainloop_trigger_t;
extern mainloop_trigger_t *mainloop_add_trigger(
int priority, gboolean (*dispatch)(gpointer user_data), gpointer userdata);
-extern void mainloop_set_trigger(mainloop_trigger_t* source);
+extern void mainloop_set_trigger(mainloop_trigger_t *source);
-extern gboolean mainloop_destroy_trigger(mainloop_trigger_t* source);
+extern gboolean mainloop_destroy_trigger(mainloop_trigger_t *source);
-typedef struct mainloop_fd_s
+typedef struct mainloop_fd_s
{
- GSource source;
- GPollFD gpoll;
- guint id;
- void *user_data;
- GDestroyNotify dnotify;
- gboolean (*dispatch)(int fd, gpointer user_data);
+ GSource source;
+ GPollFD gpoll;
+ guint id;
+ void *user_data;
+ GDestroyNotify dnotify;
+ gboolean (*dispatch)(int fd, gpointer user_data);
} mainloop_fd_t;
extern mainloop_fd_t *mainloop_add_fd(int priority, int fd,
- gboolean (*dispatch)(int fd, gpointer userdata),
- GDestroyNotify notify, gpointer userdata);
+ gboolean (*dispatch)(int fd, gpointer userdata),
+ GDestroyNotify notify, gpointer userdata);
extern gboolean mainloop_destroy_fd(mainloop_fd_t* source);
@@ -75,14 +75,14 @@ extern gboolean mainloop_destroy_fd(mainloop_fd_t* source);
typedef struct mainloop_child_s mainloop_child_t;
struct mainloop_child_s {
- pid_t pid;
- char *desc;
- unsigned timerid;
- gboolean timeout;
- void *privatedata;
+ pid_t pid;
+ char *desc;
+ unsigned timerid;
+ gboolean timeout;
+ void *privatedata;
- /* Called when a process dies */
- void (*callback)(mainloop_child_t* p, int status, int signo, int exitcode);
+ /* Called when a process dies */
+ void (*callback)(mainloop_child_t* p, int status, int signo, int exitcode);
};
@@ -92,8 +92,10 @@ extern void mainloop_track_children(int priority);
* Create a new tracked process
* To track a process group, use -pid
*/
-extern void mainloop_add_child(
- pid_t pid, int timeout, const char *desc, void * privatedata,
- void (*callback)(mainloop_child_t* p, int status, int signo, int exitcode));
+extern void mainloop_add_child(pid_t pid, int timeout, const char *desc,
+ void *privatedata,
+ void (*callback)(mainloop_child_t* p,
+ int status, int signo,
+ int exitcode));
#endif
diff --git a/src/include/matahari/mh_agent.h b/src/include/matahari/mh_agent.h
index 26fbae0..9bf86ec 100644
--- a/src/include/matahari/mh_agent.h
+++ b/src/include/matahari/mh_agent.h
@@ -6,12 +6,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -53,14 +53,16 @@ typedef struct mainloop_qmf_s {
guint id;
void *user_data;
GDestroyNotify dnotify;
- gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event, gpointer
user_data);
+ gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data);
} mainloop_qmf_t;
extern mainloop_qmf_t *mainloop_add_qmf(int priority, qmf::AgentSession session,
- gboolean (*dispatch)(qmf::AgentSession session,
qmf::AgentEvent event, gpointer userdata),
- GDestroyNotify notify, gpointer userdata);
+ gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer userdata),
+ GDestroyNotify notify, gpointer userdata);
-extern gboolean mainloop_destroy_qmf(mainloop_qmf_t* source);
+extern gboolean mainloop_destroy_qmf(mainloop_qmf_t *source);
class MatahariAgent
{
@@ -69,7 +71,8 @@ public:
~MatahariAgent() {};
virtual int setup(qmf::AgentSession session) { return 0; };
- virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer
user_data) { return FALSE; };
+ virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data) { return FALSE; };
int init(int argc, char **argv, const char* proc_name);
void run();
diff --git a/src/include/matahari/mh_dbus_common.h
b/src/include/matahari/mh_dbus_common.h
index b7edc53..e7b4936 100644
--- a/src/include/matahari/mh_dbus_common.h
+++ b/src/include/matahari/mh_dbus_common.h
@@ -30,7 +30,8 @@
#include "mh_gobject_class.h"
/* Private struct in Matahari class */
-#define MATAHARI_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MATAHARI_TYPE,
MatahariPrivate))
+#define MATAHARI_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
+ MATAHARI_TYPE, MatahariPrivate))
// Matahari error codes
#define MATAHARI_ERROR matahari_error_quark ()
@@ -44,7 +45,8 @@ matahari_error_quark (void);
* user is authorized, otherwise return FALSE and 'error' is set.
*/
gboolean
-check_authorization(const gchar *action, GError** error, DBusGMethodInvocation
*context);
+check_authorization(const gchar *action, GError** error,
+ DBusGMethodInvocation *context);
typedef struct {
int prop;
@@ -67,14 +69,16 @@ run_dbus_server(char *bus_name, char *object_path);
* action interface.name
*/
gboolean
-matahari_get(Matahari* matahari, const char *interface, const char *name,
DBusGMethodInvocation *context);
+matahari_get(Matahari* matahari, const char *interface, const char *name,
+ DBusGMethodInvocation *context);
/**
* Check the authorization for setting the parameter 'name' using PolicyKit
* action interface.name
*/
gboolean
-matahari_set(Matahari *matahari, const char *interface, const char *name, GValue *value,
DBusGMethodInvocation *context);
+matahari_set(Matahari *matahari, const char *interface, const char *name,
+ GValue *value, DBusGMethodInvocation *context);
/**
* This method is used for getting value of DBus property.
@@ -82,7 +86,8 @@ matahari_set(Matahari *matahari, const char *interface, const char
*name, GValue
* Set the value of property_id parameter to parameter value.
*/
void
-matahari_get_property(GObject *object, guint property_id, GValue *value, GParamSpec
*pspec);
+matahari_get_property(GObject *object, guint property_id, GValue *value,
+ GParamSpec *pspec);
/**
* This method is used for setting value of DBus property.
@@ -90,7 +95,8 @@ matahari_get_property(GObject *object, guint property_id, GValue *value,
GParamS
* New value of property_id is in parameter value.
*/
void
-matahari_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec
*pspec);
+matahari_set_property(GObject *object, guint property_id, const GValue *value,
+ GParamSpec *pspec);
/**
* This method is used to determine type of value in all dictionary parameters.
@@ -110,7 +116,8 @@ typedef struct
} Dict;
/**
- * Constructor of dictionary type. Key is string, type of value is defined by type of
'value'.
+ * Constructor of dictionary type. Key is string, type of value is defined
+ * by type of 'value'.
* New value will be stored in 'value'. Use dict_free after setting all values.
*/
Dict *dict_new(GValue *value);
diff --git a/src/include/matahari/mh_gobject_class.h
b/src/include/matahari/mh_gobject_class.h
index 821d0ac..fe13d1e 100644
--- a/src/include/matahari/mh_gobject_class.h
+++ b/src/include/matahari/mh_gobject_class.h
@@ -3,7 +3,7 @@
*
* Copyright (C) 2010 Red Hat, Inc.
* Written by Roman Rakus <rrakus(a)redhat.com>
- *
+ *
* 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
@@ -23,12 +23,17 @@
#ifndef MHGOBJECTCLASS_H_
#define MHGOBJECTCLASS_H_
-#define MATAHARI_TYPE (matahari_get_type())
-#define MATAHARI(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MATAHARI_TYPE,
Matahari))
-#define MATAHARI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MATAHARI_TYPE,
MatahariClass))
-#define IS_MATAHARI(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object),
MATAHARI_TYPE))
-#define IS_MATAHARI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MATAHARI_TYPE))
-#define MATAHARI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MATAHARI_TYPE,
MatahariClass))
+#define MATAHARI_TYPE (matahari_get_type())
+#define MATAHARI(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), \
+ MATAHARI_TYPE, Matahari))
+#define MATAHARI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ MATAHARI_TYPE, MatahariClass))
+#define IS_MATAHARI(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), \
+ MATAHARI_TYPE))
+#define IS_MATAHARI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ MATAHARI_TYPE))
+#define MATAHARI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ MATAHARI_TYPE, MatahariClass))
typedef struct _Matahari Matahari;
typedef struct _MatahariClass MatahariClass;
@@ -39,13 +44,13 @@ matahari_get_type(void);
struct _Matahari
{
- GObject parent;
- MatahariPrivate *priv;
+ GObject parent;
+ MatahariPrivate *priv;
};
struct _MatahariClass
{
- GObjectClass parent;
+ GObjectClass parent;
};
#endif /* MHGOBJECTCLASS_H_ */
diff --git a/src/include/matahari/services.h b/src/include/matahari/services.h
index 0a48bb8..5241e73 100644
--- a/src/include/matahari/services.h
+++ b/src/include/matahari/services.h
@@ -47,7 +47,8 @@ enum lsb_exitcode {
/* 150-199 reserved for application use */
};
-/* The return codes for the status operation are not the same for other operatios - go
figure */
+/* The return codes for the status operation are not the same for other
+ * operatios - go figure */
enum lsb_status_exitcode {
LSB_STATUS_OK = 0,
LSB_STATUS_VAR_PID = 1,
@@ -55,7 +56,7 @@ enum lsb_status_exitcode {
LSB_STATUS_NOT_RUNNING = 3,
LSB_STATUS_NOT_INSTALLED = 4,
- /* 150-199 reserved for application use */
+ /* 150-199 reserved for application use */
LSB_STATUS_UNKNOWN_ERROR = 199,
};
@@ -122,26 +123,35 @@ extern GList *services_list(void);
extern GList *resources_list_ocf_providers(void);
extern GList *resources_list_ocf_agents(const char *provider);
-extern svc_action_t *services_action_create(
- const char *name, const char *action, int interval /* ms */, int timeout /* ms */);
-
-/* After the call, 'params' is owned, and later free'd by the svc_action_t
result */
-extern svc_action_t *resources_action_create(
- const char *name, const char *provider, const char *agent,
- const char *action, int interval /* ms */, int timeout /* ms */, GHashTable
*params);
+extern svc_action_t *services_action_create(const char *name,
+ const char *action,
+ int interval /* ms */,
+ int timeout /* ms */);
+
+/* After the call, 'params' is owned, and later free'd by the
+ * svc_action_t result */
+extern svc_action_t *resources_action_create(const char *name,
+ const char *provider,
+ const char *agent,
+ const char *action,
+ int interval /* ms */,
+ int timeout /* ms */,
+ GHashTable *params);
extern void services_action_free(svc_action_t *op);
-extern gboolean services_action_sync(svc_action_t* op);
-extern gboolean services_action_async(svc_action_t* op, void
(*action_callback)(svc_action_t*));
+extern gboolean services_action_sync(svc_action_t *op);
+extern gboolean services_action_async(svc_action_t *op,
+ void (*action_callback)(svc_action_t *));
-extern gboolean services_action_cancel(const char *name, const char *action, int
interval);
+extern gboolean services_action_cancel(const char *name, const char *action,
+ int interval);
static inline enum ocf_exitcode
services_get_ocf_exitcode(char *action, int lsb_exitcode)
{
- if(action != NULL && strcmp("status", action) == 0) {
- switch(lsb_exitcode) {
+ if (action != NULL && strcmp("status", action) == 0) {
+ switch (lsb_exitcode) {
case LSB_STATUS_OK: return OCF_OK;
case LSB_STATUS_VAR_PID: return OCF_NOT_RUNNING;
case LSB_STATUS_VAR_LOCK: return OCF_NOT_RUNNING;
@@ -150,11 +160,12 @@ services_get_ocf_exitcode(char *action, int lsb_exitcode)
default: return OCF_UNKNOWN_ERROR;
}
- } else if(lsb_exitcode > LSB_NOT_RUNNING) {
+ } else if (lsb_exitcode > LSB_NOT_RUNNING) {
return OCF_UNKNOWN_ERROR;
}
- /* For non-status operations, the LSB and OCF share error code meaning for rc <= 7
*/
+ /* For non-status operations, the LSB and OCF share error code meaning
+ * for rc <= 7 */
return (enum ocf_exitcode)lsb_exitcode;
}
#endif
diff --git a/src/include/matahari/utilities.h b/src/include/matahari/utilities.h
index e48be25..60c5856 100644
--- a/src/include/matahari/utilities.h
+++ b/src/include/matahari/utilities.h
@@ -1,16 +1,16 @@
-/*
+/*
* Copyright (C) 2010 Andrew Beekhof <andrew(a)beekhof.net>
- *
+ *
* 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.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -34,7 +34,7 @@
extern const char *mh_uuid(void);
extern const char *mh_hostname(void);
extern void mh_abort(const char *file, const char *function, int line,
- const char *assert_condition, int do_core, int do_fork);
+ const char *assert_condition, int do_core, int do_fork);
#ifndef HAVE_ASPRINTF
/**
@@ -47,7 +47,7 @@ extern void mh_abort(const char *file, const char *function, int line,
extern int asprintf(char **ret, const char *fmt, ...);
#endif
-#define DIMOF(a) ((int) (sizeof(a) / sizeof(0[a])))
+#define DIMOF(a) ((int) (sizeof(a) / sizeof(0[a])))
#ifndef __GNUC__
# define __builtin_expect(expr, result) (expr)
@@ -57,16 +57,16 @@ extern int asprintf(char **ret, const char *fmt, ...);
#define __likely(expr) __builtin_expect(expr, 1)
#define __unlikely(expr) __builtin_expect(expr, 0)
-#define MH_ASSERT(expr) do { \
- if(__unlikely((expr) == 0)) { \
- mh_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, 1, 0); \
- } \
+#define MH_ASSERT(expr) do { \
+ if (__unlikely((expr) == 0)) { \
+ mh_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, 1, 0); \
+ } \
} while(0)
-#define MH_LOG_ASSERT(expr) do { \
- if(__unlikely((expr) == FALSE)) { \
- mh_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, 0, 1); \
- } \
+#define MH_LOG_ASSERT(expr) do { \
+ if (__unlikely((expr) == FALSE)) { \
+ mh_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, #expr, 0, 1); \
+ } \
} while(0)
#endif
diff --git a/src/lib/doxygen.h b/src/lib/doxygen.h
index e646258..1516eaf 100644
--- a/src/lib/doxygen.h
+++ b/src/lib/doxygen.h
@@ -1,4 +1,4 @@
-/*
+/*
* doxygen.h - Copyright (C) 2011, Russell Bryant
* Written by Russell Bryant <russell(a)russellbryant.net>
*
@@ -6,12 +6,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
diff --git a/src/lib/host.c b/src/lib/host.c
index 771ac44..6e71db0 100644
--- a/src/lib/host.c
+++ b/src/lib/host.c
@@ -63,55 +63,63 @@ static cpuinfo_t cpuinfo = {
.cores = 0,
};
-static void host_get_cpu_details(void);
+static void
+host_get_cpu_details(void);
-static void init(void)
+static void
+init(void)
{
- if(host_init.sigar_init) {
+ if (host_init.sigar_init) {
return;
}
sigar_open(&host_init.sigar);
host_init.sigar_init = TRUE;
}
-const char *mh_host_get_uuid(void)
+const char *
+mh_host_get_uuid(void)
{
return mh_uuid();
}
-const char *mh_host_get_hostname(void)
+const char *
+mh_host_get_hostname(void)
{
return mh_hostname();
}
-const char *mh_host_get_operating_system(void)
+const char *
+mh_host_get_operating_system(void)
{
static const char *operating_system = NULL;
init();
- if(operating_system == NULL) {
+ if (operating_system == NULL) {
sigar_sys_info_t sysinfo;
sigar_sys_info_get(host_init.sigar, &sysinfo);
- operating_system = g_strdup_printf("%s (%s)", sysinfo.vendor_name,
sysinfo.version);
+ operating_system = g_strdup_printf("%s (%s)", sysinfo.vendor_name,
+ sysinfo.version);
}
return operating_system;
}
-int mh_host_get_cpu_wordsize(void)
+int
+mh_host_get_cpu_wordsize(void)
{
return (int)(CHAR_BIT * sizeof(size_t));
}
-const char *mh_host_get_architecture(void)
+const char *
+mh_host_get_architecture(void)
{
static const char *arch = NULL;
init();
- if(arch == NULL) {
+ if (arch == NULL) {
sigar_sys_info_t sysinfo;
sigar_sys_info_get(host_init.sigar, &sysinfo);
@@ -121,52 +129,61 @@ const char *mh_host_get_architecture(void)
return arch;
}
-void mh_host_reboot(void)
+void
+mh_host_reboot(void)
{
host_os_reboot();
}
-void mh_host_shutdown(void)
+void
+mh_host_shutdown(void)
{
host_os_shutdown();
}
-const char *mh_host_get_cpu_model(void)
+const char *
+mh_host_get_cpu_model(void)
{
host_get_cpu_details();
return cpuinfo.model;
}
-const char *mh_host_get_cpu_flags(void)
+const char *
+mh_host_get_cpu_flags(void)
{
return host_os_get_cpu_flags();
}
-int mh_host_get_cpu_count(void)
+int
+mh_host_get_cpu_count(void)
{
host_get_cpu_details();
return cpuinfo.cpus;
}
-int mh_host_get_cpu_number_of_cores(void)
+int
+mh_host_get_cpu_number_of_cores(void)
{
host_get_cpu_details();
return cpuinfo.cores;
}
-void mh_host_get_load_averages(sigar_loadavg_t *avg)
+void
+mh_host_get_load_averages(sigar_loadavg_t *avg)
{
init();
sigar_loadavg_get(host_init.sigar, avg);
}
-void mh_host_get_processes(sigar_proc_stat_t *procs)
+void
+mh_host_get_processes(sigar_proc_stat_t *procs)
{
init();
sigar_proc_stat_get(host_init.sigar, procs);
}
-uint64_t mh_host_get_memory(void)
+uint64_t
+mh_host_get_memory(void)
{
sigar_mem_t mem;
uint64_t total;
@@ -177,7 +194,8 @@ uint64_t mh_host_get_memory(void)
return total;
}
-uint64_t mh_host_get_mem_free(void)
+uint64_t
+mh_host_get_mem_free(void)
{
sigar_mem_t mem;
uint64_t free;
@@ -188,7 +206,8 @@ uint64_t mh_host_get_mem_free(void)
return free;
}
-uint64_t mh_host_get_swap(void)
+uint64_t
+mh_host_get_swap(void)
{
sigar_swap_t swap;
uint64_t total;
@@ -199,7 +218,8 @@ uint64_t mh_host_get_swap(void)
return total;
}
-uint64_t mh_host_get_swap_free(void)
+uint64_t
+mh_host_get_swap_free(void)
{
sigar_swap_t swap;
uint64_t free;
@@ -210,12 +230,13 @@ uint64_t mh_host_get_swap_free(void)
return free;
}
-static void host_get_cpu_details(void)
+static void
+host_get_cpu_details(void)
{
int lpc = 0;
sigar_cpu_info_list_t cpus;
- if(cpuinfo.cpus) {
+ if (cpuinfo.cpus) {
return;
}
@@ -223,9 +244,9 @@ static void host_get_cpu_details(void)
sigar_cpu_info_list_get(host_init.sigar, &cpus);
cpuinfo.cpus = cpus.number;
- for(lpc = 0; lpc < cpus.number; lpc++) {
+ for (lpc = 0; lpc < cpus.number; lpc++) {
sigar_cpu_info_t *cpu = (sigar_cpu_info_t *) cpus.data;
- if(cpuinfo.model == NULL) {
+ if (cpuinfo.model == NULL) {
cpuinfo.model = g_strdup(cpu->model);
}
cpuinfo.cores += cpu->total_cores;
diff --git a/src/lib/host_linux.c b/src/lib/host_linux.c
index 96e1303..6c1babd 100644
--- a/src/lib/host_linux.c
+++ b/src/lib/host_linux.c
@@ -5,12 +5,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -35,7 +35,8 @@
#include "matahari/host.h"
#include "host_private.h"
-const char *host_os_get_cpu_flags(void)
+const char *
+host_os_get_cpu_flags(void)
{
static const char regexstr[] = "(.*\\S)\\s*:\\s*(\\S.*)";
static char *flags = NULL;
@@ -75,7 +76,7 @@ const char *host_os_get_cpu_flags(void)
regex = pcre_compile(regexstr, 0, &pcre_error, &pcre_error_offset, NULL);
if (!regex) {
mh_err("Unable to compile regular expression '%s' at offset %d:
%s",
- regexstr, pcre_error_offset, pcre_error);
+ regexstr, pcre_error_offset, pcre_error);
goto done;
}
@@ -87,8 +88,8 @@ const char *host_os_get_cpu_flags(void)
int found[9];
match = pcre_exec(regex, NULL, cur, strlen(cur),
- 0, PCRE_NOTEMPTY, found,
- sizeof(found) / sizeof(found[0]));
+ 0, PCRE_NOTEMPTY, found,
+ sizeof(found) / sizeof(found[0]));
if (match != expected || strncmp(cur + found[2], "flags", 5)) {
continue;
diff --git a/src/lib/host_private.h b/src/lib/host_private.h
index 55fd775..0994536 100644
--- a/src/lib/host_private.h
+++ b/src/lib/host_private.h
@@ -5,16 +5,16 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
+ */
/**
* \file
@@ -31,10 +31,13 @@
#include <glib.h>
-extern const char *host_os_get_cpu_flags(void);
+extern const char *
+host_os_get_cpu_flags(void);
-extern void host_os_reboot(void);
+extern void
+host_os_reboot(void);
-extern void host_os_shutdown(void);
+extern void
+host_os_shutdown(void);
#endif /* __MH_HOST_PRIVATE_H__ */
diff --git a/src/lib/host_windows.c b/src/lib/host_windows.c
index 90cb7f4..e86ff47 100644
--- a/src/lib/host_windows.c
+++ b/src/lib/host_windows.c
@@ -5,12 +5,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -47,15 +47,15 @@ static void
get_token_priv(HANDLE token, TOKEN_PRIVILEGES tkp)
{
OpenProcessToken(GetCurrentProcess(),
- TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token);
+ TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token);
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
- &tkp.Privileges[0].Luid);
+ &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(token, FALSE, &tkp, 0,
- (PTOKEN_PRIVILEGES)NULL, 0);
+ (PTOKEN_PRIVILEGES) NULL, 0);
}
void
@@ -66,7 +66,7 @@ host_os_reboot(void)
get_token_priv(token, tkp);
ExitWindowsEx(EWX_REBOOT | EWX_FORCE,
- SHTDN_REASON_FLAG_PLANNED);
+ SHTDN_REASON_FLAG_PLANNED);
}
void
@@ -77,5 +77,5 @@ host_os_shutdown(void)
get_token_priv(token, tkp);
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,
- SHTDN_REASON_FLAG_PLANNED);
+ SHTDN_REASON_FLAG_PLANNED);
}
diff --git a/src/lib/mainloop.c b/src/lib/mainloop.c
index d3426a4..1b2e276 100644
--- a/src/lib/mainloop.c
+++ b/src/lib/mainloop.c
@@ -51,12 +51,13 @@ mainloop_trigger_check(GSource *source)
}
static gboolean
-mainloop_trigger_dispatch(GSource *source, GSourceFunc callback, gpointer userdata)
+mainloop_trigger_dispatch(GSource *source, GSourceFunc callback,
+ gpointer userdata)
{
mainloop_trigger_t *trig = (mainloop_trigger_t *) source;
trig->trigger = FALSE;
- if(callback) {
+ if (callback) {
return callback(trig->user_data);
}
return TRUE;
@@ -81,7 +82,7 @@ mainloop_setup_trigger(GSource *source, int priority,
trigger->trigger = FALSE;
trigger->user_data = userdata;
- if(dispatch) {
+ if (dispatch) {
g_source_set_callback(source, dispatch, trigger, NULL);
}
@@ -134,13 +135,13 @@ static gboolean
mainloop_signal_dispatch(GSource *source, GSourceFunc callback,
gpointer userdata)
{
- mainloop_signal_t *sig = (mainloop_signal_t*)source;
+ mainloop_signal_t *sig = (mainloop_signal_t *) source;
#if __linux__
mh_info("Invoking handler for signal %d: %s",
- sig->signal, strsignal(sig->signal));
+ sig->signal, strsignal(sig->signal));
#endif
sig->trigger.trigger = FALSE;
- if(sig->handler) {
+ if (sig->handler) {
sig->handler(sig->signal);
}
return TRUE;
@@ -149,8 +150,8 @@ mainloop_signal_dispatch(GSource *source, GSourceFunc callback,
static void
mainloop_signal_handler(int sig)
{
- if(sig > 0 && sig < NSIG && mainloop_signals[sig] != NULL) {
- mainloop_set_trigger((mainloop_trigger_t*)mainloop_signals[sig]);
+ if (sig > 0 && sig < NSIG && mainloop_signals[sig] != NULL) {
+ mainloop_set_trigger((mainloop_trigger_t *) mainloop_signals[sig]);
}
}
@@ -169,7 +170,7 @@ mainloop_signal(int sig, void (*dispatch)(int sig))
struct sigaction sa;
struct sigaction old;
- if(sigemptyset(&mask) < 0) {
+ if (sigemptyset(&mask) < 0) {
mh_perror(LOG_ERR, "Call to sigemptyset failed");
return FALSE;
}
@@ -178,8 +179,9 @@ mainloop_signal(int sig, void (*dispatch)(int sig))
sa.sa_flags = SA_RESTART;
sa.sa_mask = mask;
- if(sigaction(sig, &sa, &old) < 0) {
- mh_perror(LOG_ERR, "Could not install signal handler for signal %d",
sig);
+ if (sigaction(sig, &sa, &old) < 0) {
+ mh_perror(LOG_ERR, "Could not install signal handler for signal %d",
+ sig);
return FALSE;
}
@@ -195,7 +197,7 @@ mainloop_add_signal(int sig, void (*dispatch)(int sig))
{
GSource *source = NULL;
int priority = G_PRIORITY_HIGH - 1;
- if(sig == SIGTERM) {
+ if (sig == SIGTERM) {
/* TERM is higher priority than other signals,
* signals are higher priority than other ipc.
* Yes, minus: smaller is "higher"
@@ -203,11 +205,11 @@ mainloop_add_signal(int sig, void (*dispatch)(int sig))
priority--;
}
- if(sig >= NSIG || sig < 0) {
+ if (sig >= NSIG || sig < 0) {
mh_err("Signal %d is out of range", sig);
return FALSE;
- } else if(mainloop_signals[sig] != NULL) {
+ } else if (mainloop_signals[sig] != NULL) {
mh_err("Signal handler for %d is already installed", sig);
return FALSE;
}
@@ -215,19 +217,20 @@ mainloop_add_signal(int sig, void (*dispatch)(int sig))
MH_ASSERT(sizeof(mainloop_signal_t) > sizeof(GSource));
source = g_source_new(&mainloop_signal_funcs, sizeof(mainloop_signal_t));
- mainloop_signals[sig] = (mainloop_signal_t*)mainloop_setup_trigger(source, priority,
NULL, NULL);
- if(mainloop_signals[sig] == NULL) {
+ mainloop_signals[sig] = (mainloop_signal_t *) mainloop_setup_trigger(
+ source, priority, NULL, NULL);
+ if (mainloop_signals[sig] == NULL) {
return FALSE;
}
mainloop_signals[sig]->handler = dispatch;
mainloop_signals[sig]->signal = sig;
- if(mainloop_signal(sig, mainloop_signal_handler) == FALSE) {
+ if (mainloop_signal(sig, mainloop_signal_handler) == FALSE) {
mainloop_signal_t *tmp = mainloop_signals[sig];
mainloop_signals[sig] = NULL;
- mainloop_destroy_trigger((mainloop_trigger_t*)tmp);
+ mainloop_destroy_trigger((mainloop_trigger_t *) tmp);
return FALSE;
}
@@ -239,21 +242,22 @@ mainloop_destroy_signal(int sig)
{
mainloop_signal_t *tmp = NULL;
- if(sig >= NSIG || sig < 0) {
+ if (sig >= NSIG || sig < 0) {
mh_err("Signal %d is out of range", sig);
return FALSE;
- } else if(mainloop_signal(sig, NULL) == FALSE) {
- mh_perror(LOG_ERR, "Could not uninstall signal handler for signal %d",
sig);
+ } else if (mainloop_signal(sig, NULL) == FALSE) {
+ mh_perror(LOG_ERR, "Could not uninstall signal handler for signal %d",
+ sig);
return FALSE;
- } else if(mainloop_signals[sig] == NULL) {
+ } else if (mainloop_signals[sig] == NULL) {
return TRUE;
}
tmp = mainloop_signals[sig];
mainloop_signals[sig] = NULL;
- mainloop_destroy_trigger((mainloop_trigger_t*)tmp);
+ mainloop_destroy_trigger((mainloop_trigger_t *) tmp);
return TRUE;
}
@@ -326,15 +330,16 @@ mainloop_add_fd(int priority, int fd,
source = g_source_new(&mainloop_fd_funcs, sizeof(mainloop_fd_t));
MH_ASSERT(source != NULL);
- fd_source = (mainloop_fd_t*)source;
+ fd_source = (mainloop_fd_t *) source;
fd_source->id = 0;
fd_source->gpoll.fd = fd;
fd_source->gpoll.events = G_IO_ERR|G_IO_NVAL|G_IO_IN|G_IO_PRI|G_IO_HUP;
fd_source->gpoll.revents = 0;
/*
- * Normally we'd use g_source_set_callback() to specify the dispatch function,
- * But we want to supply the fd too, so we store it in fd_source->dispatch
instead
+ * Normally we'd use g_source_set_callback() to specify the dispatch
+ * function, but we want to supply the fd too, so we store it in
+ * fd_source->dispatch instead
*/
fd_source->dnotify = notify;
fd_source->dispatch = dispatch;
@@ -351,10 +356,10 @@ mainloop_add_fd(int priority, int fd,
gboolean
mainloop_destroy_fd(mainloop_fd_t *source)
{
- g_source_remove_poll((GSource*)source, &source->gpoll);
+ g_source_remove_poll((GSource *) source, &source->gpoll);
g_source_remove(source->id);
source->id = 0;
- g_source_unref((GSource*)source);
+ g_source_unref((GSource *) source);
return TRUE;
}
@@ -363,7 +368,8 @@ static gboolean
child_timeout_callback(gpointer p)
{
pid_t pid = (pid_t) GPOINTER_TO_INT(p);
- mainloop_child_t *pinfo = (mainloop_child_t *)
g_hash_table_lookup(mainloop_process_table, p);
+ mainloop_child_t *pinfo = (mainloop_child_t *) g_hash_table_lookup(
+ mainloop_process_table, p);
if (pinfo == NULL) {
return FALSE;
@@ -398,7 +404,7 @@ child_timeout_callback(gpointer p)
void
mainloop_add_child(pid_t pid, int timeout, const char *desc, void * privatedata,
void (*callback)(mainloop_child_t *p, int status, int signo,
- int exitcode))
+ int exitcode))
{
mainloop_child_t *p = g_new(mainloop_child_t, 1);
@@ -414,7 +420,7 @@ mainloop_add_child(pid_t pid, int timeout, const char *desc, void *
privatedata,
p->privatedata = privatedata;
p->callback = callback;
- if(timeout) {
+ if (timeout) {
p->timerid = g_timeout_add(
timeout, child_timeout_callback, GINT_TO_POINTER(pid));
}
@@ -427,12 +433,13 @@ static void
child_death_dispatch(int sig)
{
int status = 0;
- while(TRUE) {
+ while (TRUE) {
pid_t pid = wait3(&status, WNOHANG, NULL);
if (pid > 0) {
- int signo = 0, exitcode = 0;
+ int signo = 0, exitcode = 0;
- mainloop_child_t *p = g_hash_table_lookup(mainloop_process_table,
GINT_TO_POINTER(pid));
+ mainloop_child_t *p = g_hash_table_lookup(mainloop_process_table,
+ GINT_TO_POINTER(pid));
mh_trace("Managed process %d exited: %p", pid, p);
if (p == NULL) {
continue;
@@ -440,11 +447,13 @@ child_death_dispatch(int sig)
if (WIFEXITED(status)) {
exitcode = WEXITSTATUS(status);
- mh_trace("Managed process %d (%s) exited with rc=%d", pid,
p->desc, exitcode);
+ mh_trace("Managed process %d (%s) exited with rc=%d", pid,
+ p->desc, exitcode);
} else if (WIFSIGNALED(status)) {
signo = WTERMSIG(status);
- mh_trace("Managed process %d (%s) exited with signal=%d", pid,
p->desc, signo);
+ mh_trace("Managed process %d (%s) exited with signal=%d", pid,
+ p->desc, signo);
}
#ifdef WCOREDUMP
if (WCOREDUMP(status)) {
@@ -462,7 +471,7 @@ child_death_dispatch(int sig)
return;
} else {
- if(errno != ECHILD) {
+ if (errno != ECHILD) {
mh_perror(LOG_ERR, "wait3() failed");
}
break;
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index 23f5e3f..2b04857 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -52,33 +52,38 @@ using namespace std;
void
shutdown(int /*signal*/)
{
- exit(0);
+ exit(0);
}
#ifdef WIN32
#define BUFFER_SIZE 1024
static void
-RegistryRead (HKEY hHive, const wchar_t *szKeyPath, const wchar_t *szValue, char **out)
+RegistryRead(HKEY hHive, const wchar_t *szKeyPath, const wchar_t *szValue,
+ char **out)
{
HKEY hKey;
DWORD nSize = BUFFER_SIZE;
wchar_t szData[BUFFER_SIZE];
- long lSuccess = RegOpenKey (hHive, szKeyPath, &hKey);
+ long lSuccess = RegOpenKey(hHive, szKeyPath, &hKey);
if (lSuccess != ERROR_SUCCESS) {
- mh_debug("Could not open %ls key from the registry: %ld", szKeyPath,
lSuccess);
+ mh_debug("Could not open %ls key from the registry: %ld", szKeyPath,
+ lSuccess);
return;
}
- lSuccess = RegQueryValueEx (hKey, szValue, NULL, NULL, (LPBYTE) szData, &nSize);
+ lSuccess = RegQueryValueEx(hKey, szValue, NULL, NULL, (LPBYTE) szData,
+ &nSize);
if (lSuccess != ERROR_SUCCESS) {
- mh_debug("Could not read '%ls[%ls]' from the registry: %ld",
szKeyPath, szValue, lSuccess);
+ mh_debug("Could not read '%ls[%ls]' from the registry: %ld",
szKeyPath,
+ szValue, lSuccess);
return;
}
- mh_info("Obtained '%ls[%ls]' = '%ls' from the registry",
szKeyPath, szValue, szData);
- if(out) {
- *out = (char *)malloc( BUFFER_SIZE );
- wcstombs(*out, szData, (size_t)BUFFER_SIZE);
+ mh_info("Obtained '%ls[%ls]' = '%ls' from the registry",
szKeyPath, szValue,
+ szData);
+ if (out) {
+ *out = (char *) malloc(BUFFER_SIZE);
+ wcstombs(*out, szData, (size_t) BUFFER_SIZE);
}
}
#else
@@ -103,20 +108,24 @@ print_usage(const char *proc_name)
printf("\t-h | --help print this help message.\n");
printf("\t-b | --broker specify broker host name..\n");
printf("\t-g | --gssapi force GSSAPI authentication.\n");
- printf("\t-u | --username username to use for authentication
purproses.\n");
- printf("\t-P | --password password to use for authentication
purproses.\n");
- printf("\t-s | --service service name to use for authentication
purproses.\n");
+ printf("\t-u | --username username to use for authentication "
+ "purproses.\n");
+ printf("\t-P | --password password to use for authentication "
+ "purproses.\n");
+ printf("\t-s | --service service name to use for authentication "
+ "purproses.\n");
printf("\t-p | --port specify broker port.\n");
printf("\t-r | --reconnect attempt to reconnect on failure.\n");
}
#endif
static gboolean
-mh_qpid_callback(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data)
+mh_qpid_callback(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data)
{
MatahariAgent *agent = (MatahariAgent*) user_data;
mh_trace("Qpid message recieved");
- if(event.hasDataAddr()) {
+ if (event.hasDataAddr()) {
mh_trace("Message is for %s (type: %s)",
event.getDataAddr().getName().c_str(),
event.getDataAddr().getAgentName().c_str());
@@ -160,8 +169,8 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
L"DebugLevel",
&value);
- if(value) {
- mh_log_level = LOG_INFO+atoi(value);
+ if (value) {
+ mh_log_level = LOG_INFO + atoi(value);
free(value);
value = NULL;
}
@@ -178,7 +187,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
L"Port",
&value);
- if(value) {
+ if (value) {
serverport = atoi(value);
free(value);
value = NULL;
@@ -290,7 +299,8 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
// Set up the cleanup handler for sigint
signal(SIGINT, shutdown);
- mh_info("Connecting to Qpid broker at %s on port %d", servername,
serverport);
+ mh_info("Connecting to Qpid broker at %s on port %d", servername,
+ serverport);
// Create a v2 API options map.
qpid::types::Variant::Map options;
@@ -309,7 +319,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
}
std::stringstream url;
- url << servername << ":" << serverport ;
+ url << servername << ":" << serverport;
_amqp_connection = qpid::messaging::Connection(url.str(), options);
_amqp_connection.open();
@@ -321,7 +331,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
_agent_session.open();
/* Do any setup required by our agent */
- if(this->setup(_agent_session) < 0) {
+ if (this->setup(_agent_session) < 0) {
mh_err("Failed to set up broker connection to %s on %d for %s\n",
servername, serverport, proc_name);
res = -1;
@@ -329,8 +339,9 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
}
this->mainloop = g_main_new(FALSE);
- this->qpid_source = mainloop_add_qmf(
- G_PRIORITY_HIGH, _agent_session, mh_qpid_callback, mh_qpid_disconnect, this);
+ this->qpid_source = mainloop_add_qmf(G_PRIORITY_HIGH, _agent_session,
+ mh_qpid_callback, mh_qpid_disconnect,
+ this);
return_cleanup:
@@ -352,7 +363,7 @@ MatahariAgent::run()
static gboolean
mainloop_qmf_prepare(GSource* source, gint *timeout)
{
- mainloop_qmf_t *qmf = (mainloop_qmf_t*)source;
+ mainloop_qmf_t *qmf = (mainloop_qmf_t *) source;
if (qmf->event) {
return TRUE;
}
@@ -364,11 +375,12 @@ mainloop_qmf_prepare(GSource* source, gint *timeout)
static gboolean
mainloop_qmf_check(GSource* source)
{
- mainloop_qmf_t *qmf = (mainloop_qmf_t*)source;
+ mainloop_qmf_t *qmf = (mainloop_qmf_t *) source;
if (qmf->event) {
return TRUE;
- } else if(qmf->session.nextEvent(qmf->event,
qpid::messaging::Duration::IMMEDIATE)) {
+ } else if (qmf->session.nextEvent(qmf->event,
+ qpid::messaging::Duration::IMMEDIATE)) {
return TRUE;
}
return FALSE;
@@ -377,13 +389,13 @@ mainloop_qmf_check(GSource* source)
static gboolean
mainloop_qmf_dispatch(GSource *source, GSourceFunc callback, gpointer userdata)
{
- mainloop_qmf_t *qmf = (mainloop_qmf_t*)source;
+ mainloop_qmf_t *qmf = (mainloop_qmf_t *) source;
mh_trace("%p", source);
if (qmf->dispatch != NULL) {
qmf::AgentEvent event = qmf->event;
qmf->event = NULL;
- if(qmf->dispatch(qmf->session, event, qmf->user_data) == FALSE) {
+ if (qmf->dispatch(qmf->session, event, qmf->user_data) == FALSE) {
g_source_unref(source); /* Really? */
return FALSE;
}
@@ -393,9 +405,9 @@ mainloop_qmf_dispatch(GSource *source, GSourceFunc callback, gpointer
userdata)
}
static void
-mainloop_qmf_destroy(GSource* source)
+mainloop_qmf_destroy(GSource *source)
{
- mainloop_qmf_t *qmf = (mainloop_qmf_t*)source;
+ mainloop_qmf_t *qmf = (mainloop_qmf_t *) source;
mh_trace("%p", source);
if (qmf->dnotify) {
@@ -410,10 +422,11 @@ static GSourceFuncs mainloop_qmf_funcs = {
mainloop_qmf_destroy,
};
-mainloop_qmf_t*
+mainloop_qmf_t *
mainloop_add_qmf(int priority, qmf::AgentSession session,
- gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event,
gpointer userdata),
- GDestroyNotify notify, gpointer userdata)
+ gboolean (*dispatch)(qmf::AgentSession session,
+ qmf::AgentEvent event, gpointer userdata),
+ GDestroyNotify notify, gpointer userdata)
{
GSource *source = NULL;
mainloop_qmf_t *qmf_source = NULL;
@@ -421,14 +434,15 @@ mainloop_add_qmf(int priority, qmf::AgentSession session,
source = g_source_new(&mainloop_qmf_funcs, sizeof(mainloop_qmf_t));
MH_ASSERT(source != NULL);
- qmf_source = (mainloop_qmf_t*)source;
+ qmf_source = (mainloop_qmf_t *) source;
qmf_source->id = 0;
qmf_source->event = NULL;
qmf_source->session = session;
/*
- * Normally we'd use g_source_set_callback() to specify the dispatch function,
- * But we want to supply the qmf session too, so we store it in
qmf_source->dispatch instead
+ * Normally we'd use g_source_set_callback() to specify the dispatch
+ * function, but we want to supply the qmf session too, so we store it in
+ * qmf_source->dispatch instead
*/
qmf_source->dnotify = notify;
qmf_source->dispatch = dispatch;
@@ -443,11 +457,11 @@ mainloop_add_qmf(int priority, qmf::AgentSession session,
}
gboolean
-mainloop_destroy_qmf(mainloop_qmf_t* source)
+mainloop_destroy_qmf(mainloop_qmf_t *source)
{
g_source_remove(source->id);
source->id = 0;
- g_source_unref((GSource*)source);
+ g_source_unref((GSource *) source);
return TRUE;
}
diff --git a/src/lib/mh_dbus_common.c b/src/lib/mh_dbus_common.c
index d975ece..a58c8a1 100644
--- a/src/lib/mh_dbus_common.c
+++ b/src/lib/mh_dbus_common.c
@@ -36,126 +36,107 @@ const DBusGObjectInfo dbus_glib_matahari_object_info;
GQuark
matahari_error_quark (void)
{
- return g_quark_from_static_string ("matahari-error-quark");
+ return g_quark_from_static_string ("matahari-error-quark");
}
gboolean
-check_authorization(const gchar *action, GError** error, DBusGMethodInvocation *context)
+check_authorization(const gchar *action, GError** error,
+ DBusGMethodInvocation *context)
{
- GError *err;
- PolkitAuthorizationResult *result;
- PolkitSubject *subject;
- PolkitAuthority *authority;
- gboolean res;
-
- if (context == NULL)
- {
- g_printerr("Context is not set!\n");
- return FALSE;
- }
- err = NULL;
- subject = polkit_system_bus_name_new(dbus_g_method_get_sender(context));
- authority = polkit_authority_get_sync(NULL, &err);
- if (err != NULL)
- {
- g_printerr("Error in obtaining authority: %s\n", err->message);
- g_set_error(error, MATAHARI_ERROR, MATAHARI_AUTHENTICATION_ERROR, err->message);
- g_error_free(err);
- return FALSE;
- }
-
- result = polkit_authority_check_authorization_sync(authority, subject, action, NULL,
POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, NULL, &err);
- if (err != NULL)
- {
- g_printerr("Error in checking authorization: %s\n", err->message);
- g_set_error(error, MATAHARI_ERROR, MATAHARI_AUTHENTICATION_ERROR, err->message);
- g_error_free(err);
- return FALSE;
- }
- res = polkit_authorization_result_get_is_authorized(result);
- g_object_unref(subject);
- g_object_unref(result);
- g_object_unref(authority);
- if (!res)
- {
- g_set_error(error, MATAHARI_ERROR, MATAHARI_AUTHENTICATION_ERROR, "You are not
authorized for specified action");
- g_printerr("Caller is not authorized for action %s\n", action);
- }
- return res;
+ GError *err;
+ PolkitAuthorizationResult *result;
+ PolkitSubject *subject;
+ PolkitAuthority *authority;
+ gboolean res;
+
+ if (context == NULL) {
+ g_printerr("Context is not set!\n");
+ return FALSE;
+ }
+ err = NULL;
+ subject = polkit_system_bus_name_new(dbus_g_method_get_sender(context));
+ authority = polkit_authority_get_sync(NULL, &err);
+ if (err != NULL) {
+ g_printerr("Error in obtaining authority: %s\n", err->message);
+ g_set_error(error, MATAHARI_ERROR, MATAHARI_AUTHENTICATION_ERROR,
+ err->message);
+ g_error_free(err);
+ return FALSE;
+ }
+
+ result = polkit_authority_check_authorization_sync(authority, subject,
+ action, NULL,
+ POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, NULL,
+ &err);
+ if (err != NULL) {
+ g_printerr("Error in checking authorization: %s\n", err->message);
+ g_set_error(error, MATAHARI_ERROR, MATAHARI_AUTHENTICATION_ERROR,
+ err->message);
+ g_error_free(err);
+ return FALSE;
+ }
+ res = polkit_authorization_result_get_is_authorized(result);
+ g_object_unref(subject);
+ g_object_unref(result);
+ g_object_unref(authority);
+ if (!res) {
+ g_set_error(error, MATAHARI_ERROR, MATAHARI_AUTHENTICATION_ERROR,
+ "You are not authorized for specified action");
+ g_printerr("Caller is not authorized for action %s\n", action);
+ }
+ return res;
}
gboolean
get_paramspec_from_property(Property prop, GParamSpec** pspec)
{
GType value_type;
- switch (prop.type)
- {
- case 's':
- *pspec = g_param_spec_string(prop.name,
- prop.nick,
- prop.desc,
- NULL,
- prop.flags);
- break;
- case 'b':
- *pspec = g_param_spec_boolean(prop.name,
- prop.nick,
- prop.desc,
- FALSE,
- prop.flags);
- break;
- case 'n':
- case 'i':
- *pspec = g_param_spec_int(prop.name,
- prop.nick,
- prop.desc,
- G_MININT, G_MAXINT, 0,
+ switch (prop.type) {
+ case 's':
+ *pspec = g_param_spec_string(prop.name, prop.nick, prop.desc,
+ NULL, prop.flags);
+ break;
+ case 'b':
+ *pspec = g_param_spec_boolean(prop.name, prop.nick, prop.desc,
+ FALSE, prop.flags);
+ break;
+ case 'n':
+ case 'i':
+ *pspec = g_param_spec_int(prop.name, prop.nick, prop.desc,
+ G_MININT, G_MAXINT, 0, prop.flags);
+ break;
+ case 'x':
+ *pspec = g_param_spec_int64(prop.name, prop.nick, prop.desc,
+ G_MININT64, G_MAXINT64, 0, prop.flags);
+
+ break;
+ case 'y':
+ case 'q':
+ case 'u':
+ *pspec = g_param_spec_uint(prop.name, prop.nick, prop.desc,
+ 0, G_MAXUINT, 0, prop.flags);
+ break;
+ case 't':
+ *pspec = g_param_spec_uint64(prop.name, prop.nick, prop.desc,
+ 0, G_MAXUINT64, 0, prop.flags);
+ break;
+ case 'd':
+ *pspec = g_param_spec_double(prop.name, prop.nick, prop.desc,
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0,
prop.flags);
- break;
- case 'x':
- *pspec = g_param_spec_int64(prop.name,
- prop.nick,
- prop.desc,
- G_MININT64, G_MAXINT64, 0,
- prop.flags);
-
- break;
- case 'y':
- case 'q':
- case 'u':
- *pspec = g_param_spec_uint(prop.name,
- prop.nick,
- prop.desc,
- 0, G_MAXUINT, 0,
- prop.flags);
- break;
- case 't':
- *pspec = g_param_spec_uint64(prop.name,
- prop.nick,
- prop.desc,
- 0, G_MAXUINT64, 0,
- prop.flags);
-
- break;
- case 'd':
- *pspec = g_param_spec_double(prop.name,
- prop.nick,
- prop.desc,
- -G_MAXDOUBLE, G_MAXDOUBLE, 0,
- prop.flags);
- break;
- case 'e':
- // Type is map - key is string, type of value must be added manually!
- value_type = matahari_dict_type(prop.prop);
- *pspec = g_param_spec_boxed(prop.name,
- prop.nick,
- prop.desc,
- dbus_g_type_get_map("GHashTable",
G_TYPE_STRING, value_type),
- prop.flags);
- break;
- default:
- return FALSE;
+ break;
+ case 'e':
+ // Type is map - key is string, type of value must be added manually!
+ value_type = matahari_dict_type(prop.prop);
+ *pspec = g_param_spec_boxed(prop.name, prop.nick, prop.desc,
+ dbus_g_type_get_map("GHashTable",
+ G_TYPE_STRING,
+ value_type),
+ prop.flags);
+ break;
+ default:
+ return FALSE;
}
return TRUE;
@@ -164,146 +145,143 @@ get_paramspec_from_property(Property prop, GParamSpec** pspec)
int
run_dbus_server(char *bus_name, char *object_path)
{
- GMainLoop* loop = NULL;
- DBusGConnection *connection = NULL;
- GError *error = NULL;
- GObject *obj = NULL;
- DBusGProxy *driver_proxy = NULL;
- guint32 request_name_ret;
-
- mh_log_init(bus_name, LOG_DEBUG, FALSE);
-
- loop = g_main_loop_new(NULL, FALSE);
-
- /* Obtain a connection to the system bus */
- connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
- if (!connection)
- {
- g_printerr(_("Failed to open connection to bus: %s\n"),
error->message);
- g_error_free(error);
- return 1;
+ GMainLoop* loop = NULL;
+ DBusGConnection *connection = NULL;
+ GError *error = NULL;
+ GObject *obj = NULL;
+ DBusGProxy *driver_proxy = NULL;
+ guint32 request_name_ret;
+
+ mh_log_init(bus_name, LOG_DEBUG, FALSE);
+
+ loop = g_main_loop_new(NULL, FALSE);
+
+ // Obtain a connection to the system bus
+ connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+ if (!connection) {
+ g_printerr(_("Failed to open connection to bus: %s\n"),
error->message);
+ g_error_free(error);
+ return 1;
}
- obj = g_object_new(MATAHARI_TYPE, NULL);
- dbus_g_connection_register_g_object(connection, object_path, obj);
+ obj = g_object_new(MATAHARI_TYPE, NULL);
+ dbus_g_connection_register_g_object(connection, object_path, obj);
- driver_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
+ driver_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS);
- if (!org_freedesktop_DBus_request_name(driver_proxy, bus_name, 0,
- &request_name_ret, &error))
- {
- g_printerr(_("Failed to get name: %s\n"), error->message);
- g_error_free(error);
- return 1;
+ if (!org_freedesktop_DBus_request_name(driver_proxy, bus_name, 0,
+ &request_name_ret, &error)) {
+ g_printerr(_("Failed to get name: %s\n"), error->message);
+ g_error_free(error);
+ return 1;
}
- switch (request_name_ret)
- {
- case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
- break;
- case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
- g_printerr(
- _("Looks like another server of this type is already running: Reply in
queue\n"));
- return 1;
- case DBUS_REQUEST_NAME_REPLY_EXISTS:
- g_printerr(
- _("Looks like another server of this type is already running: Reply
exists\n"));
- return 1;
- case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
- g_printerr(_("We are already running\n"));
- return 1;
- default:
- g_printerr(_("Unspecified error\n"));
- return 1;
+ switch (request_name_ret) {
+ case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
+ break;
+ case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
+ g_printerr(_("Looks like another server of this type is already "
+ "running: Reply in queue\n"));
+ return 1;
+ case DBUS_REQUEST_NAME_REPLY_EXISTS:
+ g_printerr(_("Looks like another server of this type is already "
+ "running: Reply exists\n"));
+ return 1;
+ case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
+ g_printerr(_("We are already running\n"));
+ return 1;
+ default:
+ g_printerr(_("Unspecified error\n"));
+ return 1;
}
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
- g_object_unref(obj);
- g_object_unref(driver_proxy);
- return 0;
+ g_main_loop_run(loop);
+ g_main_loop_unref(loop);
+ g_object_unref(obj);
+ g_object_unref(driver_proxy);
+ return 0;
}
gboolean
-matahari_get(Matahari* matahari, const char *interface, const char *name,
DBusGMethodInvocation *context)
+matahari_get(Matahari* matahari, const char *interface, const char *name,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- GParamSpec *spec;
- GValue value = {0, };
-
- char *action = malloc((strlen(interface) + strlen(name) + 2) * sizeof(char));
- sprintf(action, "%s.%s", interface, name);
- if (!check_authorization(action, &error, context))
- {
- dbus_g_method_return_error(context, error);
+ GError* error = NULL;
+ GParamSpec *spec;
+ GValue value = {0, };
+
+ char *action = malloc((strlen(interface) + strlen(name) + 2) * sizeof(char));
+ sprintf(action, "%s.%s", interface, name);
+ if (!check_authorization(action, &error, context)) {
+ dbus_g_method_return_error(context, error);
+ free(action);
+ return FALSE;
+ }
free(action);
- return FALSE;
- }
- free(action);
-
- spec = g_object_class_find_property(G_OBJECT_GET_CLASS(matahari), name);
- g_value_init(&value, spec->value_type);
- g_object_get_property(G_OBJECT(matahari), name, &value);
- dbus_g_method_return(context, &value);
- return TRUE;
+
+ spec = g_object_class_find_property(G_OBJECT_GET_CLASS(matahari), name);
+ g_value_init(&value, spec->value_type);
+ g_object_get_property(G_OBJECT(matahari), name, &value);
+ dbus_g_method_return(context, &value);
+ return TRUE;
}
gboolean
-matahari_set(Matahari *matahari, const char *interface, const char *name, GValue *value,
DBusGMethodInvocation *context)
+matahari_set(Matahari *matahari, const char *interface, const char *name,
+ GValue *value, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- char *action = malloc((strlen(interface) + strlen(name) + 2) * sizeof(char));
- sprintf(action, "%s.%s", interface, name);
- if (!check_authorization(action, &error, context))
- {
- dbus_g_method_return_error(context, error);
+ GError* error = NULL;
+ char *action = malloc((strlen(interface) + strlen(name) + 2) * sizeof(char));
+ sprintf(action, "%s.%s", interface, name);
+ if (!check_authorization(action, &error, context)) {
+ dbus_g_method_return_error(context, error);
+ free(action);
+ return FALSE;
+ }
free(action);
- return FALSE;
- }
- free(action);
- g_object_set_property(G_OBJECT(matahari), name, value);
- dbus_g_method_return(context);
- return TRUE;
+ g_object_set_property(G_OBJECT(matahari), name, value);
+ dbus_g_method_return(context);
+ return TRUE;
}
/* Class init */
static void
matahari_class_init(MatahariClass *matahari_class)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS(matahari_class);
- GParamSpec *pspec = NULL;
-
- //g_type_class_add_private(matahari_class, sizeof (MatahariPrivate));
-
- gobject_class->set_property = matahari_set_property;
- gobject_class->get_property = matahari_get_property;
-
- int i;
- for (i = 0; properties[i].name != NULL; i++)
- {
- if (!get_paramspec_from_property(properties[i], &pspec))
- {
- g_printerr("Unknown type: %c\n", properties[i].type);
- pspec = NULL;
+ GObjectClass *gobject_class = G_OBJECT_CLASS(matahari_class);
+ GParamSpec *pspec = NULL;
+
+ gobject_class->set_property = matahari_set_property;
+ gobject_class->get_property = matahari_get_property;
+
+ int i;
+ for (i = 0; properties[i].name != NULL; i++) {
+ if (!get_paramspec_from_property(properties[i], &pspec)) {
+ g_printerr("Unknown type: %c\n", properties[i].type);
+ pspec = NULL;
+ }
+ if (pspec)
+ g_object_class_install_property(gobject_class, properties[i].prop,
+ pspec);
}
- if (pspec)
- g_object_class_install_property(gobject_class, properties[i].prop, pspec);
- }
- dbus_g_object_type_install_info(MATAHARI_TYPE, &dbus_glib_matahari_object_info);
+ dbus_g_object_type_install_info(MATAHARI_TYPE,
+ &dbus_glib_matahari_object_info);
}
/* Instance init */
static void
matahari_init(Matahari *matahari)
{
- MatahariPrivate *priv;
- matahari->priv = priv = MATAHARI_GET_PRIVATE(matahari);
+ MatahariPrivate *priv;
+ matahari->priv = priv = MATAHARI_GET_PRIVATE(matahari);
}
-Dict *dict_new(GValue *value)
+Dict *
+dict_new(GValue *value)
{
gpointer ret;
Dict *dict = malloc(sizeof(Dict));
@@ -318,13 +296,15 @@ Dict *dict_new(GValue *value)
return dict;
}
-void dict_add(Dict *dict, const gchar *key, GValue *value)
+void
+dict_add(Dict *dict, const gchar *key, GValue *value)
{
g_value_set_static_string(dict->key, key);
dbus_g_type_specialized_map_append (&(dict->appendctx), dict->key, value);
}
-void dict_free(Dict *dict)
+void
+dict_free(Dict *dict)
{
free(dict->key);
free(dict);
diff --git a/src/lib/network.c b/src/lib/network.c
index b30fb31..d502d34 100644
--- a/src/lib/network.c
+++ b/src/lib/network.c
@@ -41,15 +41,15 @@ query_interface_table(void)
sigar_open(&sigar);
status = sigar_net_interface_list_get(sigar, &iflist);
- if(status == SIGAR_OK) {
- for(lpc = 0; lpc < iflist.number; lpc++) {
+ if (status == SIGAR_OK) {
+ for (lpc = 0; lpc < iflist.number; lpc++) {
ifconfig = g_new0(sigar_net_interface_config_t, 1);
- status = sigar_net_interface_config_get(sigar, iflist.data[lpc],
- ifconfig);
- if(status == SIGAR_OK)
+ status = sigar_net_interface_config_get(sigar, iflist.data[lpc],
+ ifconfig);
+ if (status == SIGAR_OK)
interfaces = g_list_prepend(interfaces, ifconfig);
}
- sigar_net_interface_list_destroy(sigar, &iflist);
+ sigar_net_interface_list_destroy(sigar, &iflist);
}
sigar_close(sigar);
return interfaces;
@@ -90,9 +90,9 @@ mh_network_status(const char *iface, uint64_t *flags)
sigar_net_interface_config_t *ifconfig;
list = mh_network_get_interfaces();
- for(plist = g_list_first(list); plist; plist = g_list_next(plist)) {
+ for (plist = g_list_first(list); plist; plist = g_list_next(plist)) {
ifconfig = (sigar_net_interface_config_t *)plist->data;
- if((g_str_equal(ifconfig->name, iface)) == TRUE) {
+ if ((g_str_equal(ifconfig->name, iface)) == TRUE) {
*flags = ifconfig->flags;
}
}
@@ -108,9 +108,9 @@ mh_network_get_ip_address(const char *iface)
char *paddr_str;
list = mh_network_get_interfaces();
- for(plist = g_list_first(list); plist; plist = g_list_next(plist)) {
+ for (plist = g_list_first(list); plist; plist = g_list_next(plist)) {
ifconfig = (sigar_net_interface_config_t *)plist->data;
- if((g_str_equal(ifconfig->name, iface)) == TRUE) {
+ if ((g_str_equal(ifconfig->name, iface)) == TRUE) {
sigar_net_address_to_string(NULL, &ifconfig->address, addr_str);
paddr_str = g_strdup(addr_str);
return paddr_str;
@@ -128,9 +128,9 @@ mh_network_get_mac_address(const char *iface)
char *mac;
list = mh_network_get_interfaces();
- for(plist = g_list_first(list); plist; plist = g_list_next(plist)) {
+ for (plist = g_list_first(list); plist; plist = g_list_next(plist)) {
ifconfig = (sigar_net_interface_config_t *)plist->data;
- if((g_str_equal(ifconfig->name, iface)) == TRUE) {
+ if ((g_str_equal(ifconfig->name, iface)) == TRUE) {
mac = g_strdup_printf("%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
ifconfig->hwaddr.addr.mac[0],
ifconfig->hwaddr.addr.mac[1],
diff --git a/src/lib/network_linux.c b/src/lib/network_linux.c
index 23c9595..0bfd8a0 100644
--- a/src/lib/network_linux.c
+++ b/src/lib/network_linux.c
@@ -32,8 +32,9 @@ network_os_start(const char *iface)
"/sbin/ifup", (gchar *) iface, NULL
};
- ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL,
&error);
- if(ret == FALSE) {
+ ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL,
+ &error);
+ if (ret == FALSE) {
g_error_free(error);
}
}
@@ -47,8 +48,9 @@ network_os_stop(const char *iface)
"/sbin/ifdown", (gchar *) iface, NULL
};
- ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL,
&error);
- if(ret == FALSE) {
+ ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL,
+ &error);
+ if (ret == FALSE) {
g_error_free(error);
}
}
diff --git a/src/lib/network_private.h b/src/lib/network_private.h
index 04ba74f..859e63d 100644
--- a/src/lib/network_private.h
+++ b/src/lib/network_private.h
@@ -5,16 +5,16 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
+ */
#include <glib.h>
diff --git a/src/lib/network_windows.c b/src/lib/network_windows.c
index d735ef3..8e017ad 100644
--- a/src/lib/network_windows.c
+++ b/src/lib/network_windows.c
@@ -40,7 +40,8 @@ network_os_stop(const char *iface)
char *exe_path;
p = getenv("WINDIR");
- exe_path = g_strdup_printf("%s\\system32\\netsh interface set interface %s
disabled", p, iface);
+ exe_path = g_strdup_printf("%s\\system32\\netsh interface set interface "
+ "%s disabled", p, iface);
gboolean ok = CreateProcess(NULL,
exe_path,
@@ -67,7 +68,8 @@ network_os_start(const char *iface)
char *exe_path;
p = getenv("WINDIR");
- exe_path = g_strdup_printf("%s\\system32\\netsh interface set interface %s
enabled", p, iface);
+ exe_path = g_strdup_printf("%s\\system32\\netsh interface set interface "
+ "%s enabled", p, iface);
gboolean ok = CreateProcess(NULL,
exe_path,
diff --git a/src/lib/services.c b/src/lib/services.c
index fc20165..5c33cae 100644
--- a/src/lib/services.c
+++ b/src/lib/services.c
@@ -1,16 +1,16 @@
-/*
+/*
* Copyright (C) 2010 Andrew Beekhof <andrew(a)beekhof.net>
- *
+ *
* 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.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -34,8 +34,9 @@ MH_TRACE_INIT_DATA(mh_services);
GHashTable *recurring_actions = NULL;
-svc_action_t *services_action_create(
- const char *name, const char *action, int interval, int timeout)
+svc_action_t *
+services_action_create(const char *name, const char *action, int interval,
+ int timeout)
{
svc_action_t *op;
@@ -54,9 +55,10 @@ svc_action_t *services_action_create(
return op;
}
-svc_action_t *resources_action_create(
- const char *name, const char *provider, const char *agent,
- const char *action, int interval, int timeout, GHashTable *params)
+svc_action_t *
+resources_action_create(const char *name, const char *provider,
+ const char *agent, const char *action, int interval,
+ int timeout, GHashTable *params)
{
svc_action_t *op;
@@ -71,17 +73,18 @@ svc_action_t *resources_action_create(
op->provider = strdup(provider);
op->params = params;
asprintf(&op->id, "%s_%s_%d", name, action, interval);
- asprintf(&op->opaque->exec, "%s/resource.d/%s/%s", OCF_ROOT,
- provider, agent);
+ asprintf(&op->opaque->exec, "%s/resource.d/%s/%s", OCF_ROOT,
provider,
+ agent);
op->opaque->args[0] = strdup(op->opaque->exec);
op->opaque->args[1] = strdup(action);
return op;
}
-void services_action_free(svc_action_t *op)
+void
+services_action_free(svc_action_t *op)
{
- if(op == NULL) {
+ if (op == NULL) {
return;
}
@@ -103,7 +106,7 @@ void services_action_free(svc_action_t *op)
free(op->stdout_data);
free(op->stderr_data);
- if(op->params) {
+ if (op->params) {
g_hash_table_destroy(op->params);
op->params = NULL;
}
@@ -111,7 +114,8 @@ void services_action_free(svc_action_t *op)
free(op);
}
-gboolean services_action_cancel(const char *name, const char *action, int interval)
+gboolean
+services_action_cancel(const char *name, const char *action, int interval)
{
svc_action_t* op = NULL;
char id[512];
@@ -124,7 +128,7 @@ gboolean services_action_cancel(const char *name, const char *action,
int interv
op->opaque->cancel = TRUE;
mh_debug("Removing %s", op->id);
- if(op->opaque->repeat_timer) {
+ if (op->opaque->repeat_timer) {
g_source_remove(op->opaque->repeat_timer);
}
services_action_free(op);
@@ -133,18 +137,18 @@ gboolean services_action_cancel(const char *name, const char
*action, int interv
}
gboolean
-services_action_async(svc_action_t* op, void (*action_callback)(svc_action_t*))
+services_action_async(svc_action_t* op, void (*action_callback)(svc_action_t *))
{
- if(action_callback) {
+ if (action_callback) {
op->opaque->callback = action_callback;
}
- if(recurring_actions == NULL) {
- recurring_actions = g_hash_table_new_full(
- g_str_hash, g_str_equal, NULL, NULL);
+ if (recurring_actions == NULL) {
+ recurring_actions = g_hash_table_new_full(g_str_hash, g_str_equal,
+ NULL, NULL);
}
- if(op->interval > 0) {
+ if (op->interval > 0) {
g_hash_table_replace(recurring_actions, op->id, op);
}
@@ -155,11 +159,12 @@ gboolean
services_action_sync(svc_action_t* op)
{
gboolean rc = services_os_action_execute(op, TRUE);
- mh_trace(" > %s_%s_%d: %s = %d", op->rsc, op->action,
op->interval, op->opaque->exec, op->rc);
- if(op->stdout_data) {
+ mh_trace(" > %s_%s_%d: %s = %d", op->rsc, op->action,
op->interval,
+ op->opaque->exec, op->rc);
+ if (op->stdout_data) {
mh_trace(" > stdout: %s", op->stdout_data);
}
- if(op->stderr_data) {
+ if (op->stderr_data) {
mh_trace(" > stderr: %s", op->stderr_data);
}
return rc;
@@ -171,18 +176,20 @@ get_directory_list(const char *root, gboolean files)
return services_os_get_directory_list(root, files);
}
-GList *services_list(void)
+GList *
+services_list(void)
{
return services_os_list();
}
-GList *resources_list_ocf_providers(void)
+GList *
+resources_list_ocf_providers(void)
{
return resources_os_list_ocf_providers();
}
-GList *resources_list_ocf_agents(const char *provider)
+GList *
+resources_list_ocf_agents(const char *provider)
{
return resources_os_list_ocf_agents(provider);
}
-
diff --git a/src/lib/services_linux.c b/src/lib/services_linux.c
index 3a54386..de1e014 100644
--- a/src/lib/services_linux.c
+++ b/src/lib/services_linux.c
@@ -38,7 +38,7 @@ set_fd_opts(int fd, int opts)
{
int flag;
if ((flag = fcntl(fd, F_GETFL)) >= 0) {
- if (fcntl(fd, F_SETFL, flag|opts) < 0) {
+ if (fcntl(fd, F_SETFL, flag | opts) < 0) {
mh_perror(LOG_ERR, "fcntl() write failed");
}
} else {
@@ -52,30 +52,30 @@ read_output(int fd, gpointer user_data)
char * data = NULL;
int rc = 0, len = 0;
gboolean is_err = FALSE;
- svc_action_t* op = (svc_action_t *)user_data;
+ svc_action_t* op = (svc_action_t *) user_data;
char buf[500];
static const size_t buf_read_len = sizeof(buf) - 1;
- if(fd == op->opaque->stderr_fd) {
+ if (fd == op->opaque->stderr_fd) {
is_err = TRUE;
- if(op->stderr_data) {
+ if (op->stderr_data) {
len = strlen(op->stderr_data);
data = op->stderr_data;
}
- } else if(op->stdout_data) {
+ } else if (op->stdout_data) {
len = strlen(op->stdout_data);
data = op->stdout_data;
}
do {
rc = read(fd, buf, buf_read_len);
- if(rc > 0) {
+ if (rc > 0) {
buf[rc] = 0;
data = realloc(data, len + rc + 1);
- sprintf(data+len, "%s", buf);
+ sprintf(data + len, "%s", buf);
len += rc;
- } else if(errno != EINTR) {
+ } else if (errno != EINTR) {
/* error or EOF
* Cleanup happens in pipe_done()
*/
@@ -87,7 +87,7 @@ read_output(int fd, gpointer user_data)
if (data != NULL && is_err) {
op->stderr_data = data;
- } else if(data != NULL) {
+ } else if (data != NULL) {
op->stdout_data = data;
}
@@ -97,7 +97,7 @@ read_output(int fd, gpointer user_data)
static void
pipe_out_done(gpointer user_data)
{
- svc_action_t* op = (svc_action_t *)user_data;
+ svc_action_t* op = (svc_action_t *) user_data;
op->opaque->stdout_gsource = NULL;
if (op->opaque->stdout_fd > STDERR_FILENO) {
close(op->opaque->stdout_fd);
@@ -108,7 +108,7 @@ pipe_out_done(gpointer user_data)
static void
pipe_err_done(gpointer user_data)
{
- svc_action_t* op = (svc_action_t *)user_data;
+ svc_action_t* op = (svc_action_t *) user_data;
op->opaque->stderr_gsource = NULL;
if (op->opaque->stderr_fd > STDERR_FILENO) {
close(op->opaque->stderr_fd);
@@ -129,7 +129,7 @@ set_ocf_env_with_prefix(gpointer key, gpointer value, gpointer
user_data)
{
/* TODO: Add OCF_RESKEY_ prefix to 'key' */
char buffer[500];
- snprintf(buffer, sizeof(buffer), "OCF_RESKEY_%s", (char*)key);
+ snprintf(buffer, sizeof(buffer), "OCF_RESKEY_%s", (char *) key);
set_ocf_env(buffer, value, user_data);
}
@@ -140,7 +140,7 @@ add_OCF_env_vars(svc_action_t *op)
return;
}
- if(op->params) {
+ if (op->params) {
g_hash_table_foreach(op->params, set_ocf_env_with_prefix, NULL);
}
@@ -148,7 +148,7 @@ add_OCF_env_vars(svc_action_t *op)
set_ocf_env("OCF_RA_VERSION_MINOR", "0", NULL);
set_ocf_env("OCF_ROOT", OCF_ROOT, NULL);
- if(op->rsc) {
+ if (op->rsc) {
set_ocf_env("OCF_RESOURCE_INSTANCE", op->rsc, NULL);
}
@@ -186,13 +186,15 @@ operation_finished(mainloop_child_t *p, int status, int signo, int
exitcode)
op->status = LRM_OP_DONE;
MH_ASSERT(op->pid == p->pid);
- if( signo ) {
- if( p->timeout ) {
- mh_warn("%s:%d - timed out after %dms", op->id, op->pid,
op->timeout);
+ if (signo) {
+ if (p->timeout) {
+ mh_warn("%s:%d - timed out after %dms", op->id, op->pid,
+ op->timeout);
op->status = LRM_OP_TIMEOUT;
} else {
- mh_warn("%s:%d - terminated with signal %d", op->id, op->pid,
signo);
+ mh_warn("%s:%d - terminated with signal %d", op->id,
op->pid,
+ signo);
op->status = LRM_OP_ERROR;
}
@@ -200,45 +202,50 @@ operation_finished(mainloop_child_t *p, int status, int signo, int
exitcode)
op->rc = exitcode;
mh_debug("%s:%d - exited with rc=%d", op->id, op->pid,
exitcode);
- if(op->stdout_data) {
+ if (op->stdout_data) {
next = op->stdout_data;
do {
offset = next;
next = strchrnul(offset, '\n');
- mh_debug("%s:%d [ %.*s ]", op->id, op->pid,
(int)(next-offset), offset);
- if(next[0] != 0) {
+ mh_debug("%s:%d [ %.*s ]", op->id, op->pid,
+ (int) (next - offset), offset);
+ if (next[0] != 0) {
next++;
}
- } while(next != NULL && next[0] != 0);
+ } while (next != NULL && next[0] != 0);
}
- if(op->stderr_data) {
+ if (op->stderr_data) {
next = op->stderr_data;
do {
offset = next;
next = strchrnul(offset, '\n');
- mh_notice("%s:%d [ %.*s ]", op->id, op->pid,
(int)(next-offset), offset);
- if(next[0] != 0) {
+ mh_notice("%s:%d [ %.*s ]", op->id, op->pid,
+ (int) (next - offset), offset);
+ if (next[0] != 0) {
next++;
}
- } while(next != NULL && next[0] != 0);
+ } while (next != NULL && next[0] != 0);
}
}
- if(op->interval && op->opaque->cancel == FALSE) {
- op->opaque->repeat_timer = g_timeout_add(op->interval,
recurring_action_timer, (void*)op);
+ if (op->interval && op->opaque->cancel == FALSE) {
+ op->opaque->repeat_timer = g_timeout_add(op->interval,
+ recurring_action_timer,
+ (void *) op);
}
op->pid = 0;
- if(op->opaque->callback) {
- /* Callback might call cancel which would result in the message being free'd
+ if (op->opaque->callback) {
+ /* Callback might call cancel which would result in the message
+ * being free'd
* Do not access 'op' after this line
*/
op->opaque->callback(op);
- } else if(op->opaque->repeat_timer == 0) {
+ } else if (op->opaque->repeat_timer == 0) {
services_action_free(op);
}
}
@@ -250,69 +257,69 @@ services_os_action_execute(svc_action_t* op, gboolean synchronous)
int stdout_fd[2];
int stderr_fd[2];
- if ( pipe(stdout_fd) < 0 ) {
+ if (pipe(stdout_fd) < 0) {
mh_perror(LOG_ERR, "pipe() failed");
}
- if ( pipe(stderr_fd) < 0 ) {
+ if (pipe(stderr_fd) < 0) {
mh_perror(LOG_ERR, "pipe() failed");
}
op->pid = fork();
- switch(op->pid) {
- case -1:
- mh_perror(LOG_ERR, "fork() failed");
- close(stdout_fd[0]);
+ switch (op->pid) {
+ case -1:
+ mh_perror(LOG_ERR, "fork() failed");
+ close(stdout_fd[0]);
+ close(stdout_fd[1]);
+ close(stderr_fd[0]);
+ close(stderr_fd[1]);
+ return FALSE;
+
+ case 0: /* Child */
+ /* Man: The call setpgrp() is equivalent to setpgid(0,0)
+ * _and_ compiles on BSD variants too
+ * need to investigate if it works the same too.
+ */
+ setpgid(0, 0);
+ close(stdout_fd[0]);
+ close(stderr_fd[0]);
+ if (STDOUT_FILENO != stdout_fd[1]) {
+ if (dup2(stdout_fd[1], STDOUT_FILENO) != STDOUT_FILENO) {
+ mh_perror(LOG_ERR, "dup2() failed (stdout)");
+ }
close(stdout_fd[1]);
- close(stderr_fd[0]);
+ }
+ if (STDERR_FILENO != stderr_fd[1]) {
+ if (dup2(stderr_fd[1], STDERR_FILENO) != STDERR_FILENO) {
+ mh_perror(LOG_ERR, "dup2() failed (stderr)");
+ }
close(stderr_fd[1]);
- return FALSE;
+ }
- case 0: /* Child */
- /* Man: The call setpgrp() is equivalent to setpgid(0,0)
- * _and_ compiles on BSD variants too
- * need to investigate if it works the same too.
- */
- setpgid(0,0);
- close(stdout_fd[0]);
- close(stderr_fd[0]);
- if (STDOUT_FILENO != stdout_fd[1]) {
- if (dup2(stdout_fd[1], STDOUT_FILENO)!=STDOUT_FILENO) {
- mh_perror(LOG_ERR, "dup2() failed (stdout)");
- }
- close(stdout_fd[1]);
- }
- if (STDERR_FILENO != stderr_fd[1]) {
- if (dup2(stderr_fd[1], STDERR_FILENO)!=STDERR_FILENO) {
- mh_perror(LOG_ERR, "dup2() failed (stderr)");
- }
- close(stderr_fd[1]);
- }
+ /* close all descriptors except stdin/out/err and channels to logd */
+ for (lpc = getdtablesize() - 1; lpc > STDERR_FILENO; lpc--) {
+ close(lpc);
+ }
- /* close all descriptors except stdin/out/err and channels to logd */
- for (lpc = getdtablesize() - 1; lpc > STDERR_FILENO; lpc--) {
- close(lpc);
- }
+ /* Setup environment correctly */
+ add_OCF_env_vars(op);
- /* Setup environment correctly */
- add_OCF_env_vars(op);
-
- /* execute the RA */
- execvp(op->opaque->exec, op->opaque->args);
-
- switch (errno) { /* see execve(2) */
- case ENOENT: /* No such file or directory */
- case EISDIR: /* Is a directory */
- rc = OCF_NOT_INSTALLED;
- break;
- case EACCES: /* permission denied (various errors) */
- rc = OCF_INSUFFICIENT_PRIV;
- break;
- default:
- rc = OCF_UNKNOWN_ERROR;
- break;
- }
- _exit(rc);
+ /* execute the RA */
+ execvp(op->opaque->exec, op->opaque->args);
+
+ switch (errno) { /* see execve(2) */
+ case ENOENT: /* No such file or directory */
+ case EISDIR: /* Is a directory */
+ rc = OCF_NOT_INSTALLED;
+ break;
+ case EACCES: /* permission denied (various errors) */
+ rc = OCF_INSUFFICIENT_PRIV;
+ break;
+ default:
+ rc = OCF_UNKNOWN_ERROR;
+ break;
+ }
+ _exit(rc);
}
/* Only the parent reaches here */
@@ -325,21 +332,22 @@ services_os_action_execute(svc_action_t* op, gboolean synchronous)
op->opaque->stderr_fd = stderr_fd[0];
set_fd_opts(op->opaque->stderr_fd, O_NONBLOCK);
- if(synchronous) {
+ if (synchronous) {
int status = 0;
int timeout = 1 + op->timeout / 1000;
mh_trace("Waiting for %d", op->pid);
- while(timeout > 0 && waitpid(op->pid, &status, WNOHANG) <=
0) {
+ while (timeout > 0 && waitpid(op->pid, &status, WNOHANG) <=
0) {
sleep(1);
timeout--;
}
mh_trace("Child done: %d", op->pid);
- if(timeout == 0) {
+ if (timeout == 0) {
int killrc = sigar_proc_kill(op->pid, 9 /*SIGKILL*/);
op->status = LRM_OP_TIMEOUT;
- mh_warn("%s:%d - timed out after %dms", op->id, op->pid,
op->timeout);
+ mh_warn("%s:%d - timed out after %dms", op->id, op->pid,
+ op->timeout);
if (killrc != SIGAR_OK && killrc != ESRCH) {
mh_err("kill(%d, KILL) failed: %d", op->pid, killrc);
@@ -348,12 +356,14 @@ services_os_action_execute(svc_action_t* op, gboolean synchronous)
} else if (WIFEXITED(status)) {
op->status = LRM_OP_DONE;
op->rc = WEXITSTATUS(status);
- mh_err("Managed %s process %d exited with rc=%d", op->id,
op->pid, op->rc);
+ mh_err("Managed %s process %d exited with rc=%d", op->id,
op->pid,
+ op->rc);
} else if (WIFSIGNALED(status)) {
int signo = WTERMSIG(status);
op->status = LRM_OP_ERROR;
- mh_err("Managed %s process %d exited with signal=%d", op->id,
op->pid, signo);
+ mh_err("Managed %s process %d exited with signal=%d", op->id,
+ op->pid, signo);
}
#ifdef WCOREDUMP
if (WCOREDUMP(status)) {
@@ -366,13 +376,14 @@ services_os_action_execute(svc_action_t* op, gboolean synchronous)
} else {
mh_trace("Async waiting for %d - %s", op->pid,
op->opaque->exec);
- mainloop_add_child(op->pid, op->timeout, op->id, op,
operation_finished);
+ mainloop_add_child(op->pid, op->timeout, op->id, op,
+ operation_finished);
- op->opaque->stdout_gsource = mainloop_add_fd(
- G_PRIORITY_LOW, op->opaque->stdout_fd, read_output, pipe_out_done,
op);
+ op->opaque->stdout_gsource = mainloop_add_fd(G_PRIORITY_LOW,
+ op->opaque->stdout_fd, read_output, pipe_out_done, op);
- op->opaque->stderr_gsource = mainloop_add_fd(
- G_PRIORITY_LOW, op->opaque->stderr_fd, read_output, pipe_err_done,
op);
+ op->opaque->stderr_gsource = mainloop_add_fd(G_PRIORITY_LOW,
+ op->opaque->stderr_fd, read_output, pipe_err_done, op);
}
return TRUE;
@@ -381,7 +392,7 @@ services_os_action_execute(svc_action_t* op, gboolean synchronous)
GList *
services_os_get_directory_list(const char *root, gboolean files)
{
- GList* list = NULL;
+ GList *list = NULL;
#if __linux__
struct dirent **namelist;
int entries = 0, lpc = 0;
@@ -402,20 +413,20 @@ services_os_get_directory_list(const char *root, gboolean files)
snprintf(buffer, sizeof(buffer), "%s/%s", root,
namelist[lpc]->d_name);
stat(buffer, &sb);
- if(S_ISDIR(sb.st_mode)) {
- if(files) {
+ if (S_ISDIR(sb.st_mode)) {
+ if (files) {
free(namelist[lpc]);
continue;
}
- } else if(S_ISREG(sb.st_mode)) {
- if(files == FALSE) {
+ } else if (S_ISREG(sb.st_mode)) {
+ if (files == FALSE) {
free(namelist[lpc]);
continue;
- } else if( (sb.st_mode & S_IXUSR) == 0
+ } else if ((sb.st_mode & S_IXUSR) == 0
&& (sb.st_mode & S_IXGRP) == 0
- && (sb.st_mode & S_IXOTH) == 0 ) {
+ && (sb.st_mode & S_IXOTH) == 0) {
free(namelist[lpc]);
continue;
}
@@ -430,16 +441,16 @@ services_os_get_directory_list(const char *root, gboolean files)
}
void
-services_os_set_exec(svc_action_t* op)
+services_os_set_exec(svc_action_t *op)
{
- if(strcmp("enable", op->action) == 0) {
+ if (strcmp("enable", op->action) == 0) {
op->opaque->exec = strdup("/sbin/chkconfig");
op->opaque->args[0] = strdup(op->opaque->exec);
op->opaque->args[1] = strdup(op->agent);
op->opaque->args[2] = strdup("on");
op->opaque->args[3] = NULL;
- } else if(strcmp("disable", op->action) == 0) {
+ } else if (strcmp("disable", op->action) == 0) {
op->opaque->exec = strdup("/sbin/chkconfig");
op->opaque->args[0] = strdup(op->opaque->exec);
op->opaque->args[1] = strdup(op->agent);
@@ -454,22 +465,26 @@ services_os_set_exec(svc_action_t* op)
}
}
-GList *services_os_list(void)
+GList *
+services_os_list(void)
{
return get_directory_list(LSB_ROOT, TRUE);
}
-GList *resources_os_list_ocf_providers(void)
+GList *
+resources_os_list_ocf_providers(void)
{
- return get_directory_list(OCF_ROOT"/resource.d", FALSE);
+ return get_directory_list(OCF_ROOT "/resource.d", FALSE);
}
-GList *resources_os_list_ocf_agents(const char *provider)
+GList *
+resources_os_list_ocf_agents(const char *provider)
{
- if(provider) {
+ if (provider) {
char buffer[500];
- snprintf(buffer, sizeof(buffer), "%s//resource.d/%s", OCF_ROOT,
provider);
+ snprintf(buffer, sizeof(buffer), "%s//resource.d/%s", OCF_ROOT,
+ provider);
return get_directory_list(buffer, TRUE);
}
return NULL;
diff --git a/src/lib/services_private.h b/src/lib/services_private.h
index 2b30228..c413528 100644
--- a/src/lib/services_private.h
+++ b/src/lib/services_private.h
@@ -1,21 +1,22 @@
-struct svc_action_private_s
+struct svc_action_private_s
{
- char *exec;
- char *args[4];
- gboolean cancel;
-
- guint repeat_timer;
- void (*callback)(svc_action_t *op);
-
- int stderr_fd;
- mainloop_fd_t *stderr_gsource;
+ char *exec;
+ char *args[4];
+ gboolean cancel;
- int stdout_fd;
- mainloop_fd_t *stdout_gsource;
+ guint repeat_timer;
+ void (*callback)(svc_action_t *op);
+
+ int stderr_fd;
+ mainloop_fd_t *stderr_gsource;
+
+ int stdout_fd;
+ mainloop_fd_t *stdout_gsource;
};
extern GList *services_os_get_directory_list(const char *root, gboolean files);
-extern gboolean services_os_action_execute(svc_action_t* op, gboolean synchronous);
+extern gboolean services_os_action_execute(svc_action_t* op,
+ gboolean synchronous);
extern void services_os_set_exec(svc_action_t* op);
extern GList *services_os_list(void);
extern GList *resources_os_list_ocf_providers(void);
diff --git a/src/lib/services_windows.c b/src/lib/services_windows.c
index ae1e2be..b3f43e5 100644
--- a/src/lib/services_windows.c
+++ b/src/lib/services_windows.c
@@ -1,23 +1,23 @@
-/*
+/*
* Copyright (C) 2010 Andrew Beekhof <andrew(a)beekhof.net>
- *
+ *
* 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.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <windows.h>
+#include <windows.h>
#include <tchar.h>
-#include <stdio.h>
+#include <stdio.h>
#include "matahari/logging.h"
#include "matahari/mainloop.h"
@@ -27,25 +27,28 @@
/* Some code adapted from
http://msdn.microsoft.com/en-us/library/ms682499(v=vs.85).aspx
*/
-static wchar_t *char2wide(const char *str)
+static wchar_t *
+char2wide(const char *str)
{
wchar_t *result = NULL;
- if(str != NULL) {
- size_t str_size = strlen(str) + 1;
- result = malloc(str_size * sizeof(wchar_t));
- mbstowcs(result, str, str_size);
+ if (str != NULL) {
+ size_t str_size = strlen(str) + 1;
+ result = malloc(str_size * sizeof(wchar_t));
+ mbstowcs(result, str, str_size);
}
return result;
}
-static void create_service_key(const wchar_t *template, wchar_t *buffer, int size, char
*name)
+static void
+create_service_key(const wchar_t *template, wchar_t *buffer, int size,
+ char *name)
{
#ifdef HAVE_SWPRINTF_S
- swprintf_s
+ swprintf_s
#else
- snwprintf
+ snwprintf
#endif
- ( buffer, size, template, name);
+ (buffer, size, template, name);
}
static gboolean
@@ -58,58 +61,61 @@ windows_service_control(char *name, int command)
wchar_t *value = NULL;
wchar_t szRegistryPath[1024];
- create_service_key(
- L"SYSTEM\\CurrentControlSet\\services\\%s", szRegistryPath,
DIMOF(szRegistryPath), name);
+ create_service_key(L"SYSTEM\\CurrentControlSet\\services\\%s",
+ szRegistryPath, DIMOF(szRegistryPath), name);
- fSuccess = RegOpenKey (HKEY_LOCAL_MACHINE, szRegistryPath, &key_service);
- if(fSuccess != ERROR_SUCCESS) {
- printf("Could not read key at '%ls' - %d\n\r", szRegistryPath,
fSuccess);
- return FALSE;
+ fSuccess = RegOpenKey(HKEY_LOCAL_MACHINE, szRegistryPath, &key_service);
+ if (fSuccess != ERROR_SUCCESS) {
+ printf("Could not read key at '%ls' - %d\n\r", szRegistryPath,
+ fSuccess);
+ return FALSE;
}
itoa(command, raw, 10);
value = char2wide(raw);
- value_bytes = 2 * (lstrlen(value) +1);
+ value_bytes = 2 * (lstrlen(value) + 1);
+
+ fSuccess = RegSetValueEx(key_service, L"Start", 0, REG_SZ, (LPBYTE) value,
+ value_bytes);
+ mh_info("Setting Start='%ls' for %s: %s (%d)\n\r", value, name,
+ fSuccess == ERROR_SUCCESS ? "PASS" : "FAIL", fSuccess);
- fSuccess = RegSetValueEx (key_service, L"Start", 0, REG_SZ, (LPBYTE) value,
value_bytes);
- mh_info("Setting Start='%ls' for %s: %s (%d)\n\r",
- value, name, fSuccess==ERROR_SUCCESS?"PASS":"FAIL", fSuccess);
-
RegCloseKey(key_service);
free(value);
-
- return fSuccess==ERROR_SUCCESS;
+
+ return fSuccess == ERROR_SUCCESS;
}
#define BUFSIZE 4096
-static void read_output(HANDLE h, char **output, int *length)
+static void
+read_output(HANDLE h, char **output, int *length)
{
/* Read output from the child process's pipe for STDOUT
* Stop when there is no more data.
*/
int len = 0;
- DWORD bytes = 0;
+ DWORD bytes = 0;
char buf[BUFSIZE];
char *data = NULL;
-
- while(1) {
- if( ReadFile(h, buf, BUFSIZE, &bytes, NULL) == 0 ) {
- break;
- } else if(bytes == 0) {
- break;
- }
-
- data = realloc(data, len + (int)bytes + 1);
- mh_info("Read %d: %.*s", len, (int)bytes, buf);
- sprintf(data+len, "%s", buf);
- data[len+bytes] = 0;
- len += (int)bytes;
+
+ while (1) {
+ if (ReadFile(h, buf, BUFSIZE, &bytes, NULL) == 0) {
+ break;
+ } else if (bytes == 0) {
+ break;
+ }
+
+ data = realloc(data, len + (int) bytes + 1);
+ mh_info("Read %d: %.*s", len, (int) bytes, buf);
+ sprintf(data + len, "%s", buf);
+ data[len + bytes] = 0;
+ len += (int)bytes;
}
*length = len;
*output = data;
mh_info("Read %d bytes", len);
-}
+}
static int
extract_service_status(const char *unmutable, int max)
@@ -117,241 +123,246 @@ extract_service_status(const char *unmutable, int max)
int lpc = 0, last = 0;
int rc = LSB_STATUS_UNKNOWN_ERROR;
- if(unmutable == NULL || max < 10) {
- return rc;
+ if (unmutable == NULL || max < 10) {
+ return rc;
+ }
+
+ for (; lpc < max; lpc++) {
+ switch (unmutable[lpc]) {
+ case '\n':
+ case '\r':
+ case 0:
+ if (lpc - last > 1) {
+ char name[512];
+ char value[512];
+ char next[2048];
+ /* char *next = malloc(1+lpc-last); */
+ int rc = 0, number = 0;
+
+ strncpy(next, unmutable + last, lpc - last);
+ next[lpc - last] = 0;
+
+ rc = sscanf(next, " %[^:]: %d %[^:]", name,
&number,
+ value);
+ if (rc == 3) {
+ mh_info(" '%s' = '%s' %d", name, value,
number);
+ if (strncmp("STATE", name, 5) == 0) {
+ switch (number) {
+ case 1:
+ rc = LSB_STATUS_NOT_RUNNING;
+ break;
+ case 3:
+ /* Stopping but not stopped - treat as active */
+ rc = LSB_STATUS_OK;
+ break;
+ case 4:
+ rc = LSB_STATUS_OK;
+ break;
+ default:
+ mh_info("Unknown status: %s", next);
+ }
+ /* free(next); */
+ return rc;
+ }
+ }
+ /* free(next); */
+ }
+ last = lpc + 1;
+ break;
+ }
}
-
- for(; lpc < max; lpc++) {
- switch(unmutable[lpc]) {
- case '\n':
- case '\r':
- case 0:
- if(lpc - last > 1) {
- char name[512];
- char value[512];
- char next[2048];
- /* char *next = malloc(1+lpc-last); */
- int rc = 0, number = 0;
-
- strncpy(next, unmutable+last, lpc-last);
- next[lpc-last] = 0;
-
- rc = sscanf(next, " %[^:]: %d %[^:]", name, &number, value);
- if(rc == 3) {
- mh_info(" '%s' = '%s' %d", name, value, number);
- if(strncmp("STATE", name, 5) == 0) {
- switch(number) {
- case 1:
- rc = LSB_STATUS_NOT_RUNNING;
- break;
- case 3:
- /* Stopping but not stopped - treat as active */
- rc = LSB_STATUS_OK;
- break;
- case 4:
- rc = LSB_STATUS_OK;
- break;
- default:
- mh_info("Unknown status: %s", next);
- }
- /* free(next); */
- return rc;
- }
- }
- /* free(next); */
- }
- last = lpc+1;
- break;
- }
- }
mh_info("Couldn't parse service status");
return rc;
}
gboolean
-services_os_action_execute(svc_action_t* op, gboolean synchronous)
+services_os_action_execute(svc_action_t *op, gboolean synchronous)
{
int max = 0;
DWORD status = 0;
wchar_t *exec_w = NULL;
STARTUPINFO siStartInfo;
- SECURITY_ATTRIBUTES saAttr;
- PROCESS_INFORMATION piProcInfo;
+ SECURITY_ATTRIBUTES saAttr;
+ PROCESS_INFORMATION piProcInfo;
HANDLE child_pipe_rd = NULL;
HANDLE child_pipe_wr = NULL;
gboolean is_status_op = FALSE;
- if(strcmp("status", op->action) == 0) {
- is_status_op = TRUE;
-
- } else if(strcmp("disable", op->action) == 0) {
- return windows_service_control(op->rsc, SERVICE_DISABLED);
+ if (strcmp("status", op->action) == 0) {
+ is_status_op = TRUE;
- } else if(strcmp("enable", op->action) == 0) {
- return windows_service_control(op->rsc, SERVICE_AUTO_START);
+ } else if (strcmp("disable", op->action) == 0) {
+ return windows_service_control(op->rsc, SERVICE_DISABLED);
+
+ } else if (strcmp("enable", op->action) == 0) {
+ return windows_service_control(op->rsc, SERVICE_AUTO_START);
}
-
+
/* Initialize all structures */
- ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
- ZeroMemory( &saAttr, sizeof(SECURITY_ATTRIBUTES) );
- ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
-
+ ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
+ ZeroMemory(&saAttr, sizeof(SECURITY_ATTRIBUTES));
+ ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
+
/* Set the bInheritHandle flag so pipe handles are inherited. */
- saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
- saAttr.bInheritHandle = TRUE;
- saAttr.lpSecurityDescriptor = NULL;
+ saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
+ saAttr.bInheritHandle = TRUE;
+ saAttr.lpSecurityDescriptor = NULL;
/* Create a pipe for the child process's stdout */
- if ( ! CreatePipe(&child_pipe_rd, &child_pipe_wr, &saAttr, 0) ) {
- mh_err("Couldn't create child pipe");
- goto fail;
+ if (!CreatePipe(&child_pipe_rd, &child_pipe_wr, &saAttr, 0)) {
+ mh_err("Couldn't create child pipe");
+ goto fail;
}
/* Ensure the read handle to the pipe for STDOUT is not inherited. */
- if ( ! SetHandleInformation(child_pipe_rd, HANDLE_FLAG_INHERIT, 0) ) {
- mh_err("Couldn't set pipe handle information");
- goto fail;
+ if (!SetHandleInformation(child_pipe_rd, HANDLE_FLAG_INHERIT, 0)) {
+ mh_err("Couldn't set pipe handle information");
+ goto fail;
}
-
- siStartInfo.cb = sizeof(STARTUPINFO);
+
+ siStartInfo.cb = sizeof(STARTUPINFO);
siStartInfo.hStdError = child_pipe_wr;
siStartInfo.hStdOutput = child_pipe_wr;
/* siStartInfo.hStdInput = g_hChildStd_IN_Rd; */
siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
exec_w = char2wide(op->opaque->exec);
- if( !CreateProcess(NULL,
- exec_w, // command line
- NULL, // process security attributes
- NULL, // primary thread security attributes
- TRUE, // handles are inherited
- 0, // creation flags
- NULL, // use parent's environment
- NULL, // use parent's current directory
- &siStartInfo, // STARTUPINFO pointer
- &piProcInfo) // receives PROCESS_INFORMATION
- ) {
- mh_err("Could not create child process");
- goto fail;
-
- /* For now, run all commands synchronously */
- /* } else if(synchronous == FALSE) { */
- /* return TRUE; */
+ if (!CreateProcess(NULL,
+ exec_w, // command line
+ NULL, // process security attributes
+ NULL, // primary thread security attributes
+ TRUE, // handles are inherited
+ 0, // creation flags
+ NULL, // use parent's environment
+ NULL, // use parent's current directory
+ &siStartInfo, // STARTUPINFO pointer
+ &piProcInfo)) { // receives PROCESS_INFORMATION
+ mh_err("Could not create child process");
+ goto fail;
+
+ /* For now, run all commands synchronously */
+ /* } else if(synchronous == FALSE) { */
+ /* return TRUE; */
}
-
+
WaitForSingleObject(piProcInfo.hProcess, op->timeout /* Or INFINITE */);
- if(GetExitCodeProcess(piProcInfo.hProcess, &status) == 0) {
- mh_err("Could not get exit code: %lu", GetLastError());
- status = STILL_ACTIVE;
+ if (GetExitCodeProcess(piProcInfo.hProcess, &status) == 0) {
+ mh_err("Could not get exit code: %lu", GetLastError());
+ status = STILL_ACTIVE;
}
-
- if(status == STILL_ACTIVE) {
- op->rc = LSB_UNKNOWN_ERROR;
- op->status = LRM_OP_TIMEOUT;
- TerminateProcess(piProcInfo.hProcess, 1);
- mh_err("Operation for %s timeout out after %dms", op->id, op->timeout);
-
- } else if(status == 1062 && strcmp("stop", op->action) == 0) {
- /* Stopping something thats stopped is a success */
- op->status = LRM_OP_DONE;
- op->rc = LSB_OK;
-
- } else if(status == 1056 && strcmp("start", op->action) == 0) {
- /* Starting something thats started is a success */
- op->status = LRM_OP_DONE;
- op->rc = LSB_OK;
-
- } else if(status == 0) {
- op->status = LRM_OP_DONE;
- op->rc = LSB_OK;
+
+ if (status == STILL_ACTIVE) {
+ op->rc = LSB_UNKNOWN_ERROR;
+ op->status = LRM_OP_TIMEOUT;
+ TerminateProcess(piProcInfo.hProcess, 1);
+ mh_err("Operation for %s timeout out after %dms", op->id,
op->timeout);
+
+ } else if (status == 1062 && strcmp("stop", op->action) == 0) {
+ /* Stopping something thats stopped is a success */
+ op->status = LRM_OP_DONE;
+ op->rc = LSB_OK;
+
+ } else if (status == 1056 && strcmp("start", op->action) == 0)
{
+ /* Starting something thats started is a success */
+ op->status = LRM_OP_DONE;
+ op->rc = LSB_OK;
+
+ } else if (status == 0) {
+ op->status = LRM_OP_DONE;
+ op->rc = LSB_OK;
} else {
- op->status = LRM_OP_ERROR;
- op->rc = LSB_UNKNOWN_ERROR;
- mh_info("Result of '%ls' for '%s' was %d", exec_w, op->id,
(int)status);
+ op->status = LRM_OP_ERROR;
+ op->rc = LSB_UNKNOWN_ERROR;
+ mh_info("Result of '%ls' for '%s' was %d", exec_w,
op->id, (int)status);
}
/* Nice to log it somewhere */
- if(op->rc == LSB_OK) {
- mh_debug("Result of '%ls' for '%s' was %d", exec_w, op->id,
(int)status);
+ if (op->rc == LSB_OK) {
+ mh_debug("Result of '%ls' for '%s' was %d", exec_w,
op->id, (int)status);
}
-
- /* Close the write end of the pipe before reading from the
+
+ /* Close the write end of the pipe before reading from the
* read end of the pipe, to control child process execution.
* The pipe is assumed to have enough buffer space to hold the
* data the child process has already written to it.
*/
if (!CloseHandle(child_pipe_wr)) {
- mh_err("Couldn't close write end of child pipe");
+ mh_err("Couldn't close write end of child pipe");
}
-
+
read_output(child_pipe_rd, &op->stdout_data, &max);
- if(op->stdout_data) {
- mh_debug("RAW: %s", op->stdout_data);
+ if (op->stdout_data) {
+ mh_debug("RAW: %s", op->stdout_data);
}
- if(is_status_op && op->status == LRM_OP_DONE) {
- op->rc = extract_service_status(op->stdout_data, max);
+ if (is_status_op && op->status == LRM_OP_DONE) {
+ op->rc = extract_service_status(op->stdout_data, max);
}
-
+
CloseHandle(piProcInfo.hProcess);
CloseHandle(piProcInfo.hThread);
CloseHandle(child_pipe_rd);
- if(is_status_op && op->rc == LSB_UNKNOWN_ERROR) {
- op->rc = LSB_STATUS_UNKNOWN_ERROR;
+ if (is_status_op && op->rc == LSB_UNKNOWN_ERROR) {
+ op->rc = LSB_STATUS_UNKNOWN_ERROR;
}
-
+
return TRUE;
- fail:
+fail:
op->status = LRM_OP_ERROR;
op->rc = LSB_UNKNOWN_ERROR;
- if(is_status_op && op->rc == LSB_UNKNOWN_ERROR) {
- op->rc = LSB_STATUS_UNKNOWN_ERROR;
+ if (is_status_op && op->rc == LSB_UNKNOWN_ERROR) {
+ op->rc = LSB_STATUS_UNKNOWN_ERROR;
}
return FALSE;
}
void
-services_os_set_exec(svc_action_t* op)
+services_os_set_exec(svc_action_t *op)
{
char *p = getenv("WINDIR");
- if(strcmp("status", op->action) == 0) {
- op->opaque->exec = g_strdup_printf("%s\\system32\\sc.exe query %s", p,
op->rsc);
- /* op->opaque->exec = g_strdup_printf("sc query %s", op->rsc); */
+ if (strcmp("status", op->action) == 0) {
+ op->opaque->exec = g_strdup_printf("%s\\system32\\sc.exe query
%s", p,
+ op->rsc);
+ /* op->opaque->exec = g_strdup_printf("sc query %s", op->rsc);
*/
} else {
- op->opaque->exec = g_strdup_printf("%s\\system32\\sc.exe %s %s", p,
op->action, op->rsc);
- /* op->opaque->exec = g_strdup_printf("sc %s %s", op->action,
op->rsc); */
+ op->opaque->exec = g_strdup_printf("%s\\system32\\sc.exe %s %s",
p,
+ op->action, op->rsc);
+ /* op->opaque->exec = g_strdup_printf("sc %s %s", op->action,
op->rsc); */
}
}
GList *
services_os_get_directory_list(const char *root, gboolean files)
{
- /* For now, this is unsupported/unnecessary on Windows, return an empty list */
+ /* For now, this is unsupported/unnecessary on Windows,
+ * return an empty list */
return NULL;
}
-GList *services_os_list(void)
+GList *
+services_os_list(void)
{
/* Need to implement */
- /* SC QUERY state= all | findstr "SERVICE_NAME" */
+ /* SC QUERY state= all | findstr "SERVICE_NAME" */
return NULL;
}
-
-GList *resources_os_list_ocf_providers(void)
+GList *
+resources_os_list_ocf_providers(void)
{
/* Unsupported on Windows, return an empty list */
return NULL;
}
-GList *resources_os_list_ocf_agents(const char *provider)
+GList *
+resources_os_list_ocf_agents(const char *provider)
{
/* Unsupported on Windows, return an empty list */
return NULL;
diff --git a/src/lib/utilities.c b/src/lib/utilities.c
index 1151c00..57929a2 100644
--- a/src/lib/utilities.c
+++ b/src/lib/utilities.c
@@ -1,16 +1,16 @@
-/*
+/*
* Copyright (C) 2010 Andrew Beekhof <andrew(a)beekhof.net>
- *
+ *
* 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.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -48,7 +48,8 @@ gboolean mh_stderr_enabled = FALSE;
#if SUPPORT_TRACING
static int
-mh_update_trace_data(struct _mh_ddebug_query *query, struct _mh_ddebug *start, struct
_mh_ddebug *stop)
+mh_update_trace_data(struct _mh_ddebug_query *query, struct _mh_ddebug *start,
+ struct _mh_ddebug *stop)
{
int lpc = 0;
unsigned nfound = 0;
@@ -59,51 +60,53 @@ mh_update_trace_data(struct _mh_ddebug_query *query, struct _mh_ddebug
*start, s
MH_ASSERT(start != NULL);
/* fprintf(stderr, "checking for fns: %s files: %s fmts: %s\n", */
- /* query->functions, query->files, query->formats); */
-
+ /* query->functions, query->files, query->formats); */
+
for (dp = start; dp != stop; dp++) {
- gboolean bump = FALSE;
- lpc++;
- /* fprintf(stderr, "checking: %-12s %20s:%u fmt:%s\n", */
- /* dp->function, dp->filename, dp->lineno, dp->format); */
-
- if (query->functions && strstr(query->functions, dp->function) != NULL)
{
- match = "function";
- bump = TRUE;
- }
-
- if(query->files) {
- char token[500];
- const char *offset = NULL;
- const char *next = query->files;
-
- do {
- offset = next;
- next = strchrnul(offset, ',');
- snprintf(token, 499, "%.*s", (int)(next-offset), offset);
-
- if (query->files && strstr(dp->filename, token) != NULL) {
- match = "file";
- bump = TRUE;
-
- } else if(next[0] != 0) {
- next++;
- }
-
- } while(bump == FALSE && next != NULL && next[0] != 0);
- }
-
- if (query->formats && strstr(query->formats, dp->format) != NULL) {
- match = "format";
- bump = TRUE;
- }
-
- if(bump) {
- nfound++;
- dp->bump = LOG_NOTICE;
- mh_log_always(LOG_INFO, "Detected '%s' match: %-12s %20s:%u
fmt:%s",
- match, dp->function, dp->filename, dp->lineno, dp->format);
- }
+ gboolean bump = FALSE;
+ lpc++;
+ /* fprintf(stderr, "checking: %-12s %20s:%u fmt:%s\n", */
+ /* dp->function, dp->filename, dp->lineno, dp->format); */
+
+ if (query->functions &&
+ strstr(query->functions, dp->function) != NULL) {
+ match = "function";
+ bump = TRUE;
+ }
+
+ if (query->files) {
+ char token[500];
+ const char *offset = NULL;
+ const char *next = query->files;
+
+ do {
+ offset = next;
+ next = strchrnul(offset, ',');
+ snprintf(token, 499, "%.*s", (int)(next - offset), offset);
+
+ if (query->files && strstr(dp->filename, token) != NULL) {
+ match = "file";
+ bump = TRUE;
+
+ } else if (next[0] != 0) {
+ next++;
+ }
+
+ } while (bump == FALSE && next != NULL && next[0] != 0);
+ }
+
+ if (query->formats && strstr(query->formats, dp->format) !=
NULL) {
+ match = "format";
+ bump = TRUE;
+ }
+
+ if (bump) {
+ nfound++;
+ dp->bump = LOG_NOTICE;
+ mh_log_always(LOG_INFO, "Detected '%s' match: %-12s %20s:%u
fmt:%s",
+ match, dp->function, dp->filename, dp->lineno,
+ dp->format);
+ }
}
query->total += lpc;
@@ -114,195 +117,202 @@ mh_update_trace_data(struct _mh_ddebug_query *query, struct
_mh_ddebug *start, s
static int
mh_ddebug_callback(struct dl_phdr_info *info, size_t size, void *data)
{
- if(strlen(info->dlpi_name) > 0) {
- struct _mh_ddebug_query *query = data;
-
- void *handle;
- void *start;
- void *stop;
- char *error;
-
- handle = dlopen (info->dlpi_name, RTLD_LAZY);
- error = dlerror();
- if (!handle || error) {
- mh_err("%s", error);
- if(handle) {
- dlclose(handle);
- }
- return 0;
- }
-
- start = dlsym(handle, "__start___verbose");
- error = dlerror();
- if (error) {
- goto done;
- }
-
- stop = dlsym(handle, "__stop___verbose");
- error = dlerror();
- if (error) {
- goto done;
-
- } else {
- unsigned long int len = (unsigned long int)stop - (unsigned long int)start;
- mh_info("Checking for query matches in %lu trace symbols from: %s (offset:
%p)",
- len/sizeof(struct _mh_ddebug), info->dlpi_name, start);
-
- mh_update_trace_data(query, start, stop);
- }
- done:
- dlclose(handle);
+ if (strlen(info->dlpi_name) > 0) {
+ struct _mh_ddebug_query *query = data;
+
+ void *handle;
+ void *start;
+ void *stop;
+ char *error;
+
+ handle = dlopen (info->dlpi_name, RTLD_LAZY);
+ error = dlerror();
+ if (!handle || error) {
+ mh_err("%s", error);
+ if (handle) {
+ dlclose(handle);
+ }
+ return 0;
+ }
+
+ start = dlsym(handle, "__start___verbose");
+ error = dlerror();
+ if (error) {
+ goto done;
+ }
+
+ stop = dlsym(handle, "__stop___verbose");
+ error = dlerror();
+ if (error) {
+ goto done;
+
+ } else {
+ unsigned long int len = (unsigned long int) stop -
+ (unsigned long int) start;
+ mh_info("Checking for query matches in %lu trace symbols from: "
+ "%s (offset: %p)", len / sizeof(struct _mh_ddebug),
+ info->dlpi_name, start);
+
+ mh_update_trace_data(query, start, stop);
+ }
+ done:
+ dlclose(handle);
}
-
+
return 0;
}
#endif
static void
-mh_glib_handler(const gchar *log_domain, GLogLevelFlags flags, const gchar *message,
gpointer user_data)
+mh_glib_handler(const gchar *log_domain, GLogLevelFlags flags,
+ const gchar *message, gpointer user_data)
{
int log_level = LOG_WARNING;
GLogLevelFlags msg_level = (flags & G_LOG_LEVEL_MASK);
- switch(msg_level) {
- case G_LOG_LEVEL_CRITICAL:
- /* log and record how we got here */
- mh_abort(__FILE__,__PRETTY_FUNCTION__,__LINE__, message, TRUE, TRUE);
- return;
-
- case G_LOG_FLAG_FATAL: log_level = LOG_CRIT; break;
- case G_LOG_LEVEL_ERROR: log_level = LOG_ERR; break;
- case G_LOG_LEVEL_MESSAGE: log_level = LOG_NOTICE; break;
- case G_LOG_LEVEL_INFO: log_level = LOG_INFO; break;
- case G_LOG_LEVEL_DEBUG: log_level = LOG_DEBUG; break;
-
- case G_LOG_LEVEL_WARNING:
- case G_LOG_FLAG_RECURSION:
- case G_LOG_LEVEL_MASK:
- log_level = LOG_WARNING;
- break;
+ switch (msg_level) {
+ case G_LOG_LEVEL_CRITICAL:
+ /* log and record how we got here */
+ mh_abort(__FILE__, __PRETTY_FUNCTION__, __LINE__, message, TRUE, TRUE);
+ return;
+
+ case G_LOG_FLAG_FATAL: log_level = LOG_CRIT; break;
+ case G_LOG_LEVEL_ERROR: log_level = LOG_ERR; break;
+ case G_LOG_LEVEL_MESSAGE: log_level = LOG_NOTICE; break;
+ case G_LOG_LEVEL_INFO: log_level = LOG_INFO; break;
+ case G_LOG_LEVEL_DEBUG: log_level = LOG_DEBUG; break;
+
+ case G_LOG_LEVEL_WARNING:
+ case G_LOG_FLAG_RECURSION:
+ case G_LOG_LEVEL_MASK:
+ log_level = LOG_WARNING;
+ break;
}
mh_log(log_level, "%s: %s", log_domain, message);
}
-void mh_enable_stderr(gboolean to_stderr)
+void
+mh_enable_stderr(gboolean to_stderr)
{
mh_stderr_enabled = to_stderr;
}
-void mh_log_init(const char *ident, int level, gboolean to_stderr)
+void
+mh_log_init(const char *ident, int level, gboolean to_stderr)
{
#if SUPPORT_TRACING
gboolean search = FALSE;
const char *env_value = NULL;
struct _mh_ddebug_query query;
#endif
-
+
mh_log_level = level;
mh_stderr_enabled = to_stderr;
#ifdef __linux__
- openlog(ident, LOG_NDELAY|LOG_PID, LOG_DAEMON);
+ openlog(ident, LOG_NDELAY | LOG_PID, LOG_DAEMON);
#endif
/* Consistant glib logging */
g_log_set_default_handler(mh_glib_handler, NULL);
-
+
/* and for good measure... - this enum is a bit field (!) */
- g_log_set_always_fatal((GLogLevelFlags)0); /*value out of range*/
+ g_log_set_always_fatal((GLogLevelFlags) 0); /*value out of range*/
#if SUPPORT_TRACING
memset(&query, 0, sizeof(struct _mh_ddebug_query));
env_value = getenv("MH_trace_files");
- if(env_value) {
- search = TRUE;
- query.files = env_value;
+ if (env_value) {
+ search = TRUE;
+ query.files = env_value;
}
env_value = getenv("MH_trace_formats");
- if(env_value) {
- search = TRUE;
- query.formats = env_value;
+ if (env_value) {
+ search = TRUE;
+ query.formats = env_value;
}
env_value = getenv("MH_trace_functions");
- if(env_value) {
- search = TRUE;
- query.functions = env_value;
+ if (env_value) {
+ search = TRUE;
+ query.functions = env_value;
}
-
- if(search) {
- mh_update_trace_data(&query, __start___verbose, __stop___verbose);
- dl_iterate_phdr(mh_ddebug_callback, &query);
- if(query.matches == 0) {
- mh_log_always(LOG_DEBUG,
- "no matches for query: {fn='%s', file='%s', fmt='%s'}
in %llu entries",
- query.functions?query.functions:"N/A",
- query.files?query.files:"N/A",
- query.formats?query.formats:"N/A",
- query.total);
- } else {
- mh_log_always(LOG_INFO,
- "%llu matches for query: {fn='%s', file='%s', fmt='%s'}
in %llu entries",
- query.matches,
- query.functions?query.functions:"N/A",
- query.files?query.files:"N/A",
- query.formats?query.formats:"N/A",
- query.total);
- }
+
+ if (search) {
+ mh_update_trace_data(&query, __start___verbose, __stop___verbose);
+ dl_iterate_phdr(mh_ddebug_callback, &query);
+ if (query.matches == 0) {
+ mh_log_always(LOG_DEBUG, "no matches for query: {fn='%s',
"
+ "file='%s', fmt='%s'} in %llu
entries",
+ query.functions ? query.functions : "N/A",
+ query.files ? query.files : "N/A",
+ query.formats ? query.formats : "N/A",
+ query.total);
+ } else {
+ mh_log_always(LOG_INFO, "%llu matches for query: {fn='%s',
"
+ "file='%s', fmt='%s'} in %llu
entries",
+ query.matches,
+ query.functions ? query.functions : "N/A",
+ query.files ? query.files : "N/A",
+ query.formats ? query.formats : "N/A",
+ query.total);
+ }
}
#endif
}
void
mh_abort(const char *file, const char *function, int line,
- const char *assert_condition, int do_core, int do_fork)
+ const char *assert_condition, int do_core, int do_fork)
{
#ifdef __linux__
int rc = 0;
int pid = 0;
int status = 0;
- if(do_core == 0) {
- mh_err("%s: Triggered assert at %s:%d : %s",
- function, file, line, assert_condition);
- return;
+ if (do_core == 0) {
+ mh_err("%s: Triggered assert at %s:%d : %s",
+ function, file, line, assert_condition);
+ return;
- } else if(do_fork) {
- pid=fork();
+ } else if (do_fork) {
+ pid = fork();
} else {
- mh_err("%s: Triggered fatal assert at %s:%d : %s",
- function, file, line, assert_condition);
+ mh_err("%s: Triggered fatal assert at %s:%d : %s",
+ function, file, line, assert_condition);
}
-
- switch(pid) {
- case -1:
- mh_crit("%s: Cannot create core for non-fatal assert at %s:%d : %s",
- function, file, line, assert_condition);
- return;
-
- default: /* Parent */
- mh_err("%s: Forked child %d to record non-fatal assert at %s:%d : %s",
- function, pid, file, line, assert_condition);
- do {
- rc = waitpid(pid, &status, 0);
- if(rc < 0 && errno != EINTR) {
- mh_perror(LOG_ERR, "%s: Cannot wait on forked child %d", function, pid);
- }
-
- } while(rc < 0 && errno == EINTR);
-
- return;
-
- case 0: /* Child */
- abort();
- break;
+
+ switch (pid) {
+ case -1:
+ mh_crit("%s: Cannot create core for non-fatal assert at %s:%d : %s",
+ function, file, line, assert_condition);
+ return;
+
+ default: /* Parent */
+ mh_err("%s: Forked child %d to record non-fatal assert at %s:%d : %s",
+ function, pid, file, line, assert_condition);
+ do {
+ rc = waitpid(pid, &status, 0);
+ if (rc < 0 && errno != EINTR) {
+ mh_perror(LOG_ERR, "%s: Cannot wait on forked child %d",
+ function, pid);
+ }
+
+ } while (rc < 0 && errno == EINTR);
+
+ return;
+
+ case 0: /* Child */
+ abort();
+ break;
}
#else
- mh_err("%s: Triggered assert at %s:%d : %s", function, file, line,
assert_condition);
+ mh_err("%s: Triggered assert at %s:%d : %s", function, file, line,
+ assert_condition);
abort();
#endif
}
@@ -313,86 +323,86 @@ mh_log_fn(int priority, const char * fmt, ...)
va_list ap;
if (mh_stderr_enabled) {
- va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
#ifdef __linux__
- fprintf(stderr, "\n");
+ fprintf(stderr, "\n");
#else
- fprintf(stderr, "\n\r");
-#endif
- va_end(ap);
+ fprintf(stderr, "\n\r");
+#endif
+ va_end(ap);
#ifdef __linux__
} else {
- va_start(ap, fmt);
- vsyslog(priority, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ vsyslog(priority, fmt, ap);
+ va_end(ap);
#endif
}
-
+
return;
}
const char *
mh_hostname(void)
{
- static char *hostname = NULL;
-
- if(hostname == NULL) {
- sigar_t *sigar;
- sigar_net_info_t netinfo;
- sigar_open(&sigar);
- sigar_net_info_get(sigar, &netinfo);
- hostname = strdup(netinfo.host_name);
- }
-
- if(hostname != NULL && strcmp(hostname, "localhost") == 0) {
- free(hostname);
- hostname = strdup(mh_uuid());
- }
-
- mh_trace("Got hostname: %s", hostname);
- return hostname;
+ static char *hostname = NULL;
+
+ if (hostname == NULL) {
+ sigar_t *sigar;
+ sigar_net_info_t netinfo;
+ sigar_open(&sigar);
+ sigar_net_info_get(sigar, &netinfo);
+ hostname = strdup(netinfo.host_name);
+ }
+
+ if (hostname != NULL && strcmp(hostname, "localhost") == 0) {
+ free(hostname);
+ hostname = strdup(mh_uuid());
+ }
+
+ mh_trace("Got hostname: %s", hostname);
+ return hostname;
}
const char *
mh_uuid(void)
{
- static char *uuid = NULL;
+ static char *uuid = NULL;
- if(uuid == NULL) {
+ if (uuid == NULL) {
#ifdef __linux__
- char *buffer = NULL;
- int chunk = 512, data_length = 0, read_chars = 0;
- const char *uuid_file = "/var/lib/dbus/machine-id";
- FILE *input = fopen(uuid_file, "r");
- if(input) {
- do {
- buffer = realloc(buffer, chunk + data_length + 1);
- read_chars = fread(buffer + data_length, 1, chunk, input);
- data_length += read_chars;
- } while (read_chars > 0);
- }
- if(data_length == 0) {
- mh_warn("Could not read from %s", uuid_file);
- uuid = strdup("unknown");
-
- } else {
- char *tmp = strchrnul(buffer, '\n');
- *tmp = '\0';
- uuid = strdup(buffer);
- }
- if(input) {
- fclose(input);
- }
- free(buffer);
+ char *buffer = NULL;
+ int chunk = 512, data_length = 0, read_chars = 0;
+ const char *uuid_file = "/var/lib/dbus/machine-id";
+ FILE *input = fopen(uuid_file, "r");
+ if (input) {
+ do {
+ buffer = realloc(buffer, chunk + data_length + 1);
+ read_chars = fread(buffer + data_length, 1, chunk, input);
+ data_length += read_chars;
+ } while (read_chars > 0);
+ }
+ if (data_length == 0) {
+ mh_warn("Could not read from %s", uuid_file);
+ uuid = strdup("unknown");
+
+ } else {
+ char *tmp = strchrnul(buffer, '\n');
+ *tmp = '\0';
+ uuid = strdup(buffer);
+ }
+ if (input) {
+ fclose(input);
+ }
+ free(buffer);
#else
- uuid = strdup("unknown");
+ uuid = strdup("unknown");
#endif
- }
+ }
- mh_trace("Got uuid: %s", uuid);
- return uuid;
+ mh_trace("Got uuid: %s", uuid);
+ return uuid;
}
#ifndef HAVE_ASPRINTF
diff --git a/src/network/network-dbus.c b/src/network/network-dbus.c
index cb35da0..31040d2 100644
--- a/src/network/network-dbus.c
+++ b/src/network/network-dbus.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2010 Red Hat, Inc.
* Written by Radek Novacek <rnovacek(a)redhat.com>
- *
+ *
* 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
@@ -43,14 +43,15 @@
enum status { INACTIVE = 0, RUNNING };
/* Get status of the interface */
-static enum status interface_status(const char *iface)
+static enum status
+interface_status(const char *iface)
{
- uint64_t flags = 0;
- mh_network_status(iface, &flags);
+ uint64_t flags = 0;
+ mh_network_status(iface, &flags);
- if(flags & SIGAR_IFF_UP)
- return RUNNING;
- return INACTIVE; /* Inactive */
+ if (flags & SIGAR_IFF_UP)
+ return RUNNING;
+ return INACTIVE; /* Inactive */
}
/* Dbus methods */
@@ -58,123 +59,123 @@ static enum status interface_status(const char *iface)
gboolean
Network_list(Matahari *matahari, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- GList *interface_list;
- GList *plist;
- sigar_net_interface_config_t *ifconfig;
- char **list;
- int i = 0;
-
- if (!check_authorization(NETWORK_BUS_NAME ".list", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
-
- // Get the list of interfaces
- interface_list = mh_network_get_interfaces();
-
- // Alloc array for list of interface names
- list = g_new(char *, g_list_length(interface_list) + 1);
-
- // Convert list of interfaces to the array of names
- for(plist = g_list_first(interface_list); plist; plist = g_list_next(plist))
- {
- ifconfig = (sigar_net_interface_config_t *)plist->data;
- list[i++] = strdup(ifconfig->name);
- }
- list[i] = NULL; // Sentinel
-
- dbus_g_method_return(context, list);
- g_strfreev(list);
- g_list_free(interface_list);
- return TRUE;
+ GError* error = NULL;
+ GList *interface_list;
+ GList *plist;
+ sigar_net_interface_config_t *ifconfig;
+ char **list;
+ int i = 0;
+
+ if (!check_authorization(NETWORK_BUS_NAME ".list", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ // Get the list of interfaces
+ interface_list = mh_network_get_interfaces();
+
+ // Alloc array for list of interface names
+ list = g_new(char *, g_list_length(interface_list) + 1);
+
+ // Convert list of interfaces to the array of names
+ for (plist = g_list_first(interface_list);
+ plist;
+ plist = g_list_next(plist)) {
+ ifconfig = (sigar_net_interface_config_t *)plist->data;
+ list[i++] = strdup(ifconfig->name);
+ }
+ list[i] = NULL; // Sentinel
+
+ dbus_g_method_return(context, list);
+ g_strfreev(list);
+ g_list_free(interface_list);
+ return TRUE;
}
gboolean
-Network_start(Matahari *matahari, const char *iface, DBusGMethodInvocation *context)
+Network_start(Matahari *matahari, const char *iface,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- int status;
-
- if (!check_authorization(NETWORK_BUS_NAME ".start", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
-
- status = interface_status(iface);
- if (status != RUNNING)
- {
- mh_network_start(iface);
+ GError* error = NULL;
+ int status;
+
+ if (!check_authorization(NETWORK_BUS_NAME ".start", &error, context))
{
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
status = interface_status(iface);
- }
- dbus_g_method_return(context, status);
- return TRUE;
+ if (status != RUNNING) {
+ mh_network_start(iface);
+ status = interface_status(iface);
+ }
+ dbus_g_method_return(context, status);
+ return TRUE;
}
gboolean
-Network_stop(Matahari *matahari, const char *iface, DBusGMethodInvocation *context)
+Network_stop(Matahari *matahari, const char *iface,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- int status;
-
- if (!check_authorization(NETWORK_BUS_NAME ".stop", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
-
- status = interface_status(iface);
- if (status != INACTIVE)
- {
- mh_network_stop(iface);
+ GError* error = NULL;
+ int status;
+
+ if (!check_authorization(NETWORK_BUS_NAME ".stop", &error, context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
status = interface_status(iface);
- }
- dbus_g_method_return(context, status);
- return TRUE;
+ if (status != INACTIVE) {
+ mh_network_stop(iface);
+ status = interface_status(iface);
+ }
+ dbus_g_method_return(context, status);
+ return TRUE;
}
gboolean
-Network_status(Matahari *matahari, const char *iface, DBusGMethodInvocation *context)
+Network_status(Matahari *matahari, const char *iface,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(NETWORK_BUS_NAME ".status", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
-
- dbus_g_method_return(context, interface_status(iface));
- return TRUE;
+ GError* error = NULL;
+ if (!check_authorization(NETWORK_BUS_NAME ".status", &error, context))
{
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ dbus_g_method_return(context, interface_status(iface));
+ return TRUE;
}
gboolean
-Network_get_ip_address(Matahari *matahari, const char *iface, DBusGMethodInvocation
*context)
+Network_get_ip_address(Matahari *matahari, const char *iface,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(NETWORK_BUS_NAME ".get_ip_address", &error,
context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
-
- dbus_g_method_return(context, g_strdup(mh_network_get_ip_address(iface)));
- return TRUE;
+ GError* error = NULL;
+ if (!check_authorization(NETWORK_BUS_NAME ".get_ip_address", &error,
+ context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ dbus_g_method_return(context, g_strdup(mh_network_get_ip_address(iface)));
+ return TRUE;
}
gboolean
-Network_get_mac_address(Matahari *matahari, const char *iface, DBusGMethodInvocation
*context)
+Network_get_mac_address(Matahari *matahari, const char *iface,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(NETWORK_BUS_NAME ".get_mac_address", &error,
context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
-
- dbus_g_method_return(context, g_strdup(mh_network_get_mac_address(iface)));
- return TRUE;
+ GError* error = NULL;
+ if (!check_authorization(NETWORK_BUS_NAME ".get_mac_address", &error,
+ context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+
+ dbus_g_method_return(context, g_strdup(mh_network_get_mac_address(iface)));
+ return TRUE;
}
/* Generated dbus stuff for network
@@ -184,37 +185,38 @@ Network_get_mac_address(Matahari *matahari, const char *iface,
DBusGMethodInvoca
void
matahari_set_property(GObject *object, guint property_id, const GValue *value,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
- // We don't have writable other property...
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ // We don't have writable other property...
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
void
matahari_get_property(GObject *object, guint property_id, GValue *value,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
- switch (property_id)
- {
- case PROP_HOSTNAME:
- g_value_set_string (value, mh_hostname());
- break;
- default:
- /* We don't have any other property... */
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
+ switch (property_id) {
+ case PROP_HOSTNAME:
+ g_value_set_string (value, mh_hostname());
+ break;
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
-GType matahari_dict_type(int prop)
+GType
+matahari_dict_type(int prop)
{
- g_printerr("Type of property %s is map of unknown types\n",
properties[prop].name);
- return G_TYPE_VALUE;
+ g_printerr("Type of property %s is map of unknown types\n",
+ properties[prop].name);
+ return G_TYPE_VALUE;
}
int
main(int argc, char** argv)
{
- g_type_init();
- return run_dbus_server(NETWORK_BUS_NAME, NETWORK_OBJECT_PATH);
+ g_type_init();
+ return run_dbus_server(NETWORK_BUS_NAME, NETWORK_OBJECT_PATH);
}
diff --git a/src/network/network-qmf.cpp b/src/network/network-qmf.cpp
index c039235..8e9e247 100644
--- a/src/network/network-qmf.cpp
+++ b/src/network/network-qmf.cpp
@@ -59,16 +59,17 @@ main(int argc, char **argv)
return rc;
}
-static int interface_status(const char *iface)
+static int
+interface_status(const char *iface)
{
uint64_t flags = 0;
- if(iface == NULL)
- return 3;
+ if (iface == NULL)
+ return 3;
mh_network_status(iface, &flags);
- if(flags & SIGAR_IFF_UP) {
- return 0;
+ if (flags & SIGAR_IFF_UP) {
+ return 0;
}
return 1; /* Inactive */
}
@@ -87,7 +88,8 @@ NetAgent::setup(qmf::AgentSession session)
}
gboolean
-NetAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data)
+NetAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data)
{
if (event.getType() != qmf::AGENT_METHOD) {
session.methodSuccess(event);
@@ -104,32 +106,40 @@ NetAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
gpointer user
sigar_net_interface_config_t *ifconfig = NULL;
interface_list = mh_network_get_interfaces();
- for (plist = g_list_first(interface_list); plist; plist = g_list_next(plist)) {
+ for (plist = g_list_first(interface_list); plist;
+ plist = g_list_next(plist)) {
ifconfig = (sigar_net_interface_config_t *)plist->data;
s_list.push_back(ifconfig->name);
}
event.addReturnArgument("iface_map", s_list);
} else if (methodName == "start") {
- int rc =
interface_status(event.getArguments()["iface"].asString().c_str());
+ int rc = interface_status(
+ event.getArguments()["iface"].asString().c_str());
if (rc == 1) {
mh_network_start(event.getArguments()["iface"].asString().c_str());
- rc =
interface_status(event.getArguments()["iface"].asString().c_str());
+ rc = interface_status(
+ event.getArguments()["iface"].asString().c_str());
}
event.addReturnArgument("status", rc);
} else if (methodName == "stop") {
- int rc =
interface_status(event.getArguments()["iface"].asString().c_str());
+ int rc = interface_status(
+ event.getArguments()["iface"].asString().c_str());
if (rc == 0) {
mh_network_stop(event.getArguments()["iface"].asString().c_str());
- rc =
interface_status(event.getArguments()["iface"].asString().c_str());
+ rc = interface_status(
+ event.getArguments()["iface"].asString().c_str());
}
event.addReturnArgument("status", rc);
} else if (methodName == "status") {
- event.addReturnArgument("status",
interface_status(event.getArguments()["iface"].asString().c_str()));
+ event.addReturnArgument("status", interface_status(
+ event.getArguments()["iface"].asString().c_str()));
} else if (methodName == "get_ip_address") {
- event.addReturnArgument("ip",
mh_network_get_ip_address(event.getArguments()["iface"].asString().c_str()));
+ event.addReturnArgument("ip", mh_network_get_ip_address(
+ event.getArguments()["iface"].asString().c_str()));
} else if (methodName == "get_mac_address") {
- event.addReturnArgument("mac",
mh_network_get_mac_address(event.getArguments()["iface"].asString().c_str()));
+ event.addReturnArgument("mac", mh_network_get_mac_address(
+ event.getArguments()["iface"].asString().c_str()));
} else {
session.raiseException(event, MH_NOT_IMPLEMENTED);
goto bail;
diff --git a/src/service/service-dbus.c b/src/service/service-dbus.c
index 23768d8..8d7c56e 100644
--- a/src/service/service-dbus.c
+++ b/src/service/service-dbus.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2010 Red Hat, Inc.
* Written by Radek Novacek <rnovacek(a)redhat.com>
- *
+ *
* 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
@@ -43,174 +43,175 @@
gboolean
Services_list(Matahari *matahari, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- int i = 0;
- GList *services;
- char **list;
+ GError* error = NULL;
+ int i = 0;
+ GList *services;
+ char **list;
- if (!check_authorization(SERVICES_BUS_NAME ".list", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
+ if (!check_authorization(SERVICES_BUS_NAME ".list", &error, context))
{
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
- // Get list of services
- services = services_list();
+ // Get list of services
+ services = services_list();
- // Convert GList to (char **)
- list = g_new(char *, g_list_length(services) + 1);
- for (; services != NULL; services = services->next)
- list[i++] = strdup(services->data);
- list[i] = NULL; // Sentinel
+ // Convert GList to (char **)
+ list = g_new(char *, g_list_length(services) + 1);
+ for (; services != NULL; services = services->next)
+ list[i++] = strdup(services->data);
+ list[i] = NULL; // Sentinel
- dbus_g_method_return(context, list);
- g_strfreev(list);
- g_list_free(services);
- return TRUE;
+ dbus_g_method_return(context, list);
+ g_strfreev(list);
+ g_list_free(services);
+ return TRUE;
}
gboolean
-Services_enable(Matahari *matahari, const char *name, DBusGMethodInvocation *context)
+Services_enable(Matahari *matahari, const char *name,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- svc_action_t *op;
- gboolean res;
+ GError* error = NULL;
+ svc_action_t *op;
+ gboolean res;
- if (!check_authorization(SERVICES_BUS_NAME ".enable", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- op = services_action_create(name, "enable", 0, TIMEOUT_MS);
- res = services_action_sync(op);
- services_action_free(op);
- dbus_g_method_return(context, res);
- return res;
+ if (!check_authorization(SERVICES_BUS_NAME ".enable", &error, context))
{
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ op = services_action_create(name, "enable", 0, TIMEOUT_MS);
+ res = services_action_sync(op);
+ services_action_free(op);
+ dbus_g_method_return(context, res);
+ return res;
}
gboolean
-Services_disable(Matahari *matahari, const char *name, DBusGMethodInvocation *context)
+Services_disable(Matahari *matahari, const char *name,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- svc_action_t *op;
- gboolean res;
+ GError* error = NULL;
+ svc_action_t *op;
+ gboolean res;
- if (!check_authorization(SERVICES_BUS_NAME ".disable", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- op = services_action_create(name, "disable", 0, TIMEOUT_MS);
- res = services_action_sync(op);
- services_action_free(op);
- dbus_g_method_return(context, res);
- return res;
+ if (!check_authorization(SERVICES_BUS_NAME ".disable", &error,
context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ op = services_action_create(name, "disable", 0, TIMEOUT_MS);
+ res = services_action_sync(op);
+ services_action_free(op);
+ dbus_g_method_return(context, res);
+ return res;
}
gboolean
-Services_start(Matahari *matahari, const char *name, unsigned int timeout,
DBusGMethodInvocation *context)
+Services_start(Matahari *matahari, const char *name, unsigned int timeout,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- svc_action_t *op;
- int rc;
+ GError* error = NULL;
+ svc_action_t *op;
+ int rc;
- if (!check_authorization(SERVICES_BUS_NAME ".start", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- op = services_action_create(name, "start", 0, timeout);
- services_action_sync(op);
- rc = op->rc;
- services_action_free(op);
- dbus_g_method_return(context, rc);
- return TRUE;
+ if (!check_authorization(SERVICES_BUS_NAME ".start", &error, context))
{
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ op = services_action_create(name, "start", 0, timeout);
+ services_action_sync(op);
+ rc = op->rc;
+ services_action_free(op);
+ dbus_g_method_return(context, rc);
+ return TRUE;
}
gboolean
-Services_stop(Matahari *matahari, const char *name, unsigned int timeout,
DBusGMethodInvocation *context)
+Services_stop(Matahari *matahari, const char *name, unsigned int timeout,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- svc_action_t *op;
- int rc;
+ GError* error = NULL;
+ svc_action_t *op;
+ int rc;
- if (!check_authorization(SERVICES_BUS_NAME ".stop", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- op = services_action_create(name, "stop", 0, timeout);
- services_action_sync(op);
- rc = op->rc;
- services_action_free(op);
- dbus_g_method_return(context, rc);
- return TRUE;
+ if (!check_authorization(SERVICES_BUS_NAME ".stop", &error, context))
{
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ op = services_action_create(name, "stop", 0, timeout);
+ services_action_sync(op);
+ rc = op->rc;
+ services_action_free(op);
+ dbus_g_method_return(context, rc);
+ return TRUE;
}
gboolean
-Services_status(Matahari *matahari, const char *name, unsigned int interval, unsigned int
timeout, DBusGMethodInvocation *context)
+Services_status(Matahari *matahari, const char *name, unsigned int interval,
+ unsigned int timeout, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- svc_action_t *op;
- int rc;
+ GError* error = NULL;
+ svc_action_t *op;
+ int rc;
- if (!check_authorization(SERVICES_BUS_NAME ".status", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- op = services_action_create(name, "status", interval, timeout);
- services_action_sync(op);
- rc = op->rc;
- services_action_free(op);
- dbus_g_method_return(context, rc);
- return TRUE;
+ if (!check_authorization(SERVICES_BUS_NAME ".status", &error, context))
{
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ op = services_action_create(name, "status", interval, timeout);
+ services_action_sync(op);
+ rc = op->rc;
+ services_action_free(op);
+ dbus_g_method_return(context, rc);
+ return TRUE;
}
gboolean
-Services_cancel(Matahari *matahari, const char *name, const char *action, unsigned int
interval, DBusGMethodInvocation *context)
+Services_cancel(Matahari *matahari, const char *name, const char *action,
+ unsigned int interval, DBusGMethodInvocation *context)
{
- GError* error = NULL;
- int res;
+ GError* error = NULL;
+ int res;
- if (!check_authorization(SERVICES_BUS_NAME ".cancel", &error, context))
- {
- dbus_g_method_return_error(context, error);
- return FALSE;
- }
- res = services_action_cancel(name, action, interval);
- dbus_g_method_return(context);
- return res;
+ if (!check_authorization(SERVICES_BUS_NAME ".cancel", &error, context))
{
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ res = services_action_cancel(name, action, interval);
+ dbus_g_method_return(context);
+ return res;
}
gboolean
-Services_fail(Matahari *matahari, const char *name, DBusGMethodInvocation *context)
+Services_fail(Matahari *matahari, const char *name,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(SERVICES_BUS_NAME ".fail", &error, context))
- {
+ GError* error = NULL;
+ if (!check_authorization(SERVICES_BUS_NAME ".fail", &error, context))
{
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ // TODO: Implement when implemented in backend
+ error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED,
+ "Action fail is not implemented yet!");
dbus_g_method_return_error(context, error);
- return FALSE;
- }
- // TODO: Implement when implemented in backend
- error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED, "Action fail is not
implemented yet!");
- dbus_g_method_return_error(context, error);
- return TRUE;
+ return TRUE;
}
gboolean
-Services_describe(Matahari *matahari, const char *name, DBusGMethodInvocation *context)
+Services_describe(Matahari *matahari, const char *name,
+ DBusGMethodInvocation *context)
{
- GError* error = NULL;
- if (!check_authorization(SERVICES_BUS_NAME ".describe", &error,
context))
- {
+ GError* error = NULL;
+ if (!check_authorization(SERVICES_BUS_NAME ".describe", &error,
context)) {
+ dbus_g_method_return_error(context, error);
+ return FALSE;
+ }
+ // TODO: Implement when implemented in backend
+ error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED,
+ "Action describe is not implemented yet!");
dbus_g_method_return_error(context, error);
- return FALSE;
- }
- // TODO: Implement when implemented in backend
- error = g_error_new(MATAHARI_ERROR, MATAHARI_NOT_IMPLEMENTED, "Action describe is
not implemented yet!");
- dbus_g_method_return_error(context, error);
- return TRUE;
+ return TRUE;
}
/* Generated dbus stuff for services
@@ -220,37 +221,38 @@ Services_describe(Matahari *matahari, const char *name,
DBusGMethodInvocation *c
void
matahari_set_property(GObject *object, guint property_id, const GValue *value,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
- // We don't have writable other property...
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ // We don't have writable other property...
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
void
matahari_get_property(GObject *object, guint property_id, GValue *value,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
- switch (property_id)
- {
- case PROP_HOSTNAME:
- g_value_set_string (value, mh_hostname());
- break;
- default:
- /* We don't have any other property... */
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
+ switch (property_id) {
+ case PROP_HOSTNAME:
+ g_value_set_string (value, mh_hostname());
+ break;
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
-GType matahari_dict_type(int prop)
+GType
+matahari_dict_type(int prop)
{
- g_printerr("Type of property %s is map of unknown types\n",
properties[prop].name);
- return G_TYPE_VALUE;
+ g_printerr("Type of property %s is map of unknown types\n",
+ properties[prop].name);
+ return G_TYPE_VALUE;
}
int
main(int argc, char** argv)
{
- g_type_init();
- return run_dbus_server(SERVICES_BUS_NAME, SERVICES_OBJECT_PATH);
+ g_type_init();
+ return run_dbus_server(SERVICES_BUS_NAME, SERVICES_OBJECT_PATH);
}
diff --git a/src/service/service-qmf.cpp b/src/service/service-qmf.cpp
index 06c670f..b865921 100644
--- a/src/service/service-qmf.cpp
+++ b/src/service/service-qmf.cpp
@@ -44,26 +44,28 @@ enum service_id {
class SrvAgent : public MatahariAgent
{
- private:
- void action_async(enum service_id service, qmf::AgentSession& session,
- qmf::AgentEvent& event, svc_action_t *op, bool has_rc);
+private:
+ void action_async(enum service_id service, qmf::AgentSession& session,
+ qmf::AgentEvent& event, svc_action_t *op, bool has_rc);
- qmf::Data _services;
- qmf::DataAddr _services_addr;
+ qmf::Data _services;
+ qmf::DataAddr _services_addr;
- qmf::Data _resources;
- qmf::DataAddr _resources_addr;
+ qmf::Data _resources;
+ qmf::DataAddr _resources_addr;
- gboolean invoke_services(qmf::AgentSession session, qmf::AgentEvent event,
gpointer user_data);
- gboolean invoke_resources(qmf::AgentSession session, qmf::AgentEvent event,
gpointer user_data);
+ gboolean invoke_services(qmf::AgentSession session,
+ qmf::AgentEvent event, gpointer user_data);
+ gboolean invoke_resources(qmf::AgentSession session,
+ qmf::AgentEvent event, gpointer user_data);
- qmf::org::matahariproject::PackageDefinition _package;
+ qmf::org::matahariproject::PackageDefinition _package;
- public:
- virtual int setup(qmf::AgentSession session);
- virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
- gpointer user_data);
- void raiseEvent(svc_action_t *op, enum service_id service);
+public:
+ virtual int setup(qmf::AgentSession session);
+ virtual gboolean invoke(qmf::AgentSession session,
+ qmf::AgentEvent event, gpointer user_data);
+ void raiseEvent(svc_action_t *op, enum service_id service);
};
/**
@@ -115,7 +117,7 @@ AsyncCB::mh_async_callback(svc_action_t *op)
cb_data->first_result = false;
} else if (cb_data->last_rc != op->rc) {
mh_trace("Result changed on recurring action: was '%d', now
'%d'\n",
- cb_data->last_rc, op->rc);
+ cb_data->last_rc, op->rc);
cb_data->agent->raiseEvent(op, cb_data->service);
}
@@ -127,13 +129,14 @@ AsyncCB::mh_async_callback(svc_action_t *op)
}
}
-static GHashTable *qmf_map_to_hash(::qpid::types::Variant::Map parameters)
+static GHashTable *
+qmf_map_to_hash(::qpid::types::Variant::Map parameters)
{
qpid::types::Variant::Map::const_iterator qIter;
GHashTable *hash = g_hash_table_new_full(
g_str_hash, g_str_equal, free, free);
- for (qIter=parameters.begin() ; qIter != parameters.end(); qIter++ ) {
+ for (qIter = parameters.begin(); qIter != parameters.end(); qIter++) {
char *key = strdup(qIter->first.c_str());
char *value = strdup(qIter->second.asString().c_str());
g_hash_table_insert(hash, key, value);
@@ -148,7 +151,7 @@ main(int argc, char **argv)
SrvAgent agent;
int rc = agent.init(argc, argv, "service");
- if(rc >= 0) {
+ if (rc >= 0) {
mainloop_track_children(G_PRIORITY_DEFAULT);
agent.run();
}
@@ -156,7 +159,8 @@ main(int argc, char **argv)
return rc;
}
-void SrvAgent::raiseEvent(svc_action_t *op, enum service_id service)
+void
+SrvAgent::raiseEvent(svc_action_t *op, enum service_id service)
{
uint64_t timestamp = 0L;
qmf::Data event;
@@ -165,7 +169,7 @@ void SrvAgent::raiseEvent(svc_action_t *op, enum service_id service)
timestamp = ::time(NULL);
#endif
- if(service) {
+ if (service) {
event = qmf::Data(_package.event_service_op);
} else {
event = qmf::Data(_package.event_resource_op);
@@ -209,10 +213,11 @@ SrvAgent::setup(qmf::AgentSession session)
}
gboolean
-SrvAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data)
+SrvAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data)
{
- if(event.getType() == qmf::AGENT_METHOD && event.hasDataAddr()) {
- if(_services_addr == event.getDataAddr()) {
+ if (event.getType() == qmf::AGENT_METHOD && event.hasDataAddr()) {
+ if (_services_addr == event.getDataAddr()) {
mh_info("Calling services API");
return invoke_services(session, event, user_data);
}
@@ -234,11 +239,12 @@ SrvAgent::action_async(enum service_id service,
qmf::AgentSession& session,
}
gboolean
-SrvAgent::invoke_services(qmf::AgentSession session, qmf::AgentEvent event, gpointer
user_data)
+SrvAgent::invoke_services(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data)
{
static const int default_timeout_ms = 60000;
const std::string& methodName(event.getMethodName());
- if(event.getType() != qmf::AGENT_METHOD) {
+ if (event.getType() != qmf::AGENT_METHOD) {
return TRUE;
}
@@ -250,8 +256,8 @@ SrvAgent::invoke_services(qmf::AgentSession session, qmf::AgentEvent
event, gpoi
GList *gIter = NULL;
GList *services = services_list();
- for(gIter = services; gIter != NULL; gIter = gIter->next) {
- s_list.push_back((const char *)gIter->data);
+ for (gIter = services; gIter != NULL; gIter = gIter->next) {
+ s_list.push_back((const char *) gIter->data);
}
event.addReturnArgument("services", s_list);
@@ -313,10 +319,11 @@ SrvAgent::invoke_services(qmf::AgentSession session, qmf::AgentEvent
event, gpoi
}
gboolean
-SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent event, gpointer
user_data)
+SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data)
{
const std::string& methodName(event.getMethodName());
- if(event.getType() != qmf::AGENT_METHOD) {
+ if (event.getType() != qmf::AGENT_METHOD) {
return TRUE;
}
@@ -334,8 +341,8 @@ SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent
event, gpo
GList *providers = resources_list_ocf_providers();
_qtype::Variant::List p_list;
- for(gIter = providers; gIter != NULL; gIter = gIter->next) {
- p_list.push_back((const char *)gIter->data);
+ for (gIter = providers; gIter != NULL; gIter = gIter->next) {
+ p_list.push_back((const char *) gIter->data);
}
event.addReturnArgument("providers", p_list);
@@ -345,8 +352,8 @@ SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent
event, gpo
args["provider"].asString().c_str());
_qtype::Variant::List t_list;
- for(gIter = agents; gIter != NULL; gIter = gIter->next) {
- t_list.push_back((const char *)gIter->data);
+ for (gIter = agents; gIter != NULL; gIter = gIter->next) {
+ t_list.push_back((const char *) gIter->data);
}
event.addReturnArgument("types", t_list);
diff --git a/src/tests/t_dnssrv.c b/src/tests/t_dnssrv.c
index 0829f64..91b2772 100644
--- a/src/tests/t_dnssrv.c
+++ b/src/tests/t_dnssrv.c
@@ -24,10 +24,10 @@ int main(int argc, char **argv)
struct srv_reply **srvl = NULL, *srv = NULL;
int i;
- if(srvl = srv_lookup("qpid-broker", "tcp",
"qpid-broker:49000")) {
+ if (srvl = srv_lookup("qpid-broker", "tcp",
"qpid-broker:49000")) {
srv = *srvl;
- for(i = 1; srvl[i]; i++) {
- if(srvl[i]->prio < srv->prio)
+ for (i = 1; srvl[i]; i++) {
+ if (srvl[i]->prio < srv->prio)
srv = srvl[i];
}
--
1.7.5.1