Deleted Added
full compact
1c1
< /* $NetBSD: main.c,v 1.203 2012/08/31 07:00:36 sjg Exp $ */
---
> /* $NetBSD: main.c,v 1.205 2013/01/26 15:53:00 christos Exp $ */
72c72
< static char rcsid[] = "$NetBSD: main.c,v 1.203 2012/08/31 07:00:36 sjg Exp $";
---
> static char rcsid[] = "$NetBSD: main.c,v 1.205 2013/01/26 15:53:00 christos Exp $";
84c84
< __RCSID("$NetBSD: main.c,v 1.203 2012/08/31 07:00:36 sjg Exp $");
---
> __RCSID("$NetBSD: main.c,v 1.205 2013/01/26 15:53:00 christos Exp $");
179,181d178
< #ifndef NO_CHECK_MAKE_CHDIR
< static char * Check_Cwd_av(int, char **, int);
< #endif
1207,1210d1203
< #ifndef NO_CHECK_MAKE_CHDIR
< Check_Cwd_av(0, NULL, 0); /* initialize it */
< #endif
<
1426,1452d1418
< /*
< * If MAKEOBJDIRPREFIX is in use, make ends up not in .CURDIR
< * in situations that would not arrise with ./obj (links or not).
< * This tends to break things like:
< *
< * build:
< * ${MAKE} includes
< *
< * This function spots when ${.MAKE:T} or ${.MAKE} is a command (as
< * opposed to an argument) in a command line and if so returns
< * ${.CURDIR} so caller can chdir() so that the assumptions made by
< * the Makefile hold true.
< *
< * If ${.MAKE} does not contain any '/', then ${.MAKE:T} is skipped.
< *
< * The chdir() only happens in the child process, and does nothing if
< * MAKEOBJDIRPREFIX and MAKEOBJDIR are not in the environment so it
< * should not break anything. Also if NOCHECKMAKECHDIR is set we
< * do nothing - to ensure historic semantics can be retained.
< */
< #ifdef NO_CHECK_MAKE_CHDIR
< char *
< Check_Cwd_Cmd(cmd)
< char *cmd;
< {
< return 0;
< }
1454,1628d1419
< void
< Check_Cwd(argv)
< char **argv;
< {
< return;
< }
<
< #else
<
< static int Check_Cwd_Off = 0;
<
< static char *
< Check_Cwd_av(int ac, char **av, int copy)
< {
< static char *make[4];
< static char *cur_dir = NULL;
< char **mp;
< char *cp;
< int is_cmd, next_cmd;
< int i;
< int n;
<
< if (Check_Cwd_Off) {
< if (DEBUG(CWD))
< fprintf(debug_file, "check_cwd: check is off.\n");
< return NULL;
< }
<
< if (make[0] == NULL) {
< if (Var_Exists("NOCHECKMAKECHDIR", VAR_GLOBAL)) {
< Check_Cwd_Off = 1;
< if (DEBUG(CWD))
< fprintf(debug_file, "check_cwd: turning check off.\n");
< return NULL;
< }
<
< make[1] = Var_Value(".MAKE", VAR_GLOBAL, &cp);
< if ((make[0] = strrchr(make[1], '/')) == NULL) {
< make[0] = make[1];
< make[1] = NULL;
< } else
< ++make[0];
< make[2] = NULL;
< cur_dir = Var_Value(".CURDIR", VAR_GLOBAL, &cp);
< }
< if (ac == 0 || av == NULL) {
< if (DEBUG(CWD))
< fprintf(debug_file, "check_cwd: empty command.\n");
< return NULL; /* initialization only */
< }
<
< if (getenv("MAKEOBJDIR") == NULL &&
< getenv("MAKEOBJDIRPREFIX") == NULL) {
< if (DEBUG(CWD))
< fprintf(debug_file, "check_cwd: no obj dirs.\n");
< return NULL;
< }
<
<
< next_cmd = 1;
< for (i = 0; i < ac; ++i) {
< is_cmd = next_cmd;
<
< n = strlen(av[i]);
< cp = &(av[i])[n - 1];
< if (strspn(av[i], "|&;") == (size_t)n) {
< next_cmd = 1;
< continue;
< } else if (*cp == ';' || *cp == '&' || *cp == '|' || *cp == ')') {
< next_cmd = 1;
< if (copy) {
< do {
< *cp-- = '\0';
< } while (*cp == ';' || *cp == '&' || *cp == '|' ||
< *cp == ')' || *cp == '}') ;
< } else {
< /*
< * XXX this should not happen.
< */
< fprintf(stderr, "%s: WARNING: raw arg ends in shell meta '%s'\n",
< progname, av[i]);
< }
< } else
< next_cmd = 0;
<
< cp = av[i];
< if (*cp == ';' || *cp == '&' || *cp == '|')
< is_cmd = 1;
<
< if (DEBUG(CWD))
< fprintf(debug_file, "av[%d] == %s '%s'",
< i, (is_cmd) ? "cmd" : "arg", av[i]);
< if (is_cmd != 0) {
< if (*cp == '(' || *cp == '{' ||
< *cp == ';' || *cp == '&' || *cp == '|') {
< do {
< ++cp;
< } while (*cp == '(' || *cp == '{' ||
< *cp == ';' || *cp == '&' || *cp == '|');
< if (*cp == '\0') {
< next_cmd = 1;
< continue;
< }
< }
< if (strcmp(cp, "cd") == 0 || strcmp(cp, "chdir") == 0) {
< if (DEBUG(CWD))
< fprintf(debug_file, " == cd, done.\n");
< return NULL;
< }
< for (mp = make; *mp != NULL; ++mp) {
< n = strlen(*mp);
< if (strcmp(cp, *mp) == 0) {
< if (DEBUG(CWD))
< fprintf(debug_file, " %s == '%s', chdir(%s)\n",
< cp, *mp, cur_dir);
< return cur_dir;
< }
< }
< }
< if (DEBUG(CWD))
< fprintf(debug_file, "\n");
< }
< return NULL;
< }
<
< char *
< Check_Cwd_Cmd(const char *cmd)
< {
< char *cp, *bp;
< char **av;
< int ac;
<
< if (Check_Cwd_Off)
< return NULL;
<
< if (cmd) {
< av = brk_string(cmd, &ac, TRUE, &bp);
< if (DEBUG(CWD))
< fprintf(debug_file, "splitting: '%s' -> %d words\n",
< cmd, ac);
< } else {
< ac = 0;
< av = NULL;
< bp = NULL;
< }
< cp = Check_Cwd_av(ac, av, 1);
< if (bp)
< free(bp);
< if (av)
< free(av);
< return cp;
< }
<
< void
< Check_Cwd(const char **argv)
< {
< char *cp;
< int ac;
<
< if (Check_Cwd_Off)
< return;
<
< for (ac = 0; argv[ac] != NULL; ++ac)
< /* NOTHING */;
< if (ac == 3 && *argv[1] == '-') {
< cp = Check_Cwd_Cmd(argv[2]);
< } else {
< cp = Check_Cwd_av(ac, UNCONST(argv), 0);
< }
< if (cp) {
< chdir(cp);
< }
< }
< #endif /* NO_CHECK_MAKE_CHDIR */
<
1955c1746,1747
< (void)writev(2, iov, 8);
---
> while (writev(2, iov, 8) == -1 && errno == EAGAIN)
> continue;