Changeset 368ee04 in mainline for uspace/lib/c/generic/loader.c
- Timestamp:
- 2017-04-05T18:10:39Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 93ad8166
- Parents:
- 39f892a9 (diff), 2166728 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/loader.c
r39f892a9 r368ee04 124 124 return ENOMEM; 125 125 126 if ( getcwd(cwd, MAX_PATH_LEN + 1) == NULL)126 if (vfs_cwd_get(cwd, MAX_PATH_LEN + 1) != EOK) 127 127 str_cpy(cwd, MAX_PATH_LEN + 1, "/"); 128 128 … … 147 147 } 148 148 149 /** Set pathname of the program to load. 150 * 151 * Sets the name of the program file to load. The name can be relative 152 * to the current working directory (it will be absolutized before 153 * sending to the loader). 149 /** Set the program to load. 154 150 * 155 151 * @param ldr Loader connection structure. 156 * @param path Pathname of the program file. 157 * 158 * @return Zero on success or negative error code. 159 * 160 */ 161 int loader_set_pathname(loader_t *ldr, const char *path) 162 { 163 size_t pa_len; 164 char *pa = vfs_absolutize(path, &pa_len); 165 if (!pa) 166 return ENOMEM; 167 168 /* Send program pathname */ 169 async_exch_t *exch = async_exchange_begin(ldr->sess); 170 152 * @param name Name to set for the spawned program. 153 * @param file Program file. 154 * 155 * @return Zero on success or negative error code. 156 * 157 */ 158 int loader_set_program(loader_t *ldr, const char *name, int file) 159 { 160 async_exch_t *exch = async_exchange_begin(ldr->sess); 161 171 162 ipc_call_t answer; 172 aid_t req = async_send_0(exch, LOADER_SET_PATHNAME, &answer); 173 sysarg_t rc = async_data_write_start(exch, (void *) pa, pa_len); 174 175 async_exchange_end(exch); 176 free(pa); 177 163 aid_t req = async_send_0(exch, LOADER_SET_PROGRAM, &answer); 164 165 sysarg_t rc = async_data_write_start(exch, name, str_size(name) + 1); 166 if (rc == EOK) { 167 async_exch_t *vfs_exch = vfs_exchange_begin(); 168 rc = vfs_pass_handle(vfs_exch, file, exch); 169 vfs_exchange_end(vfs_exch); 170 } 171 172 async_exchange_end(exch); 173 178 174 if (rc != EOK) { 179 175 async_forget(req); 180 176 return (int) rc; 181 177 } 182 178 183 179 async_wait_for(req, &rc); 184 180 return (int) rc; 185 181 } 182 183 /** Set the program to load by path. 184 * 185 * @param ldr Loader connection structure. 186 * @param path Program path. 187 * 188 * @return Zero on success or negative error code. 189 * 190 */ 191 int loader_set_program_path(loader_t *ldr, const char *path) 192 { 193 const char *name = str_rchr(path, '/'); 194 if (name == NULL) { 195 name = path; 196 } else { 197 name++; 198 } 199 200 int fd = vfs_lookup(path, 0); 201 if (fd < 0) { 202 return fd; 203 } 204 205 int rc = loader_set_program(ldr, name, fd); 206 vfs_put(fd); 207 return rc; 208 } 209 186 210 187 211 /** Set command-line arguments for the program. … … 244 268 } 245 269 246 /** Set preset files for the program. 247 * 248 * Sets the vector of preset files to be passed to the loaded 249 * program. By convention, the first three files represent stdin, 250 * stdout and stderr respectively. 251 * 252 * @param ldr Loader connection structure. 253 * @param files NULL-terminated array of pointers to files. 254 * 255 * @return Zero on success or negative error code. 256 * 257 */ 258 int loader_set_files(loader_t *ldr, int * const files[]) 259 { 260 /* Send serialized files to the loader */ 270 /** Add a file to the task's inbox. 271 * 272 * @param ldr Loader connection structure. 273 * @param name Identification of the file. 274 * @param file The file's descriptor. 275 * 276 * @return Zero on success or negative error code. 277 * 278 */ 279 int loader_add_inbox(loader_t *ldr, const char *name, int file) 280 { 261 281 async_exch_t *exch = async_exchange_begin(ldr->sess); 262 282 async_exch_t *vfs_exch = vfs_exchange_begin(); 263 283 264 int i; 265 for (i = 0; files[i]; i++); 266 267 ipc_call_t answer; 268 aid_t req = async_send_1(exch, LOADER_SET_FILES, i, &answer); 269 270 sysarg_t rc = EOK; 271 272 for (i = 0; files[i]; i++) { 273 rc = async_state_change_start(exch, VFS_PASS_HANDLE, *files[i], 274 0, vfs_exch); 275 if (rc != EOK) 276 break; 277 } 278 279 vfs_exchange_end(vfs_exch); 280 async_exchange_end(exch); 281 282 if (rc != EOK) { 283 async_forget(req); 284 return (int) rc; 285 } 286 287 async_wait_for(req, &rc); 284 aid_t req = async_send_0(exch, LOADER_ADD_INBOX, NULL); 285 286 sysarg_t rc = async_data_write_start(exch, name, str_size(name) + 1); 287 if (rc == EOK) { 288 rc = vfs_pass_handle(vfs_exch, file, exch); 289 } 290 291 async_exchange_end(vfs_exch); 292 async_exchange_end(exch); 293 294 if (rc == EOK) { 295 async_wait_for(req, &rc); 296 } else { 297 async_forget(req); 298 } 299 288 300 return (int) rc; 289 301 }
Note:
See TracChangeset
for help on using the changeset viewer.