Send Linux-ha-cvs mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]
You can reach the person managing the list at
[EMAIL PROTECTED]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Linux-ha-cvs digest..."
Today's Topics:
1. Linux-HA CVS: cim by panjiam from
([email protected])
2. Linux-HA CVS: cim by panjiam from
([email protected])
----------------------------------------------------------------------
Message: 1
Date: Wed, 22 Mar 2006 01:52:31 -0700 (MST)
From: [email protected]
Subject: [Linux-ha-cvs] Linux-HA CVS: cim by panjiam from
To: [EMAIL PROTECTED]
Message-ID: <[EMAIL PROTECTED]>
linux-ha CVS committal
Author : panjiam
Host :
Project : linux-ha
Module : cim
Dir : linux-ha/cim
Modified Files:
utils.c
Log Message:
caculate length before malloc, avoid realloc
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/cim/utils.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- utils.c 22 Mar 2006 02:49:30 -0000 1.2
+++ utils.c 22 Mar 2006 08:52:31 -0000 1.3
@@ -11,6 +11,7 @@
#include <sys/types.h>
#include <regex.h>
#include <hb_api.h>
+#include <errno.h>
#include <heartbeat.h>
#include "cluster_info.h"
#include "utils.h"
@@ -38,19 +39,22 @@
}
int
-run_shell_cmnd(const char * cmnd, int * ret,
- char *** out, char *** err)
+run_shell_cmnd(const char *cmnd, int *ret, char ***out, char ***err)
/* err not used currently */
{
FILE * fstream = NULL;
char buffer [4096];
int cmnd_rc, rc, i;
+ DEBUG_ENTER();
if ( (fstream = popen(cmnd, "r")) == NULL ){
+ cl_log(LOG_ERR, "run_shell_cmnd: popen error: %s",
+ strerror(errno));
return HA_FAIL;
}
if ( (*out = cim_malloc(sizeof(char*)) ) == NULL ) {
+ cl_log(LOG_ERR, "run_shell_cmnd: failed malloc.");
return HA_FAIL;
}
@@ -80,6 +84,8 @@
cl_log(LOG_WARNING, "failed to close pipe.");
}
*ret = cmnd_rc;
+
+ DEBUG_LEAVE();
return rc;
}
@@ -87,51 +93,49 @@
regex_search(const char * reg, const char * str, int * len)
{
regex_t regexp;
- const size_t nmatch = 16; /* max match times */
+ const int maxmatch = 16;
regmatch_t pm[16];
- int i;
- int ret;
- char ** match = NULL;
+ int i, ret, nmatch = 0;
+ char **match = NULL;
+
+ DEBUG_ENTER();
+ *len = 0;
ret = regcomp(®exp, reg, REG_EXTENDED);
if ( ret != 0) {
- cl_log(LOG_ERR, "Error regcomp regex %s", reg);
+ cl_log(LOG_ERR, "regex_search: error regcomp regex %s.", reg);
return HA_FAIL;
}
ret = regexec(®exp, str, nmatch, pm, 0);
if ( ret == REG_NOMATCH ){
regfree(®exp);
+ cl_log(LOG_ERR, "regex_search: no match.");
return NULL;
}else if (ret != 0){
- cl_log(LOG_ERR, "Error regexec\n");
+ cl_log(LOG_ERR, "regex_search: error regexec.\n");
regfree(®exp);
return NULL;
}
- *len = 0;
- for(i = 0; i < nmatch && pm[i].rm_so != -1; i++){
- int str_len = pm[i].rm_eo - pm[i].rm_so;
-
- match = cim_realloc(match, (i+1) * sizeof(char*));
- if ( match == NULL ) {
- free_2d_array(match, i, cim_free);
- regfree(®exp);
- return NULL;
- }
+ for(nmatch=0; pm[nmatch++].rm_so != -1 && nmatch <= maxmatch; );
+ cl_log(LOG_INFO, "%d, matched ", nmatch);
+ if ( (match = cim_malloc(nmatch*sizeof(char *))) == NULL ) {
+ cl_log(LOG_ERR, "regex_search: alloc_failed.");
+ regfree(®exp);
+ return NULL;
+ }
+
+ *len = nmatch;
+ for(i = 0; i < maxmatch && i < nmatch; i++){
+ int str_len = pm[i].rm_eo - pm[i].rm_so;
match[i] = cim_malloc(str_len + 1);
- if ( match[i] == NULL ) {
- free_2d_array(match, i, cim_free);
- regfree(®exp);
- return NULL;
- }
-
strncpy( match[i], str + pm[i].rm_so, str_len);
match[i][str_len] = EOS;
}
- *len = i;
regfree(®exp);
+ DEBUG_LEAVE();
return match;
}
@@ -213,10 +217,10 @@
}
char **
-split_string(const char * string, int * len, const char * delim)
+split_string(const char* string, int *len, const char *delim)
{
- char ** strings = NULL;
- const char * p;
+ char **strings = NULL;
+ const char *p;
*len = 0;
while(*string){
------------------------------
Message: 2
Date: Wed, 22 Mar 2006 01:58:04 -0700 (MST)
From: [email protected]
Subject: [Linux-ha-cvs] Linux-HA CVS: cim by panjiam from
To: [EMAIL PROTECTED]
Message-ID: <[EMAIL PROTECTED]>
linux-ha CVS committal
Author : panjiam
Host :
Project : linux-ha
Module : cim
Dir : linux-ha/cim
Modified Files:
utils.c utils.h
Log Message:
fixed a calculation error
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/cim/utils.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- utils.c 22 Mar 2006 08:52:31 -0000 1.3
+++ utils.c 22 Mar 2006 08:58:04 -0000 1.4
@@ -118,8 +118,7 @@
return NULL;
}
- for(nmatch=0; pm[nmatch++].rm_so != -1 && nmatch <= maxmatch; );
- cl_log(LOG_INFO, "%d, matched ", nmatch);
+ for(nmatch=0; pm[nmatch].rm_so != -1 && nmatch < maxmatch; nmatch++);
if ( (match = cim_malloc(nmatch*sizeof(char *))) == NULL ) {
cl_log(LOG_ERR, "regex_search: alloc_failed.");
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/cim/utils.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- utils.h 22 Mar 2006 02:49:30 -0000 1.2
+++ utils.h 22 Mar 2006 08:58:04 -0000 1.3
@@ -218,8 +218,7 @@
void dump_cim_table(CIMTable *table, const char *id);
int cim_init_logger(const char* entity);
void cim_assert(const char* assertion, int line, const char* file);
-int run_shell_cmnd(const char* cmnd,
- int* ret, char*** out, char*** err);
+int run_shell_cmnd(const char* cmnd,int* ret,char*** out,char***);
char ** regex_search(const char * reg, const char * str, int *
len);
void free_2d_array(void *array, int len, cim_free_t free);
void free_2d_zarray(void *zarray, cim_free_t free);
------------------------------
_______________________________________________
Linux-ha-cvs mailing list
[email protected]
http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs
End of Linux-ha-cvs Digest, Vol 28, Issue 55
********************************************