Changeset 5e718d9 in mainline for uspace/app/init/init.c


Ignore:
Timestamp:
2012-08-21T10:04:16Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
67edca6
Parents:
0da6c04 (diff), 6a97f2e (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 with upstream (lp:~wtachi/helenos/bithenge)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/init/init.c

    r0da6c04 r5e718d9  
    3737#include <stdio.h>
    3838#include <unistd.h>
     39#include <stdarg.h>
    3940#include <vfs/vfs.h>
    4041#include <bool.h>
     
    6566#define SRV_CONSOLE  "/srv/console"
    6667#define APP_GETTERM  "/app/getterm"
     68
     69#define SRV_COMPOSITOR  "/srv/compositor"
     70
     71#define HID_INPUT              "hid/input"
     72#define HID_OUTPUT             "hid/output"
     73#define HID_COMPOSITOR_SERVER  ":0"
     74
     75#define srv_start(path, ...) \
     76        srv_startl(path, path, ##__VA_ARGS__, NULL)
    6777
    6878/** Print banner */
     
    143153}
    144154
    145 static void spawn(const char *fname)
    146 {
    147         int rc;
     155static int srv_startl(const char *path, ...)
     156{
    148157        struct stat s;
    149        
    150         if (stat(fname, &s) == ENOENT)
    151                 return;
    152        
    153         printf("%s: Spawning %s\n", NAME, fname);
    154         rc = task_spawnl(NULL, fname, fname, NULL);
    155         if (rc != EOK) {
    156                 printf("%s: Error spawning %s (%s)\n", NAME, fname,
    157                     str_error(rc));
    158         }
    159 }
    160 
    161 static void srv_start(const char *fname)
    162 {
     158        if (stat(path, &s) == ENOENT) {
     159                printf("%s: Unable to stat %s\n", NAME, path);
     160                return ENOENT;
     161        }
     162       
     163        printf("%s: Starting %s\n", NAME, path);
     164       
     165        va_list ap;
     166        const char *arg;
     167        int cnt = 0;
     168       
     169        va_start(ap, path);
     170        do {
     171                arg = va_arg(ap, const char *);
     172                cnt++;
     173        } while (arg != NULL);
     174        va_end(ap);
     175       
     176        va_start(ap, path);
    163177        task_id_t id;
     178        int rc = task_spawn(&id, path, cnt, ap);
     179        va_end(ap);
     180       
     181        if (rc != EOK) {
     182                printf("%s: Error spawning %s (%s)\n", NAME, path,
     183                    str_error(rc));
     184                return rc;
     185        }
     186       
     187        if (!id) {
     188                printf("%s: Error spawning %s (invalid task id)\n", NAME,
     189                    path);
     190                return EINVAL;
     191        }
     192       
    164193        task_exit_t texit;
    165         int rc, retval;
    166         struct stat s;
    167        
    168         if (stat(fname, &s) == ENOENT)
    169                 return;
    170        
    171         printf("%s: Starting %s\n", NAME, fname);
    172         rc = task_spawnl(&id, fname, fname, NULL);
    173         if (!id) {
    174                 printf("%s: Error spawning %s (%s)\n", NAME, fname,
    175                     str_error(rc));
    176                 return;
    177         }
    178        
     194        int retval;
    179195        rc = task_wait(id, &texit, &retval);
    180196        if (rc != EOK) {
    181                 printf("%s: Error waiting for %s (%s)\n", NAME, fname,
    182                     str_error(rc));
    183                 return;
     197                printf("%s: Error waiting for %s (%s)\n", NAME, path,
     198                    str_error(rc));
     199                return rc;
    184200        }
    185201       
    186202        if (texit != TASK_EXIT_NORMAL) {
    187203                printf("%s: Server %s failed to start (unexpectedly "
    188                     "terminated)\n", NAME, fname);
    189                 return;
    190         }
    191 
    192         if (retval != 0) {
     204                    "terminated)\n", NAME, path);
     205                return EINVAL;
     206        }
     207       
     208        if (retval != 0)
    193209                printf("%s: Server %s failed to start (exit code %d)\n", NAME,
    194                         fname, retval);
    195         }
    196 }
    197 
    198 static void console(const char *isvc, const char *fbsvc)
    199 {
    200         printf("%s: Spawning %s %s %s\n", NAME, SRV_CONSOLE, isvc, fbsvc);
    201        
     210                    path, retval);
     211       
     212        return retval;
     213}
     214
     215static int console(const char *isvc, const char *osvc)
     216{
    202217        /* Wait for the input service to be ready */
    203218        service_id_t service_id;
     
    206221                printf("%s: Error waiting on %s (%s)\n", NAME, isvc,
    207222                    str_error(rc));
    208                 return;
    209         }
    210        
    211         /* Wait for the framebuffer service to be ready */
    212         rc = loc_service_get_id(fbsvc, &service_id, IPC_FLAG_BLOCKING);
    213         if (rc != EOK) {
    214                 printf("%s: Error waiting on %s (%s)\n", NAME, fbsvc,
    215                     str_error(rc));
    216                 return;
    217         }
    218        
    219         rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, isvc, fbsvc, NULL);
    220         if (rc != EOK) {
    221                 printf("%s: Error spawning %s %s %s (%s)\n", NAME, SRV_CONSOLE,
    222                     isvc, fbsvc, str_error(rc));
    223         }
     223                return rc;
     224        }
     225       
     226        /* Wait for the output service to be ready */
     227        rc = loc_service_get_id(osvc, &service_id, IPC_FLAG_BLOCKING);
     228        if (rc != EOK) {
     229                printf("%s: Error waiting on %s (%s)\n", NAME, osvc,
     230                    str_error(rc));
     231                return rc;
     232        }
     233       
     234        return srv_start(SRV_CONSOLE, isvc, osvc);
     235}
     236
     237static int compositor(const char *isvc, const char *name)
     238{
     239        /* Wait for the input service to be ready */
     240        service_id_t service_id;
     241        int rc = loc_service_get_id(isvc, &service_id, IPC_FLAG_BLOCKING);
     242        if (rc != EOK) {
     243                printf("%s: Error waiting on %s (%s)\n", NAME, isvc,
     244                    str_error(rc));
     245                return rc;
     246        }
     247       
     248        return srv_start(SRV_COMPOSITOR, isvc, name);
     249}
     250
     251static int gui_start(const char *app, const char *srv_name)
     252{
     253        char winreg[50];
     254        snprintf(winreg, sizeof(winreg), "%s%s%s", "comp", srv_name, "/winreg");
     255       
     256        printf("%s: Spawning %s %s\n", NAME, app, winreg);
     257       
     258        task_id_t id;
     259        int rc = task_spawnl(&id, app, app, winreg, NULL);
     260        if (rc != EOK) {
     261                printf("%s: Error spawning %s %s (%s)\n", NAME, app,
     262                    winreg, str_error(rc));
     263                return -1;
     264        }
     265       
     266        task_exit_t texit;
     267        int retval;
     268        rc = task_wait(id, &texit, &retval);
     269        if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) {
     270                printf("%s: Error retrieving retval from %s (%s)\n", NAME,
     271                    app, str_error(rc));
     272                return -1;
     273        }
     274       
     275        return retval;
    224276}
    225277
     
    227279{
    228280        char term[LOC_NAME_MAXLEN];
    229         int rc;
    230        
    231281        snprintf(term, LOC_NAME_MAXLEN, "%s/%s", LOCFS_MOUNT_POINT, svc);
    232282       
     
    235285        /* Wait for the terminal service to be ready */
    236286        service_id_t service_id;
    237         rc = loc_service_get_id(svc, &service_id, IPC_FLAG_BLOCKING);
     287        int rc = loc_service_get_id(svc, &service_id, IPC_FLAG_BLOCKING);
    238288        if (rc != EOK) {
    239289                printf("%s: Error waiting on %s (%s)\n", NAME, term,
     
    279329        if (!mount_root(STRING(RDFMT))) {
    280330                printf("%s: Exiting\n", NAME);
    281                 return -1;
     331                return 1;
    282332        }
    283333       
    284334        /* Make sure tmpfs is running. */
    285         if (str_cmp(STRING(RDFMT), "tmpfs") != 0) {
    286                 spawn("/srv/tmpfs");
    287         }
    288        
    289         spawn("/srv/locfs");
    290         spawn("/srv/taskmon");
     335        if (str_cmp(STRING(RDFMT), "tmpfs") != 0)
     336                srv_start("/srv/tmpfs");
     337       
     338        srv_start("/srv/locfs");
     339        srv_start("/srv/taskmon");
    291340       
    292341        if (!mount_locfs()) {
    293342                printf("%s: Exiting\n", NAME);
    294                 return -2;
     343                return 2;
    295344        }
    296345       
    297346        mount_tmpfs();
    298347       
    299         spawn("/srv/devman");
    300         spawn("/srv/apic");
    301         spawn("/srv/i8259");
    302         spawn("/srv/obio");
     348        srv_start("/srv/devman");
     349        srv_start("/srv/apic");
     350        srv_start("/srv/i8259");
     351        srv_start("/srv/obio");
    303352        srv_start("/srv/cuda_adb");
    304353        srv_start("/srv/s3c24xx_uart");
    305354        srv_start("/srv/s3c24xx_ts");
    306355       
    307         spawn("/srv/loopip");
    308         spawn("/srv/ethip");
    309         spawn("/srv/inetsrv");
    310         spawn("/srv/tcp");
    311         spawn("/srv/udp");
    312        
    313         spawn("/srv/fb");
    314         spawn("/srv/input");
    315         console("hid/input", "hid/fb0");
    316        
    317         spawn("/srv/clipboard");
    318         spawn("/srv/remcons");
     356        srv_start("/srv/loopip");
     357        srv_start("/srv/ethip");
     358        srv_start("/srv/inetsrv");
     359        srv_start("/srv/tcp");
     360        srv_start("/srv/udp");
     361       
     362        srv_start("/srv/clipboard");
     363        srv_start("/srv/remcons");
    319364       
    320365        /*
     
    325370        srv_start("/srv/ata_bd");
    326371        srv_start("/srv/gxe_bd");
    327 #else
    328         (void) srv_start;
    329372#endif
    330373       
    331374#ifdef CONFIG_MOUNT_DATA
    332375        /* Make sure fat is running. */
    333         if (str_cmp(STRING(RDFMT), "fat") != 0) {
     376        if (str_cmp(STRING(RDFMT), "fat") != 0)
    334377                srv_start("/srv/fat");
    335         }
     378       
    336379        mount_data();
    337380#else
     
    339382#endif
    340383       
    341         getterm("term/vc0", "/app/bdsh", true);
    342         getterm("term/vc1", "/app/bdsh", false);
    343         getterm("term/vc2", "/app/bdsh", false);
    344         getterm("term/vc3", "/app/bdsh", false);
    345         getterm("term/vc4", "/app/bdsh", false);
    346         getterm("term/vc5", "/app/bdsh", false);
    347         getterm("term/vc6", "/app/klog", false);
     384        srv_start("/srv/input", HID_INPUT);
     385        srv_start("/srv/output", HID_OUTPUT);
     386       
     387        int rc = compositor(HID_INPUT, HID_COMPOSITOR_SERVER);
     388        if (rc == EOK) {
     389                gui_start("/app/vlaunch", HID_COMPOSITOR_SERVER);
     390                gui_start("/app/vterm", HID_COMPOSITOR_SERVER);
     391        } else {
     392                rc = console(HID_INPUT, HID_OUTPUT);
     393                if (rc == EOK) {
     394                        getterm("term/vc0", "/app/bdsh", true);
     395                        getterm("term/vc1", "/app/bdsh", false);
     396                        getterm("term/vc2", "/app/bdsh", false);
     397                        getterm("term/vc3", "/app/bdsh", false);
     398                        getterm("term/vc4", "/app/bdsh", false);
     399                        getterm("term/vc5", "/app/bdsh", false);
     400                        getterm("term/vc6", "/app/klog", false);
     401                }
     402        }
    348403       
    349404        return 0;
Note: See TracChangeset for help on using the changeset viewer.