Changeset 63c1dd5 in mainline for uspace/app/init/init.c


Ignore:
Timestamp:
2018-10-09T08:40:53Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63a045c
Parents:
ee9c703
git-author:
Jiri Svoboda <jiri@…> (2018-10-08 18:38:16)
git-committer:
Jiri Svoboda <jiri@…> (2018-10-09 08:40:53)
Message:

Persistence of Tetris highscore table. Detect live mode and create directory structure in init task. Reading volume configuration, vol -c.

File:
1 edited

Legend:

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

    ree9c703 r63c1dd5  
    4747#include <config.h>
    4848#include <io/logctl.h>
     49#include <vol.h>
    4950#include "untar.h"
    5051#include "init.h"
     
    7071#define srv_start(path, ...) \
    7172        srv_startl(path, path, ##__VA_ARGS__, NULL)
     73
     74static const char *sys_dirs[] = {
     75        "/w/cfg",
     76        "/w/data"
     77};
    7278
    7379/** Print banner */
     
    320326}
    321327
     328/** Init system volume.
     329 *
     330 * See if system volume is configured. If so, try to wait for it to become
     331 * available. If not, create basic directories for live image omde.
     332 */
     333static errno_t init_sysvol(void)
     334{
     335        vol_t *vol = NULL;
     336        vol_info_t vinfo;
     337        volume_id_t *volume_ids = NULL;
     338        size_t nvols;
     339        size_t i;
     340        errno_t rc;
     341        bool found_cfg;
     342        const char **cp;
     343
     344        rc = vol_create(&vol);
     345        if (rc != EOK) {
     346                printf("Error contacting volume service.\n");
     347                goto error;
     348        }
     349
     350        rc = vol_get_volumes(vol, &volume_ids, &nvols);
     351        if (rc != EOK) {
     352                printf("Error getting list of volumes.\n");
     353                goto error;
     354        }
     355
     356        /* XXX This could be handled more efficiently by volsrv itself */
     357        found_cfg = false;
     358        for (i = 0; i < nvols; i++) {
     359                rc = vol_info(vol, volume_ids[i], &vinfo);
     360                if (rc != EOK) {
     361                        printf("Error getting volume information.\n");
     362                        rc = EIO;
     363                        goto error;
     364                }
     365
     366                if (str_cmp(vinfo.path, "/w") == 0) {
     367                        found_cfg = true;
     368                        break;
     369                }
     370        }
     371
     372        vol_destroy(vol);
     373        free(volume_ids);
     374
     375        if (!found_cfg) {
     376                /* Prepare directory structure for live image mode */
     377                printf("%s: Creating live image directory structure.\n", NAME);
     378                cp = sys_dirs;
     379                while (*cp != NULL) {
     380                        rc = vfs_link_path(*cp, KIND_DIRECTORY, NULL);
     381                        if (rc != EOK) {
     382                                printf("%s: Error creating directory '%s'.\n",
     383                                    NAME, *cp);
     384                                return rc;
     385                        }
     386
     387                        ++cp;
     388                }
     389        } else {
     390                printf("%s: System volume is configured.\n", NAME);
     391        }
     392
     393        return EOK;
     394error:
     395        vol_destroy(vol);
     396        if (volume_ids != NULL)
     397                free(volume_ids);
     398
     399        return rc;
     400}
     401
    322402int main(int argc, char *argv[])
    323403{
     
    375455        srv_start("/srv/hound");
    376456
     457        init_sysvol();
     458
    377459        if (!config_key_exists("console")) {
    378460                rc = compositor(HID_INPUT, HID_COMPOSITOR_SERVER);
Note: See TracChangeset for help on using the changeset viewer.