diff options
Diffstat (limited to 'contrib/bmake/meta.c')
-rw-r--r-- | contrib/bmake/meta.c | 82 |
1 files changed, 42 insertions, 40 deletions
diff --git a/contrib/bmake/meta.c b/contrib/bmake/meta.c index a7a4b19..f4acbde 100644 --- a/contrib/bmake/meta.c +++ b/contrib/bmake/meta.c @@ -1,4 +1,4 @@ -/* $NetBSD: meta.c,v 1.41 2015/11/30 23:37:56 sjg Exp $ */ +/* $NetBSD: meta.c,v 1.53 2016/03/07 21:45:43 christos Exp $ */ /* * Implement 'meta' mode. @@ -6,7 +6,7 @@ * --sjg */ /* - * Copyright (c) 2009-2010, Juniper Networks, Inc. + * Copyright (c) 2009-2016, Juniper Networks, Inc. * Portions Copyright (c) 2009, John Birrell. * * Redistribution and use in source and binary forms, with or without @@ -37,7 +37,6 @@ #endif #include <sys/stat.h> #include <sys/ioctl.h> -#include <fcntl.h> #ifdef HAVE_LIBGEN_H #include <libgen.h> #elif !defined(HAVE_DIRNAME) @@ -60,7 +59,9 @@ char * dirname(char *); static BuildMon Mybm; /* for compat */ static Lst metaBailiwick; /* our scope of control */ +static char *metaBailiwickStr; /* string storage for the list */ static Lst metaIgnorePaths; /* paths we deliberately ignore */ +static char *metaIgnorePathsStr; /* string storage for the list */ #ifndef MAKE_META_IGNORE_PATHS #define MAKE_META_IGNORE_PATHS ".MAKE.META.IGNORE_PATHS" @@ -148,8 +149,8 @@ filemon_open(BuildMon *pbm) err(1, "Could not set filemon file descriptor!"); } /* we don't need these once we exec */ - (void)fcntl(pbm->mon_fd, F_SETFD, 1); - (void)fcntl(pbm->filemon_fd, F_SETFD, 1); + (void)fcntl(pbm->mon_fd, F_SETFD, FD_CLOEXEC); + (void)fcntl(pbm->filemon_fd, F_SETFD, FD_CLOEXEC); } /* @@ -300,8 +301,7 @@ meta_name(struct GNode *gn, char *mname, size_t mnamelen, } free(tp); for (i--; i >= 0; i--) { - if (p[i]) - free(p[i]); + free(p[i]); } return (mname); } @@ -328,7 +328,7 @@ is_submake(void *cmdp, void *gnp) } cp = strchr(cmd, '$'); if ((cp)) { - mp = Var_Subst(NULL, cmd, gn, FALSE, TRUE); + mp = Var_Subst(NULL, cmd, gn, VARF_WANTRES); cmd = mp; } cp2 = strstr(cmd, p_make); @@ -353,8 +353,7 @@ is_submake(void *cmdp, void *gnp) } } } - if (mp) - free(mp); + free(mp); return (rc); } @@ -371,11 +370,10 @@ printCMD(void *cmdp, void *mfpp) char *cp = NULL; if (strchr(cmd, '$')) { - cmd = cp = Var_Subst(NULL, cmd, mfp->gn, FALSE, TRUE); + cmd = cp = Var_Subst(NULL, cmd, mfp->gn, VARF_WANTRES); } fprintf(mfp->fp, "CMD %s\n", cmd); - if (cp) - free(cp); + free(cp); return 0; } @@ -466,7 +464,7 @@ meta_create(BuildMon *pbm, GNode *gn) char *mp; /* Describe the target we are building */ - mp = Var_Subst(NULL, "${" MAKE_META_PREFIX "}", gn, FALSE, TRUE); + mp = Var_Subst(NULL, "${" MAKE_META_PREFIX "}", gn, VARF_WANTRES); if (*mp) fprintf(stdout, "%s\n", mp); free(mp); @@ -480,9 +478,6 @@ meta_create(BuildMon *pbm, GNode *gn) fflush(stdout); - if (strcmp(cp, makeDependfile) == 0) - goto out; - if (!writeMeta) /* Don't create meta data. */ goto out; @@ -524,8 +519,7 @@ meta_create(BuildMon *pbm, GNode *gn) } out: for (i--; i >= 0; i--) { - if (p[i]) - free(p[i]); + free(p[i]); } return (mf.fp); @@ -609,10 +603,10 @@ meta_mode_init(const char *make_mode) * We consider ourselves master of all within ${.MAKE.META.BAILIWICK} */ metaBailiwick = Lst_Init(FALSE); - cp = Var_Subst(NULL, "${.MAKE.META.BAILIWICK:O:u:tA}", VAR_GLOBAL, - FALSE, TRUE); - if (cp) { - str2Lst_Append(metaBailiwick, cp, NULL); + metaBailiwickStr = Var_Subst(NULL, "${.MAKE.META.BAILIWICK:O:u:tA}", + VAR_GLOBAL, VARF_WANTRES); + if (metaBailiwickStr) { + str2Lst_Append(metaBailiwick, metaBailiwickStr, NULL); } /* * We ignore any paths that start with ${.MAKE.META.IGNORE_PATHS} @@ -620,11 +614,11 @@ meta_mode_init(const char *make_mode) metaIgnorePaths = Lst_Init(FALSE); Var_Append(MAKE_META_IGNORE_PATHS, "/dev /etc /proc /tmp /var/run /var/tmp ${TMPDIR}", VAR_GLOBAL); - cp = Var_Subst(NULL, + metaIgnorePathsStr = Var_Subst(NULL, "${" MAKE_META_IGNORE_PATHS ":O:u:tA}", VAR_GLOBAL, - FALSE, TRUE); - if (cp) { - str2Lst_Append(metaIgnorePaths, cp, NULL); + VARF_WANTRES); + if (metaIgnorePathsStr) { + str2Lst_Append(metaIgnorePaths, metaIgnorePathsStr, NULL); } } @@ -693,9 +687,9 @@ meta_job_error(Job *job, GNode *gn, int flags, int status) if (job != NULL) { pbm = &job->bm; - } else { if (!gn) gn = job->node; + } else { pbm = &Mybm; } if (pbm->mfp != NULL) { @@ -709,7 +703,7 @@ meta_job_error(Job *job, GNode *gn, int flags, int status) } getcwd(cwd, sizeof(cwd)); Var_Set(".ERROR_CWD", cwd, VAR_GLOBAL, 0); - if (pbm && pbm->meta_fname[0]) { + if (pbm->meta_fname[0]) { Var_Set(".ERROR_META_FILE", pbm->meta_fname, VAR_GLOBAL, 0); } meta_job_finish(job); @@ -734,7 +728,7 @@ meta_job_output(Job *job, char *cp, const char *nl) char *cp2; meta_prefix = Var_Subst(NULL, "${" MAKE_META_PREFIX "}", - VAR_GLOBAL, FALSE, TRUE); + VAR_GLOBAL, VARF_WANTRES); if ((cp2 = strchr(meta_prefix, '$'))) meta_prefix_len = cp2 - meta_prefix; else @@ -785,6 +779,15 @@ meta_job_finish(Job *job) } } +void +meta_finish(void) +{ + Lst_Destroy(metaBailiwick, NULL); + free(metaBailiwickStr); + Lst_Destroy(metaIgnorePaths, NULL); + free(metaIgnorePathsStr); +} + /* * Fetch a full line from fp - growing bufp if needed * Return length in bufp. @@ -1035,14 +1038,12 @@ meta_oodate(GNode *gn, Boolean oodate) ldir = Var_Value(ldir_vname, VAR_GLOBAL, &tp); if (ldir) { strlcpy(latestdir, ldir, sizeof(latestdir)); - if (tp) - free(tp); + free(tp); } ldir = Var_Value(lcwd_vname, VAR_GLOBAL, &tp); if (ldir) { strlcpy(lcwd, ldir, sizeof(lcwd)); - if (tp) - free(tp); + free(tp); } } /* Skip past the pid. */ @@ -1320,7 +1321,7 @@ meta_oodate(GNode *gn, Boolean oodate) if (DEBUG(META)) fprintf(debug_file, "%s: %d: cannot compare command using .OODATE\n", fname, lineno); } - cmd = Var_Subst(NULL, cmd, gn, TRUE, TRUE); + cmd = Var_Subst(NULL, cmd, gn, VARF_WANTRES|VARF_UNDEFERR); if ((cp = strchr(cmd, '\n'))) { int n; @@ -1382,7 +1383,6 @@ meta_oodate(GNode *gn, Boolean oodate) fprintf(debug_file, "%s: missing files: %s...\n", fname, (char *)Lst_Datum(Lst_First(missingFiles))); oodate = TRUE; - Lst_Destroy(missingFiles, (FreeProc *)free); } } else { if ((gn->type & OP_META)) { @@ -1391,6 +1391,9 @@ meta_oodate(GNode *gn, Boolean oodate) oodate = TRUE; } } + + Lst_Destroy(missingFiles, (FreeProc *)free); + if (oodate && needOODATE) { /* * Target uses .OODATE which is empty; or we wouldn't be here. @@ -1399,8 +1402,7 @@ meta_oodate(GNode *gn, Boolean oodate) */ Var_Delete(OODATE, gn); Var_Set(OODATE, Var_Value(ALLSRC, gn, &cp), gn, 0); - if (cp) - free(cp); + free(cp); } return oodate; } @@ -1427,8 +1429,8 @@ meta_compat_start(void) if (pipe(childPipe) < 0) Punt("Cannot create pipe: %s", strerror(errno)); /* Set close-on-exec flag for both */ - (void)fcntl(childPipe[0], F_SETFD, 1); - (void)fcntl(childPipe[1], F_SETFD, 1); + (void)fcntl(childPipe[0], F_SETFD, FD_CLOEXEC); + (void)fcntl(childPipe[1], F_SETFD, FD_CLOEXEC); } void |