diff options
author | Simon J. Gerraty <sjg@FreeBSD.org> | 2015-04-21 04:40:38 +0000 |
---|---|---|
committer | Simon J. Gerraty <sjg@FreeBSD.org> | 2015-04-21 04:40:38 +0000 |
commit | db29cad8157b2f3afdb890831ddf73da0f4c01c0 (patch) | |
tree | d4404a0b758eb6a0547daa01b5eec4d7df64362f /contrib/bmake/meta.c | |
parent | 3554283a7b05e2b218f7fe4bad83fc2aa341ec1f (diff) | |
parent | 023e89e5efa694577b481488bb5ea251d3ec1966 (diff) | |
download | src-db29cad8157b2f3afdb890831ddf73da0f4c01c0.tar.gz src-db29cad8157b2f3afdb890831ddf73da0f4c01c0.zip |
Merge bmake-20150418
PR: 199486
Notes
Notes:
svn path=/head/; revision=281812
Diffstat (limited to 'contrib/bmake/meta.c')
-rw-r--r-- | contrib/bmake/meta.c | 87 |
1 files changed, 64 insertions, 23 deletions
diff --git a/contrib/bmake/meta.c b/contrib/bmake/meta.c index ddced23b730e..5600a772bed4 100644 --- a/contrib/bmake/meta.c +++ b/contrib/bmake/meta.c @@ -1,4 +1,4 @@ -/* $NetBSD: meta.c,v 1.33 2013/10/01 05:37:17 sjg Exp $ */ +/* $NetBSD: meta.c,v 1.38 2015/04/11 05:24:30 sjg Exp $ */ /* * Implement 'meta' mode. @@ -155,8 +155,8 @@ filemon_open(BuildMon *pbm) static void filemon_read(FILE *mfp, int fd) { - FILE *fp; char buf[BUFSIZ]; + int n; /* Check if we're not writing to a meta data file.*/ if (mfp == NULL) { @@ -166,17 +166,14 @@ filemon_read(FILE *mfp, int fd) } /* rewind */ (void)lseek(fd, (off_t)0, SEEK_SET); - if ((fp = fdopen(fd, "r")) == NULL) - err(1, "Could not read build monitor file '%d'", fd); fprintf(mfp, "\n-- filemon acquired metadata --\n"); - while (fgets(buf, sizeof(buf), fp)) { - fprintf(mfp, "%s", buf); + while ((n = read(fd, buf, sizeof(buf))) > 0) { + fwrite(buf, 1, n, mfp); } fflush(mfp); - clearerr(fp); - fclose(fp); + close(fd); } #endif @@ -662,17 +659,21 @@ meta_job_child(Job *job) { #ifdef USE_FILEMON BuildMon *pbm; - pid_t pid; if (job != NULL) { pbm = &job->bm; } else { pbm = &Mybm; } - pid = getpid(); - if (pbm->mfp != NULL && useFilemon) { - if (ioctl(pbm->filemon_fd, FILEMON_SET_PID, &pid) < 0) { - err(1, "Could not set filemon pid!"); + if (pbm->mfp != NULL) { + close(fileno(pbm->mfp)); + if (useFilemon) { + pid_t pid; + + pid = getpid(); + if (ioctl(pbm->filemon_fd, FILEMON_SET_PID, &pid) < 0) { + err(1, "Could not set filemon pid!"); + } } } #endif @@ -844,9 +845,10 @@ string_match(const void *p, const void *q) /* * When running with 'meta' functionality, a target can be out-of-date - * if any of the references in it's meta data file is more recent. + * if any of the references in its meta data file is more recent. * We have to track the latestdir on a per-process basis. */ +#define LCWD_VNAME_FMT ".meta.%d.lcwd" #define LDIR_VNAME_FMT ".meta.%d.ldir" /* @@ -872,11 +874,14 @@ meta_oodate(GNode *gn, Boolean oodate) { static char *tmpdir = NULL; static char cwd[MAXPATHLEN]; + char lcwd_vname[64]; char ldir_vname[64]; + char lcwd[MAXPATHLEN]; char latestdir[MAXPATHLEN]; char fname[MAXPATHLEN]; char fname1[MAXPATHLEN]; char fname2[MAXPATHLEN]; + char fname3[MAXPATHLEN]; char *p; char *cp; char *link_src; @@ -928,6 +933,8 @@ meta_oodate(GNode *gn, Boolean oodate) err(1, "Could not get current working directory"); cwdlen = strlen(cwd); } + strlcpy(lcwd, cwd, sizeof(lcwd)); + strlcpy(latestdir, cwd, sizeof(latestdir)); if (!tmpdir) { tmpdir = getTmpdir(); @@ -1011,9 +1018,11 @@ meta_oodate(GNode *gn, Boolean oodate) char *tp; if (lastpid > 0) { - /* We need to remember this. */ + /* We need to remember these. */ + Var_Set(lcwd_vname, lcwd, VAR_GLOBAL, 0); Var_Set(ldir_vname, latestdir, VAR_GLOBAL, 0); } + snprintf(lcwd_vname, sizeof(lcwd_vname), LCWD_VNAME_FMT, pid); snprintf(ldir_vname, sizeof(ldir_vname), LDIR_VNAME_FMT, pid); lastpid = pid; ldir = Var_Value(ldir_vname, VAR_GLOBAL, &tp); @@ -1021,15 +1030,22 @@ meta_oodate(GNode *gn, Boolean oodate) strlcpy(latestdir, ldir, sizeof(latestdir)); if (tp) free(tp); - } else - strlcpy(latestdir, cwd, sizeof(latestdir)); + } + ldir = Var_Value(lcwd_vname, VAR_GLOBAL, &tp); + if (ldir) { + strlcpy(lcwd, ldir, sizeof(lcwd)); + if (tp) + free(tp); + } } /* Skip past the pid. */ if (strsep(&p, " ") == NULL) continue; #ifdef DEBUG_META_MODE if (DEBUG(META)) - fprintf(debug_file, "%s: %d: cwd=%s ldir=%s\n", fname, lineno, cwd, latestdir); + fprintf(debug_file, "%s: %d: %d: %c: cwd=%s lcwd=%s ldir=%s\n", + fname, lineno, + pid, buf[0], cwd, lcwd, latestdir); #endif break; } @@ -1039,6 +1055,7 @@ meta_oodate(GNode *gn, Boolean oodate) /* Process according to record type. */ switch (buf[0]) { case 'X': /* eXit */ + Var_Delete(lcwd_vname, VAR_GLOBAL); Var_Delete(ldir_vname, VAR_GLOBAL); lastpid = 0; /* no need to save ldir_vname */ break; @@ -1050,15 +1067,30 @@ meta_oodate(GNode *gn, Boolean oodate) child = atoi(p); if (child > 0) { + snprintf(cldir, sizeof(cldir), LCWD_VNAME_FMT, child); + Var_Set(cldir, lcwd, VAR_GLOBAL, 0); snprintf(cldir, sizeof(cldir), LDIR_VNAME_FMT, child); Var_Set(cldir, latestdir, VAR_GLOBAL, 0); +#ifdef DEBUG_META_MODE + if (DEBUG(META)) + fprintf(debug_file, "%s: %d: %d: cwd=%s lcwd=%s ldir=%s\n", + fname, lineno, + child, cwd, lcwd, latestdir); +#endif } } break; case 'C': /* Chdir */ - /* Update the latest directory. */ - strlcpy(latestdir, p, sizeof(latestdir)); + /* Update lcwd and latest directory. */ + strlcpy(latestdir, p, sizeof(latestdir)); + strlcpy(lcwd, p, sizeof(lcwd)); + Var_Set(lcwd_vname, lcwd, VAR_GLOBAL, 0); + Var_Set(ldir_vname, lcwd, VAR_GLOBAL, 0); +#ifdef DEBUG_META_MODE + if (DEBUG(META)) + fprintf(debug_file, "%s: %d: cwd=%s ldir=%s\n", fname, lineno, cwd, lcwd); +#endif break; case 'M': /* renaMe */ @@ -1207,11 +1239,16 @@ meta_oodate(GNode *gn, Boolean oodate) snprintf(fname1, sizeof(fname1), "%s/%s", latestdir, p); sdirs[sdx++] = fname1; - if (strcmp(latestdir, cwd) != 0) { - /* Check vs cwd */ - snprintf(fname2, sizeof(fname2), "%s/%s", cwd, p); + if (strcmp(latestdir, lcwd) != 0) { + /* Check vs lcwd */ + snprintf(fname2, sizeof(fname2), "%s/%s", lcwd, p); sdirs[sdx++] = fname2; } + if (strcmp(lcwd, cwd) != 0) { + /* Check vs cwd */ + snprintf(fname3, sizeof(fname3), "%s/%s", cwd, p); + sdirs[sdx++] = fname3; + } } sdirs[sdx++] = NULL; @@ -1250,6 +1287,10 @@ meta_oodate(GNode *gn, Boolean oodate) oodate = TRUE; } } + if (buf[0] == 'E') { + /* previous latestdir is no longer relevant */ + strlcpy(latestdir, lcwd, sizeof(latestdir)); + } break; default: break; |