Example #1
0
int parseFstabLine(char *line)
{
	char *saveptr;
	
	char *mountpoint = strtok_r(line, " \t", &saveptr);
	if (mountpoint == NULL) return 1;
	
	char *type = strtok_r(NULL, " \t", &saveptr);
	if (type == NULL) return 1;
	
	char *device = strtok_r(NULL, " \t", &saveptr);
	if (device == NULL) return 1;
	
	char mountPrefix[256];
	strcpy(mountPrefix, mountpoint);
	if (mountPrefix[strlen(mountPrefix)-1] != '/') strcat(mountPrefix, "/");

	if (_glidix_mount(type, device, mountPrefix, 0, NULL, 0) != 0)
	{
		perror(progName);
		return 1;
	};
	
	return 0;
};
Example #2
0
int load_config(const char *filename)
{
    struct stat st;
    if (stat(filename, &st) == -1)
    {
        perror(filename);
        return -1;
    };

    char *config_raw = (char*) malloc(st.st_size);
    int fd = open(filename, O_RDONLY);
    if (fd == -1)
    {
        perror(filename);
        return -1;
    };

    read(fd, config_raw, st.st_size);
    close(fd);

    config_raw[st.st_size] = 0;

    char *saveptr;
    char *token;

    for (token=strtok_r(config_raw, "\n", &saveptr); token!=NULL; token=strtok_r(NULL, "\n", &saveptr))
    {
        if (token[0] == 0)
        {
            continue;
        }
        else if (token[0] == '#')
        {
            continue;
        }
        else
        {
            if (interpret_config_option(token) == -1) return -1;
        };
    };

    if (confRootType == NULL)
    {
        fprintf(stderr, "init: no root filesystem sepcified\n");
        return -1;
    };

    if (confExec == NULL)
    {
        fprintf(stderr, "init: no exec command specified\n");
        return -1;
    };

    if (_glidix_mount(confRootType, confRootDevice, "/", 0) != 0)
    {
        perror("init: mount root");
        printf("init: failed to mount root device %s (%s)\n", confRootDevice, confRootType);
        return -1;
    };

    if (stat(confExec[0], &st) != 0)
    {
        _glidix_unmount("/");
        printf("init: cannot stat executable %s\n", confExec[0]);
        return -1;
    };

    if (fork() == 0)
    {
        execv(confExec[0], confExec);
        exit(1);
    };

    return 0;
};