TEST(Subprocess, BadCommand) { SubprocessSet subprocs_; Subprocess subproc(&subprocs_); EXPECT_TRUE(subproc.Start("cmd.exe /c ninja_no_such_command")); subprocs_.Add(&subproc); // Pretend we discovered that stderr was ready for writing. //subproc.OnFDReady(subproc.stderr_.fd_); while (!subproc.done()) { subprocs_.DoWork(); } EXPECT_FALSE(subproc.Finish()); EXPECT_EQ("", subproc.stdout_.buf_); EXPECT_NE("", subproc.stderr_.buf_); }
static void rm(size_t pend, const char *base, const int olddir, int ssub, int level) { struct stat st; if (lstat(base, &st) < 0) { if (fflag == 0 || errno != ENOENT) { if (sysv3) fprintf(stderr, "%s: %s non-existent\n", progname, path); else fprintf(stderr, "%s: %s\n", path, strerror(errno)); errcnt |= 4; } return; } if ((st.st_mode&S_IFMT) == S_IFDIR) { if (rflag) { struct direc *dp; struct getdb *db; int df, err; if (ssub == 0 && (iflag #ifdef SUS || (!fflag && ontty && access(base, W_OK) < 0) #endif )) { msg("directory %s: ? ", path); if (confirm() == 0) return; } if ((df = open(base, O_RDONLY #ifdef O_DIRECTORY | O_DIRECTORY #endif #ifdef O_NOFOLLOW | O_NOFOLLOW #endif )) < 0 || (db = getdb_alloc(base, df)) == NULL) { if (errno == EMFILE) { int sres; sres = subproc(pend, base, level); if (sres >= 0) { errcnt |= sres; goto remove; } } /* * Maybe the directory is empty and can just * be removed. */ if (rmfile(base, &st) < 0) { fprintf(stderr, "%s: cannot read " "directory %s\n", progname, path); errcnt |= 4; } return; } if (fchdir(df) < 0) { if (rmfile(base, &st) < 0) { fprintf(stderr, "%s: cannot chdir to %s\n", progname, path); errcnt |= 4; } getdb_free(db); close(df); return; } setlevel(level, db, df); while ((dp = getdir(db, &err)) != NULL) { if (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || dp->d_name[1] == '.' && dp->d_name[2] == '\0')) continue; rm(catpath(pend, dp->d_name), dp->d_name, df, 0, level + 1); path[pend] = '\0'; } if (err) { fprintf(stderr, "%s: error reading directory %s\n", progname, path); errcnt |= 4; } if (olddir >= 0 && fchdir(olddir) < 0) { fprintf(stderr, "%s: cannot change backwards\n", progname); exit(1); } getdb_free(db); close(df); } else { fprintf(stderr, "%s: %s directory\n", progname, path); errcnt |= 1; return; } } if (ssub == 0) remove: rmfile(base, &st); }