forked from menault/TD2_DEV51_Qualite_Algo
compte rendu
This commit is contained in:
@@ -22,6 +22,32 @@
|
||||
Return value :
|
||||
Ping value as a string or NULL if an error occured
|
||||
*/
|
||||
|
||||
char* ifFunct(FILE* fd, regex_t *p_reg, regmatch_t* pmatch){
|
||||
char* ping = NULL;
|
||||
if(p_reg == NULL){
|
||||
return ping; /* NULL */
|
||||
}
|
||||
if(fd == NULL){
|
||||
free(p_reg);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0){
|
||||
//if(p_reg != NULL){
|
||||
free(p_reg);
|
||||
//}
|
||||
(void) fclose(fd);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
if(pmatch == NULL){
|
||||
(void) fclose(fd);
|
||||
regfree(p_reg);
|
||||
free(p_reg);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
return ping;
|
||||
}
|
||||
|
||||
/*@null@*/char* get_ping_from_temp_log(){
|
||||
|
||||
/* Variables */
|
||||
@@ -38,34 +64,19 @@
|
||||
|
||||
/* regex struct memory allocation */
|
||||
p_reg = (regex_t *) malloc(sizeof(*p_reg));
|
||||
if(p_reg == NULL){
|
||||
return ping; /* NULL */
|
||||
}
|
||||
|
||||
|
||||
/* Open ping log file */
|
||||
fd = fopen("/var/log/ping-report/last-ping.log","r");
|
||||
if(fd == NULL){
|
||||
free(p_reg);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
|
||||
|
||||
/* Construct regex to get ping from log file */
|
||||
if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0){
|
||||
if(p_reg != NULL){
|
||||
free(p_reg);
|
||||
}
|
||||
(void) fclose(fd);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
|
||||
|
||||
/* match info memory allocation */
|
||||
pmatch = malloc(sizeof(*pmatch) * nmatch);
|
||||
if(pmatch == NULL){
|
||||
(void) fclose(fd);
|
||||
regfree(p_reg);
|
||||
free(p_reg);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
|
||||
ping = ifFunct(fd, p_reg, pmatch);
|
||||
|
||||
/* Read file */
|
||||
while(getline(&read_line,&n,fd) != -1){
|
||||
@@ -113,9 +124,9 @@
|
||||
regfree(p_reg);
|
||||
free(p_reg);
|
||||
free(pmatch);
|
||||
if(read_line != NULL){
|
||||
free(read_line);
|
||||
}
|
||||
//if(read_line != NULL){
|
||||
// free(read_line);
|
||||
//}
|
||||
|
||||
(void) fclose(fd);
|
||||
|
||||
|
Reference in New Issue
Block a user