void run_server_scripts( execute_on_t execute_on, char *config, disk_t *dp, int level) { identlist_t pp_scriptlist; for (pp_scriptlist = dp->pp_scriptlist; pp_scriptlist != NULL; pp_scriptlist = pp_scriptlist->next) { pp_script_t *pp_script = lookup_pp_script((char *)pp_scriptlist->data); g_assert(pp_script != NULL); run_server_script(pp_script, execute_on, config, dp, level); } }
void run_server_global_scripts( execute_on_t execute_on, char *config) { identlist_t pp_scriptlist; disk_t *dp; am_host_t *host; GHashTable* executed = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); for (host = get_hostlist(); host != NULL; host = host->next) { for (dp = host->disks; dp != NULL; dp = dp->hostnext) { if (dp->todo) { for (pp_scriptlist = dp->pp_scriptlist; pp_scriptlist != NULL; pp_scriptlist = pp_scriptlist->next) { int todo = 1; pp_script_t *pp_script = lookup_pp_script((char *)pp_scriptlist->data); g_assert(pp_script != NULL); if (pp_script_get_single_execution(pp_script)) { todo = g_hash_table_lookup(executed, pp_script_get_plugin(pp_script)) == NULL; } if (todo) { run_server_script(pp_script, execute_on, config, dp, -1); if (pp_script_get_single_execution(pp_script)) { g_hash_table_insert(executed, pp_script_get_plugin(pp_script), GINT_TO_POINTER(1)); } } } } } } g_hash_table_destroy(executed); }
int child(struct async *as, int is_status_server, int status_wfd, struct conf **confs, struct conf **cconfs) { int ret=-1; int srestore=0; int timer_ret=0; char *incexc=NULL; const char *confs_user; const char *cconfs_user; const char *confs_group; const char *cconfs_group; const char *s_script_pre; const char *s_script_post; // If we are not a status server, we are a normal child - set up the // parent socket to write status to. if(status_wfd>0) { if(!(wasfd=setup_asfd(as, "child status pipe", &status_wfd))) goto end; wasfd->attempt_reads=0; } /* Has to be before the chuser/chgrp stuff to allow clients to switch to different clients when both clients have different user/group settings. */ if(extra_comms(as, &incexc, &srestore, confs, cconfs)) { log_and_send(as->asfd, "running extra comms failed on server"); goto end; } // Needs to happen after extra_comms, in case extra_comms resets them. confs_user=get_string(confs[OPT_USER]); cconfs_user=get_string(cconfs[OPT_USER]); confs_group=get_string(confs[OPT_GROUP]); cconfs_group=get_string(cconfs[OPT_GROUP]); /* Now that the client conf is loaded, we might want to chuser or chgrp. The main process could have already done this, so we don't want to try doing it again if cconfs has the same values, because it will fail. */ if( (!confs_user || (cconfs_user && strcmp(confs_user, cconfs_user))) ||(!confs_group ||(cconfs_group && strcmp(confs_group,cconfs_group)))) { if(chuser_and_or_chgrp(cconfs_user, cconfs_group)) { log_and_send(as->asfd, "chuser_and_or_chgrp failed on server"); goto end; } } if(as->asfd->read(as->asfd)) goto end; // If this is a status server, run the status server. if(is_status_server) { ret=status_server(as, cconfs); goto end; } ret=0; s_script_pre=get_string(cconfs[OPT_S_SCRIPT_PRE]); s_script_post=get_string(cconfs[OPT_S_SCRIPT_POST]); // FIX THIS: Make the script components part of a struct, and just // pass in the correct struct. Same below. if(s_script_pre) ret=run_server_script(as->asfd, "pre", s_script_pre, get_strlist(cconfs[OPT_S_SCRIPT_PRE_ARG]), get_int(cconfs[OPT_S_SCRIPT_PRE_NOTIFY]), cconfs, ret, timer_ret); if(!ret) ret=run_action_server(as, incexc, srestore, &timer_ret, cconfs); if((!ret || get_int(cconfs[OPT_S_SCRIPT_POST_RUN_ON_FAIL])) && s_script_post) ret=run_server_script(as->asfd, "post", s_script_post, get_strlist(cconfs[OPT_S_SCRIPT_POST_ARG]), get_int(cconfs[OPT_S_SCRIPT_POST_NOTIFY]), cconfs, ret, timer_ret); end: return ret; }