Changeset 7c7a3209 in mainline


Ignore:
Timestamp:
2009-10-15T18:11:05Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7591b27d
Parents:
e035612 (diff), d8ef374 (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.
Message:

Merge support for passing the current working directory to the spawned task.

Location:
uspace
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/scli.c

    re035612 r7c7a3209  
    6161        usr->line = (char *) NULL;
    6262        usr->name = "root";
    63         usr->home = "/";
    6463        usr->cwd = (char *) NULL;
    6564        usr->prompt = (char *) NULL;
    66         chdir(usr->home);
    6765        usr->lasterr = 0;
    6866        return (int) cli_set_prompt(usr);
  • uspace/app/bdsh/scli.h

    re035612 r7c7a3209  
    77typedef struct {
    88        char *name;
    9         char *home;
    109        char *line;
    1110        char *cwd;
  • uspace/lib/libc/generic/libc.c

    re035612 r7c7a3209  
    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

    re035612 r7c7a3209  
    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

    re035612 r7c7a3209  
    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/generic/vfs/vfs.c

    re035612 r7c7a3209  
    664664char *getcwd(char *buf, size_t size)
    665665{
     666        if (!cwd_size)
     667                return NULL;
    666668        if (!size)
    667669                return NULL;
  • uspace/lib/libc/include/ipc/loader.h

    re035612 r7c7a3209  
    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

    re035612 r7c7a3209  
    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

    re035612 r7c7a3209  
    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

    re035612 r7c7a3209  
    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.