source: mainline/uspace/lib/libc/generic/task.c@ ce4a3dae

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ce4a3dae was 24345a5, checked in by Jiri Svoboda <jirik.svoboda@…>, 17 years ago

Set meaningful names for loaded programs. Now 'tasks' kconsole command is much less obscure.

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[f30e6a0b]1/*
[df4ed85]2 * Copyright (c) 2006 Jakub Jermar
[c98e6ee]3 * Copyright (c) 2008 Jiri Svoboda
[f30e6a0b]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[b2951e2]28 */
29
[fadd381]30/** @addtogroup libc
[b2951e2]31 * @{
32 */
33/** @file
[f30e6a0b]34 */
35
36#include <task.h>
37#include <libc.h>
[c98e6ee]38#include <stdlib.h>
39#include <errno.h>
[45454e9b]40#include <loader/loader.h>
[f30e6a0b]41
[d3b8c1f]42task_id_t task_get_id(void)
[f30e6a0b]43{
44 task_id_t task_id;
45
[d3b8c1f]46 (void) __SYSCALL1(SYS_TASK_GET_ID, (sysarg_t) &task_id);
[f30e6a0b]47
48 return task_id;
49}
[b2951e2]50
[45454e9b]51/** Create a new task by running an executable from the filesystem.
52 *
53 * This is really just a convenience wrapper over the more complicated
54 * loader API.
[c98e6ee]55 *
56 * @param path pathname of the binary to execute
57 * @param argv command-line arguments
58 * @return ID of the newly created task or zero on error.
59 */
[2e3355a]60task_id_t task_spawn(const char *path, char *const argv[])
[c98e6ee]61{
[45454e9b]62 loader_t *ldr;
[47e0a05b]63 task_id_t task_id;
[45454e9b]64 int rc;
[17b2aac]65
[4470e26]66 /* Spawn a program loader. */
[24345a5]67 ldr = loader_spawn(path);
[45454e9b]68 if (ldr == NULL)
[17b2aac]69 return 0;
[c98e6ee]70
[47e0a05b]71 /* Get task ID. */
[45454e9b]72 rc = loader_get_task_id(ldr, &task_id);
73 if (rc != EOK)
[47e0a05b]74 goto error;
75
[4470e26]76 /* Send program pathname. */
[45454e9b]77 rc = loader_set_pathname(ldr, path);
78 if (rc != EOK)
[17b2aac]79 goto error;
[c98e6ee]80
[4470e26]81 /* Send arguments. */
[45454e9b]82 rc = loader_set_args(ldr, argv);
[17b2aac]83 if (rc != EOK)
84 goto error;
[c98e6ee]85
[4470e26]86 /* Load the program. */
87 rc = loader_load_program(ldr);
88 if (rc != EOK)
89 goto error;
90
91 /* Run it. */
92 /* Load the program. */
93 rc = loader_run(ldr);
[17b2aac]94 if (rc != EOK)
95 goto error;
[c98e6ee]96
97 /* Success */
[4470e26]98
99 free(ldr);
[47e0a05b]100 return task_id;
[c98e6ee]101
102 /* Error exit */
103error:
[45454e9b]104 loader_abort(ldr);
[4470e26]105 free(ldr);
106
[c98e6ee]107 return 0;
[adb4d6c2]108}
109
[fadd381]110/** @}
[b2951e2]111 */
Note: See TracBrowser for help on using the repository browser.