Ejemplo n.º 1
0
void read_applications_from_file(char *file){

    FILE *fd;
    long i;
    char pattern[50];
    char *pattern_aux;
    long servers = get_servers();
    application app;

    app.info.start_time = 0;
    app.info.end_time = 0;
    app.info.n_flows = 0;
    app.info.flows_distance = 0;
    app.info.flows_latency = 0;
    app.packets = 8192;
    app.comp_time = 10;
    app.phases = 1;
    app.running = 0;
    app.tasks_finished = 0;
    app.info.id = 1;

    if((fd = fopen(file, "r")) == NULL){
        printf("Error opening the workload file.\n");  
        exit(-1);
    }

    while(!feof(fd)){  
        fscanf(fd,"%llu %s %ld %s\n",&app.info.arrive_time, pattern, &app.size, app.allocation_type); 
        if(app.size > servers){
            printf("WARNING: Application %ld with size %ld is larger than the network: %ld.\n",app.info.id,app.size, servers);
            exit(-1);
        } 
        pattern_aux = strtok(pattern, "_");
        if(!literal_value(tpatterns_l, pattern_aux, (int *) &app.pattern)) {
            printf("Error: Unknown traffic pattern - %s\n", pattern_aux);
            exit(-1);
        }
        app.pattern_nparam=0;
        if(app.pattern == FILE_PATTERN){
            pattern_aux = strtok(NULL, "_");
            sscanf(pattern_aux, "%s", app.pattern_file);
        }
        
            while ( (pattern_aux = strtok(NULL, "_")) && app.pattern_nparam < MAX_TRAFFIC_PARAMS){
                app.pattern_params[app.pattern_nparam++] = atoi(pattern_aux);
            }
        
        for (i = app.pattern_nparam; i < MAX_TRAFFIC_PARAMS; i++)
            app.pattern_params[i] = -1; // undefine values, should not be checking these anyway.

        if(!literal_value(allocation_l, app.allocation_type, (int *) &app.allocation)) {
            printf("Error: Unknown allocation pattern - %s\n", app.allocation_type);
            exit(-1);
        }
        app.phases = app.pattern_params[0];
        list_append(&workload, &app);
        app.info.id++;
    }  
    fclose(fd);
}
Ejemplo n.º 2
0
static bool print_tree(struct user_auth_info *user_info)
{
        struct smb_name_list *wg, *sv, *sh;

        /* List workgroups */

        if (!get_workgroups(user_info))
                return False;

        for (wg = workgroups; wg; wg = wg->next) {

                printf("%s\n", wg->name);

                /* List servers */

                free_name_list(servers);
                servers = NULL;

                if (level == LEV_WORKGROUP || 
                    !get_servers(wg->name, user_info))
                        continue;

                for (sv = servers; sv; sv = sv->next) {

                        printf("\t\\\\%-15s\t\t%s\n", 
			       sv->name, sv->comment);

                        /* List shares */

                        free_name_list(shares);
                        shares = NULL;

                        if (level == LEV_SERVER ||
                            !get_shares(sv->name, user_info))
                                continue;

                        for (sh = shares; sh; sh = sh->next) {
                                printf("\t\t\\\\%s\\%-15s\t%s\n", 
				       sv->name, sh->name, sh->comment);
                        }
                }
        }

        return True;
}
Ejemplo n.º 3
0
void *get_serverlists(void *value)
{
	struct name_list *wg, *sv;
	//struct smbEventProxyCmd *pcmd = (struct smbEventProxyCmd *)cmd;
	char buf[MAX_NAME_LEN] = {0};
	int get_serverlists_by_nmblookup_state = 0; /*0:fail; 1:ok*/
	int id = (int *)value;
	struct smbEventProxyCmd *pevent = NULL;
	char samba_workgroup[16] = {0};
#ifdef CONF_SAMBA_SUPPORT_ONLY_BROWSE_WORKGROUP_SERVERS
	securesoho_samba_workgroup_get(samba_workgroup);
#else //CONF_SAMBA_SUPPORT_ONLY_BROWSE_WORKGROUP_SERVERS
	get_serverlists_by_nmblookup_state = get_serverlists_by_nmblookup(id);
#endif //CONF_SAMBA_SUPPORT_ONLY_BROWSE_WORKGROUP_SERVERS

	/* List workgroups */
	if(workgroups) {
		free_name_list(workgroups);
		workgroups = NULL;
	}
	if (!get_workgroups(&cmdline_auth_info)) {
		is_getserver_done = 1;
#ifdef CONF_SAMBA_SUPPORT_ONLY_BROWSE_WORKGROUP_SERVERS
		SMBTREE_send_event_to_OSD(SMB_CMD_REFRESH_SERVER_RESPONSE, SMB_REFRESHED_FAILED, id, NULL);
		printf("%s[%d], It's finish to search samba server(s).\n", __FILE__, __LINE__);
		return NULL;
#else //CONF_SAMBA_SUPPORT_ONLY_BROWSE_WORKGROUP_SERVERS
		if(get_serverlists_by_nmblookup_state) {
			SMBTREE_send_event_to_OSD(SMB_CMD_REFRESH_SERVER_RESPONSE, SMB_REFRESHED_OK, id, NULL);
			printf("%s[%d], It's finish to search samba server(s). id:[%d]\n", __FILE__, __LINE__, id);
			return NULL;
		} else {
			SMBTREE_send_event_to_OSD(SMB_CMD_REFRESH_SERVER_RESPONSE, SMB_REFRESHED_FAILED, id, NULL);
			printf("%s[%d], It's finish to search samba server(s).\n", __FILE__, __LINE__);
			return NULL;
		}	
#endif //CONF_SAMBA_SUPPORT_ONLY_BROWSE_WORKGROUP_SERVERS
	}

	for (wg = workgroups; wg; wg = wg->next) {
#ifdef ENABLE_SMBTREE_DEBUG_MODE
		printf("%s[%d], WorkGroup : [%s]\n", __FILE__, __LINE__, wg->name);
#endif //ENABLE_SMBTREE_DEBUG_MODE
		/* List servers */

#ifdef CONF_SAMBA_SUPPORT_ONLY_BROWSE_WORKGROUP_SERVERS
		printf("samba_workgroup:[%s], wg->name:[%s]\n", samba_workgroup, wg->name);
		if(strcasecmp(samba_workgroup, wg->name) != 0)
			continue;
#endif //CONF_SAMBA_SUPPORT_ONLY_BROWSE_WORKGROUP_SERVERS
		if(servers) {
			free_name_list(servers);
			servers = NULL;
		}

		if (level == LEV_WORKGROUP || !get_servers(wg->name, &cmdline_auth_info))
			continue;

		for (sv = servers; sv; sv = sv->next) {

			char* ip = NULL;
			nmblookup_ip(sv->name, &ip);
			if(ip != NULL) {
				snprintf(buf, sizeof(buf), "%s\\%s\\0", sv->name,ip); 
#ifdef ENABLE_SMBTREE_DEBUG_MODE
				printf("\t\\\\%-15s\t\t%s buf:%s\n", sv->name, sv->comment, buf);
#endif //ENABLE_SMBTREE_DEBUG_MODE
#ifdef ENABLE_PTHREAD
				pevent = malloc(sizeof(struct smbEventProxyCmd));
				pevent->cmd = SMB_CMD_REFRESH_SERVER_RESPONSE;
				pevent->status = SMB_REFRESHING;
				pevent->id = id;
				pevent->datalen = strlen(buf) + 1;
				strcpy((char *)pevent->data, buf);
				XLinkedList_Lock(serverlist);
					XLinkedList_AddTail(serverlist, (void *)pevent);
				XLinkedList_UnLock(serverlist);
#else
				SMBTREE_send_event_to_OSD(SMB_CMD_REFRESH_SERVER_RESPONSE, SMB_REFRESHING, id, buf);
#endif
				free(ip);
				ip = NULL;
			}
		}
	}

	printf("%s[%d], It's finish to search samba server(s). id:[%d]\n", __FILE__, __LINE__, id);
	SMBTREE_send_event_to_OSD(SMB_CMD_REFRESH_SERVER_RESPONSE, SMB_REFRESHED_OK, id, NULL);
	is_getserver_done = 1;

	if(workgroups) {
		free_name_list(workgroups);
		workgroups = NULL;
	}

	if(servers) {
		free_name_list(servers);
		servers = NULL;
	}

	return NULL;
}
Ejemplo n.º 4
0
int main(int argc, char **argv) {
  char name[INET_ADDRSTRLEN];
  pthread_t runner_thread;
  host_port *my_hostport;
  
  //Set our termination method
  signal(SIGINT, finish);
  signal(SIGPIPE, pipe_error);
  
  //Setup Jobs Folder
  if(mkdir("./jobs", S_IRWXU)) {
    if(errno == EEXIST) {
#ifdef VERBOSE2
      problem("Jobs directory already exists...\n");
#endif
    } else {
      problem("mkdir failed with %d\n", errno);
    }
  }
  
  //Setup Job Queue
  my_queue = (queue *)malloc(sizeof(queue));
  backup_queue = (queue *)malloc(sizeof(queue));
  init_queue(my_queue);
  init_queue(backup_queue);

  //Build host_port
  my_hostport = malloc(sizeof(host_port));
  get_my_ip(my_hostport->ip);
  my_hostport->port = atoi(argv[1]);
  while(my_hostport->port < 1000) 
    scanf("%d", &(my_hostport->port));
  my_hostport->jobs = 0;
  my_hostport->time_stamp = 0;
  my_hostport->location = 0;
  my_hostport->id = 0;
  
  //Start listener
  listener_set_up(my_hostport);

  if(argc < 4) {
    server_list = new_host_list(my_hostport);
    my_host = server_list->head;
  } else {
    if(get_servers(argv[2], atoi(argv[3]), 1, &server_list) < 0) {
      problem("Get servers failed!\n");
      exit(FAILURE);
    }
    if(acquire_add_lock(server_list)) {
      problem("Fatal error. Failed to acquire add lock.\n");
      relinquish_add_lock(server_list);
      finish(0);
      exit(-1);
    }
    my_hostport->id = server_list->id;
    server_list->id++;
    my_host = integrate_host(my_hostport);
    distribute_update();
    relinquish_add_lock(server_list);
  }
  heartbeat_dest = my_host->next;
  
  //User interaction thread
  pthread_create(&user_thread, NULL, (void *(*)(void *))print_method, NULL);
  
  //Runner/Heartbeat thread
  pthread_create(&runner_thread, NULL, (void *(*)(void *))runner, NULL);
  pthread_join(runner_thread, NULL);
}