diff --git a/src/server/distrend.c b/src/server/distrend.c --- a/src/server/distrend.c +++ b/src/server/distrend.c @@ -196,7 +196,7 @@ void status_report_generator(struct blen blendjob_ptr = *blendjobs_head; workers_working = 0; numjobs = 0; - + while(blendjob_ptr) { if(blendjob_ptr->priority != 0) @@ -230,7 +230,7 @@ void status_report_generator(struct blen pending_frames ++; workers_working ++; } - + framecounter ++; } /* while(framecounter < blendjob_ptr->total_frames) */ @@ -250,25 +250,25 @@ void status_report_generator(struct blen blendjob_ptr->priority = 0; /*< set priority to zero to indicate job is complete */ blendjob_remove(blendjobs_head, blendjob_ptr); /*< remove this job from the linkedlist */ general_info.total_finished_jobs++; /*< add one to the total finished jobs */ - + } else if (finished_frames > blendjob_ptr->total_frames) /* just in case ;-) */ { fprintf(stderr, "%s:%d: finished_frames (%lu) > blendjob_ptr->total_frames (%d)", - __FILE__, __LINE__, - finished_frames, + __FILE__, __LINE__, + finished_frames, blendjob_ptr->total_frames); abort(); } } general_info.rendering_clients = workers_working; /*< should this be a +=? */ - + blendjob_ptr = blendjob_ptr->next; /*< This is the essence of linked lists and iterating through them */ numjobs ++; } /* while(blendjob_ptr) */ - + general_info.jobs_in_queue = (highest_jobnum - general_info.total_finished_jobs); /*< extraneous parentheses! */ } @@ -304,46 +304,46 @@ void frame_num_struct_builder(struct ble int frame_finder(struct blendjob *head, struct blendjob **job, struct frameset **frame) { int your_frame; // your_frame is an interger value that will be given to the client as the frame number to render - + unsigned short int found; unsigned short int priority; - + struct blendjob *blendjob_ptr; - + found = 0; while(!found) { /* enumerate through priority levels */ for(priority = 10; priority > 0 - && !found; + && !found; priority --) /* Find the job with the highest priority */ - for(blendjob_ptr = head; - blendjob_ptr != NULL - && !found; + for(blendjob_ptr = head; + blendjob_ptr != NULL + && !found; blendjob_ptr = blendjob_ptr->next) if(blendjob_ptr->priority == priority) found = 1; - + if(!found) { fprintf(stderr, "out of jobs to render\n"); return 1; } - + found = 0; - for(your_frame = 0; + for(your_frame = 0; your_frame < blendjob_ptr->total_frames; your_frame ++) if(blendjob_ptr->frameset[your_frame].status == 0) found = 1; - + if(!found) { /* there are no frames left in this job */ blendjob_ptr->priority --; - + /* If that job had no open frames for some reason, run the status report generator so that */ status_report_generator(&head); @@ -351,7 +351,7 @@ int frame_finder(struct blendjob *head, fprintf(stderr, "Job %d is finished, this is probably the place to call the job-removal function\n", blendjob_ptr->jobnum); } } /* while(!found) */ - + fprintf(stderr, "Missing apostrophe !!!!!!!!!!!!!!\n"); abort(); /* sets the value of the frame to 1, which means its taken !!!!!! MISSSING APOSTROPHE!!!!!!! */ blendjob_ptr->frameset[your_frame].status++; @@ -379,9 +379,9 @@ void blend_frame_watchdog(struct blendjo for(counter = 0; counter < blendjob_ptr->total_frames; counter ++) /* iterate through all frames for this job*/ { - if((blendjob_ptr->frameset[counter].start_time + (watchdog_forgiveness * 3600)) < clock()) + if((blendjob_ptr->frameset[counter].start_time + (watchdog_forgiveness * 3600)) < clock()) /* - If frame is not completed within the number of hours specified by watchdog_forgiveness + If frame is not completed within the number of hours specified by watchdog_forgiveness Then change the frame status to unassigned */ blendjob_ptr->frameset[counter].status = 0; @@ -397,7 +397,7 @@ void blend_frame_watchdog(struct blendjo struct blendjob *blendjob_get(struct blendjob *head, jobnum_t jobnum) { struct blendjob *blendjob_ptr; - + /* The conditions of the for loop will leave blendjob_ptr at NULL if the end of the list is reached. It will leave it pointing to the correct job if it is found. */ @@ -405,7 +405,7 @@ struct blendjob *blendjob_get(struct ble blendjob_ptr && blendjob_ptr->jobnum != jobnum; blendjob_ptr = blendjob_ptr->next); - + return blendjob_ptr; } @@ -418,25 +418,25 @@ struct blendjob *blendjob_get(struct ble void blendjob_remove(struct blendjob **head, struct blendjob *bj) { struct blendjob *previous_blendjob; - + if(bj == *head) *head = bj->next; else { - + for(previous_blendjob = *head; previous_blendjob && previous_blendjob->next != bj; /*< stop on the blendjob that comes before bj */ previous_blendjob = previous_blendjob->next) /* all of the action is in the definition of the for loop itself */; - + /* This removes references to bj from the linked list. I.E., we now skip bj when iterating through the list */ previous_blendjob->next = bj->next; } - - /* + + /* @lordofwar: the magic deallocation of memory ;-) */ free(bj); @@ -571,154 +571,3 @@ blend_frame_watchdog(); return 0; } - - - - - - - -/* - * ********************************************************************************** - * Slave functions / etc resides below. Wouldn't a seperate file make this easier?? - * - * Slave listens on server for a command in the format of each function... - * We need if's for returns... ==> watchdog - * ********************************************************************************** -*/ - - -///////////////////// Semi-pseudo Slave Code /////////////////////////// -/* -int slavestatus = 0; - -if(no username in config file, no key present){ - fprintf(stderr "run distrend -c username] [emailaddr] to register") -} -if(they use a -c flag according to getopt, with 2 args){ - register_user(username, email); which returns a uniquely random url to a key - get(uniquely-random-url-to-key); - fprintf(stderr, "you registered, hopefully successfully. Invoke distrend with no args now."); -} -if(username is in conf file and key is present){ - loginuser(username); -} - -if(slave recieves "start frame#, job#"){ - get(http://distren.protofusion.org/srv/job#.tgz); - tar -xvf job#.tgz /tmp/distren/job#; somehow - exec_blender(job#.blend, job#.frame#.JPG, job#); (check the args, we'll need to adjust for different output formats)... set SLAVESTATUS=1 while rendering, SLAVESTATUS=2 when done -} -if(SLAVESTATUS==2){ - tell the server "done with frame# in job#"; - SLAVESTATUS=0 -} -if(SLAVESTATUS==0){ - tell the server "i ain't got no frames to render"; -} -while(SLAVESTATUS==1){ - tell the server "rendering this friggn frame"; - delay(1000); -} -*/ -//////////////////////////////////////////////////////////////////////// - - - - - - - - - - - - -// Registration on server. Needs attention. Prevent account spamming. -// Key transfer? -// Set up something like: distrend -c username email@example.com -void registeruser(char *username, char *email){ - // Logs into sandboxed user on zserver2 and registers a user. Should eventually generate a key on the server and return it to the user. - // All created user accounts should be sandboxed accordingly, requiring a different skel, and the default shell to be rbash. Also, - // a custom path defined in the .bash_profile of the skel is needed. - char buf[10]; - struct execio *testrem; - char *execargv[] = - { - "ssh", - "distren_setup@protofusion.org", - "-i", - "setup.rsa", // default distributed key, account can only create users. - "-p", - "23", - "sudo /usr/sbin/useradd", - "-M", - "-c", - email, - "-d", - "/home/distren", - "--gid", - "541", // Add in shellscript to generate ssh key and return it to the user somehow - username, - (char *)NULL - }; - size_t readlen; - fprintf(stderr, "Opening stream:\n", execio_open(&testrem, "ssh", execargv)); - buf[9] = '\0'; // null-terminating the array... - while(!execio_read(testrem, buf, 9, &readlen)) // What's with the readlen stuff? - { - if(readlen > 9) { - fprintf(stderr, "!!!! Something is terribly wrong!\n"); - } - buf[readlen] = '\0'; // Null-terminating the end of it again based on how large the data is? - fprintf(stderr, "read \"%s\"\n", buf); - } - execio_close(testrem); -} - - -void loginuser(char *username){ - // Logs into sandboxed user on zserver2 as a client, currently does nothing - char buf[10]; - struct execio *testrem; - char *execargv[] = - { - "ssh", - "username@protofusion.org", // username must be read from the conf - "-i", - "username.rsa", // Key created from registeruser() - "-p", - "23", - "echo", - "hello", // This should eventually open a non-terminating connection to the server for communication - (char *)NULL - }; - size_t readlen; - fprintf(stderr, "Opening stream:\n", execio_open(&testrem, "ssh", execargv)); - buf[9] = '\0'; // null-terminating the array... - while(!execio_read(testrem, buf, 9, &readlen)) // What's with the readlen stuff? - { - if(readlen > 9) { - fprintf(stderr, "!!!! Something is terribly wrong!\n"); - } - buf[readlen] = '\0'; // Null-terminating the end of it again based on how large the data is? - fprintf(stderr, "read \"%s\"\n", buf); - } - execio_close(testrem); -} - - -// Executors - -/* - It seems that the client will need to know the job number. Is finish_frame going to be on the client or the server? we gotta figure that out! -*/ -void exec_blender(struct blendjob* blendjob, char *input, char *output, int frame) -{ - char *frame_str; - asprintf(frame,frame_str); // GNU/*nix compatible only, fix before releasing win32, although dll for windows for asprintf exists! - int ret; - char *cmd[] = { "blender", "-b", "-o", output, input, "-f", frame_str, (char *)0 }; - ret = execv("/usr/bin/blender", cmd); - finish_frame(blendjob, frame); -} diff --git a/src/server/slave.c b/src/server/slave.c new file mode 100644 --- /dev/null +++ b/src/server/slave.c @@ -0,0 +1,142 @@ +/* + * ********************************************************************************** + * Slave functions / etc resides below. Wouldn't a seperate file make this easier?? + * + * Slave listens on server for a command in the format of each function... + * We need if's for returns... ==> watchdog + * ********************************************************************************** +*/ + + +///////////////////// Semi-pseudo Slave Code /////////////////////////// + +int slavestatus = 0; + +if(no username in config file, no key present){ + fprintf(stderr "run distrend -c username] [emailaddr] to register") +} +if(they use a -c flag according to getopt, with 2 args){ + register_user(username, email); which returns a uniquely random url to a key + get(uniquely-random-url-to-key); + fprintf(stderr, "you registered, hopefully successfully. Invoke distrend with no args now."); +} +if(username is in conf file and key is present){ + loginuser(username); +} + +if(slave recieves "start frame#, job#"){ + get(http://distren.protofusion.org/srv/job#.tgz); + tar -xvf job#.tgz /tmp/distren/job#; somehow + exec_blender(job#.blend, job#.frame#.JPG, job#); (check the args, we'll need to adjust for different output formats)... set SLAVESTATUS=1 while rendering, SLAVESTATUS=2 when done +} +if(SLAVESTATUS==2){ + tell the server "done with frame# in job#"; + SLAVESTATUS=0 +} +if(SLAVESTATUS==0){ + tell the server "i ain't got no frames to render"; +} +while(SLAVESTATUS==1){ + tell the server "rendering this friggn frame"; + delay(1000); +} + + + + + + + + + + + + +// Registration on server. Needs attention. Prevent account spamming. +// Key transfer? +// Set up something like: distrend -c username email@example.com +void registeruser(char *username, char *email){ + // Logs into sandboxed user on zserver2 and registers a user. Should eventually generate a key on the server and return it to the user. + // All created user accounts should be sandboxed accordingly, requiring a different skel, and the default shell to be rbash. Also, + // a custom path defined in the .bash_profile of the skel is needed. + char buf[10]; + struct execio *testrem; + char *execargv[] = + { + "ssh", + "distren_setup@protofusion.org", + "-i", + "setup.rsa", // default distributed key, account can only create users. + "-p", + "23", + "sudo /usr/sbin/useradd", + "-M", + "-c", + email, + "-d", + "/home/distren", + "--gid", + "541", // Add in shellscript to generate ssh key and return it to the user somehow + username, + (char *)NULL + }; + size_t readlen; + fprintf(stderr, "Opening stream:\n", execio_open(&testrem, "ssh", execargv)); + buf[9] = '\0'; // null-terminating the array... + while(!execio_read(testrem, buf, 9, &readlen)) // What's with the readlen stuff? + { + if(readlen > 9) { + fprintf(stderr, "!!!! Something is terribly wrong!\n"); + } + buf[readlen] = '\0'; // Null-terminating the end of it again based on how large the data is? + fprintf(stderr, "read \"%s\"\n", buf); + } + execio_close(testrem); +} + + +void loginuser(char *username){ + // Logs into sandboxed user on zserver2 as a client, currently does nothing + char buf[10]; + struct execio *testrem; + char *execargv[] = + { + "ssh", + "username@protofusion.org", // username must be read from the conf + "-i", + "username.rsa", // Key created from registeruser() + "-p", + "23", + "echo", + "hello", // This should eventually open a non-terminating connection to the server for communication + (char *)NULL + }; + size_t readlen; + fprintf(stderr, "Opening stream:\n", execio_open(&testrem, "ssh", execargv)); + buf[9] = '\0'; // null-terminating the array... + while(!execio_read(testrem, buf, 9, &readlen)) // What's with the readlen stuff? + { + if(readlen > 9) { + fprintf(stderr, "!!!! Something is terribly wrong!\n"); + } + buf[readlen] = '\0'; // Null-terminating the end of it again based on how large the data is? + fprintf(stderr, "read \"%s\"\n", buf); + } + execio_close(testrem); +} + + +// Executors + +/* + It seems that the client will need to know the job number. Is finish_frame going to be on the client or the server? we gotta figure that out! +*/ +void exec_blender(struct blendjob* blendjob, char *input, char *output, int frame) +{ + char *frame_str; + asprintf(frame,frame_str); // GNU/*nix compatible only, fix before releasing win32, although dll for windows for asprintf exists! + int ret; + char *cmd[] = { "blender", "-b", "-o", output, input, "-f", frame_str, (char *)0 }; + ret = execv("/usr/bin/blender", cmd); + finish_frame(blendjob, frame); +}