Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/freebsd/poudriere.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2012-11-06 02:39:33 +0400
committerBaptiste Daroussin <bapt@FreeBSD.org>2012-11-06 02:39:33 +0400
commit4d014f929d0999a62ba0325fc1edba7730f92dec (patch)
treea4b59944e2622079fb6524977304b2a8355939cc
parent4b7a43002b617b5eb95b2e3888e87568daaf010a (diff)
Make the pipe non blocking in injail, while here add the ability to retrieve the pid if neededc_version
-rw-r--r--src/bulk.c26
-rw-r--r--src/utils.c38
-rw-r--r--src/utils.h3
3 files changed, 28 insertions, 39 deletions
diff --git a/src/bulk.c b/src/bulk.c
index ab8c0d8d..78bfa0f6 100644
--- a/src/bulk.c
+++ b/src/bulk.c
@@ -103,7 +103,7 @@ delete_ifold(struct pjail *j, const char *path)
linecap = 0;
line = NULL;
- if ((fp = injail(j, arg)) != NULL) {
+ if ((fp = injail(j, arg, NULL)) != NULL) {
while (getline(&line, &linecap, fp) > 0) {
p = calloc(0, sizeof(struct port));
strlcpy(p->origin, origin, sizeof(p->origin));
@@ -146,6 +146,7 @@ compute_deps(struct pjail *j, struct pport_tree *p, const char *orig)
size_t linecap = 0;
char *pkgname = NULL;
int nbel, i;
+ int linenb = 0;
FILE *fp;
STAILQ_FOREACH(pkg, &queue, next) {
@@ -184,8 +185,11 @@ compute_deps(struct pjail *j, struct pport_tree *p, const char *orig)
snprintf(cmd, sizeof(cmd), "/usr/ports/%s", orig);
argv[2] = cmd;
- if ((fp = injail(j, argv)) != NULL) {
+ if ((fp = injail(j, argv, NULL)) != NULL) {
while (getline(&line, &linecap, fp) > 0) {
+ linenb++;
+ if (linenb > 8)
+ break;
if (line[strlen(line) - 1] == '\n')
line[strlen(line) - 1] = '\0';
if (pkgname == NULL) {
@@ -325,6 +329,7 @@ check_pkgtools(struct pjail *j)
size_t linecap = 0;
int linenb = 0;
char *line = NULL;
+ pid_t pid;
conf.pkgng = true;
char *argv[] = {
@@ -338,7 +343,7 @@ check_pkgtools(struct pjail *j)
};
printf("====>> build will use: ");
- if ((fp = injail(j, argv)) != NULL) {
+ if ((fp = injail(j, argv, &pid)) != NULL) {
while (getline(&line, &linecap, fp) > 0) {
linenb++;
if (linenb == 1) {
@@ -352,10 +357,11 @@ check_pkgtools(struct pjail *j)
if (line[strlen(line) -1] == '\n')
line[strlen(line) -1] = '\0';
strlcpy(conf.pkg_delete, pos, sizeof(conf.pkg_delete));
- break;
}
+ if (waitpid(-1, NULL, WNOHANG) == -1)
+ break;
}
- fclose(fp);
+ pclose(fp);
free(line);
}
@@ -518,18 +524,20 @@ build(struct pjail *j)
snprintf(cmd, sizeof(cmd), "/usr/ports/%s", j->pkg->origin);
arg[2] = cmd;
- if ((fp = injail(j, arg)) != NULL) {
+ if ((fp = injail(j, arg, NULL)) != NULL) {
while (getline(&line, &linecap, fp) > 0) {
linenb++;
+ if (linenb > 2)
+ break;
if (line[0] == '\n')
continue;
if (linenb == 1) {
printf("====>> Marked as IGNORED, aborting: %s", line);
exit(IGNORED);
- }
- if (linenb == 2)
- exit(BROKEN);
+ } else if (linenb == 2) {
printf("====>> Marked as BROKEN, aborting: %s", line);
+ exit(BROKEN);
+ }
}
fclose(fp);
}
diff --git a/src/utils.c b/src/utils.c
index d4a0839f..4b1ea614 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -11,6 +11,7 @@
#include <sys/sysctl.h>
#include <ctype.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
@@ -69,32 +70,6 @@ split_chr(char *str, char sep)
return nbel;
}
-struct sbuf *
-injail_buf(struct pjail *j, char *cmd[])
-{
- FILE *fp;
- char buf[BUFSIZ];
- struct sbuf *res;
-
- if ((fp = injail(j, cmd)) == NULL)
- return (NULL);
-
- res = sbuf_new_auto();
- while (fgets(buf, BUFSIZ, fp) != NULL)
- sbuf_cat(res, buf);
-
- fclose(fp);
-
- if (sbuf_len(res) == 0) {
- sbuf_delete(res);
- return (NULL);
- }
-
- sbuf_finish(res);
-
- return (res);
-}
-
int
exec(char *path, char *const argv[])
{
@@ -640,12 +615,13 @@ jail_setup(struct pjail *j)
}
FILE *
-injail(struct pjail *j, char *cmd[])
+injail(struct pjail *j, char *cmd[], pid_t *pid)
{
int pdes[2];
int jid;
struct passwd *pw;
int ngroups;
+ pid_t p;
jid = jail_getid(j->name);
if (jid < 0) {
@@ -656,7 +632,9 @@ injail(struct pjail *j, char *cmd[])
if (pipe(pdes) < 0)
return (NULL);
- switch (vfork()) {
+ fcntl(pdes[0], F_SETFL, O_NONBLOCK);
+
+ switch ((p = vfork())) {
case -1:
close(pdes[0]);
close(pdes[1]);
@@ -681,5 +659,9 @@ injail(struct pjail *j, char *cmd[])
/* not reached */
exit (-1);
}
+
+ if (pid != NULL)
+ *pid = p;
+
return (fdopen(pdes[0], "r"));
}
diff --git a/src/utils.h b/src/utils.h
index aa6e46c2..db81247f 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -67,9 +67,8 @@ void jail_kill(struct pjail *j);
void jail_run(struct pjail *j, bool network);
int exec(char *, char * const argv[]);
int jexec(struct pjail *j, char *argv[]);
-struct sbuf *injail_buf(struct pjail *j, char *cmd[]);
void mount_nullfs(struct pjail *j, struct pport_tree *p);
int split_chr(char *str, char sep);
-FILE *injail(struct pjail *j, char *cmd[]);
+FILE *injail(struct pjail *j, char *cmd[], pid_t *p);
#endif