Changeset 622cdbe in mainline


Ignore:
Timestamp:
2009-10-15T17:45:16Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d8ef374
Parents:
81342f7
Message:

Inherit the current working directory from the spawner to the spawnee task.

Location:
uspace
Files:
7 edited

Legend:

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

    r81342f7 r622cdbe  
    8080                __stdio_init(0, NULL);
    8181        } else {
     82                (void) chdir(__pcb->cwd);
    8283                argc = __pcb->argc;
    8384                argv = __pcb->argv;
  • uspace/lib/libc/generic/loader.c

    r81342f7 r622cdbe  
    101101}
    102102
     103/** Set current working directory for the loaded task.
     104 *
     105 * Sets the current working directory for the loaded task.
     106 *
     107 * @param ldr  Loader connection structure.
     108 *
     109 * @return Zero on success or negative error code.
     110 *
     111 */
     112int loader_set_cwd(loader_t *ldr)
     113{
     114        char *cwd;
     115        size_t len;
     116
     117        cwd = (char *) malloc(MAX_PATH_LEN + 1);
     118        if (!cwd)
     119                return ENOMEM;
     120        if (!getcwd(cwd, MAX_PATH_LEN + 1))
     121                str_cpy(cwd, MAX_PATH_LEN + 1, "/");
     122        len = str_length(cwd);
     123       
     124        ipc_call_t answer;
     125        aid_t req = async_send_0(ldr->phone_id, LOADER_SET_CWD, &answer);
     126        int rc = async_data_write_start(ldr->phone_id, cwd, len);
     127        free(cwd);
     128        if (rc != EOK) {
     129                async_wait_for(req, NULL);
     130                return rc;
     131        }
     132       
     133        ipcarg_t retval;
     134        async_wait_for(req, &retval);
     135        return (int) retval;
     136}
     137
    103138/** Set pathname of the program to load.
    104139 *
  • uspace/lib/libc/generic/task.c

    r81342f7 r622cdbe  
    8989                goto error;
    9090       
     91        /* Send spawner's current working directory. */
     92        rc = loader_set_cwd(ldr);
     93        if (rc != EOK)
     94                goto error;
     95       
    9196        /* Send program pathname. */
    9297        rc = loader_set_pathname(ldr, path);
     
    98103        if (rc != EOK)
    99104                goto error;
    100        
    101105       
    102106        /* Send default files */
  • uspace/lib/libc/include/ipc/loader.h

    r81342f7 r622cdbe  
    4141        LOADER_HELLO = IPC_FIRST_USER_METHOD,
    4242        LOADER_GET_TASKID,
     43        LOADER_SET_CWD,
    4344        LOADER_SET_PATHNAME,
    4445        LOADER_SET_ARGS,
  • uspace/lib/libc/include/loader/loader.h

    r81342f7 r622cdbe  
    4949extern loader_t *loader_connect(void);
    5050extern int loader_get_task_id(loader_t *, task_id_t *);
     51extern int loader_set_cwd(loader_t *);
    5152extern int loader_set_pathname(loader_t *, const char *);
    5253extern int loader_set_args(loader_t *, char *const[]);
  • uspace/lib/libc/include/loader/pcb.h

    r81342f7 r622cdbe  
    5252        /** Program entry point. */
    5353        entry_point_t entry;
     54
     55        /** Current working directory. */
     56        char *cwd;
    5457       
    5558        /** Number of command-line arguments. */
  • uspace/srv/loader/main.c

    r81342f7 r622cdbe  
    7272static pcb_t pcb;
    7373
     74/** Current working directory */
     75static char *cwd = NULL;
     76
    7477/** Number of arguments */
    7578static int argc = 0;
     
    115118}
    116119
     120/** Receive a call setting the current working directory.
     121 *
     122 * @param rid
     123 * @param request
     124 */
     125static void ldr_set_cwd(ipc_callid_t rid, ipc_call_t *request)
     126{
     127        ipc_callid_t callid;
     128        size_t len;
     129       
     130        if (!async_data_write_receive(&callid, &len)) {
     131                ipc_answer_0(callid, EINVAL);
     132                ipc_answer_0(rid, EINVAL);
     133                return;
     134        }
     135       
     136        cwd = malloc(len + 1);
     137        if (!cwd) {
     138                ipc_answer_0(callid, ENOMEM);
     139                ipc_answer_0(rid, ENOMEM);
     140                return;
     141        }
     142       
     143        async_data_write_finalize(callid, cwd, len);
     144        cwd[len] = '\0';
     145       
     146        ipc_answer_0(rid, EOK);
     147}
    117148
    118149/** Receive a call setting pathname of the program to execute.
     
    313344        elf_create_pcb(&prog_info, &pcb);
    314345       
     346        pcb.cwd = cwd;
     347       
    315348        pcb.argc = argc;
    316349        pcb.argv = argv;
     
    406439                case LOADER_GET_TASKID:
    407440                        ldr_get_taskid(callid, &call);
     441                        continue;
     442                case LOADER_SET_CWD:
     443                        ldr_set_cwd(callid, &call);
    408444                        continue;
    409445                case LOADER_SET_PATHNAME:
Note: See TracChangeset for help on using the changeset viewer.