예제 #1
0
int main( int argc, char *argv[] )
{
    int size;
    char filename[100];

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    sprintf(filename, "log%d.txt", rank);
    logfid = fopen(filename,"a");
    rankprintf("rank %d of %d\n", rank, size);
    if (1 == size) {
      //Run just one degrid 
      // For testing
      memset(token_list, 0, sizeof(token*)*256);
      int data[3];
      data[0] = TASK_GENVIS;
      data[1] = 45;
      data[2] = NPOINTS;
      exec_task(data);
      data[0] = TASK_GENIMG;
      data[1] = 46;
      data[2] = IMG_SIZE;
      exec_task(data);
      data[0] = TASK_DEGRID;
      data[1] = 45;
      data[2] = 46;
      exec_task(data);
      rankprintf("All tasks complete\n");
      return 0;
    }
    if (size < 3)
    {
        rankprintf("Three processes needed to run this test.\n");fflush(stdout);
        MPI_Finalize();
        return 0;
    }

    if (rank == 0)
    {
       run_client(size);
    }
    else 
    {
       run_server(size);
    }
    fclose(logfid);
    MPI_Barrier(MPI_COMM_WORLD);
    MPI_Finalize();
    return 0;
}
예제 #2
0
파일: scheduler.c 프로젝트: mrdg/flim
void dispatch(PtTimestamp time, void *data)
{
    struct scheduler *scheduler =
        (struct scheduler * ) data;

    struct task *first = dequeue(scheduler->queue, time);

    if (first == NULL) {
        return;
    } else {

        struct task *current = first;
        struct task *prev    = current;

        assert(current == first);
        assert(prev == current);

        while (current != NULL) {
            exec_task(scheduler, current);
            prev = current;
            current = current->next;
            free(prev);
        }
    }

}
예제 #3
0
main()
{
int nprocs = 4;

//tempo

struct timeval iniciotmp, finaltmp;

int tempogasto;


int pidf,id_wait;
void dt_shareG();

   mc_var_inic ();

   def_task (0, "inicializa_matriz", sizeof (__inicializa_matriz__));
   def_task (1, "multiplica_matriz", sizeof (__multiplica_matriz__));
   id_wait=sem_wait_inic(2);


   alloc_proc(nprocs);
      
   pidf = exec_task (0, nprocs);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      inicializa_matriz();
      end_task();            /* --- rs31() - create --- */
   }

    wait_all();
    gettimeofday(&iniciotmp, NULL);
      
   pidf = exec_task (1, nprocs);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      multiplica_matriz();
      end_task();            /* --- rs31() - create --- */
   }

    wait_all();
    gettimeofday(&finaltmp, NULL);
    tempogasto = (int) (1000 * (finaltmp.tv_sec - iniciotmp.tv_sec) + (finaltmp.tv_usec - iniciotmp.tv_usec) / 1000);
    printf("Tempo decorrido: %d\n", tempogasto);
       wait_all();      /* --- rs307()  */
   end_program();
   remove_semaforo(id_wait);
