[12] | 1 | /* $Id$ */ |
---|
[1] | 2 | /* |
---|
| 3 | * FedStage DRMAA for PBS Pro |
---|
| 4 | * Copyright (C) 2006-2007 FedStage Systems |
---|
| 5 | * |
---|
| 6 | * This program is free software: you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #ifdef HAVE_CONFIG_H |
---|
| 21 | # include <config.h> |
---|
| 22 | #endif |
---|
| 23 | |
---|
| 24 | #include <signal.h> |
---|
| 25 | #include <drmaa_utils/drmaa_base.h> |
---|
| 26 | #include <drmaa_utils/session.h> |
---|
| 27 | #include <drmaa_utils/template.h> |
---|
| 28 | #include <drmaa_utils/drmaa_attrib.h> |
---|
| 29 | #include <drmaa_utils/iter.h> |
---|
| 30 | #include <drmaa_utils/logging.h> |
---|
| 31 | #include <pbs_drmaa/session.h> |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | static fsd_drmaa_session_t * |
---|
| 35 | pbsdrmaa_new_session( fsd_drmaa_singletone_t *self, const char *contact ) |
---|
| 36 | { |
---|
| 37 | return pbsdrmaa_session_new( contact ); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | static fsd_template_t * |
---|
| 41 | pbsdrmaa_new_job_template( fsd_drmaa_singletone_t *self ) |
---|
| 42 | { |
---|
| 43 | return drmaa_template_new(); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | static const char * |
---|
| 47 | pbsdrmaa_get_contact( fsd_drmaa_singletone_t *self ) |
---|
| 48 | { |
---|
| 49 | const char *contact = NULL; |
---|
| 50 | fsd_mutex_lock( &self->session_mutex ); |
---|
| 51 | if( self->session ) |
---|
| 52 | contact = self->session->contact; |
---|
| 53 | if( contact == NULL ) |
---|
| 54 | contact = "localhost"; |
---|
| 55 | fsd_mutex_unlock( &self->session_mutex ); |
---|
| 56 | return contact; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | static void |
---|
| 60 | pbsdrmaa_get_version( fsd_drmaa_singletone_t *self, |
---|
| 61 | unsigned *major, unsigned *minor ) |
---|
| 62 | { |
---|
| 63 | *major = 1; *minor = 0; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | static const char * |
---|
| 67 | pbsdrmaa_get_DRM_system( fsd_drmaa_singletone_t *self ) |
---|
| 68 | { |
---|
| 69 | #ifdef PBS_PROFESSIONAL |
---|
| 70 | return "PBS Professional"; |
---|
| 71 | #else |
---|
| 72 | return "Torque"; |
---|
| 73 | #endif |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | static const char * |
---|
| 77 | pbsdrmaa_get_DRMAA_implementation( fsd_drmaa_singletone_t *self ) |
---|
| 78 | { |
---|
| 79 | return PACKAGE_NAME" v. "PACKAGE_VERSION |
---|
| 80 | " <http://sourceforge.net/projects/pbspro-drmaa/>"; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | fsd_iter_t * |
---|
| 85 | pbsdrmaa_get_attribute_names( fsd_drmaa_singletone_t *self ) |
---|
| 86 | { |
---|
| 87 | static const char *attribute_names[] = { |
---|
| 88 | DRMAA_REMOTE_COMMAND, |
---|
| 89 | DRMAA_JS_STATE, |
---|
| 90 | DRMAA_WD, |
---|
| 91 | DRMAA_JOB_CATEGORY, |
---|
| 92 | DRMAA_NATIVE_SPECIFICATION, |
---|
| 93 | DRMAA_BLOCK_EMAIL, |
---|
| 94 | DRMAA_START_TIME, |
---|
| 95 | DRMAA_JOB_NAME, |
---|
| 96 | DRMAA_INPUT_PATH, |
---|
| 97 | DRMAA_OUTPUT_PATH, |
---|
| 98 | DRMAA_ERROR_PATH, |
---|
| 99 | DRMAA_JOIN_FILES, |
---|
| 100 | DRMAA_TRANSFER_FILES, |
---|
| 101 | DRMAA_WCT_HLIMIT, |
---|
| 102 | DRMAA_DURATION_HLIMIT, |
---|
| 103 | NULL |
---|
| 104 | }; |
---|
| 105 | return fsd_iter_new_const( attribute_names, -1 ); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | fsd_iter_t * |
---|
| 109 | pbsdrmaa_get_vector_attribute_names( fsd_drmaa_singletone_t *self ) |
---|
| 110 | { |
---|
| 111 | static const char *attribute_names[] = { |
---|
| 112 | DRMAA_V_ARGV, |
---|
| 113 | DRMAA_V_ENV, |
---|
| 114 | DRMAA_V_EMAIL, |
---|
| 115 | NULL |
---|
| 116 | }; |
---|
| 117 | return fsd_iter_new_const( attribute_names, -1 ); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | static int |
---|
| 121 | pbsdrmaa_wifexited( |
---|
| 122 | int *exited, int stat, |
---|
| 123 | char *error_diagnosis, size_t error_diag_len |
---|
| 124 | ) |
---|
| 125 | { |
---|
[23] | 126 | *exited = (stat <= 125) && (stat != -1); |
---|
[1] | 127 | return DRMAA_ERRNO_SUCCESS; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | static int |
---|
| 131 | pbsdrmaa_wexitstatus( |
---|
| 132 | int *exit_status, int stat, |
---|
| 133 | char *error_diagnosis, size_t error_diag_len |
---|
| 134 | ) |
---|
| 135 | { |
---|
| 136 | *exit_status = stat & 0xff; |
---|
| 137 | return DRMAA_ERRNO_SUCCESS; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | static int |
---|
| 141 | pbsdrmaa_wifsignaled( |
---|
| 142 | int *signaled, int stat, |
---|
| 143 | char *error_diagnosis, size_t error_diag_len |
---|
| 144 | ) |
---|
| 145 | { |
---|
| 146 | *signaled = (stat > 128 ); |
---|
| 147 | return DRMAA_ERRNO_SUCCESS; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | static int |
---|
| 151 | pbsdrmaa_wtermsig( |
---|
| 152 | char *signal, size_t signal_len, int stat, |
---|
| 153 | char *error_diagnosis, size_t error_diag_len |
---|
| 154 | ) |
---|
| 155 | { |
---|
| 156 | int sig = stat & 0x7f; |
---|
| 157 | strlcpy( signal, fsd_strsignal(sig), signal_len ); |
---|
| 158 | return DRMAA_ERRNO_SUCCESS; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | static int |
---|
| 162 | pbsdrmaa_wcoredump( |
---|
| 163 | int *core_dumped, int stat, |
---|
| 164 | char *error_diagnosis, size_t error_diag_len |
---|
| 165 | ) |
---|
| 166 | { |
---|
| 167 | *core_dumped = 0; |
---|
| 168 | return DRMAA_ERRNO_SUCCESS; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | static int |
---|
| 172 | pbsdrmaa_wifaborted( |
---|
| 173 | int *aborted, int stat, |
---|
| 174 | char *error_diagnosis, size_t error_diag_len |
---|
| 175 | ) |
---|
| 176 | { |
---|
| 177 | fsd_log_debug(("wifaborted(%d)", stat)); |
---|
| 178 | |
---|
| 179 | if ( stat == -1 ) |
---|
| 180 | { |
---|
| 181 | *aborted = true; |
---|
| 182 | } |
---|
| 183 | else if ( stat <= 125 ) |
---|
| 184 | { |
---|
| 185 | *aborted = false; |
---|
| 186 | } |
---|
| 187 | else if ( stat == 126 || stat == 127 ) |
---|
| 188 | { |
---|
| 189 | *aborted = true; |
---|
| 190 | } |
---|
| 191 | else switch( stat & 0x7f ) |
---|
| 192 | { |
---|
| 193 | case SIGTERM: case SIGKILL: |
---|
| 194 | *aborted = true; |
---|
| 195 | break; |
---|
| 196 | default: |
---|
| 197 | *aborted = false; |
---|
| 198 | break; |
---|
| 199 | } |
---|
| 200 | return DRMAA_ERRNO_SUCCESS; |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | fsd_drmaa_singletone_t _fsd_drmaa_singletone = { |
---|
| 205 | NULL, |
---|
| 206 | FSD_MUTEX_INITIALIZER, |
---|
| 207 | |
---|
| 208 | pbsdrmaa_new_session, |
---|
| 209 | pbsdrmaa_new_job_template, |
---|
| 210 | |
---|
| 211 | pbsdrmaa_get_contact, |
---|
| 212 | pbsdrmaa_get_version, |
---|
| 213 | pbsdrmaa_get_DRM_system, |
---|
| 214 | pbsdrmaa_get_DRMAA_implementation, |
---|
| 215 | |
---|
| 216 | pbsdrmaa_get_attribute_names, |
---|
| 217 | pbsdrmaa_get_vector_attribute_names, |
---|
| 218 | |
---|
| 219 | pbsdrmaa_wifexited, |
---|
| 220 | pbsdrmaa_wexitstatus, |
---|
| 221 | pbsdrmaa_wifsignaled, |
---|
| 222 | pbsdrmaa_wtermsig, |
---|
| 223 | pbsdrmaa_wcoredump, |
---|
| 224 | pbsdrmaa_wifaborted |
---|
| 225 | }; |
---|
| 226 | |
---|