ERROR_CODE stop_module_diag(struct environment_t *environment, struct module_t *module) { /* retrieves the name, version and description of the current module loaded */ unsigned char *name = name_viriatum_mod_diag(); unsigned char *version = version_viriatum_mod_diag(); unsigned char *description = description_viriatum_mod_diag(); /* retrieves the (environment) service, that is going to be used for certain global operations */ struct service_t *service = environment->service; /* retrieves the mod diag module (from the module) and uses it to retrieve the create http handler */ struct mod_diag_module_t *mod_diag_module = (struct mod_diag_module_t *) module->lower; struct http_handler_t *http_handler = mod_diag_module->http_handler; /* prints a debug message about the unloading of the current module, for debugging purposes */ V_DEBUG_F("Stopping the module '%s' (%s) v%s\n", name, description, version); /* removes the http handler from the service, it can no longer be used to handle any request from this point on, then deletes both the http handler and the mod diag module (to avoid memory leaks) */ service->remove_http_handler(service, http_handler); if(http_handler != NULL) { service->delete_http_handler(service, http_handler); } delete_mod_diag_module(mod_diag_module); /* cleans up the pool based memory allocation system releasing all of its memory before the exit (no leaks) then returns the control flow to the caller function with success state */ cleanup_palloc(); RAISE_NO_ERROR; }
int main(int argc, char *argv[]) { /* allocates the space for the "final" result code that is going to be returned as part of the normal command execution, a positive or negative values should idicate an error, a zero value indicates that a normal execution has just finished */ ERROR_CODE return_value; /* allocates space for the name of the program (process) to be executed */ char *program_name; /* allocates the map that will contain the various processed arguments, indexed by name */ struct hash_map_t *arguments; /* prints a debug message */ V_DEBUG_F("Receiving %d argument(s)\n", argc); /* in case the number of arguments is less than one (exception case) returns in error */ if(argc < 1) { cleanup(NULL); RAISE_ERROR_S(1); } /* retrieves the first argument value as the name of the process (program) to be executed */ program_name = argv[0]; /* processes the various arguments into a map and then executes the corresponding (initial) actions */ process_arguments(argc, argv, &arguments); return_value = execute_arguments(program_name, arguments); /* cleans the current process information so that no remaining structure or resource is left in an invalid or erroneous state */ cleanup(arguments); /* deletes the processed arguments and then cleans up the pool based memory allocation system releasing all of its memory before the exit (no leaks) */ delete_arguments(arguments); cleanup_palloc(); /* prints a debug message about the ending of the sytem for the execution of the service and then returns the normal return code (success status) to the caller process */ V_DEBUG_F( "Finishing process [%ld pending]\n", (long int) ALLOCATIONS ); RAISE_AGAIN(return_value); }