void monitor_agents() { char **cr_agents; char **av_agents; av_agents = get_agents(GA_ACTIVE); /* No agent saved */ if(!mond.agents) { mond.agents = av_agents; return; } /* Checking if any of the previous available agents * are disconnected. */ cr_agents = mond.agents; while(*cr_agents) { int available = 0; char **tmp_av; tmp_av = av_agents; while(tmp_av && *tmp_av) { if(strcmp(*cr_agents, *tmp_av) == 0) { available = 1; break; } tmp_av++; } /* Agent disconnected */ if(available == 0) { char str[OS_SIZE_1024 +1]; /* Sending disconnected message */ snprintf(str, OS_SIZE_1024 -1, OS_AG_DISCON, *cr_agents); if(SendMSG(mond.a_queue, str, ARGV0, LOCALFILE_MQ) < 0) { merror(QUEUE_SEND, ARGV0); } } cr_agents++; } /* Removing old agent list and adding currently one */ free_agents(mond.agents); mond.agents = av_agents; return; }
/** main **/ int main(int argc, char **argv) { char *dir = DEFAULTDIR; char *group = GROUPGLOBAL; char *user = USER; char *msg; char **agent_list; int gid; int uid; int flag = 0; /* Setting the name */ OS_SetName(ARGV0); /* user arguments */ if(argc < 2) { helpmsg(); } /* Getting the group name */ gid = Privsep_GetGroup(group); uid = Privsep_GetUser(user); if(gid < 0) { ErrorExit(USER_ERROR, ARGV0, user, group); } /* Setting the group */ if(Privsep_SetGroup(gid) < 0) { ErrorExit(SETGID_ERROR,ARGV0, group); } /* Chrooting to the default directory */ if(Privsep_Chroot(dir) < 0) { ErrorExit(CHROOT_ERROR, ARGV0, dir); } /* Inside chroot now */ nowChroot(); /* Setting the user */ if(Privsep_SetUser(uid) < 0) { ErrorExit(SETUID_ERROR, ARGV0, user); } /* User options */ if(strcmp(argv[1], "-h") == 0) { helpmsg(); } else if(strcmp(argv[1], "-a") == 0) { flag = GA_ALL; msg = "is available."; } else if(strcmp(argv[1], "-c") == 0) { flag = GA_ACTIVE; msg = "is active."; } else if(strcmp(argv[1], "-n") == 0) { flag = GA_NOTACTIVE; msg = "is not active."; } else { printf("\n** Invalid option '%s'.\n", argv[1]); helpmsg(); } agent_list = get_agents(flag); if(agent_list) { char **agent_list_pt = agent_list; while(*agent_list) { printf("%s %s\n", *agent_list, msg); agent_list++; } free_agents(agent_list_pt); } else { printf("** No agent available.\n"); } return(0); }