int chirp_acl_init_root(const char *path) { char aclpath[CHIRP_PATH_MAX]; char username[USERNAME_MAX]; CHIRP_FILE *file; if(!cfs->do_acl_check()) return 1; file = chirp_acl_open(path); if(file) { chirp_acl_close(file); return 1; } username_get(username); sprintf(aclpath, "%s/%s", path, CHIRP_ACL_BASE_NAME); file = cfs_fopen(aclpath, "w"); if(file) { cfs_fprintf(file, "unix:%s %s\n", username, chirp_acl_flags_to_text(CHIRP_ACL_READ | CHIRP_ACL_WRITE | CHIRP_ACL_DELETE | CHIRP_ACL_LIST | CHIRP_ACL_ADMIN)); cfs_fclose(file); return 1; } else { return 0; } }
int makeflow_catalog_summary(struct dag* d, char* name, batch_queue_type_t type, timestamp_t start){ struct dag_node *n; dag_node_state_t state; int tasks_completed = 0; int tasks_aborted = 0; int tasks_waiting = 0; int tasks_running = 0; int tasks_failed = 0; for (n = d->nodes; n; n = n->next) { state = n->state; if (state == DAG_NODE_STATE_FAILED) tasks_failed++; else if (state == DAG_NODE_STATE_ABORTED) tasks_aborted++; else if (state == DAG_NODE_STATE_COMPLETE) tasks_completed++; else if(state == DAG_NODE_STATE_RUNNING) tasks_running++; else if(state == DAG_NODE_STATE_WAITING) tasks_waiting++; } //transmit report here char* host = CATALOG_HOST; char username[USERNAME_MAX]; username_get(username); const char* batch_type = batch_queue_type_to_string(type); struct jx *j = jx_object(0); jx_insert_string(j,"type","makeflow"); jx_insert_integer(j,"total",itable_size(d->node_table)); jx_insert_integer(j,"running",tasks_running); jx_insert_integer(j,"waiting",tasks_waiting); jx_insert_integer(j,"aborted",tasks_aborted); jx_insert_integer(j,"completed",tasks_completed); jx_insert_integer(j,"failed",tasks_failed); jx_insert_string(j,"project",name); jx_insert_string(j,"owner",username); char* timestring = string_format("%" PRIu64 "", start); jx_insert_string(j,"time_started",timestring); jx_insert_string(j,"batch_type",batch_type); //creates memory char* text = jx_print_string(j); int resp = catalog_query_send_update(host, text); free(text); free(timestring); jx_delete(j); return resp;//all good }
int advertise_master_to_catalog(const char *catalog_host, int catalog_port, const char *project_name, const char *master_address, struct work_queue_stats *s, struct work_queue_resources *r, const char *workers_by_pool ) { char address[DATAGRAM_ADDRESS_MAX]; char owner[USERNAME_MAX]; buffer_t *buffer = NULL; const char *text; size_t text_size; if(!outgoing_datagram) { outgoing_datagram = datagram_create(0); if(!outgoing_datagram) { fprintf(stderr, "Failed to advertise master to catalog server: couldn't create outgoing udp datagram!\n"); return 0; } } if(!username_get(owner)) { strcpy(owner,"unknown"); } buffer = buffer_create(); int total_workers_working = s->workers_busy + s->workers_full; int total_workers = total_workers_working + s->workers_ready; debug(D_WQ,"%s advertising resources to the Catalog -- cores:%d memory:%d disk:%d\n",project_name,r->cores.total,r->memory.total,r->disk.total); //debug to see if information is being passed buffer_printf(buffer, "type wq_master\n" "project %s\nstarttime %llu\npriority %d\n" "port %d\nlifetime %d\n" "tasks_waiting %d\ntasks_complete %d\ntasks_running %d\ntotal_tasks_dispatched %d\n" "workers_init %d\nworkers_ready %d\nworkers_busy %d\nworkers %d\nworkers_by_pool %s\n" "cores_total %d\nmemory_total %d\ndisk_total %d\n" "capacity %d\n" "my_master %s\n" "version %d.%d.%s\nowner %s", project_name, (s->start_time)/1000000, s->priority, s->port, WORK_QUEUE_CATALOG_MASTER_AD_LIFETIME, s->tasks_waiting, s->total_tasks_complete, s->tasks_running, s->total_tasks_dispatched, s->workers_init, s->workers_ready, total_workers_working, total_workers, workers_by_pool, r->cores.total, r->memory.total, r->disk.total, s->capacity, master_address, CCTOOLS_VERSION_MAJOR, CCTOOLS_VERSION_MINOR, CCTOOLS_VERSION_MICRO, owner); text = buffer_tostring(buffer, &text_size); if(domain_name_cache_lookup(catalog_host, address)) { debug(D_WQ, "Advertising master status to the catalog server at %s:%d ...", catalog_host, catalog_port); datagram_send(outgoing_datagram, text, strlen(text), address, catalog_port); } buffer_delete(buffer); return 1; }
int advertise_pool_decision_to_catalog(const char *catalog_host, int catalog_port, const char *pool_name, pid_t pid, time_t start_time, const char *decision, int workers_requested) { char address[DATAGRAM_ADDRESS_MAX]; char owner[USERNAME_MAX]; buffer_t B; const char *text; size_t text_size; static time_t last_update_time = 0; if(time(0) - last_update_time < WORK_QUEUE_CATALOG_POOL_UPDATE_INTERVAL) return 1; if(!outgoing_datagram) { outgoing_datagram = datagram_create(0); if(!outgoing_datagram) { fprintf(stderr, "Couldn't create outgoing udp port, thus work queue master info won't be sent to the catalog server!\n"); return 0; } } if(!username_get(owner)) { strcpy(owner,"unknown"); } // port = MAX_TCP_PORT + process id, this is for the catalog server to // distinguish the worker pools from the same host. See make_hash_key() // function in catalog_server.c INT64_T port = 65535 + pid; buffer_init(&B); buffer_abortonfailure(&B, 1); buffer_printf(&B, "type wq_pool\npool_name %s\nport %" PRId64 "\nstarttime %llu\ndecision %s\nworkers_requested %d\nowner %s\nlifetime %d", pool_name, port, (unsigned long long) start_time, decision, workers_requested, owner, WORK_QUEUE_CATALOG_POOL_AD_LIFETIME); text = buffer_tostring(&B, &text_size); debug(D_WQ, "Pool AD: \n%s\n", text); if(domain_name_cache_lookup(catalog_host, address)) { debug(D_WQ, "Sending the pool decision to the catalog server at %s:%d ...", catalog_host, catalog_port); datagram_send(outgoing_datagram, text, text_size, address, catalog_port); } buffer_free(&B); last_update_time = time(0); return 1; }
int advertise_master_to_catalog(const char *catalog_host, int catalog_port, const char *project_name, struct work_queue_stats *s, const char *workers_by_pool, int now) { char address[DATAGRAM_ADDRESS_MAX]; char owner[USERNAME_MAX]; buffer_t *buffer = NULL; const char *text; size_t text_size; static time_t last_update_time = 0; if(!now) { if(time(0) - last_update_time < WORK_QUEUE_CATALOG_UPDATE_INTERVAL) return 1; } if(!outgoing_datagram) { outgoing_datagram = datagram_create(0); if(!outgoing_datagram) { fprintf(stderr, "Failed to advertise master to catalog server: couldn't create outgoing udp datagram!\n"); return 0; } } if(!username_get(owner)) { strcpy(owner,"unknown"); } buffer = buffer_create(); buffer_printf(buffer, "type wq_master\nproject %s\nstart_time %llu\npriority %d\nport %d\nlifetime %d\ntasks_waiting %d\ntasks_complete %d\ntask_running %d\ntotal_tasks_dispatched %d\nworkers_init %d\nworkers_ready %d\nworkers_busy %d\nworkers %d\nworkers_by_pool %s\ncapacity %d\nversion %d.%d.%d\nowner %s", project_name, s->start_time, s->priority, s->port, WORK_QUEUE_CATALOG_LIFETIME, s->tasks_waiting, s->total_tasks_complete, s->workers_busy, s->total_tasks_dispatched, s->workers_init, s->workers_ready, s->workers_busy, s->workers_ready + s->workers_busy, workers_by_pool, s->capacity, CCTOOLS_VERSION_MAJOR, CCTOOLS_VERSION_MINOR, CCTOOLS_VERSION_MICRO, owner); text = buffer_tostring(buffer, &text_size); if(domain_name_cache_lookup(catalog_host, address)) { debug(D_WQ, "Advertising master status to the catalog server at %s:%d ...", catalog_host, catalog_port); datagram_send(outgoing_datagram, text, strlen(text), address, catalog_port); } buffer_delete(buffer); last_update_time = time(0); return 1; }
int advertise_pool_decision_to_catalog(const char *catalog_host, int catalog_port, const char *pool_name, const char *decision) { char address[DATAGRAM_ADDRESS_MAX]; char owner[USERNAME_MAX]; buffer_t *buffer = NULL; const char *text; size_t text_size; static time_t last_update_time = 0; if(time(0) - last_update_time < WORK_QUEUE_CATALOG_UPDATE_INTERVAL) return 1; if(!outgoing_datagram) { outgoing_datagram = datagram_create(0); if(!outgoing_datagram) { fprintf(stderr, "Couldn't create outgoing udp port, thus work queue master info won't be sent to the catalog server!\n"); return 0; } } if(!username_get(owner)) { strcpy(owner,"unknown"); } buffer = buffer_create(); buffer_printf(buffer, "type wq_pool\npool_name %s\ndecision %s\nowner %s", pool_name, decision, owner); text = buffer_tostring(buffer, &text_size); debug(D_WQ, "Pool AD: \n%s\n", text); if(domain_name_cache_lookup(catalog_host, address)) { debug(D_WQ, "Sending the pool decision to the catalog server at %s:%d ...", catalog_host, catalog_port); datagram_send(outgoing_datagram, text, text_size, address, catalog_port); } buffer_delete(buffer); last_update_time = time(0); return 1; }
int main(int argc, char *argv[]) { struct link *link, *list_port = 0; char ch; time_t current; int is_daemon = 0; char *pidfile = NULL; outgoing_host_list = list_create(); debug_config(argv[0]); while((ch = getopt(argc, argv, "bB:d:hH:l:L:m:M:n:o:O:p:ST:u:U:v")) != (char) -1) { switch (ch) { case 'b': is_daemon = 1; break; case 'B': free(pidfile); pidfile = strdup(optarg); break; case 'd': debug_flags_set(optarg); break; case 'h': default: show_help(argv[0]); return 1; case 'l': lifetime = string_time_parse(optarg); break; case 'L': logfilename = strdup(optarg); break; case 'H': history_dir = strdup(optarg); break; case 'm': child_procs_max = atoi(optarg); break; case 'M': max_server_size = string_metric_parse(optarg); break; case 'n': preferred_hostname = optarg; break; case 'o': free(debug_filename); debug_filename = strdup(optarg); break; case 'O': debug_config_file_size(string_metric_parse(optarg)); break; case 'p': port = atoi(optarg); break; case 'S': fork_mode = 0; break; case 'T': child_procs_timeout = string_time_parse(optarg); break; case 'u': list_push_head(outgoing_host_list, xxstrdup(optarg)); break; case 'U': outgoing_timeout = string_time_parse(optarg); break; case 'v': cctools_version_print(stdout, argv[0]); return 0; } } if (is_daemon) daemonize(0, pidfile); debug_config_file(debug_filename); cctools_version_debug(D_DEBUG, argv[0]); if(logfilename) { logfile = fopen(logfilename,"a"); if(!logfile) fatal("couldn't open %s: %s\n",optarg,strerror(errno)); } current = time(0); debug(D_ALL, "*** %s starting at %s", argv[0], ctime(¤t)); if(!list_size(outgoing_host_list)) { list_push_head(outgoing_host_list, CATALOG_HOST_DEFAULT); } install_handler(SIGPIPE, ignore_signal); install_handler(SIGHUP, ignore_signal); install_handler(SIGCHLD, ignore_signal); install_handler(SIGINT, shutdown_clean); install_handler(SIGTERM, shutdown_clean); install_handler(SIGQUIT, shutdown_clean); install_handler(SIGALRM, shutdown_clean); if(!preferred_hostname) { domain_name_cache_guess(hostname); preferred_hostname = hostname; } username_get(owner); starttime = time(0); table = nvpair_database_create(history_dir); if(!table) fatal("couldn't create directory %s: %s\n",history_dir,strerror(errno)); update_dgram = datagram_create(port); if(!update_dgram) fatal("couldn't listen on udp port %d", port); outgoing_dgram = datagram_create(0); if(!outgoing_dgram) fatal("couldn't create outgoing udp port"); list_port = link_serve(port); if(!list_port) fatal("couldn't listen on tcp port %d", port); while(1) { fd_set rfds; int ufd = datagram_fd(update_dgram); int lfd = link_fd(list_port); int result, maxfd; struct timeval timeout; remove_expired_records(); if(time(0) > outgoing_alarm) { update_all_catalogs(outgoing_dgram); outgoing_alarm = time(0) + outgoing_timeout; } while(1) { int status; pid_t pid = waitpid(-1, &status, WNOHANG); if(pid>0) { child_procs_count--; continue; } else { break; } } FD_ZERO(&rfds); FD_SET(ufd, &rfds); if(child_procs_count < child_procs_max) { FD_SET(lfd, &rfds); } maxfd = MAX(ufd, lfd) + 1; timeout.tv_sec = 5; timeout.tv_usec = 0; result = select(maxfd, &rfds, 0, 0, &timeout); if(result <= 0) continue; if(FD_ISSET(ufd, &rfds)) { handle_updates(update_dgram); } if(FD_ISSET(lfd, &rfds)) { link = link_accept(list_port, time(0) + 5); if(link) { if(fork_mode) { pid_t pid = fork(); if(pid == 0) { alarm(child_procs_timeout); handle_query(link); _exit(0); } else if (pid>0) { child_procs_count++; } } else { handle_query(link); } link_close(link); } } } return 1; }
int main(int argc, char *argv[]) { struct link *link, *list_port = 0; signed char ch; time_t current; int is_daemon = 0; char *pidfile = NULL; char *interface = NULL; outgoing_host_list = list_create(); debug_config(argv[0]); static const struct option long_options[] = { {"background", no_argument, 0, 'b'}, {"pid-file", required_argument, 0, 'B'}, {"debug", required_argument, 0, 'd'}, {"help", no_argument, 0, 'h'}, {"history", required_argument, 0, 'H'}, {"lifetime", required_argument, 0, 'l'}, {"update-log", required_argument, 0, 'L'}, {"max-jobs", required_argument, 0, 'm'}, {"server-size", required_argument, 0, 'M'}, {"name", required_argument, 0, 'n'}, {"interface", required_argument, 0, 'I'}, {"debug-file", required_argument, 0, 'o'}, {"debug-rotate-max", required_argument, 0, 'O'}, {"port", required_argument, 0, 'p'}, {"single", no_argument, 0, 'S'}, {"timeout", required_argument, 0, 'T'}, {"update-host", required_argument, 0, 'u'}, {"update-interval", required_argument, 0, 'U'}, {"version", no_argument, 0, 'v'}, {"port-file", required_argument, 0, 'Z'}, {0,0,0,0}}; while((ch = getopt_long(argc, argv, "bB:d:hH:I:l:L:m:M:n:o:O:p:ST:u:U:vZ:", long_options, NULL)) > -1) { switch (ch) { case 'b': is_daemon = 1; break; case 'B': free(pidfile); pidfile = strdup(optarg); break; case 'd': debug_flags_set(optarg); break; case 'h': default: show_help(argv[0]); return 1; case 'l': lifetime = string_time_parse(optarg); break; case 'L': logfilename = strdup(optarg); break; case 'H': history_dir = strdup(optarg); break; case 'I': free(interface); interface = strdup(optarg); break; case 'm': child_procs_max = atoi(optarg); break; case 'M': max_server_size = string_metric_parse(optarg); break; case 'n': preferred_hostname = optarg; break; case 'o': debug_config_file(optarg); break; case 'O': debug_config_file_size(string_metric_parse(optarg)); break; case 'p': port = atoi(optarg); break; case 'S': fork_mode = 0; break; case 'T': child_procs_timeout = string_time_parse(optarg); break; case 'u': list_push_head(outgoing_host_list, xxstrdup(optarg)); break; case 'U': outgoing_timeout = string_time_parse(optarg); break; case 'v': cctools_version_print(stdout, argv[0]); return 0; case 'Z': port_file = optarg; port = 0; break; } } if (is_daemon) daemonize(0, pidfile); cctools_version_debug(D_DEBUG, argv[0]); if(logfilename) { logfile = fopen(logfilename,"a"); if(!logfile) fatal("couldn't open %s: %s\n",optarg,strerror(errno)); } current = time(0); debug(D_NOTICE, "*** %s starting at %s", argv[0], ctime(¤t)); if(!list_size(outgoing_host_list)) { list_push_head(outgoing_host_list, CATALOG_HOST_DEFAULT); } install_handler(SIGPIPE, ignore_signal); install_handler(SIGHUP, ignore_signal); install_handler(SIGCHLD, ignore_signal); install_handler(SIGINT, shutdown_clean); install_handler(SIGTERM, shutdown_clean); install_handler(SIGQUIT, shutdown_clean); install_handler(SIGALRM, shutdown_clean); if(!preferred_hostname) { domain_name_cache_guess(hostname); preferred_hostname = hostname; } username_get(owner); starttime = time(0); table = nvpair_database_create(history_dir); if(!table) fatal("couldn't create directory %s: %s\n",history_dir,strerror(errno)); list_port = link_serve_address(interface, port); if(list_port) { /* If a port was chosen automatically, read it back so that the same one can be used for the update port. There is the possibility that the UDP listen will fail because that port is in use. */ if(port==0) { char addr[LINK_ADDRESS_MAX]; link_address_local(list_port,addr,&port); } } else { if(interface) fatal("couldn't listen on TCP address %s port %d", interface, port); else fatal("couldn't listen on TCP port %d", port); } outgoing_dgram = datagram_create(0); if(!outgoing_dgram) fatal("couldn't create outgoing udp port"); update_dgram = datagram_create_address(interface, port); if(!update_dgram) { if(interface) fatal("couldn't listen on UDP address %s port %d", interface, port); else fatal("couldn't listen on UDP port %d", port); } opts_write_port_file(port_file,port); while(1) { fd_set rfds; int ufd = datagram_fd(update_dgram); int lfd = link_fd(list_port); int result, maxfd; struct timeval timeout; remove_expired_records(); if(time(0) > outgoing_alarm) { update_all_catalogs(outgoing_dgram); outgoing_alarm = time(0) + outgoing_timeout; } while(1) { int status; pid_t pid = waitpid(-1, &status, WNOHANG); if(pid>0) { child_procs_count--; continue; } else { break; } } FD_ZERO(&rfds); FD_SET(ufd, &rfds); if(child_procs_count < child_procs_max) { FD_SET(lfd, &rfds); } maxfd = MAX(ufd, lfd) + 1; timeout.tv_sec = 5; timeout.tv_usec = 0; result = select(maxfd, &rfds, 0, 0, &timeout); if(result <= 0) continue; if(FD_ISSET(ufd, &rfds)) { handle_updates(update_dgram); } if(FD_ISSET(lfd, &rfds)) { link = link_accept(list_port, time(0) + 5); if(link) { if(fork_mode) { pid_t pid = fork(); if(pid == 0) { alarm(child_procs_timeout); handle_query(link); _exit(0); } else if (pid>0) { child_procs_count++; } } else { handle_query(link); } link_close(link); } } } return 1; }
int main(int argc, char *argv[]) { char *host = CATALOG_HOST; int port = CATALOG_PORT; static const struct option long_options[] = { {"catalog", required_argument, 0, 'c'}, {0,0,0,0} }; signed int c; while ((c = getopt_long(argc, argv, "c:", long_options, NULL)) > -1) { switch (c) { case 'c': host = optarg; break; default: show_help(argv[0]); return EXIT_FAILURE; } } struct datagram *d; d = datagram_create(DATAGRAM_PORT_ANY); if (!d) { fatal("could not create datagram port!"); } struct utsname name; int cpus; int uptime; double load[3]; UINT64_T memory_total, memory_avail; char owner[USERNAME_MAX]; uname(&name); string_tolower(name.sysname); string_tolower(name.machine); string_tolower(name.release); load_average_get(load); cpus = load_average_get_cpus(); host_memory_info_get(&memory_avail, &memory_total); uptime = uptime_get(); username_get(owner); struct jx *j = jx_object(0); jx_insert_string(j,"type","node"); jx_insert(j,jx_string("version"),jx_format("%d.%d.%d",CCTOOLS_VERSION_MAJOR, CCTOOLS_VERSION_MINOR, CCTOOLS_VERSION_MICRO)); jx_insert_string(j,"cpu",name.machine); jx_insert_string(j,"opsys",name.sysname); jx_insert_string(j,"opsysversion",name.release); jx_insert_double(j,"load1",load[0]); jx_insert_double(j,"load5",load[1]); jx_insert_double(j,"load15",load[2]); jx_insert_integer(j,"memory_total",memory_total); jx_insert_integer(j,"memory_avail",memory_avail); jx_insert_integer(j,"cpus",cpus); jx_insert_integer(j,"uptime,",uptime); jx_insert_string(j,"owner",owner); int i; for (i = optind; i < argc; i++) { char *name; char *value; name = argv[i]; value = strchr(name, '='); if (!value) { fatal("invalid name/value pair = %s", name); } else { *value++ = 0; } jx_insert_string(j,name,value); } char *text = jx_print_string(j); char address[DATAGRAM_ADDRESS_MAX]; if (domain_name_cache_lookup(host, address)) { datagram_send(d, text, strlen(text), address, port); } else { fatal("unable to lookup address of host: %s", host); } jx_delete(j); datagram_delete(d); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { char *host = CATALOG_HOST; int port = CATALOG_PORT; static struct option long_options[] = {{"catalog", required_argument, 0, 'c'}, {0,0,0,0}}; signed int c; while ((c = getopt_long(argc, argv, "c:", long_options, NULL)) > -1) { switch (c) { case 'c': host = optarg; break; default: show_help(argv[0]); return EXIT_FAILURE; } } struct datagram *d; d = datagram_create(DATAGRAM_PORT_ANY); if (!d) { fatal("could not create datagram port!"); } buffer_t B; const char *text; size_t text_size; buffer_init(&B); buffer_abortonfailure(&B, 1); struct utsname name; int cpus; int uptime; double load[3]; UINT64_T memory_total, memory_avail; char owner[USERNAME_MAX]; uname(&name); string_tolower(name.sysname); string_tolower(name.machine); string_tolower(name.release); load_average_get(load); cpus = load_average_get_cpus(); memory_info_get(&memory_avail, &memory_total); uptime = uptime_get(); username_get(owner); buffer_printf(&B, "type %s\nversion %d.%d.%s\ncpu %s\nopsys %s\nopsysversion %s\nload1 %0.02lf\nload5 %0.02lf\nload15 %0.02lf\nmemory_total %llu\nmemory_avail %llu\ncpus %d\nuptime %d\nowner %s\n", DEFAULT_TYPE, CCTOOLS_VERSION_MAJOR, CCTOOLS_VERSION_MINOR, CCTOOLS_VERSION_MICRO, name.machine, name.sysname, name.release, load[0], load[1], load[2], (unsigned long long) memory_total, (unsigned long long) memory_avail, cpus, uptime, owner ); int i; for (i = optind; i < argc; i++) { char *name; char *value; name = argv[i]; value = strchr(name, '='); if (!value) { fatal("invalid name/value pair = %s", name); } else { *value++ = 0; } buffer_printf(&B, "%s %s\n", name, value); } text = buffer_tostring(&B, &text_size); char address[DATAGRAM_ADDRESS_MAX]; if (domain_name_cache_lookup(host, address)) { datagram_send(d, text, text_size, address, port); } else { fatal("unable to lookup address of host: %s", host); } buffer_free(&B); datagram_delete(d); return EXIT_SUCCESS; }
struct chirp_matrix *chirp_matrix_create(const char *host, const char *path, int width, int height, int element_size, int nhosts, time_t stoptime) { char host_file[CHIRP_LINE_MAX]; int result; unsigned int i; char **hosts; int nfiles = nhosts; while(1) { INT64_T n_row_per_file = height / nfiles; if(height % nfiles) n_row_per_file++; INT64_T file_size = n_row_per_file * width * element_size; if(file_size > GIGABYTE) { nfiles *= 2; continue; } else { break; } } char line[CHIRP_LINE_MAX * nfiles]; FILE *file = NULL; if(getenv("CHIRP_HOSTS")) { sprintf(host_file, "%s", getenv("CHIRP_HOSTS")); file = fopen(host_file, "r"); } if(!file) { if(getenv("HOME")) { sprintf(host_file, "%s/.chirp/hosts", getenv("HOME")); file = fopen(host_file, "r"); } } if(!file) { sprintf(host_file, "./chirp_hosts"); file = fopen(host_file, "r"); if(!file) { file = fopen(host_file, "w"); char hostname[CHIRP_LINE_MAX]; gethostname(hostname, CHIRP_LINE_MAX - 1); // get hostname, this may not have domain name, though! fprintf(file, "%s\n", hostname); fclose(file); file = fopen(host_file, "r"); } } if(!file) { debug(D_NOTICE | D_CHIRP, "matrix: could not open host list in %s: %s\n", host_file, strerror(errno)); errno = EINVAL; return 0; } hosts = malloc(sizeof(*hosts) * nhosts); for(i = 0; (int) i < nhosts; i++) { if(!fgets(line, sizeof(line), file)) { rewind(file); fgets(line, sizeof(line), file); } hosts[i] = strdup(line); int len = strlen(hosts[i]); hosts[i][len - 1] = '\0'; } fclose(file); sprintf(line, "%d\n%d\n%d\n%d\n%d\n", width, height, element_size, nhosts, nfiles); char datapath1[CHIRP_LINE_MAX]; char datapath2[CHIRP_LINE_MAX]; char datapath3[CHIRP_LINE_MAX]; char username[USERNAME_MAX]; char cookie[16]; username_get(username); string_cookie(cookie, sizeof(cookie)); sprintf(datapath1, "/%s", username); sprintf(datapath2, "/%s/matrixdata", username); sprintf(datapath3, "/%s/matrixdata/%s", username, cookie); for(i = 0; (int) i < nfiles; i++) { const char *datahost = hosts[i % nhosts]; result = chirp_reli_mkdir(datahost, datapath1, 0700, stoptime); result = chirp_reli_mkdir(datahost, datapath2, 0700, stoptime); result = chirp_reli_mkdir(datahost, datapath3, 0700, stoptime); sprintf(&line[strlen(line)], "%s %s/data.%d\n", datahost, datapath3, i); } for(i = 0; (int) i < nhosts; i++) { free(hosts[i]); } free(hosts); char metapath[CHIRP_LINE_MAX]; strcpy(metapath, path); result = chirp_reli_putfile_buffer(host, path, line, 0700, strlen(line), stoptime); if(result < 0) { for(i = 1; i < strlen(metapath); i++) if(metapath[i] == '/') { metapath[i] = '\0'; result = chirp_reli_mkdir(host, metapath, 0700, stoptime); if(result < 0 && errno != EEXIST) { debug(D_CHIRP, "matrix: could not build directory /chirp/%s/%s to create metadata file: %s\n", host, metapath, strerror(errno)); return 0; } metapath[i] = '/'; } result = chirp_reli_putfile_buffer(host, path, line, 0700, strlen(line), stoptime); if(result < 0) { debug(D_CHIRP, "matrix: could not create metadata file /chirp/%s/%s: %s\n", host, path, strerror(errno)); return 0; } } debug(D_CHIRP, "matrix: created matrix %s/%s -- now opening\n", host, path); return chirp_matrix_open(host, path, stoptime); }