return 0;
}
예제 #4
0
static gboolean packages_item(GNode* node, gpointer data) {
	gchar command[COMMAND_SIZE];
	g_snprintf(command, COMMAND_SIZE, "/usr/bin/swupd bundle-add %s",
		(char*)node->data);
	LOG(MOD "Installing %s..\n", (char*)node->data);
	exec_task(command);
	return false;
}
예제 #5
0
파일: scheduler.c 프로젝트: mrdg/flim
void schedule_task(struct scheduler *sched, struct task *t)
{
    PtTimestamp now = Pt_Time();
    if (t->start <= now) {
        exec_task(sched, t);
    } else {
        enqueue(sched->queue, t);
    }
}
예제 #6
0
static void runcmd_item(GNode* node, gpointer command_line) {
	if (!node->data) {
		g_node_children_foreach(node, G_TRAVERSE_ALL, runcmd_item, command_line);
		if (!exec_task(((GString*)command_line)->str)) {
			LOG(MOD "Execute command failed\n");
		}
		g_string_set_size((GString*)command_line, 0);
	} else {
		g_string_append_printf((GString*)command_line, "%s ", (char*)node->data);
	}
}
예제 #7
0
파일: fork.c 프로젝트: antontest/c
int main(int agrc, char *agrv[])
{
        if (agrc != 2) {
                printf("Please input shell command.\n");
                return -1;
        }

        exec_task(agrv[1]);

        return 0;
}
예제 #8
0
static void runcmd_item(GNode* node, gpointer data) {
	gchar command_line[COMMAND_SIZE] = { 0 };
	if (!node->data) {
		g_node_children_foreach(node, G_TRAVERSE_ALL, runcmd_item, command_line);
		if (!exec_task(command_line)) {
			LOG(MOD "Execute command failed\n");
		}
	} else {
		g_strlcat(data, node->data,COMMAND_SIZE);
		g_strlcat(data, " ", COMMAND_SIZE);
	}
}
예제 #9
0
static void groups_item(GNode* node, gpointer data) {
	gchar command_groupadd[COMMAND_SIZE];
	gchar command_usermod[COMMAND_SIZE];

	if (!node->data) {
		/* null placeholder */
		g_node_children_foreach(node, G_TRAVERSE_ALL,
			groups_item, data);
	} else if (!data) {
		/* add new group */
		LOG(MOD "Adding %s group...\n", (char*)node->data);
		g_snprintf(command_groupadd, COMMAND_SIZE, GROUPADD_PATH " -f '%s'",
			(char*)node->data);
		exec_task(command_groupadd);
		g_node_children_foreach(node, G_TRAVERSE_ALL,
			groups_item, node->data);
	} else {
		/* add user to new group */
		LOG(MOD "Adding %s to %s group...\n", (char*)node->data, (char*)data);
		g_snprintf(command_usermod, COMMAND_SIZE, USERMOD_PATH " -a -G  '%s' '%s'",
			(char*)data, (char*)node->data);
		exec_task(command_usermod);
	}
}
예제 #10
0
static gboolean packages_item(GNode* node, __unused__ gpointer data) {
	gchar command[COMMAND_SIZE];
	g_snprintf(command, COMMAND_SIZE,
#if defined(PACKAGE_MANAGER_SWUPD)
		"/usr/bin/swupd bundle-add %s",
#elif defined(PACKAGE_MANAGER_YUM)
		"/usr/bin/yum --assumeyes install %s",
#elif defined(PACKAGE_MANAGER_DNF)
		"/usr/bin/dnf install %s",
#elif defined(PACKAGE_MANAGER_APT)
		"/usr/bin/apt-get install %s",
#elif defined(PACKAGE_MANAGER_TDNF)
		"/usr/bin/tdnf --assumeyes install %s",
#endif
		(char*)node->data);
	LOG(MOD "Installing %s..\n", (char*)node->data);
	exec_task(command);
	return false;
}
예제 #11
0
파일: exec.c 프로젝트: AltenSesto/MemSched
int schedule(FILE *fp, int m, int loop_1ms, int time)
{
	int i, j, ret, status;
	pid_t pid;

	/* task[] must be freed in the end. */
	nr_tasks = read_taskset(fp);
	deadline_monotonic_priority();

	/* all the global variables must be set before.
	   otherwise, the child processes cannot share the variables. */
	for (i = 0; i < nr_tasks; i++) {
		pid = fork();
		if (pid == 0) { /* the child process. */
			/* execute the task. 
			   note that the funtion never returns. */
			exec_task(&tasks[i], loop_1ms, time);
		}
	}

	/* default return value. */
	ret = TRUE;

	/* wait for the child processes. */
	for (i = 0; i < nr_tasks; i++) {
		pid = wait(&status);
		if (WIFEXITED(status)) {
			if (WEXITSTATUS(status) == RET_MISS) {
				ret = FALSE;
			}
		}
		else {
			printf("Anomaly exit.\n");
			ret = FALSE;
		}
	}

 out:
	free(tasks);

	return ret;
}
예제 #12
0
파일: kernel.c 프로젝트: TheFakeCake/os
void runKernel()
{
    // Initializing the GDT
    gdt_init();

    // Initializing the screen
    init_display();

    // Initializing the interruption controler (PIC)
    pic_init();

    // Initializing the IDT
    idt_init();

    // Initializing timer @ 100Hz
    timer_init(100);

    // Initializing the keyboard);
    keyboard_init();

    // Init the file system superblock
    superblock_init();

    // Enables hardware interruptions
    sti();

    #ifdef TEST

    // Runs the test procedure if test mode is enabled
    runFileSystemTests();

    #else

    // Executing the Shell
    exec_task("shell");

    #endif

    halt();
}
예제 #13
0
파일: main.c 프로젝트: grail/clr-cloud-init
int main(int argc, char *argv[]) {
	int result_code = EXIT_SUCCESS;
	bool first_boot = false;
	bool openstack_mf = false;
	bool no_growpart = false;
	int c;
	int i;
	gchar* userdata_filename = NULL;
	gchar* tmp_metafile = NULL;
	gchar metadata_filename[PATH_MAX] = { 0 };
	gchar command[LINE_MAX];
	gchar* root_disk;

	while (true) {
		c = getopt_long(argc, argv, "u:hvb", opts, &i);

		if (c == -1) {
			break;
		}

		switch (c) {

		case 'u':
			userdata_filename = g_strdup(optarg);
			break;

		case 'h':
			LOG("Usage: %s [options]\n", argv[0]);
			LOG("-u, --user-data-file [file]            specify a custom user data file\n");
			LOG("    --openstack-metadata-file [file]   specify an Openstack metadata file\n");
			LOG("-h, --help                             display this help message\n");
			LOG("-v, --version                          display the version number of this program\n");
			LOG("-b, --first-boot                       set up the system in its first boot\n");
			LOG("    --no-growpart                      Do not verify disk partitions.\n");
			LOG("                                       %s will not resize the filesystem\n", argv[0]);
			LOG("\nIf no user data or metadata is provided on the command line,\n");
			LOG("%s will fetch these through the datasources API's.\n", argv[0]);
			exit(EXIT_SUCCESS);
			break;

		case 'v':
			fprintf(stdout, PACKAGE_NAME " " PACKAGE_VERSION "\n");
			exit(EXIT_SUCCESS);
			break;

		case 'b':
			first_boot = true;
			break;

		case '?':
			exit(EXIT_FAILURE);
			break;

		case OPT_OPENSTACK_METADATA_FILE:
			tmp_metafile = g_strdup(optarg);
			openstack_mf = true;
			break;

		case OPT_NO_GROWPART:
			no_growpart = true;
			break;
		}
	}

	/* check if metadata file exists */
	if (tmp_metafile) {
		if (!realpath(tmp_metafile, metadata_filename)) {
			LOG("Unable to determine real file path for '%s'\n", tmp_metafile);
		}
		g_free(tmp_metafile);
	}

	#ifdef HAVE_CONFIG_H
		LOG("clr-cloud-init version: %s\n", PACKAGE_VERSION);
	#endif /* HAVE_CONFIG_H */

	/* at one point in time this should likely be a fatal error */
	if (geteuid() != 0) {
		LOG("%s isn't running as root, this will most likely fail!\n", argv[0]);
	}

	if (!no_growpart) {
		root_disk = disk_for_path("/");
		if (root_disk) {
			if (!disk_resize_grow(root_disk)) {
				LOG("Resizing and growing disk '%s' failed\n", root_disk);
			}
		} else {
			LOG("Root disk not found\n");
		}
	}

	if (first_boot) {
		/* default user will be used by ccmodules and datasources */
		command[0] = 0;
		snprintf(command, LINE_MAX, "useradd"
				" -U -d '%s' -G '%s' -f '%s' -e '%s' -s '%s' -c '%s' -p '%s' '%s'"
				, DEFAULT_USER_HOME_DIR
				, DEFAULT_USER_GROUPS
				, DEFAULT_USER_INACTIVE
				, DEFAULT_USER_EXPIREDATE
				, DEFAULT_USER_SHELL
				, DEFAULT_USER_GECOS
				, DEFAULT_USER_PASSWORD
				, DEFAULT_USER_USERNAME);
		exec_task(command);

		/* default user will be able to use sudo */
		write_sudo_string(DEFAULT_USER_USERNAME"-cloud-init", DEFAULT_USER_SUDO);

		/* lock root account for security */
		snprintf(command, LINE_MAX, "usermod -p '!' root");
		exec_task(command);
	}

	/* process userdata file */
	if (userdata_filename) {
		result_code = userdata_process_file(userdata_filename);
	}

	/* process metadata file */
	if (metadata_filename[0]) {
		if (openstack_mf) {
			result_code = openstack_process_metadata(metadata_filename);
		}
	}

	if (!userdata_filename && !metadata_filename[0]) {
		/* get/process userdata and metadata from datasources */
		for (i = 0; cloud_structs[i] != NULL; ++i) {
			result_code = cloud_structs[i]->handler(first_boot);
			if (EXIT_SUCCESS == result_code) {
				break;
			}
		}
	}

	exit(result_code);
}
예제 #14
0
static gboolean hostname_item(GNode *node, __unused__ gpointer data) {
	gchar command[LINE_MAX];
	g_snprintf(command, LINE_MAX, HOSTNAMECTL_PATH " set-hostname '%s'", (char*)node->data);
	exec_task(command);
	return true;
}
예제 #15
0
int main()
{
int i, j;


int pidf,id_wait;
void dt_shareG();

   mc_var_inic ();

   def_task (0, "multiplicarAB", sizeof (__multiplicarAB__));
   def_task (1, "multiplicarCD", sizeof (__multiplicarCD__));
   def_task (2, "sumar", sizeof (__sumar__));
   def_task (3, "print", sizeof (__print__));
   id_wait=sem_wait_inic(4);


   for (i=0; i<100; i++){
        for (j = 0; j < 100; j++)
        {
            /*A[i][j] = i + j;
            B[i][j] = i + 2*j;
            C[i][j] = i*2 + j*3;
            D[i][j] = i*2 + j;*/
            sharedG->A[i][j] = 1;
            sharedG->B[i][j] = 1;
            sharedG->C[i][j] = 1;
            sharedG->D[i][j] = 1;
        }
    }

    alloc_proc(4);

      
   pidf = exec_task (0, 1);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      multiplicarAB();
      end_task();            /* --- rs31() - create --- */
   }

      
   pidf = exec_task (1, 1);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      multiplicarCD();
      end_task();            /* --- rs31() - create --- */
   }


    wait_all();

      
   pidf = exec_task (2, 1);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      sumar();
      end_task();            /* --- rs31() - create --- */
   }

    
    
   wait_proc (2);    /* --- wait_proc() --- */


      
   pidf = exec_task (3, 1);  /* --- rs30() - create --- */
   if (pidf == 0)   {
      print();
      end_task();            /* --- rs31() - create --- */
   }


       wait_all();      /* --- rs307()  */
   end_program();
   remove_semaforo(id_wait);
