Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/loader.c

    rd96d9bc r6afc9d7  
    124124                return ENOMEM;
    125125       
    126         if (vfs_cwd_get(cwd, MAX_PATH_LEN + 1) != EOK)
     126        if (getcwd(cwd, MAX_PATH_LEN + 1) == NULL)
    127127                str_cpy(cwd, MAX_PATH_LEN + 1, "/");
    128128       
     
    147147}
    148148
    149 /** Set the program to load.
     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).
    150154 *
    151155 * @param ldr  Loader connection structure.
    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 
    162         ipc_call_t answer;
    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 
    174         if (rc != EOK) {
    175                 async_forget(req);
    176                 return (int) rc;
    177         }
    178 
    179         async_wait_for(req, &rc);
    180         return (int) rc;
    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 
     156 * @param path Pathname of the program file.
     157 *
     158 * @return Zero on success or negative error code.
     159 *
     160 */
     161int 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       
     171        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       
     178        if (rc != EOK) {
     179                async_forget(req);
     180                return (int) rc;
     181        }
     182       
     183        async_wait_for(req, &rc);
     184        return (int) rc;
     185}
    210186
    211187/** Set command-line arguments for the program.
     
    268244}
    269245
    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 {
     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 */
     258int loader_set_files(loader_t *ldr, int * const files[])
     259{
     260        /* Send serialized files to the loader */
    281261        async_exch_t *exch = async_exchange_begin(ldr->sess);
    282262        async_exch_t *vfs_exch = vfs_exchange_begin();
    283263       
    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        
     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);
    300288        return (int) rc;
    301289}
Note: See TracChangeset for help on using the changeset viewer.