compte rendu
This commit is contained in:
parent
eeb103dace
commit
7949ba7f52
@ -10,7 +10,7 @@
|
||||
|
||||
* ping_request() : 2 complexité cyclomatique
|
||||
|
||||
* send_check() : 3 complexité cyclomatique
|
||||
* send_check() : 4 complexité cyclomatique
|
||||
|
||||
* check_keep_working() : 4 complexité cyclomatique
|
||||
|
||||
@ -30,14 +30,33 @@
|
||||
|
||||
### 4. stats.C :
|
||||
|
||||
* get_ping_from_temp_log() : 11 complexité cyclomatique
|
||||
* get_ping_from_temp_log() : 13 complexité cyclomatique
|
||||
|
||||
* write_ping_log() : 4 complexité cyclomatiquue
|
||||
|
||||
* set_stats_ping() : 9 complexité cyclomatique
|
||||
* set_stats_ping() : 23 complexité cyclomatique
|
||||
|
||||
### 5. utils.c :
|
||||
|
||||
* write_pid_file() : 2 complexité cyclomatique
|
||||
|
||||
* remove_file() : 1 complexité cyclomatique
|
||||
|
||||
|
||||
## DIAGRAMMES
|
||||
|
||||
|
||||
## OPTIMISATION DU CODE DE LA FONCTION get_ping_from_temp_log() :
|
||||
|
||||
ligne de 127 à 130 mis en commentaire
|
||||
|
||||
les if :
|
||||
|
||||
- if(p_reg == NULL)
|
||||
- if(fd == NULL)
|
||||
- if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0)
|
||||
- if(pmatch == NULL)
|
||||
|
||||
on été décaler dans une fonction a part et nous retourne le ping ce qui nous rend a la fonction get_ping_from_temp_log et la nouvelle fonction crées à 5 complexité cyclomatique chacune.
|
||||
|
||||
## NOUVEAU DIAGRAMMES
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user