Rev 3022 | Rev 4296 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3022 | Rev 4055 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Jakub Jermar |
2 | * Copyright (c) 2006 Jakub Jermar |
- | 3 | * Copyright (c) 2008 Jiri Svoboda |
|
3 | * All rights reserved. |
4 | * All rights reserved. |
4 | * |
5 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * are met: |
Line 32... | Line 33... | ||
32 | /** @file |
33 | /** @file |
33 | */ |
34 | */ |
34 | 35 | ||
35 | #include <task.h> |
36 | #include <task.h> |
36 | #include <libc.h> |
37 | #include <libc.h> |
- | 38 | #include <stdlib.h> |
|
- | 39 | #include <errno.h> |
|
- | 40 | #include <loader/loader.h> |
|
- | 41 | #include <string.h> |
|
37 | 42 | ||
38 | task_id_t task_get_id(void) |
43 | task_id_t task_get_id(void) |
39 | { |
44 | { |
40 | task_id_t task_id; |
45 | task_id_t task_id; |
41 | 46 | ||
42 | (void) __SYSCALL1(SYS_TASK_GET_ID, (sysarg_t) &task_id); |
47 | (void) __SYSCALL1(SYS_TASK_GET_ID, (sysarg_t) &task_id); |
43 | 48 | ||
44 | return task_id; |
49 | return task_id; |
45 | } |
50 | } |
46 | 51 | ||
- | 52 | /** Set the task name. |
|
- | 53 | * |
|
- | 54 | * @param name The new name, typically the command used to execute the |
|
- | 55 | * program. |
|
- | 56 | * @return Zero on success or negative error code. |
|
- | 57 | */ |
|
- | 58 | int task_set_name(const char *name) |
|
- | 59 | { |
|
- | 60 | return __SYSCALL2(SYS_TASK_SET_NAME, (sysarg_t) name, strlen(name)); |
|
- | 61 | } |
|
- | 62 | ||
- | 63 | /** Create a new task by running an executable from the filesystem. |
|
- | 64 | * |
|
- | 65 | * This is really just a convenience wrapper over the more complicated |
|
- | 66 | * loader API. |
|
- | 67 | * |
|
- | 68 | * @param path pathname of the binary to execute |
|
- | 69 | * @param argv command-line arguments |
|
- | 70 | * @return ID of the newly created task or zero on error. |
|
- | 71 | */ |
|
- | 72 | task_id_t task_spawn(const char *path, char *const argv[]) |
|
- | 73 | { |
|
- | 74 | loader_t *ldr; |
|
- | 75 | task_id_t task_id; |
|
- | 76 | int rc; |
|
- | 77 | ||
- | 78 | /* Connect to a program loader. */ |
|
- | 79 | ldr = loader_connect(); |
|
- | 80 | if (ldr == NULL) |
|
- | 81 | return 0; |
|
- | 82 | ||
- | 83 | /* Get task ID. */ |
|
- | 84 | rc = loader_get_task_id(ldr, &task_id); |
|
- | 85 | if (rc != EOK) |
|
- | 86 | goto error; |
|
- | 87 | ||
- | 88 | /* Send program pathname. */ |
|
- | 89 | rc = loader_set_pathname(ldr, path); |
|
- | 90 | if (rc != EOK) |
|
- | 91 | goto error; |
|
- | 92 | ||
- | 93 | /* Send arguments. */ |
|
- | 94 | rc = loader_set_args(ldr, argv); |
|
- | 95 | if (rc != EOK) |
|
- | 96 | goto error; |
|
- | 97 | ||
- | 98 | /* Load the program. */ |
|
- | 99 | rc = loader_load_program(ldr); |
|
- | 100 | if (rc != EOK) |
|
- | 101 | goto error; |
|
- | 102 | ||
- | 103 | /* Run it. */ |
|
- | 104 | rc = loader_run(ldr); |
|
- | 105 | if (rc != EOK) |
|
- | 106 | goto error; |
|
- | 107 | ||
- | 108 | /* Success */ |
|
- | 109 | ||
- | 110 | free(ldr); |
|
- | 111 | return task_id; |
|
- | 112 | ||
- | 113 | /* Error exit */ |
|
- | 114 | error: |
|
- | 115 | loader_abort(ldr); |
|
- | 116 | free(ldr); |
|
- | 117 | ||
- | 118 | return 0; |
|
- | 119 | } |
|
- | 120 | ||
47 | /** @} |
121 | /** @} |
48 | */ |
122 | */ |