- Timestamp:
- 09/12/12 20:30:13 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/pbs_drmaa/submit.c
r72 r73 30 30 31 31 #include <drmaa_utils/conf.h> 32 #include <drmaa_utils/exec.h> 32 33 #include <drmaa_utils/drmaa.h> 33 34 #include <drmaa_utils/drmaa_util.h> … … 820 821 pbsdrmaa_submit_filter(struct attrl *pbs_attr) 821 822 { 822 fsd_log_enter(( "({pbs_attr=%p})", pbs_attr)); 823 824 if (getenv(PBSDRMAA_SUBMIT_FILTER_ENV) == NULL) { 823 fsd_log_enter(( "({pbs_attr=%p})", (void*)pbs_attr)); 824 825 if (getenv(PBSDRMAA_SUBMIT_FILTER_ENV) == NULL) 826 { 825 827 return pbs_attr; 826 } else { 828 } 829 else 830 { 827 831 struct attrl *ii = NULL; 832 char *empty_args[] = { NULL }; 833 int exit_status = -1; 828 834 const char *submit_filter = getenv(PBSDRMAA_SUBMIT_FILTER_ENV); 829 830 fsd_log_info(("Executing filter script: %s", submit_filter)); 831 832 for (ii = pbs_attr; ii; ii = ii->next) { 833 fsd_log_info(("FILTER: %s=%s ", ii->name, ii->value)); 834 } 835 char *stdin_buf = NULL; 836 int stdin_size = 0; 837 char *stdout_buf = NULL; 838 char *stderr_buf = NULL; 839 char *output_line = NULL; 840 char *ctx = NULL; 841 842 fsd_log_debug(("Executing filter script: %s", submit_filter)); 843 844 845 for (ii = pbs_attr; ii; ii = ii->next) 846 { 847 stdin_size += strlen(ii->name) + strlen(ii->value) + 2 /* '=' and '\n' */; 848 if (ii->resource) 849 { 850 stdin_size += strlen(ii->resource) + 1; /* '.' */ 851 } 852 } 853 854 stdin_size+=1; /* '\0' */ 855 856 stdin_buf = fsd_calloc(stdin_buf, stdin_size, char); 857 stdin_buf[0] = '\0'; 858 859 for (ii = pbs_attr; ii; ii = ii->next) 860 { 861 strcat(stdin_buf, ii->name); 862 if (ii->resource) 863 { 864 strcat(stdin_buf, "."); 865 strcat(stdin_buf, ii->resource); 866 } 867 strcat(stdin_buf, "="); 868 strcat(stdin_buf, ii->value); 869 strcat(stdin_buf, "\n"); 870 } 871 872 exit_status = fsd_exec_sync(submit_filter, empty_args, stdin_buf, &stdout_buf, &stderr_buf); 873 874 if (exit_status != 0) 875 { 876 fsd_log_error(("Filter script %s exited with non-zero code: %d", submit_filter, exit_status)); 877 fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "Submit filter script failed (code: %d, message: %s)", exit_status, stderr_buf); 878 } 879 880 fsd_log_debug(("Submit filter exit_status=%d, stderr=%s", exit_status, stderr_buf)); 881 882 pbsdrmaa_free_attrl(pbs_attr); 883 pbs_attr = NULL; 884 885 /* exit_status == 0 */ 886 for (output_line = strtok_r(stdin_buf, "\n", &ctx); output_line ; output_line = strtok_r(NULL, "\n", &ctx)) 887 { 888 char *attr_name = NULL; 889 char *attr_value = NULL; 890 891 attr_value = strstr(output_line,"="); 892 attr_name = output_line; 893 894 if (!attr_value) 895 { 896 fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_FORMAT, "Invalid output line of submit filter:", output_line); 897 } 898 else 899 { 900 *attr_value = '\0'; 901 attr_value++; 902 } 903 904 905 fsd_log_debug(("Submit filter generated attribute: name=%s, value=%s", attr_name, attr_value)); 906 pbs_attr = pbsdrmaa_add_attr( pbs_attr, attr_name, attr_value ); 907 } 908 835 909 836 910 return pbs_attr; 837 } 838 839 840 } 841 911 } 912 913 } 914
Note: See TracChangeset
for help on using the changeset viewer.