[PATCH 1/5] Make build output slightly less verbose.
by russell@russellbryant.net
This tells gnu make not to print out messages as it enters and leaves
directories.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
GNUmakefile | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/GNUmakefile b/GNUmakefile
index ce16738..8cf41cf 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -37,13 +37,13 @@ linux.build:
@echo "=::=::=::= Setting up for Linux =::=::=::= "
mkdir -p $@
cd $@ && eval "`rpm --eval "%{cmake}" | grep -v -e "^%"`" -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
- @$(MAKE) -C $@
+ @$(MAKE) --no-print-dir -C $@
windows.build:
@echo "=::=::=::= Setting up for Windows =::=::=::= "
mkdir -p $@
cd $@ && eval "`rpm --eval "%{_mingw32_cmake}"`" -DCMAKE_BUILD_TYPE=Release ..
- @$(MAKE) -C $@
+ @$(MAKE) --no-print-dir -C $@
%.check: %.build
DESTDIR=`pwd`/$@ make -C $^ all install
--
1.7.4
13 years, 1 month
[PATCH] src/lib/utilities.c: Fix/simplify part of matahari_uuid()
by russell@russellbryant.net
I first started looking at this particular function because of a
warning emitted by valgrind:
==18466== Conditional jump or move depends on uninitialised value(s)
==18466== at 0x3186A4919E: vfprintf (in /lib64/libc-2.13.90.so)
==18466== by 0x3186A71451: vsnprintf (in /lib64/libc-2.13.90.so)
==18466== by 0x3186A51FE1: snprintf (in /lib64/libc-2.13.90.so)
==18466== by 0x4C20697: host_os_get_uuid (in /usr/lib64/libmhost.so.0.0.1)
==18466== by 0x40CC9D: HostAgent::setup(qpid::management::ManagementAgent*) (in /usr/sbin/matahari-hostd)
==18466== by 0x43A9AA: MatahariAgent::init(int, char**, char const*) (in /usr/sbin/matahari-hostd)
==18466== by 0x40BB9E: main (in /usr/sbin/matahari-hostd)
The changes are:
1) Instead of open coding a loop looking for an end of line or
the end of the buffer, use strchrnul().
2) The old code ignored a possible allocation failure and would
have crashed on snprintf() in that rare case.
3) The old code would also leak memory if the input file had
more than one line in it.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/lib/utilities.c | 12 +++---------
1 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/src/lib/utilities.c b/src/lib/utilities.c
index cb822fe..01bf26a 100644
--- a/src/lib/utilities.c
+++ b/src/lib/utilities.c
@@ -374,15 +374,9 @@ const char *matahari_uuid(void)
uuid = strdup("unknown");
} else {
- int lpc = 0;
- for (; lpc < data_length; lpc++) {
- switch(buffer[lpc]) {
- case '\0':
- case '\n':
- uuid = malloc(lpc);
- snprintf(uuid, lpc-1, "%s", buffer);
- }
- }
+ char *tmp = strchrnul(buffer, '\n');
+ *tmp = '\0';
+ uuid = strdup(buffer);
}
if(input) {
fclose(input);
--
1.7.4
13 years, 1 month
[PATCH] src/lib/utilities.c: resolve compiler warning
by russell@russellbryant.net
Constify a variable so that the compiler is happy with the usage of
matahari_uuid().
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
CMakeLists.txt | 2 +-
src/lib/utilities.c | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 19db062..8431e6b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 2.6)
project (MATAHARI)
-set(CMAKE_VERBOSE_MAKEFILE ON)
+set(CMAKE_VERBOSE_MAKEFILE OFF)
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "4")
diff --git a/src/lib/utilities.c b/src/lib/utilities.c
index b9d2e0d..cb822fe 100644
--- a/src/lib/utilities.c
+++ b/src/lib/utilities.c
@@ -332,7 +332,7 @@ mh_log_fn(int priority, const char * fmt, ...)
const char *matahari_hostname(void)
{
- static char *hostname = NULL;
+ static const char *hostname = NULL;
if(hostname == NULL) {
sigar_t *sigar;
@@ -343,11 +343,12 @@ const char *matahari_hostname(void)
}
if(hostname != NULL && strcmp(hostname, "localhost") == 0) {
- free(hostname);
+ free((char *) hostname);
hostname = matahari_uuid();
}
mh_trace("Got hostname: %s", hostname);
+
return hostname;
}
--
1.7.4
13 years, 1 month
[PATCH] src/lib/host.c: Resolve memory leaks, minor optimizations
by russell@russellbryant.net
1) Fix memory leaks in host_get_operating_system() and
host_get_architecture(). The code was written as if the local data
buffer was static, but it was not.
2) Minor optimizations - localize variables, only call init() when
the local buffer has not already been populated.
3) One formatting tweak to move a return to its own line.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/lib/host.c | 20 +++++++++++++-------
1 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/lib/host.c b/src/lib/host.c
index 73e1f6a..cd40db2 100644
--- a/src/lib/host.c
+++ b/src/lib/host.c
@@ -47,7 +47,9 @@ cpuinfo_t cpuinfo = { NULL, 0, 0 };
static void
init(void)
{
- if(host_init.sigar_init) return;
+ if(host_init.sigar_init) {
+ return;
+ }
sigar_open(&host_init.sigar);
host_init.sigar_init = TRUE;
}
@@ -67,14 +69,16 @@ host_get_hostname(void)
const char *
host_get_operating_system(void)
{
- init();
- sigar_sys_info_t sysinfo;
- char *operating_system = NULL;
+ static const char *operating_system = NULL;
if(operating_system == NULL) {
+ sigar_sys_info_t sysinfo;
+
+ init();
sigar_sys_info_get(host_init.sigar, &sysinfo);
operating_system = g_strdup_printf("%s (%s)", sysinfo.vendor_name, sysinfo.version);
}
+
return operating_system;
}
@@ -87,14 +91,16 @@ host_get_cpu_wordsize(void)
const char *
host_get_architecture(void)
{
- init();
- sigar_sys_info_t sysinfo;
- char *arch = NULL;
+ static const char *arch = NULL;
if(arch == NULL) {
+ sigar_sys_info_t sysinfo;
+
+ init();
sigar_sys_info_get(host_init.sigar, &sysinfo);
arch = g_strdup(sysinfo.arch);
}
+
return arch;
}
--
1.7.4
13 years, 1 month
[PATCH] src/lib/host_linux.c: refactor host_os_get_cpu_flags().
by russell@russellbryant.net
This patch refactors a lot of host_get_cpu_flags() and addresses
the following things:
1) Gracefully handle the case where /proc/cpuinfo can't be opened
for some reason.
2) Gracefully handle memory allocation failures.
3) Add a call to pcre_free() so that there is not a memory leak
of the compiled regex.
4) Eliminate unnecessary malloc()/free() calls to improve efficiency.
5) Refactor the loop that looks through the cpuinfo output to take
less code and be more readable (at least to me).
6) Reduce nesting, make formatting more consistent.
7) Localize some variables, make constants static const.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/lib/host_linux.c | 130 ++++++++++++++++++++++++++------------------------
1 files changed, 67 insertions(+), 63 deletions(-)
diff --git a/src/lib/host_linux.c b/src/lib/host_linux.c
index f522562..96e1303 100644
--- a/src/lib/host_linux.c
+++ b/src/lib/host_linux.c
@@ -35,83 +35,89 @@
#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;
-
- size_t chunk = 512;
+
size_t read_chars = 0;
size_t data_length = 0;
-
char *buffer = NULL;
FILE *input = NULL;
+ const char *pcre_error;
+ int pcre_error_offset;
+ pcre *regex = NULL;
+ char *cur, *next;
+
+ if (flags) {
+ return flags;
+ }
- if(flags) {
- return flags;
+ if (!(input = fopen("/proc/cpuinfo", "r"))) {
+ goto done;
}
-
- input = fopen("/proc/cpuinfo", "r");
do {
- buffer = realloc(buffer, chunk + data_length + 1);
- read_chars = fread(buffer + data_length, 1, chunk, input);
- data_length += read_chars;
+ static const size_t chunk = 512;
+
+ 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 /proc/cpuinfo");
-
- } else {
- const char *regexstr = "(.*\\S)\\s*:\\s*(\\S.*)";
- int expected = 3;
- int found[9];
- const char* pcre_error;
- int pcre_error_offset;
- pcre* regex;
- int offset = 0, lpc = 0, match = 0;
-
- buffer[data_length] = '\0';
- 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);
- goto done;
- }
-
- for(lpc = 0; lpc < data_length; lpc++) {
-
- switch(buffer[lpc]) {
- case '\n':
- case '\0':
- match = pcre_exec(regex, NULL, buffer+offset, lpc-offset,
- 0, PCRE_NOTEMPTY, found, 9);
-
- if(match == expected) {
- char *name = malloc(2 + found[3] - found[2]);
- snprintf(name, 1 + found[3] - found[2], "%s", buffer + offset + found[2]);
-
- if (strcmp(name, "flags") == 0) {
- flags = malloc(2 + found[5] - found[4]);
- snprintf(flags, 1 + found[5] - found[4], "%s", buffer + offset + found[4]);
- free(name);
- goto done;
- }
- free(name);
- }
- offset = lpc+1;
- }
- }
+ if (data_length == 0) {
+ mh_warn("Could not read from /proc/cpuinfo");
+ goto done;
+ }
+
+ buffer[data_length] = '\0';
+
+ 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);
+ goto done;
}
-
- done:
- fclose(input);
+
+ next = buffer;
+ while ((cur = strsep(&next, "\n"))) {
+ static const int expected = 3;
+ size_t len;
+ int match;
+ int found[9];
+
+ match = pcre_exec(regex, NULL, cur, strlen(cur),
+ 0, PCRE_NOTEMPTY, found,
+ sizeof(found) / sizeof(found[0]));
+
+ if (match != expected || strncmp(cur + found[2], "flags", 5)) {
+ continue;
+ }
+
+ len = 1 + found[5] - found[4];
+ if (!(flags = malloc(len))) {
+ goto done;
+ }
+ strncpy(flags, cur + found[4], len);
+ flags[len - 1] = '\0';
+ break;
+ }
+
+done:
+ if (input) {
+ fclose(input);
+ }
+
free(buffer);
- if(flags == NULL) {
- flags = strdup("unknown");
+ if (regex) {
+ pcre_free(regex);
}
-
+
+ if (flags == NULL) {
+ flags = strdup("unknown");
+ }
+
return flags;
}
@@ -126,5 +132,3 @@ host_os_shutdown(void)
{
reboot(LINUX_REBOOT_CMD_HALT);
}
-
-
--
1.7.4
13 years, 1 month
[PATCH] MatahariAgent: formatting changes
by russell@russellbryant.net
Strip trailing whitespace. Resolve mixed usage of tabs and spaces
for indentation.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/lib/mh_agent.cpp | 308 ++++++++++++++++++++++++-------------------------
1 files changed, 151 insertions(+), 157 deletions(-)
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index e103dc1..2048b53 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -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
@@ -64,21 +64,21 @@ RegistryRead (HKEY hHive, const wchar_t *szKeyPath, const wchar_t *szValue, char
DWORD nSize = BUFFER_SIZE;
wchar_t szData[BUFFER_SIZE];
long lSuccess = RegOpenKey (hHive, szKeyPath, &hKey);
-
+
if (lSuccess != ERROR_SUCCESS) {
- mh_debug("Could not open %ls key from the registry: %ld", szKeyPath, lSuccess);
- return;
+ mh_debug("Could not open %ls key from the registry: %ld", szKeyPath, lSuccess);
+ return;
}
-
+
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);
- return;
+ 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);
+ *out = (char *)malloc( BUFFER_SIZE );
+ wcstombs(*out, szData, (size_t)BUFFER_SIZE);
}
}
#else
@@ -109,15 +109,15 @@ print_usage(const char *proc_name)
}
#endif
-static gboolean
+static gboolean
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()) {
- mh_trace("Message is for %s (type: %s)",
- event.getDataAddr().getName().c_str(),
- event.getDataAddr().getAgentName().c_str());
+ mh_trace("Message is for %s (type: %s)",
+ event.getDataAddr().getName().c_str(),
+ event.getDataAddr().getAgentName().c_str());
}
return agent->invoke(session, event, user_data);
}
@@ -147,159 +147,153 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
int serverport = MATAHARI_PORT;
/* Set up basic logging */
- mh_log_init(proc_name, LOG_INFO, FALSE);
+ mh_log_init(proc_name, LOG_INFO, FALSE);
#ifdef WIN32
- RegistryRead (
- HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- L"DebugLevel",
- &value);
+ RegistryRead(HKEY_LOCAL_MACHINE,
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"DebugLevel",
+ &value);
if(value) {
- mh_log_level = LOG_INFO+atoi(value);
- free(value);
- value = NULL;
+ mh_log_level = LOG_INFO+atoi(value);
+ free(value);
+ value = NULL;
}
-
- RegistryRead (
- HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- L"Broker",
- &value);
+
+ RegistryRead(HKEY_LOCAL_MACHINE,
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"Broker",
+ &value);
if(value) {
- servername = value;
- free(value);
- value = NULL;
+ servername = value;
+ free(value);
+ value = NULL;
}
- RegistryRead (
- HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- L"Port",
- &value);
+ RegistryRead(HKEY_LOCAL_MACHINE,
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"Port",
+ &value);
if(value) {
- serverport = atoi(value);
- free(value);
- value = NULL;
+ serverport = atoi(value);
+ free(value);
+ value = NULL;
}
- RegistryRead (
- HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- L"Service",
- &value);
+ RegistryRead(HKEY_LOCAL_MACHINE,
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"Service",
+ &value);
if(value) {
- service = value;
- free(value);
- value = NULL;
+ service = value;
+ free(value);
+ value = NULL;
}
- RegistryRead (
- HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- L"User",
- &value);
+ RegistryRead(HKEY_LOCAL_MACHINE,
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"User",
+ &value);
if(value) {
username = value;
- free(value);
- value = NULL;
+ free(value);
+ value = NULL;
}
- RegistryRead (
- HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- L"Password",
- &value);
+ RegistryRead(HKEY_LOCAL_MACHINE,
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"Password",
+ &value);
if(value) {
password = value;
- free(value);
- value = NULL;
+ free(value);
+ value = NULL;
}
#else
-
+
// Get args
while ((arg = getopt_long(argc, argv, "hdb:gu:P:s:p:v", opt, &idx)) != -1) {
- switch (arg) {
- case 'h':
- case '?':
- print_usage(proc_name);
- exit(0);
- break;
- case 'd':
- daemonize = true;
- break;
- case 'v':
- mh_log_level++;
- mh_enable_stderr(1);
- break;
- case 's':
- if (optarg) {
- service = optarg;
- } else {
- print_usage(proc_name);
- exit(1);
- }
- break;
- case 'u':
- if (optarg) {
- username = optarg;
- } else {
- print_usage(proc_name);
- exit(1);
- }
- break;
- case 'P':
- if (optarg) {
- password = optarg;
- } else {
- print_usage(proc_name);
- exit(1);
- }
- break;
- case 'g':
- gssapi = true;
- break;
- case 'p':
- if (optarg) {
- serverport = atoi(optarg);
- } else {
- print_usage(proc_name);
- exit(1);
- }
- break;
- case 'b':
- if (optarg) {
- servername = optarg;
- } else {
- print_usage(proc_name);
- exit(1);
- }
- break;
- default:
- fprintf(stderr, "unsupported option '-%c'. See --help.\n", arg);
- print_usage(proc_name);
- exit(0);
- break;
- }
+ switch (arg) {
+ case 'h':
+ case '?':
+ print_usage(proc_name);
+ exit(0);
+ break;
+ case 'd':
+ daemonize = true;
+ break;
+ case 'v':
+ mh_log_level++;
+ mh_enable_stderr(1);
+ break;
+ case 's':
+ if (optarg) {
+ service = optarg;
+ } else {
+ print_usage(proc_name);
+ exit(1);
+ }
+ break;
+ case 'u':
+ if (optarg) {
+ username = optarg;
+ } else {
+ print_usage(proc_name);
+ exit(1);
+ }
+ break;
+ case 'P':
+ if (optarg) {
+ password = optarg;
+ } else {
+ print_usage(proc_name);
+ exit(1);
+ }
+ break;
+ case 'g':
+ gssapi = true;
+ break;
+ case 'p':
+ if (optarg) {
+ serverport = atoi(optarg);
+ } else {
+ print_usage(proc_name);
+ exit(1);
+ }
+ break;
+ case 'b':
+ if (optarg) {
+ servername = optarg;
+ } else {
+ print_usage(proc_name);
+ exit(1);
+ }
+ break;
+ default:
+ fprintf(stderr, "unsupported option '-%c'. See --help.\n", arg);
+ print_usage(proc_name);
+ exit(0);
+ break;
+ }
}
if (daemonize == true) {
- if (daemon(0, 0) < 0) {
- fprintf(stderr, "Error daemonizing: %s\n", strerror(errno));
- exit(1);
- }
+ if (daemon(0, 0) < 0) {
+ fprintf(stderr, "Error daemonizing: %s\n", strerror(errno));
+ exit(1);
+ }
}
#endif
if (servername.length() == 0) {
- servername = MATAHARI_BROKER;
+ servername = MATAHARI_BROKER;
}
/* Re-initialize logging now that we've completed option processing */
@@ -312,16 +306,16 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
qpid::types::Variant::Map options;
options["reconnect"] = bool(true);
if (!username.empty()) {
- options["username"] = username.c_str();
+ options["username"] = username.c_str();
}
if (!password.empty()) {
- options["password"] = password.c_str();
+ options["password"] = password.c_str();
}
if (!service.empty()) {
- options["sasl-service"] = service.c_str();
+ options["sasl-service"] = service.c_str();
}
if (gssapi) {
- options["sasl-mechanism"] = "GSSAPI";
+ options["sasl-mechanism"] = "GSSAPI";
}
std::stringstream url;
@@ -341,14 +335,14 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
/* Do any setup required by our agent */
if(this->setup(_agent_session) < 0) {
- mh_err("Failed to set up broker connection to %s for %s\n",
- url.str().c_str(), proc_name);
- return -1;
+ mh_err("Failed to set up broker connection to %s for %s\n",
+ url.str().c_str(), proc_name);
+ return -1;
}
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 0;
}
@@ -365,9 +359,9 @@ mainloop_qmf_prepare(GSource* source, gint *timeout)
{
mainloop_qmf_t *qmf = (mainloop_qmf_t*)source;
if (qmf->event) {
- return TRUE;
+ return TRUE;
}
-
+
*timeout = 1;
return FALSE;
}
@@ -377,10 +371,9 @@ mainloop_qmf_check(GSource* source)
{
mainloop_qmf_t *qmf = (mainloop_qmf_t*)source;
if (qmf->event) {
- return TRUE;
-
+ return TRUE;
} else if(qmf->session.nextEvent(qmf->event, qpid::messaging::Duration::IMMEDIATE)) {
- return TRUE;
+ return TRUE;
}
return FALSE;
}
@@ -391,15 +384,15 @@ mainloop_qmf_dispatch(GSource *source, GSourceFunc callback, gpointer userdata)
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) {
- g_source_unref(source); /* Really? */
- return FALSE;
- }
+ qmf::AgentEvent event = qmf->event;
+ qmf->event = NULL;
+
+ if(qmf->dispatch(qmf->session, event, qmf->user_data) == FALSE) {
+ g_source_unref(source); /* Really? */
+ return FALSE;
+ }
}
-
+
return TRUE;
}
@@ -410,7 +403,7 @@ mainloop_qmf_destroy(GSource* source)
mh_trace("%p", source);
if (qmf->dnotify) {
- qmf->dnotify(qmf->user_data);
+ qmf->dnotify(qmf->user_data);
}
}
@@ -423,8 +416,9 @@ static GSourceFuncs mainloop_qmf_funcs = {
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;
@@ -447,7 +441,7 @@ mainloop_add_qmf(int priority, qmf::AgentSession session,
g_source_set_priority(source, priority);
g_source_set_can_recurse(source, FALSE);
-
+
qmf_source->id = g_source_attach(source, NULL);
mh_info("Added source: %d", qmf_source->id);
return qmf_source;
@@ -459,6 +453,6 @@ mainloop_destroy_qmf(mainloop_qmf_t* source)
g_source_remove(source->id);
source->id = 0;
g_source_unref((GSource*)source);
-
+
return TRUE;
}
--
1.7.4
13 years, 1 month
[PATCH] Allow a full build using a top level 'make'.
by russell@russellbryant.net
The top-level Makefile runs cmake to generate a build system and then
instructs you to cd into the appropriate directory to complete the
build. This patch just allows you to run 'make' from the top level
directory to both run cmake and do the full build.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
GNUmakefile | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/GNUmakefile b/GNUmakefile
index f7fc981..ce16738 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -37,13 +37,13 @@ linux.build:
@echo "=::=::=::= Setting up for Linux =::=::=::= "
mkdir -p $@
cd $@ && eval "`rpm --eval "%{cmake}" | grep -v -e "^%"`" -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
- @echo "Now enter the $@ directory and run 'make' as usual"
+ @$(MAKE) -C $@
windows.build:
@echo "=::=::=::= Setting up for Windows =::=::=::= "
mkdir -p $@
cd $@ && eval "`rpm --eval "%{_mingw32_cmake}"`" -DCMAKE_BUILD_TYPE=Release ..
- @echo "Now enter the $@ directory and run 'make' as usual"
+ @$(MAKE) -C $@
%.check: %.build
DESTDIR=`pwd`/$@ make -C $^ all install
--
1.7.4
13 years, 1 month
[PATCH] Fix a couple of bugs in src/lib/network_linux.c.
by russell@russellbryant.net
1) There was a memory leak here. The 2nd argument was allocated
with strdup(), but as far as I can tell, it's not necessary.
2) There was some stack corruption happening here, too. The argv
array was only declared as 2 elements, but the code wrote into the
3rd index of the array.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/lib/network_linux.c | 14 ++++++--------
1 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/lib/network_linux.c b/src/lib/network_linux.c
index 2fc1420..94f424c 100644
--- a/src/lib/network_linux.c
+++ b/src/lib/network_linux.c
@@ -26,13 +26,12 @@
void
network_os_start(const char *iface)
{
- char *argv[2];
gboolean ret;
GError *error = NULL;
+ gchar *argv[] = {
+ "/sbin/ifup", iface, NULL
+ };
- argv[0] = "/sbin/ifup";
- argv[1] = strdup(iface);
- argv[2] = NULL;
ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
if(ret == FALSE) {
g_error_free(error);
@@ -42,13 +41,12 @@ network_os_start(const char *iface)
void
network_os_stop(const char *iface)
{
- char *argv[2];
gboolean ret;
GError *error = NULL;
+ gchar *argv[] = {
+ "/sbin/ifdown", iface, NULL
+ };
- argv[0] = "/sbin/ifdown";
- argv[1] = strdup(iface);
- argv[2] = NULL;
ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
if(ret == FALSE) {
g_error_free(error);
--
1.7.4
13 years, 1 month
[PATCH] Add linux.build to .gitignore
by russell@russellbryant.net
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
.gitignore | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
index 6d5748c..3ecf135 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,3 +22,4 @@ build
build-win
src/include/matahari.h
src/matahari-*
+linux.build
--
1.7.4
13 years, 1 month