Example #1
0
static void
lint2(void)
{
    char	*path, **args;

    args = xcalloc(1, sizeof (char *));

    if (!Bflag) {
        path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint2") +
                       strlen(target_prefix));
        (void)sprintf(path, "%s/%slint2", PATH_LIBEXEC,
                      target_prefix);
    } else {
        /*
         * XXX Unclear whether we should be using target_prefix
         * XXX here.  [email protected]
         */
        path = xmalloc(strlen(libexec_path) + sizeof ("/lint2"));
        (void)sprintf(path, "%s/lint2", libexec_path);
    }

    appcstrg(&args, path);
    applst(&args, l2flags);
    applst(&args, l2libs);
    applst(&args, p2in);

    runchild(path, args, p2out, -1);
    free(path);
    freelst(&args);
    free(args);
}
Example #2
0
int main(int argc, char* argv[]) {
   
   pid_t pid;
   
   printf("Rebuild the jarfile\n");
   pid = fork();
   if (pid==0) {// child
      execlp("ant", "ant", "dist", NULL);
      perror("execlp ant failed");
      exit(1);   
   }
   wait(NULL);
   
   printf("Start %d childs, and keep the pool full\n", CHILDCOUNT);
   for (int i=0; i<CHILDCOUNT; i++){
      pids[i] = fork();
      if (pids[i] == 0) 
	runchild();
      printf(" launch child #%d\n",i);
      fflush(stdout);
      sleep(DELAY);
   }
   printf("All childs are launched\n");
   
   /* Kill everyone on Ctrl-C */
   signal(SIGINT, inthandler);
   
   while (1) {
      int status;
      pid = wait(&status);
      if (!armagedon)
	for (int i=0; i<CHILDCOUNT; i++)
	  if (pids[i] == pid) {
	     pids[i] = fork();
	     if (pids[i] == 0)
	       runchild();
	  }      
   }
}
Example #3
0
/*
 * Read a file name from the command line
 * and pass it through lint1 if it is a C source.
 */
static void
fname(const char *name)
{
    const	char *bn, *suff;
    char	**args, *ofn, *p, *pathname;
    size_t	len;
    int is_stdin;
    int	fd;

    is_stdin = (strcmp(name, "-") == 0);
    bn = lbasename(name, '/');
    suff = lbasename(bn, '.');

    if (strcmp(suff, "ln") == 0) {
        /* only for lint2 */
        if (!iflag)
            appcstrg(&p2in, name);
        return;
    }

    if (!is_stdin && strcmp(suff, "c") != 0 &&
            (strncmp(bn, "llib-l", 6) != 0 || bn != suff)) {
        warnx("unknown file type: %s\n", name);
        return;
    }

    if (!iflag || !first)
        (void)printf("%s:\n",
                     is_stdin ? "{standard input}" : Fflag ? name : bn);

    /* build the name of the output file of lint1 */
    if (oflag) {
        ofn = outputfn;
        outputfn = NULL;
        oflag = 0;
    } else if (iflag) {
        if (is_stdin) {
            warnx("-i not supported without -o for standard input");
            return;
        }
        ofn = xmalloc(strlen(bn) + (bn == suff ? 4 : 2));
        len = bn == suff ? strlen(bn) : (size_t)((suff - 1) - bn);
        (void)sprintf(ofn, "%.*s", (int)len, bn);
        (void)strcat(ofn, ".ln");
    } else {
        ofn = xmalloc(strlen(tmpdir) + sizeof ("lint1.XXXXXX"));
        (void)sprintf(ofn, "%slint1.XXXXXX", tmpdir);
        fd = mkstemp(ofn);
        if (fd == -1) {
            warn("can't make temp");
            terminate(-1);
        }
        close(fd);
    }
    if (!iflag)
        appcstrg(&p1out, ofn);

    args = xcalloc(1, sizeof (char *));

    /* run cc */

    if (getenv("CC") == NULL) {
        pathname = xmalloc(strlen(PATH_USRBIN) + sizeof ("/cc"));
        (void)sprintf(pathname, "%s/cc", PATH_USRBIN);
        appcstrg(&args, pathname);
    } else {
        pathname = strdup(getenv("CC"));
        for (p = strtok(pathname, " \t"); p; p = strtok(NULL, " \t"))
            appcstrg(&args, p);
    }

    applst(&args, cflags);
    applst(&args, lcflags);
    appcstrg(&args, name);

    /* we reuse the same tmp file for cpp output, so rewind and truncate */
    if (lseek(cppoutfd, (off_t)0, SEEK_SET) != 0) {
        warn("lseek");
        terminate(-1);
    }
    if (ftruncate(cppoutfd, (off_t)0) != 0) {
        warn("ftruncate");
        terminate(-1);
    }

    runchild(pathname, args, cppout, cppoutfd);
    free(pathname);
    freelst(&args);

    /* run lint1 */

    if (!Bflag) {
        pathname = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint1") +
                           strlen(target_prefix));
        (void)sprintf(pathname, "%s/%slint1", PATH_LIBEXEC,
                      target_prefix);
    } else {
        /*
         * XXX Unclear whether we should be using target_prefix
         * XXX here.  [email protected]
         */
        pathname = xmalloc(strlen(libexec_path) + sizeof ("/lint1"));
        (void)sprintf(pathname, "%s/lint1", libexec_path);
    }

    appcstrg(&args, pathname);
    applst(&args, l1flags);
    appcstrg(&args, cppout);
    appcstrg(&args, ofn);

    runchild(pathname, args, ofn, -1);
    free(pathname);
    freelst(&args);

    appcstrg(&p2in, ofn);
    free(ofn);

    free(args);
}