Changes in / [0b81cad0:0578271] in mainline


Ignore:
Location:
uspace
Files:
4 deleted
11 edited

Legend:

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

    r0b81cad0 r0578271  
    4141#include <fcntl.h>
    4242#include <str_error.h>
    43 #include <errno.h>
    4443
    4544#include "config.h"
     
    117116        task_exit_t texit;
    118117        char *tmp;
    119         int rc, retval;
     118        int retval;
    120119
    121120        tmp = str_dup(find_command(cmd));
    122121        free(found);
    123122
    124         rc = task_spawnv(&tid, tmp, (const char **) argv);
     123        tid = task_spawn(tmp, (const char **) argv, &retval);
    125124        free(tmp);
    126125
    127         if (rc != 0) {
     126        if (tid == 0) {
    128127                cli_error(CL_EEXEC, "%s: Cannot spawn `%s' (%s)", progname, cmd,
    129                     str_error(rc));
     128                    str_error(retval));
    130129                return 1;
    131130        }
    132131       
    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) {
     132        task_wait(tid, &texit, &retval);
     133        if (texit != TASK_EXIT_NORMAL) {
    137134                printf("%s: Command failed (unexpectedly terminated)\n", progname);
    138135        } else if (retval != 0) {
    139                 printf("%s: Command failed (exit code %d)\n",
    140                     progname, retval);
     136                printf("%s: Command failed (%s)\n",
     137                    progname, str_error(retval));
    141138        }
    142139
  • uspace/app/getterm/getterm.c

    r0b81cad0 r0578271  
    4141#include <task.h>
    4242#include <str_error.h>
    43 #include <errno.h>
    4443#include "version.h"
    4544
     
    7574static task_id_t spawn(const char *fname)
    7675{
    77         task_id_t id;
    78         int rc;
     76        const char *args[2];
    7977       
    80         rc = task_spawnl(&id, fname, fname, NULL);
    81         if (rc != EOK) {
     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)
    8285                printf("%s: Error spawning %s (%s)\n", APP_NAME, fname,
    83                     str_error(rc));
    84                 return 0;
    85         }
     86                    str_error(err));
    8687       
    8788        return id;
  • uspace/app/init/init.c

    r0b81cad0 r0578271  
    124124static void spawn(const char *fname)
    125125{
    126         int rc;
     126        const char *argv[2];
    127127        struct stat s;
    128128       
     
    131131       
    132132        printf("%s: Spawning %s\n", NAME, fname);
    133         rc = task_spawnl(NULL, fname, fname, NULL);
    134         if (rc != EOK) {
     133       
     134        argv[0] = fname;
     135        argv[1] = NULL;
     136       
     137        int err;
     138        if (!task_spawn(fname, argv, &err))
    135139                printf("%s: Error spawning %s (%s)\n", NAME, fname,
    136                     str_error(rc));
    137         }
     140                    str_error(err));
    138141}
    139142
    140143static void srv_start(const char *fname)
    141144{
     145        const char *argv[2];
    142146        task_id_t id;
    143147        task_exit_t texit;
     
    149153       
    150154        printf("%s: Starting %s\n", NAME, fname);
    151         rc = task_spawnl(&id, fname, fname, NULL);
     155       
     156        argv[0] = fname;
     157        argv[1] = NULL;
     158       
     159        id = task_spawn(fname, argv, &retval);
    152160        if (!id) {
    153161                printf("%s: Error spawning %s (%s)\n", NAME, fname,
    154                     str_error(rc));
     162                    str_error(retval));
    155163                return;
    156164        }
     
    159167        if (rc != EOK) {
    160168                printf("%s: Error waiting for %s (%s(\n", NAME, fname,
    161                     str_error(rc));
     169                    str_error(retval));
    162170                return;
    163171        }
    164172       
    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);
     173        if ((texit != TASK_EXIT_NORMAL) || (retval != 0)) {
     174                printf("%s: Server %s failed to start (%s)\n", NAME,
     175                        fname, str_error(retval));
    174176        }
    175177}
     
    177179static void console(const char *dev)
    178180{
     181        const char *argv[3];
    179182        char hid_in[DEVMAP_NAME_MAXLEN];
    180183        int rc;
     
    187190        dev_handle_t handle;
    188191        rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
    189         if (rc != EOK) {
     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
    190202                printf("%s: Error waiting on %s (%s)\n", NAME, hid_in,
    191203                    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         }
    200204}
    201205
    202206static void getterm(const char *dev, const char *app)
    203207{
     208        const char *argv[4];
    204209        char term[DEVMAP_NAME_MAXLEN];
    205210        int rc;
     
    212217        dev_handle_t handle;
    213218        rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
    214         if (rc != EOK) {
     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
    215230                printf("%s: Error waiting on %s (%s)\n", NAME, term,
    216231                    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         }
    225232}
    226233
  • uspace/app/netstart/netstart.c

    r0b81cad0 r0578271  
    5757static bool spawn(const char *desc, const char *path)
    5858{
    59         int rc;
    60 
    6159        printf("%s: Spawning %s (%s)\n", NAME, desc, path);
    62         rc = task_spawnl(NULL, path, path, NULL);
    63         if (rc != EOK) {
     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) {
    6468                fprintf(stderr, "%s: Error spawning %s (%s)\n", NAME, path,
    65                     str_error(rc));
     69                    str_error(err));
    6670                return false;
    6771        }
  • uspace/app/redir/redir.c

    r0b81cad0 r0578271  
    4343#include <task.h>
    4444#include <str_error.h>
    45 #include <errno.h>
    4645
    4746#define NAME  "redir"
     
    7776static task_id_t spawn(int argc, char *argv[])
    7877{
    79         const char **args;
    80         task_id_t id;
    81         int rc;
    82 
    83         args = (const char **) calloc(argc + 1, sizeof(char *));
     78        const char **args = (const char **) calloc(argc + 1, sizeof(char *));
    8479        if (!args) {
    8580                printf("No memory available\n");
     
    9388        args[argc] = NULL;
    9489       
    95         rc = task_spawnv(&id, argv[0], args);
     90        int err;
     91        task_id_t id = task_spawn(argv[0], args, &err);
    9692       
    9793        free(args);
    9894       
    99         if (rc != EOK) {
     95        if (id == 0)
    10096                printf("%s: Error spawning %s (%s)\n", NAME, argv[0],
    101                     str_error(rc));
    102         }
     97                    str_error(err));
    10398       
    10499        return id;
  • uspace/app/sbi/src/os/helenos.c

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

    r0b81cad0 r0578271  
    3939#include <errno.h>
    4040#include <loader/loader.h>
    41 #include <stdarg.h>
    4241#include <str.h>
    4342#include <ipc/ns.h>
     
    6968 *
    7069 * This is really just a convenience wrapper over the more complicated
    71  * loader API. Arguments are passed as a null-terminated array of strings.
     70 * loader API.
    7271 *
    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.
     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.
    7675 *
    77  * @return      Zero on success or negative error code.
     76 * @return ID of the newly created task or zero on error.
     77 *
    7878 */
    79 int task_spawnv(task_id_t *id, const char *path, const char *const args[])
     79task_id_t task_spawn(const char *path, const char *const args[], int *err)
    8080{
    81         loader_t *ldr;
    82         task_id_t task_id;
    83         int rc;
    84 
    8581        /* Connect to a program loader. */
    86         ldr = loader_connect();
    87         if (ldr == NULL)
    88                 return EREFUSED;
     82        loader_t *ldr = loader_connect();
     83        if (ldr == NULL) {
     84                if (err != NULL)
     85                        *err = EREFUSED;
     86               
     87                return 0;
     88        }
    8989       
    9090        /* Get task ID. */
    91         rc = loader_get_task_id(ldr, &task_id);
     91        task_id_t task_id;
     92        int rc = loader_get_task_id(ldr, &task_id);
    9293        if (rc != EOK)
    9394                goto error;
     
    148149        free(ldr);
    149150       
    150         if (id != NULL)
    151                 *id = task_id;
     151        if (err != NULL)
     152                *err = EOK;
    152153       
    153         return EOK;
     154        return task_id;
    154155       
    155156error:
     
    157158        loader_abort(ldr);
    158159        free(ldr);
    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  */
    173 int 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;
     160       
     161        if (err != NULL)
     162                *err = rc;
     163       
     164        return 0;
    209165}
    210166
  • uspace/lib/c/include/task.h

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

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

    r0b81cad0 r0578271  
    3737#include <ipc/devman.h>
    3838#include <devmap.h>
    39 #include <str_error.h>
    4039
    4140#include "devman.h"
     
    447446bool start_driver(driver_t *drv)
    448447{
    449         int rc;
    450 
    451448        printf(NAME ": start_driver '%s'\n", drv->name);
    452449       
    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));
     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);
    457459                return false;
    458460        }
  • uspace/srv/taskmon/taskmon.c

    r0b81cad0 r0578271  
    5050static void fault_event(ipc_callid_t callid, ipc_call_t *call)
    5151{
     52        const char *argv[6];
    5253        const char *fname;
     54        char *dump_fname;
    5355        char *s_taskid;
    54         int rc;
     56        const char **s;
    5557
    5658        task_id_t taskid;
     
    6567        }
    6668
    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 
    7469        if (asprintf(&dump_fname, "/data/core%" PRIuTASKID, taskid) < 0) {
    7570                printf("Memory allocation failed.\n");
     
    7772        }
    7873
    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);
     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;
    8283#else
    83         printf(NAME ": Executing %s -t %s\n", s_taskid);
    84         rc = task_spawnl(NULL, fname, fname, "-t", s_taskid, NULL);
     84        argv[0] = "/app/taskdump";
     85        argv[1] = "-t";
     86        argv[2] = s_taskid;
     87        argv[3] = NULL;
    8588#endif
    86         if (rc != EOK) {
     89        fname = argv[0];
     90
     91        printf(NAME ": Executing");
     92       
     93        s = argv;
     94        while (*s != NULL) {
     95                printf(" %s", *s);
     96                ++s;
     97        }
     98        putchar('\n');
     99       
     100        int err;
     101        if (!task_spawn(fname, argv, &err))
    87102                printf("%s: Error spawning %s (%s).\n", NAME, fname,
    88                     str_error(rc));
    89         }
     103                    str_error(err));
    90104}
    91105
Note: See TracChangeset for help on using the changeset viewer.