Changeset 0485135 in mainline


Ignore:
Timestamp:
2010-11-05T19:53:00Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0b81cad0
Parents:
a66e2993
Message:

For more convenience, replace task_spawn() with task_spawnv() and task_spawnl().

Location:
uspace
Files:
11 edited

Legend:

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

    ra66e2993 r0485135  
    4141#include <fcntl.h>
    4242#include <str_error.h>
     43#include <errno.h>
    4344
    4445#include "config.h"
     
    116117        task_exit_t texit;
    117118        char *tmp;
    118         int retval;
     119        int rc, retval;
    119120
    120121        tmp = str_dup(find_command(cmd));
    121122        free(found);
    122123
    123         tid = task_spawn(tmp, (const char **) argv, &retval);
     124        rc = task_spawnv(&tid, tmp, (const char **) argv);
    124125        free(tmp);
    125126
    126         if (tid == 0) {
     127        if (rc != 0) {
    127128                cli_error(CL_EEXEC, "%s: Cannot spawn `%s' (%s)", progname, cmd,
    128                     str_error(retval));
     129                    str_error(rc));
    129130                return 1;
    130131        }
    131132       
    132         task_wait(tid, &texit, &retval);
    133         if (texit != TASK_EXIT_NORMAL) {
     133        rc = task_wait(tid, &texit, &retval);
     134        if (rc != EOK) {
     135                printf("%s: Failed waiting for command (%s)\n", str_error(rc));
     136        } else if (texit != TASK_EXIT_NORMAL) {
    134137                printf("%s: Command failed (unexpectedly terminated)\n", progname);
    135138        } else if (retval != 0) {
    136                 printf("%s: Command failed (%s)\n",
    137                     progname, str_error(retval));
     139                printf("%s: Command failed (exit code %d)\n",
     140                    progname, retval);
    138141        }
    139142
  • uspace/app/getterm/getterm.c

    ra66e2993 r0485135  
    4141#include <task.h>
    4242#include <str_error.h>
     43#include <errno.h>
    4344#include "version.h"
    4445
     
    7475static task_id_t spawn(const char *fname)
    7576{
    76         const char *args[2];
     77        task_id_t id;
     78        int rc;
    7779       
    78         args[0] = fname;
    79         args[1] = NULL;
    80        
    81         int err;
    82         task_id_t id = task_spawn(fname, args, &err);
    83        
    84         if (id == 0)
     80        rc = task_spawnl(&id, fname, fname, NULL);
     81        if (rc != EOK) {
    8582                printf("%s: Error spawning %s (%s)\n", APP_NAME, fname,
    86                     str_error(err));
     83                    str_error(rc));
     84                return 0;
     85        }
    8786       
    8887        return id;
  • uspace/app/init/init.c

    ra66e2993 r0485135  
    124124static void spawn(const char *fname)
    125125{
    126         const char *argv[2];
     126        int rc;
    127127        struct stat s;
    128128       
     
    131131       
    132132        printf("%s: Spawning %s\n", NAME, fname);
    133        
    134         argv[0] = fname;
    135         argv[1] = NULL;
    136        
    137         int err;
    138         if (!task_spawn(fname, argv, &err))
     133        rc = task_spawnl(NULL, fname, fname, NULL);
     134        if (rc != EOK) {
    139135                printf("%s: Error spawning %s (%s)\n", NAME, fname,
    140                     str_error(err));
     136                    str_error(rc));
     137        }
    141138}
    142139
    143140static void srv_start(const char *fname)
    144141{
    145         const char *argv[2];
    146142        task_id_t id;
    147143        task_exit_t texit;
     
    153149       
    154150        printf("%s: Starting %s\n", NAME, fname);
    155        
    156         argv[0] = fname;
    157         argv[1] = NULL;
    158        
    159         id = task_spawn(fname, argv, &retval);
     151        rc = task_spawnl(&id, fname, fname, NULL);
    160152        if (!id) {
    161153                printf("%s: Error spawning %s (%s)\n", NAME, fname,
    162                     str_error(retval));
     154                    str_error(rc));
    163155                return;
    164156        }
     
    167159        if (rc != EOK) {
    168160                printf("%s: Error waiting for %s (%s(\n", NAME, fname,
    169                     str_error(retval));
    170                 return;
    171         }
    172        
    173         if ((texit != TASK_EXIT_NORMAL) || (retval != 0)) {
    174                 printf("%s: Server %s failed to start (%s)\n", NAME,
    175                         fname, str_error(retval));
     161                    str_error(rc));
     162                return;
     163        }
     164       
     165        if (texit != TASK_EXIT_NORMAL) {
     166                printf("%s: Server %s failed to start (unexpectedly "
     167                    "terminated)\n", NAME, fname);
     168                return;
     169        }
     170
     171        if (retval != 0) {
     172                printf("%s: Server %s failed to start (exit code %d)\n", NAME,
     173                        fname, retval);
    176174        }
    177175}
     
    179177static void console(const char *dev)
    180178{
    181         const char *argv[3];
    182179        char hid_in[DEVMAP_NAME_MAXLEN];
    183180        int rc;
     
    190187        dev_handle_t handle;
    191188        rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
    192        
    193         if (rc == EOK) {
    194                 argv[0] = SRV_CONSOLE;
    195                 argv[1] = hid_in;
    196                 argv[2] = NULL;
    197                
    198                 if (!task_spawn(SRV_CONSOLE, argv, &rc))
    199                         printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE,
    200                             hid_in, str_error(rc));
    201         } else
     189        if (rc != EOK) {
    202190                printf("%s: Error waiting on %s (%s)\n", NAME, hid_in,
    203191                    str_error(rc));
     192                return;
     193        }
     194       
     195        rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, hid_in, NULL);
     196        if (rc != EOK) {
     197                printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE,
     198                    hid_in, str_error(rc));
     199        }
    204200}
    205201
    206202static void getterm(const char *dev, const char *app)
    207203{
    208         const char *argv[4];
    209204        char term[DEVMAP_NAME_MAXLEN];
    210205        int rc;
     
    217212        dev_handle_t handle;
    218213        rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
    219        
    220         if (rc == EOK) {
    221                 argv[0] = APP_GETTERM;
    222                 argv[1] = term;
    223                 argv[2] = app;
    224                 argv[3] = NULL;
    225                
    226                 if (!task_spawn(APP_GETTERM, argv, &rc))
    227                         printf("%s: Error spawning %s %s %s (%s)\n", NAME, APP_GETTERM,
    228                             term, app, str_error(rc));
    229         } else
     214        if (rc != EOK) {
    230215                printf("%s: Error waiting on %s (%s)\n", NAME, term,
    231216                    str_error(rc));
     217                return;
     218        }
     219       
     220        rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, term, app, NULL);
     221        if (rc != EOK) {
     222                printf("%s: Error spawning %s %s %s (%s)\n", NAME,
     223                    APP_GETTERM, term, app, str_error(rc));
     224        }
    232225}
    233226
  • uspace/app/netstart/netstart.c

    ra66e2993 r0485135  
    5757static bool spawn(const char *desc, const char *path)
    5858{
     59        int rc;
     60
    5961        printf("%s: Spawning %s (%s)\n", NAME, desc, path);
    60        
    61         const char *argv[2];
    62        
    63         argv[0] = path;
    64         argv[1] = NULL;
    65        
    66         int err;
    67         if (task_spawn(path, argv, &err) == 0) {
     62        rc = task_spawnl(NULL, path, path, NULL);
     63        if (rc != EOK) {
    6864                fprintf(stderr, "%s: Error spawning %s (%s)\n", NAME, path,
    69                     str_error(err));
     65                    str_error(rc));
    7066                return false;
    7167        }
  • uspace/app/redir/redir.c

    ra66e2993 r0485135  
    4343#include <task.h>
    4444#include <str_error.h>
     45#include <errno.h>
    4546
    4647#define NAME  "redir"
     
    7677static task_id_t spawn(int argc, char *argv[])
    7778{
    78         const char **args = (const char **) calloc(argc + 1, sizeof(char *));
     79        const char **args;
     80        task_id_t id;
     81        int rc;
     82
     83        args = (const char **) calloc(argc + 1, sizeof(char *));
    7984        if (!args) {
    8085                printf("No memory available\n");
     
    8893        args[argc] = NULL;
    8994       
    90         int err;
    91         task_id_t id = task_spawn(argv[0], args, &err);
     95        rc = task_spawnv(&id, argv[0], args);
    9296       
    9397        free(args);
    9498       
    95         if (id == 0)
     99        if (rc != EOK) {
    96100                printf("%s: Error spawning %s (%s)\n", NAME, argv[0],
    97                     str_error(err));
     101                    str_error(rc));
     102        }
    98103       
    99104        return id;
  • uspace/app/sbi/src/os/helenos.c

    ra66e2993 r0485135  
    249249        task_id_t tid;
    250250        task_exit_t texit;
    251         int retval;
    252 
    253         tid = task_spawn(cmd[0], (char const * const *) cmd, &retval);
    254         if (tid == 0) {
     251        int rc, retval;
     252
     253        rc = task_spawnv(&tid, cmd[0], (char const * const *) cmd);
     254        if (rc != EOK) {
    255255                printf("Error: Failed spawning '%s' (%s).\n", cmd[0],
    256                     str_error(retval));
     256                    str_error(rc));
    257257                exit(1);
    258258        }
    259259
    260260        /* XXX Handle exit status and return value. */
    261         task_wait(tid, &texit, &retval);
     261        rc = task_wait(tid, &texit, &retval);
     262        (void) rc;
    262263
    263264        return EOK;
  • uspace/lib/c/generic/task.c

    ra66e2993 r0485135  
    3939#include <errno.h>
    4040#include <loader/loader.h>
     41#include <stdarg.h>
    4142#include <str.h>
    4243#include <ipc/ns.h>
     
    6869 *
    6970 * This is really just a convenience wrapper over the more complicated
    70  * loader API.
    71  *
    72  * @param path Pathname of the binary to execute.
    73  * @param argv Command-line arguments.
    74  * @param err  If not NULL, the error value is stored here.
    75  *
    76  * @return ID of the newly created task or zero on error.
    77  *
    78  */
    79 task_id_t task_spawn(const char *path, const char *const args[], int *err)
    80 {
     71 * loader API. Arguments are passed as a null-terminated array of strings.
     72 *
     73 * @param id    If not NULL, the ID of the task is stored here on success.
     74 * @param path  Pathname of the binary to execute.
     75 * @param argv  Command-line arguments.
     76 *
     77 * @return      Zero on success or negative error code.
     78 */
     79int task_spawnv(task_id_t *id, const char *path, const char *const args[])
     80{
     81        loader_t *ldr;
     82        task_id_t task_id;
     83        int rc;
     84
    8185        /* Connect to a program loader. */
    82         loader_t *ldr = loader_connect();
    83         if (ldr == NULL) {
    84                 if (err != NULL)
    85                         *err = EREFUSED;
    86                
    87                 return 0;
    88         }
     86        ldr = loader_connect();
     87        if (ldr == NULL)
     88                return EREFUSED;
    8989       
    9090        /* Get task ID. */
    91         task_id_t task_id;
    92         int rc = loader_get_task_id(ldr, &task_id);
     91        rc = loader_get_task_id(ldr, &task_id);
    9392        if (rc != EOK)
    9493                goto error;
     
    149148        free(ldr);
    150149       
    151         if (err != NULL)
    152                 *err = EOK;
    153        
    154         return task_id;
     150        if (id != NULL)
     151                *id = task_id;
     152       
     153        return EOK;
    155154       
    156155error:
     
    158157        loader_abort(ldr);
    159158        free(ldr);
    160        
    161         if (err != NULL)
    162                 *err = rc;
    163        
    164         return 0;
     159        return rc;
     160}
     161
     162/** Create a new task by running an executable from the filesystem.
     163 *
     164 * This is really just a convenience wrapper over the more complicated
     165 * loader API. Arguments are passed as a null-terminated list of arguments.
     166 *
     167 * @param id    If not NULL, the ID of the task is stored here on success.
     168 * @param path  Pathname of the binary to execute.
     169 * @param ...   Command-line arguments.
     170 *
     171 * @return      Zero on success or negative error code.
     172 */
     173int task_spawnl(task_id_t *task_id, const char *path, ...)
     174{
     175        va_list ap;
     176        int rc, cnt;
     177        const char *arg;
     178        const char **arglist;
     179
     180        /* Count the number of arguments. */
     181        cnt = 0;
     182        va_start(ap, path);
     183        do {
     184                arg = va_arg(ap, const char *);
     185                cnt++;
     186        } while (arg != NULL);
     187        va_end(ap);
     188
     189        /* Allocate argument list. */
     190        arglist = malloc(cnt * sizeof(const char *));
     191        if (arglist == NULL)
     192                return ENOMEM;
     193
     194        /* Fill in arguments. */
     195        cnt = 0;
     196        va_start(ap, path);
     197        do {
     198                arg = va_arg(ap, const char *);
     199                arglist[cnt++] = arg;
     200        } while (arg != NULL);
     201        va_end(ap);
     202
     203        /* Spawn task. */
     204        rc = task_spawnv(task_id, path, arglist);
     205
     206        /* Free argument list. */
     207        free(arglist);
     208        return rc;
    165209}
    166210
  • uspace/lib/c/include/task.h

    ra66e2993 r0485135  
    4848extern int task_set_name(const char *);
    4949extern task_id_t task_spawn(const char *, const char *const[], int *);
     50extern int task_spawnv(task_id_t *, const char *path, const char *const []);
     51extern int task_spawnl(task_id_t *, const char *path, ...);
     52
    5053extern int task_wait(task_id_t id, task_exit_t *, int *);
    5154extern int task_retval(int);
  • uspace/lib/net/adt/module_map.c

    ra66e2993 r0485135  
    132132task_id_t spawn(const char *fname)
    133133{
    134         const char *argv[2];
    135         task_id_t res;
     134        task_id_t id;
     135        int rc;
    136136       
    137         argv[0] = fname;
    138         argv[1] = NULL;
    139         res = task_spawn(fname, argv, NULL);
     137        rc = task_spawnl(&id, fname, fname, NULL);
     138        if (rc != EOK)
     139                return 0;
    140140       
    141         return res;
     141        return id;
    142142}
    143143
  • uspace/srv/devman/devman.c

    ra66e2993 r0485135  
    3737#include <ipc/devman.h>
    3838#include <devmap.h>
     39#include <str_error.h>
    3940
    4041#include "devman.h"
     
    446447bool start_driver(driver_t *drv)
    447448{
     449        int rc;
     450
    448451        printf(NAME ": start_driver '%s'\n", drv->name);
    449452       
    450         const char *argv[2];
    451        
    452         argv[0] = drv->name;
    453         argv[1] = NULL;
    454        
    455         int err;
    456         if (task_spawn(drv->binary_path, argv, &err) == 0) {
    457                 printf(NAME ": error spawning %s, errno = %d\n",
    458                     drv->name, err);
     453        rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL);
     454        if (rc != EOK) {
     455                printf(NAME ": error spawning %s (%s)\n",
     456                    drv->name, str_error(rc));
    459457                return false;
    460458        }
  • uspace/srv/taskmon/taskmon.c

    ra66e2993 r0485135  
    5050static void fault_event(ipc_callid_t callid, ipc_call_t *call)
    5151{
    52         const char *argv[6];
    5352        const char *fname;
    54         char *dump_fname;
    5553        char *s_taskid;
    56         const char **s;
     54        int rc;
    5755
    5856        task_id_t taskid;
     
    6765        }
    6866
     67        printf(NAME ": Task %" PRIuTASKID " fault in thread %p.\n", taskid, thread);
     68
     69        fname = "/app/taskdump";
     70
     71#ifdef CONFIG_WRITE_CORE_FILES
     72        char *dump_fname;
     73
    6974        if (asprintf(&dump_fname, "/data/core%" PRIuTASKID, taskid) < 0) {
    7075                printf("Memory allocation failed.\n");
     
    7277        }
    7378
    74         printf(NAME ": Task %" PRIuTASKID " fault in thread %p.\n", taskid, thread);
    75 
    76 #ifdef CONFIG_WRITE_CORE_FILES
    77         argv[0] = "/app/taskdump";
    78         argv[1] = "-c";
    79         argv[2] = dump_fname;
    80         argv[3] = "-t";
    81         argv[4] = s_taskid;
    82         argv[5] = NULL;
     79        printf(NAME ": Executing %s -c %s -t %s\n", dump_fname, s_taskid);
     80        rc = task_spawnl(NULL, fname, fname, "-c", dump_fname, "-t", s_taskid,
     81            NULL);
    8382#else
    84         argv[0] = "/app/taskdump";
    85         argv[1] = "-t";
    86         argv[2] = s_taskid;
    87         argv[3] = NULL;
     83        printf(NAME ": Executing %s -t %s\n", s_taskid);
     84        rc = task_spawnl(NULL, fname, fname, "-t", s_taskid, NULL);
    8885#endif
    89         fname = argv[0];
    90 
    91         printf(NAME ": Executing");
    92        
    93         s = argv;
    94         while (*s != NULL) {
    95                 printf(" %s", *s);
    96                 ++s;
     86        if (rc != EOK) {
     87                printf("%s: Error spawning %s (%s).\n", NAME, fname,
     88                    str_error(rc));
    9789        }
    98         putchar('\n');
    99        
    100         int err;
    101         if (!task_spawn(fname, argv, &err))
    102                 printf("%s: Error spawning %s (%s).\n", NAME, fname,
    103                     str_error(err));
    10490}
    10591
Note: See TracChangeset for help on using the changeset viewer.