return 0;
}
예제 #16
0
static gboolean service_action(GNode* node, gpointer data) {
	gchar c[COMMAND_SIZE];
	g_snprintf(c, COMMAND_SIZE, SYSTEMCTL_PATH " %s %s", (char*)data, (char*)node->data);
	exec_task(c);
	return false;
}
예제 #17
0
static void write_files_item(GNode* node, gpointer data) {
    const GNode* content;
    const GNode* path;
    const GNode* permissions;
    const GNode* owner;
    gchar **tokens;
    guint tokens_size;
    mode_t mode;
    const gchar* username = "";
    const gchar* groupname = "";

    CLOUD_CONFIG_KEY(CONTENT, "content");
    CLOUD_CONFIG_KEY(PATH, "path");
    CLOUD_CONFIG_KEY(OWNER, "owner");
    CLOUD_CONFIG_KEY(PERMISSIONS, "permissions");

    content = cloud_config_find(node, CONTENT);
    if (!content) {
        LOG(MOD "Unable to write file without \"content\" value.\n");
        return;
    }

    path = cloud_config_find(node, PATH);
    if (!path) {
        LOG(MOD "Unable to write file without \"path\" value.\n");
        return;
    }

    permissions = cloud_config_find(node, PERMISSIONS);
    owner = cloud_config_find(node, OWNER);

    /* assure the folder exists, and create if nexessary */
    char* dir = strdup((char *)path->data);
    dir = dirname(dir);
    int r = access(dir, W_OK);
    if (r == -1) {
        if (errno & ENOENT) {
            LOG(MOD "Creating part or all of %s\n", dir);
            gchar command[LINE_MAX];
            command[0] = 0;
            g_snprintf(command, LINE_MAX, "mkdir -p %s", dir);
            exec_task(command);
        } else {
            LOG(MOD "Path error: %s", strerror(errno));
            free(dir);
            return;
        }
    }
    free(dir);

    LOG(MOD "Writing to file %s: %s\n", (char*)path->data, (char*)content->data);

    const int fd = open(path->data, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
    if (fd == -1) {
        LOG(MOD "Cannot open %s.\n", (char*)path->data);
        return;
    }

    write(fd, content->data, strlen(content->data));

    if (permissions) {
        if (cloud_config_int_base(permissions, (int *)&mode, 8)) {
            fchmod(fd, mode);
        }
    }

    close(fd);

    if (owner) {
        tokens = g_strsplit_set(owner->data, ":.", 2);
        tokens_size = g_strv_length(tokens);
        if (tokens_size > 0) {
            username = tokens[0];
            if (tokens_size > 1) {
                groupname = tokens[1];
            }
            chown_path(path->data, username, groupname);
        }
        g_strfreev(tokens);
    }
}
예제 #18
0
static void users_item(GNode* node, gpointer data) {
	if (node->data) {
		/* to avoid bugs with key(gecos, etc) as username */
		if (node->children) {
			for (size_t i = 0; users_options[i].key != NULL; ++i) {
				if (0 == g_strcmp0(node->data, users_options[i].key)) {
					if (users_options[i].func) {
						users_options[i].func(node->children, data,
							users_options[i].data);
					}
					return;
				}
			}
			LOG(MOD "No handler for %s.\n", (char*)node->data);
			return;
		}
		users_add_username(node, data, "%s");
	} else {
		bool b;
		GString* sudo_directives;
		GString* ssh_keys;
		GString* command = g_string_new(USERADD_PATH " ");
		memset(users_current_username, 0, LOGIN_NAME_MAX);
		g_node_children_foreach(node, G_TRAVERSE_ALL, users_item, command);
		if (0 == strlen(users_current_username)) {
			LOG(MOD "Missing username.\n");
			return;
		}

		LOG(MOD "Adding %s user...\n", users_current_username);
		exec_task(command->str);

		CLOUD_CONFIG_KEY(LOCK_PASSWD, "lock-passwd");
		CLOUD_CONFIG_KEY(INACTIVE, "inactive");
		CLOUD_CONFIG_KEY(SSH_AUTH_KEYS, "ssh-authorized-keys");
		CLOUD_CONFIG_KEY(SUDO, "sudo");

		GNode *item = cloud_config_find(node, LOCK_PASSWD);
		if (item) {
			cloud_config_bool(item, &b);
			if (b) {
				LOG(MOD "Locking %s user.\n", users_current_username);
				g_string_printf(command, PASSWD_PATH " -l '%s'",
					users_current_username);
				exec_task(command->str);
			}
		}

		item = cloud_config_find(node, INACTIVE);
		if (item) {
			cloud_config_bool(item, &b);
			if (b) {
				LOG(MOD "Deactivating %s user...\n", users_current_username);
				g_string_printf(command, USERMOD_PATH " --expiredate 1 '%s'",
					users_current_username);
				exec_task(command->str);
			}
		}

		g_string_free(command, true);

		item = cloud_config_find(node, SSH_AUTH_KEYS);
		if (item) {
			ssh_keys = g_string_new("");
			g_node_traverse(item->parent, G_IN_ORDER, G_TRAVERSE_LEAVES,
				-1, users_ssh_key_item, ssh_keys);
			if (!write_ssh_keys(ssh_keys, users_current_username)) {
				LOG(MOD "Cannot write ssh keys\n");
			}
			g_string_free(ssh_keys, true);
		}

		item = cloud_config_find(node, SUDO);
		if (item) {
			sudo_directives = g_string_new("");
			g_string_printf(sudo_directives, "# Rules for %s user\n",
			    users_current_username);
			g_node_traverse(item->parent, G_IN_ORDER, G_TRAVERSE_LEAVES,
				-1, users_sudo_item, sudo_directives);
			g_string_append(sudo_directives, "\n");
			if (!write_sudo_directives(sudo_directives, "users-cloud-init",
			     O_CREAT|O_APPEND|O_WRONLY)) {
				LOG(MOD "Cannot write sudo directives\n");
			}
			g_string_free(sudo_directives, true);
		}
	}
}