diff --git a/contribs/phpext/slurm_php/config.m4.in b/contribs/phpext/slurm_php/config.m4.in index 16663776070eb6e1ee4ea858a09d80a3a70bdf21..c60eda7fd38a0720358466bc123c3c6a25b9eef5 100644 --- a/contribs/phpext/slurm_php/config.m4.in +++ b/contribs/phpext/slurm_php/config.m4.in @@ -62,6 +62,7 @@ if test "$PHP_SLURM" != "no"; then PHP_SUBST(SLURM_PHP_SHARED_LIBADD) AC_CHECK_HEADERS(stdbool.h) + AC_CHECK_HEADERS(xmalloc.h) AC_DEFINE(HAVE_SLURM_PHP, 1, [Whether you have SLURM]) #PHP_EXTENSION(slurm_php, $ext_shared) diff --git a/contribs/phpext/slurm_php/slurm_php.c b/contribs/phpext/slurm_php/slurm_php.c index ecf394bca7b77a8e4d963f5e1b0236ed4767d32e..03a6d984e5cfbc14ec46718df670606c4c7c3a2e 100644 --- a/contribs/phpext/slurm_php/slurm_php.c +++ b/contribs/phpext/slurm_php/slurm_php.c @@ -90,12 +90,17 @@ zend_module_entry slurm_php_module_entry = { ZEND_GET_MODULE(slurm_php) #endif +#ifdef HAVE_XMALLOC_H +#define malloc(size) xmalloc(size) +#define free(ptr) xfree(ptr) +#endif + /*****************************************************************************\ * TODO ***************************************************************************** * [ADJUSTING EXISTING FUNCTIONS] - * - parse_node_pointer + * - _parse_node_pointer * dynamic_plugin_data_t is currently not returned * [EXTRA FUNCTIONS] * - Functions that filter jobs on the nodes they are running on @@ -107,35 +112,35 @@ ZEND_GET_MODULE(slurm_php) * HELPER FUNCTIONS \*****************************************************************************/ -void parse_node_pointer(zval *sub_arr, node_info_t *node_arr) +void _parse_node_pointer(zval *sub_arr, node_info_t *node_arr) { zval *sub_arr_2 = NULL; - zend_add_valid_assoc_string(sub_arr, "Name", node_arr->name); - zend_add_valid_assoc_string(sub_arr, "Arch.", node_arr->arch); - zend_add_valid_assoc_time_string(sub_arr, "Boot Time", + _zend_add_valid_assoc_string(sub_arr, "Name", node_arr->name); + _zend_add_valid_assoc_string(sub_arr, "Arch.", node_arr->arch); + _zend_add_valid_assoc_time_string(sub_arr, "Boot Time", &node_arr->boot_time); add_assoc_long(sub_arr, "#CPU'S", node_arr->cpus); - add_assoc_long(sub_arr, "#Cores/CPU", node_arr->cpus); + add_assoc_long(sub_arr, "#Cores/CPU", node_arr->cores); if (node_arr->features == NULL) { add_assoc_null(sub_arr, "Features"); } else { ALLOC_INIT_ZVAL(sub_arr_2); array_init(sub_arr_2); - parse_array(node_arr->features, ",", sub_arr_2); + _parse_array(node_arr->features, ",", sub_arr_2); add_assoc_zval(sub_arr, "Features", sub_arr_2); } - zend_add_valid_assoc_string(sub_arr, "GRES", node_arr->gres); + _zend_add_valid_assoc_string(sub_arr, "GRES", node_arr->gres); add_assoc_long(sub_arr, "State", node_arr->node_state); - zend_add_valid_assoc_string(sub_arr, "OS", node_arr->os); + _zend_add_valid_assoc_string(sub_arr, "OS", node_arr->os); add_assoc_long(sub_arr, "Real Mem", node_arr->real_memory); if (node_arr->reason!=NULL) { - zend_add_valid_assoc_string(sub_arr, "Reason", + _zend_add_valid_assoc_string(sub_arr, "Reason", node_arr->reason); - zend_add_valid_assoc_time_string(sub_arr,"Reason Timestamp", + _zend_add_valid_assoc_time_string(sub_arr,"Reason Timestamp", &node_arr->reason_time); add_assoc_long(sub_arr, "Reason User Id", node_arr->reason_uid); @@ -145,7 +150,7 @@ void parse_node_pointer(zval *sub_arr, node_info_t *node_arr) add_assoc_null(sub_arr, "Reason User Id"); } - zend_add_valid_assoc_time_string(sub_arr, "Slurmd Startup Time", + _zend_add_valid_assoc_time_string(sub_arr, "Slurmd Startup Time", &node_arr->slurmd_start_time); add_assoc_long(sub_arr, "#Sockets/Node", node_arr->sockets); add_assoc_long(sub_arr, "#Threads/Core", node_arr->threads); @@ -154,7 +159,7 @@ void parse_node_pointer(zval *sub_arr, node_info_t *node_arr) } -void parse_assoc_array(char *char_arr, char *delims, zval *result_arr) +void _parse_assoc_array(char *char_arr, char *delims, zval *result_arr) { char *rslt = NULL; char *tmp; @@ -168,7 +173,7 @@ void parse_assoc_array(char *char_arr, char *delims, zval *result_arr) if (strcmp(rslt,"(null)")==0) { add_assoc_null(result_arr, tmp); } else { - zend_add_valid_assoc_string(result_arr, + _zend_add_valid_assoc_string(result_arr, tmp, rslt); } } @@ -181,7 +186,7 @@ void parse_assoc_array(char *char_arr, char *delims, zval *result_arr) } -void parse_array(char *char_arr, char *delims, zval *rslt_arr) +void _parse_array(char *char_arr, char *delims, zval *rslt_arr) { char *rslt = NULL; char *tmp = NULL; @@ -200,7 +205,7 @@ void parse_array(char *char_arr, char *delims, zval *rslt_arr) } } -void zend_add_valid_assoc_string(zval *rstl_arr, char *key, char *val) +void _zend_add_valid_assoc_string(zval *rstl_arr, char *key, char *val) { char *tmp = NULL; if (val==NULL) { @@ -214,7 +219,7 @@ void zend_add_valid_assoc_string(zval *rstl_arr, char *key, char *val) } -void zend_add_valid_assoc_time_string(zval *rstl_arr, char *key, time_t *val) +void _zend_add_valid_assoc_time_string(zval *rstl_arr, char *key, time_t *val) { char buf[80]; struct tm *timeinfo; @@ -248,7 +253,7 @@ PHP_FUNCTION(slurm_ping) PHP_FUNCTION(slurm_slurmd_status) { int err = SLURM_SUCCESS; - static slurmd_status_t *status_ptr = NULL; + slurmd_status_t *status_ptr = NULL; err = slurm_load_slurmd_status(&status_ptr); if (err) { @@ -256,9 +261,9 @@ PHP_FUNCTION(slurm_slurmd_status) } array_init(return_value); - zend_add_valid_assoc_time_string(return_value,"Booted_at", + _zend_add_valid_assoc_time_string(return_value,"Booted_at", &status_ptr->booted); - zend_add_valid_assoc_time_string(return_value,"Last_Msg", + _zend_add_valid_assoc_time_string(return_value,"Last_Msg", &status_ptr->last_slurmctld_msg); add_assoc_long(return_value,"Logging_Level", status_ptr->slurmd_debug); add_assoc_long(return_value,"Actual_CPU's", status_ptr->actual_cpus); @@ -272,13 +277,13 @@ PHP_FUNCTION(slurm_slurmd_status) add_assoc_long(return_value,"Actual_Tmp_Disk", status_ptr->actual_tmp_disk); add_assoc_long(return_value,"PID",status_ptr->pid); - zend_add_valid_assoc_string(return_value, "Hostname", + _zend_add_valid_assoc_string(return_value, "Hostname", status_ptr->hostname); - zend_add_valid_assoc_string(return_value, "Slurm Logfile", + _zend_add_valid_assoc_string(return_value, "Slurm Logfile", status_ptr->slurmd_logfile); - zend_add_valid_assoc_string(return_value, "Step List", + _zend_add_valid_assoc_string(return_value, "Step List", status_ptr->step_list); - zend_add_valid_assoc_string(return_value, "Version", + _zend_add_valid_assoc_string(return_value, "Version", status_ptr->version); if (status_ptr != NULL) { @@ -393,7 +398,7 @@ PHP_FUNCTION(slurm_array_to_hostlist) array_init(return_value); buf = slurm_hostlist_ranged_string_xmalloc(hl); - zend_add_valid_assoc_string(return_value,"HOSTLIST",buf); + _zend_add_valid_assoc_string(return_value,"HOSTLIST",buf); } @@ -405,7 +410,7 @@ PHP_FUNCTION(slurm_print_partition_names) { int err = SLURM_SUCCESS; int i; - static partition_info_msg_t *prt_ptr = NULL; + partition_info_msg_t *prt_ptr = NULL; char *tmp; err = slurm_load_partitions((time_t) NULL, &prt_ptr, 0); @@ -439,7 +444,7 @@ PHP_FUNCTION(slurm_get_specific_partition_info) { long lngth = 0; int err = SLURM_SUCCESS; - static partition_info_msg_t *prt_ptr = NULL; + partition_info_msg_t *prt_ptr = NULL; partition_info_t *prt_data = NULL; partition_info_t *prt_data_tmp = NULL; char *name = NULL; @@ -468,7 +473,7 @@ PHP_FUNCTION(slurm_get_specific_partition_info) prt_data = prt_ptr->partition_array; tmp = slurm_sprint_partition_info(prt_data, 1); array_init(return_value); - parse_assoc_array(tmp, "= ", return_value); + _parse_assoc_array(tmp, "= ", return_value); y++; break; } @@ -492,7 +497,7 @@ PHP_FUNCTION(slurm_get_partition_node_names) char *prt_name = NULL; long lngth = 0; int err = SLURM_SUCCESS; - static partition_info_msg_t *prt_ptr = NULL; + partition_info_msg_t *prt_ptr = NULL; partition_info_t *prt_data = NULL; char *tmp = NULL; int i = 0; @@ -548,7 +553,7 @@ PHP_FUNCTION(slurm_get_node_names) { int err = SLURM_SUCCESS; int i = 0; - static node_info_msg_t *node_ptr = NULL; + node_info_msg_t *node_ptr = NULL; char *tmp; err = slurm_load_node((time_t) NULL, &node_ptr, 0); @@ -581,7 +586,7 @@ PHP_FUNCTION(slurm_get_node_elements) { int err = SLURM_SUCCESS; int i = 0; - static node_info_msg_t *node_ptr; + node_info_msg_t *node_ptr; zval *sub_arr = NULL; char *tmp; @@ -595,7 +600,7 @@ PHP_FUNCTION(slurm_get_node_elements) for (i = 0; i < node_ptr->record_count; i++) { ALLOC_INIT_ZVAL(sub_arr); array_init(sub_arr); - parse_node_pointer(sub_arr, node_ptr->node_array); + _parse_node_pointer(sub_arr, node_ptr->node_array); tmp = malloc(strlen(node_ptr->node_array->name)+1); strcpy(tmp,node_ptr->node_array->name); add_assoc_zval(return_value, tmp, @@ -620,7 +625,7 @@ PHP_FUNCTION(slurm_get_node_element_by_name) { int err = SLURM_SUCCESS; int i = 0,y = 0; - static node_info_msg_t *node_ptr; + node_info_msg_t *node_ptr; char *node_name = NULL; long lngth; zval *sub_arr = NULL; @@ -646,7 +651,7 @@ PHP_FUNCTION(slurm_get_node_element_by_name) y++; ALLOC_INIT_ZVAL(sub_arr); array_init(sub_arr); - parse_node_pointer(sub_arr, node_ptr->node_array); + _parse_node_pointer(sub_arr, node_ptr->node_array); add_assoc_zval(return_value, node_name, sub_arr); break; @@ -669,7 +674,7 @@ PHP_FUNCTION(slurm_get_node_state_by_name) { int err = SLURM_SUCCESS; int i = 0,y = 0; - static node_info_msg_t *node_ptr; + node_info_msg_t *node_ptr; char *node_name = NULL; long lngth; @@ -715,7 +720,7 @@ PHP_FUNCTION(slurm_get_node_states) { int err = SLURM_SUCCESS; int i = 0; - static node_info_msg_t *node_ptr; + node_info_msg_t *node_ptr; zval *sub_arr = NULL; err = slurm_load_node((time_t) NULL, &node_ptr, 0); @@ -748,7 +753,7 @@ PHP_FUNCTION(slurm_get_node_states) PHP_FUNCTION(slurm_get_control_configuration_keys) { int err = SLURM_SUCCESS; - static slurm_ctl_conf_t *ctrl_conf_ptr; + slurm_ctl_conf_t *ctrl_conf_ptr; List lst; ListIterator iter = NULL; key_pair_t *k_p; @@ -776,7 +781,7 @@ PHP_FUNCTION(slurm_get_control_configuration_keys) PHP_FUNCTION(slurm_get_control_configuration_values) { int err = SLURM_SUCCESS; - static slurm_ctl_conf_t *ctrl_conf_ptr; + slurm_ctl_conf_t *ctrl_conf_ptr; List lst; ListIterator iter = NULL; key_pair_t *k_p; @@ -813,7 +818,7 @@ PHP_FUNCTION(slurm_load_job_information) { int err = SLURM_SUCCESS; int i = 0; - static job_info_msg_t *job_ptr; + job_info_msg_t *job_ptr; zval *sub_arr = NULL; char *tmp; @@ -828,7 +833,7 @@ PHP_FUNCTION(slurm_load_job_information) sprintf(tmp, "%d", job_ptr->job_array->job_id); ALLOC_INIT_ZVAL(sub_arr); array_init(sub_arr); - parse_assoc_array(slurm_sprint_job_info(job_ptr->job_array, 1), + _parse_assoc_array(slurm_sprint_job_info(job_ptr->job_array, 1), "= ", sub_arr); add_assoc_zval(return_value, tmp, sub_arr); job_ptr->job_array++; @@ -850,7 +855,7 @@ PHP_FUNCTION(slurm_load_partition_jobs) { int err = SLURM_SUCCESS; int i = 0; - static job_info_msg_t *job_ptr; + job_info_msg_t *job_ptr; zval *sub_arr = NULL; char *tmp; char *pname = NULL; @@ -879,7 +884,7 @@ PHP_FUNCTION(slurm_load_partition_jobs) sprintf(tmp, "%d", job_ptr->job_array->job_id); ALLOC_INIT_ZVAL(sub_arr); array_init(sub_arr); - parse_assoc_array( + _parse_assoc_array( slurm_sprint_job_info(job_ptr->job_array, 1), "= ", sub_arr); add_assoc_zval(return_value, tmp, sub_arr); diff --git a/contribs/phpext/slurm_php/slurm_php.h b/contribs/phpext/slurm_php/slurm_php.h index d763cebd8a3c2b9abad19e936c174a66ed43f2c1..89abaca2506eb8d7d6acf6590c884daf76b1bbe5 100644 --- a/contribs/phpext/slurm_php/slurm_php.h +++ b/contribs/phpext/slurm_php/slurm_php.h @@ -74,53 +74,17 @@ typedef struct key_value { \*****************************************************************************/ /* - * now - Get the current time - * RET time_t * : Pointer to the memory holding the current time - */ -time_t now(); - -/* - * ld_partition_info - Issue slurm to load the partition info into part_pptr - * - * IN part_pptr - place to store a partition configuration pointer - * IN show_flags - partition filtering options - * RET 0 or a slurm error code - * NOTE: free the response using slurm_free_partition_info_msg - */ -int ld_partition_info(partition_info_msg_t **part_pptr, uint16_t show_flags); - -/* - * ld_node_info - Issue slurm to load the node info into node_pptr - * - * IN node_pptr - place to store a node configuration pointer - * IN show_flags - partition filtering options - * RET 0 or a slurm error code - * NOTE: free the response using slurm_free_node_info_msg - */ -int ld_node_info(node_info_msg_t **node_pptr, uint16_t show_flags); - -/* - * ld_job_info - Issue slurm to load the job info into job_pptr - * - * IN job_pptr - place to store a node configuration pointer - * IN show_flags - partition filtering options - * RET 0 or a slurm error code - * NOTE: free the response using slurm_free_job_info_msg - */ -int ld_job_info(job_info_msg_t **job_pptr, uint16_t show_flags); - -/* - * parse_node_pointer - Parse a node pointer's contents into an + * _parse_node_pointer - Parse a node pointer's contents into an * assocative zval array where the key is descriptive to the * value * * IN sub_arr - array to store the contents of the node pointer * IN node_arr - node pointer that needs parsing */ -void parse_node_pointer(zval *sub_arr, node_info_t *node_arr); +void _parse_node_pointer(zval *sub_arr, node_info_t *node_arr); /* - * parse_assoc_array - Parse a character array where the elements are + * _parse_assoc_array - Parse a character array where the elements are * key-value pairs separated by delimiters into an associative * array * @@ -128,35 +92,20 @@ void parse_node_pointer(zval *sub_arr, node_info_t *node_arr); * IN delims - character array that contains the delimeters used in parsing * IN result_arr - associative array used to store the key_value pairs in */ -void parse_assoc_array(char *char_arr, char *delims, zval *result_arr); +void _parse_assoc_array(char *char_arr, char *delims, zval *result_arr); /* - * parse_array - Parse a character array where the elements are values + * _parse_array - Parse a character array where the elements are values * separated by delimiters into a numerically indexed array * * IN char_arr - character array that needs parsing * IN delims - character array that contains the delimeters used in parsing * IN result_arr - numerically indexed array used to store the values in */ -void parse_array(char *char_arr, char *delims, zval *rslt_arr); - -/* - * get_partition_from_name - Load the information about a specific partition - * by passing on a character array containing the partition name - * - * IN name - character array containing the partition name - * IN prt_data - pointer to store the partition information in (if a - * partition is found with that specific name) - * IN prt_ptr - pointer containing all the partition information of all the - * arrays - * RET partition_info_t pointer that contains the partition data, or - * null if the partition wasn't found - */ -partition_info_t *get_partition_from_name( - char *name, partition_info_t *prt_data, partition_info_msg_t *prt_ptr); +void _parse_array(char *char_arr, char *delims, zval *rslt_arr); /* - * zend_add_valid_assoc_string - checks a character array to see if + * _zend_add_valid_assoc_string - checks a character array to see if * it's NULL or not, if so an associative null is added, if not * an associative string is added. * @@ -164,10 +113,10 @@ partition_info_t *get_partition_from_name( * IN key - character array used as the associative key * IN val - character array to be validated and added as value if valid */ -void zend_add_valid_assoc_string(zval *rstl_arr, char *key, char *val); +void _zend_add_valid_assoc_string(zval *rstl_arr, char *key, char *val); /* - * zend_add_valid_assoc_time_string - checks a unix timestamp to see if it's + * _zend_add_valid_assoc_time_string - checks a unix timestamp to see if it's * 0 or not, if so an associative null is added, if not a formatted string * is added. * @@ -177,7 +126,7 @@ void zend_add_valid_assoc_string(zval *rstl_arr, char *key, char *val); * NOTE : If you'd like to change the format in which the valid strings are * returned, you can change the TIME_FORMAT_STRING macro to the needed format */ -void zend_add_valid_assoc_time_string(zval *rstl_arr, char *key, time_t *val); +void _zend_add_valid_assoc_time_string(zval *rstl_arr, char *key, time_t *val); /*****************************************************************************\