Author: sandervanderburg
Date: Thu Oct 14 12:38:40 2010
New Revision: 24286
URL: https://svn.nixos.org/websvn/nix/?rev=24286&sc=1
Log:
Refactored client interface --realise operation into libinterface
Modified:
disnix/disnix/trunk/src/build/main.c
disnix/disnix/trunk/src/libinterface/client-interface.c
Modified: disnix/disnix/trunk/src/build/main.c
==============================================================================
--- disnix/disnix/trunk/src/build/main.c Thu Oct 14 12:33:20 2010
(r24285)
+++ disnix/disnix/trunk/src/build/main.c Thu Oct 14 12:38:40 2010
(r24286)
@@ -20,8 +20,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#define _GNU_SOURCE
#include <getopt.h>
+#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/wait.h>
#include <derivationmapping.h>
@@ -119,7 +119,7 @@
}
}
- /* Iterate over the derivation array and fork processes that
realise the derivations remotely */
+ /* Iterate over the derivation array and invoke processes that
realise the derivations remotely */
output_array = g_array_new(FALSE, FALSE, sizeof(int));
@@ -129,36 +129,18 @@
int status;
DerivationItem *item = g_array_index(derivation_array,
DerivationItem*, i);
- if(pipe(pipefd) == 0)
- {
- status = fork();
+ status = exec_realise(interface, item->target,
item->derivation, pipefd);
- if(status == -1)
- {
- fprintf(stderr, "Error with forking realise
process!\n");
- exit_status = -1;
- }
- else if(status == 0)
- {
- char *args[] = {interface, "--realise", "--target",
item->target, item->derivation, NULL};
-
- fprintf(stderr, "Realising derivation: %s on target:
%s\n", item->derivation, item->target);
-
- close(pipefd[0]); /* Close read-end */
- dup2(pipefd[1], 1); /* Attach pipe to the stdout */
- execvp(interface, args); /* Run remote realise process
*/
- fprintf(stderr, "Error in executing realise
process!\n");
- _exit(1);
- }
- else
- {
- close(pipefd[1]); /* Close write-end */
- g_array_append_val(output_array, pipefd[0]); /* Append
read file descriptor to array */
- running_processes++;
- }
+ if(status == -1)
+ {
+ fprintf(stderr, "Error with forking realise process!\n");
+ exit_status = -1;
}
else
- fprintf(stderr, "Error in creating a pipe!\n");
+ {
+ g_array_append_val(output_array, pipefd[0]); /* Append read
file descriptor to array */
+ running_processes++;
+ }
}
result_array = g_array_new(FALSE, FALSE, sizeof(gchar*));
@@ -182,7 +164,7 @@
result = g_strdup(line);
g_array_append_val(result_array, result);
}
- }
+ }
close(pipefd);
}
@@ -223,7 +205,7 @@
delete_derivation_array(derivation_array);
return status;
}
- }
+ }
}
/* Cleanup */
Modified: disnix/disnix/trunk/src/libinterface/client-interface.c
==============================================================================
--- disnix/disnix/trunk/src/libinterface/client-interface.c Thu Oct 14
12:33:20 2010 (r24285)
+++ disnix/disnix/trunk/src/libinterface/client-interface.c Thu Oct 14
12:38:40 2010 (r24286)
@@ -17,9 +17,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/
+#include "client-interface.h"
#include <sys/wait.h>
#include <sys/types.h>
-#include "client-interface.h"
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
int wait_to_finish(pid_t pid)
{
@@ -178,3 +181,33 @@
{
return exec_copy_closure("--to", interface, target, component);
}
+
+pid_t exec_realise(gchar *interface, gchar *target, gchar *derivation, int
pipefd[2])
+{
+ if(pipe(pipefd) == 0)
+ {
+ pid_t pid = fork();
+
+ if(pid == 0)
+ {
+ char *args[] = {interface, "--realise", "--target", target,
derivation, NULL};
+ close(pipefd[0]); /* Close read-end */
+ dup2(pipefd[1], 1); /* Attach pipe to the stdout */
+ execvp(interface, args); /* Run process */
+ _exit(1);
+ }
+ else if(pid == -1)
+ {
+ close(pipefd[0]); /* Close read-end */
+ close(pipefd[1]); /* Close write-end */
+ return pid;
+ }
+ else
+ {
+ close(pipefd[1]); /* Close write-end */
+ return pid;
+ }
+ }
+ else
+ return -1;
+}
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits