Changeset 1290 for trunk/src/kmk/job.c


Ignore:
Timestamp:
Dec 1, 2007, 1:22:28 AM (18 years ago)
Author:
bird
Message:

Allow builtins to spawn and schedule spawning.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/job.c

    r1164 r1290  
    12111211    {
    12121212      int    rc;
     1213      char **argv_spawn = NULL;
    12131214      char **p2 = argv;
    1214       while (*p2 && strncmp(*p2, "kmk_builtin_", sizeof("kmk_builtin_") - 1))
    1215           p2++;
    1216       assert(*p2);
     1215      while (*p2 && strncmp (*p2, "kmk_builtin_", sizeof("kmk_builtin_") - 1))
     1216        p2++;
     1217      assert (*p2);
    12171218      set_command_state (child->file, cs_running);
     1219      child->pid = 0;
    12181220      if (p2 != argv)
    1219           rc = kmk_builtin_command(*p2);
     1221        rc = kmk_builtin_command (*p2, &argv_spawn, &child->pid);
    12201222      else
    1221       {
     1223        {
    12221224          int argc = 1;
    12231225          while (argv[argc])
    1224               argc++;
    1225           rc = kmk_builtin_command_parsed(argc, argv);
    1226       }
     1226            argc++;
     1227          rc = kmk_builtin_command_parsed (argc, argv, &argv_spawn, &child->pid);
     1228        }
     1229
    12271230#ifndef VMS
    12281231      free (argv[0]);
    12291232      free ((char *) argv);
    12301233#endif
    1231       if (!rc)
    1232           goto next_command;
    1233       child->pid = (pid_t)42424242;
    1234       child->status = rc << 8;
    1235       child->has_status = 1;
    1236       return;
     1234
     1235      /* synchronous command execution? */
     1236      if (!rc && !argv_spawn)
     1237        goto next_command;
     1238
     1239      /* spawned a child? */
     1240      if (!rc && child->pid)
     1241        {
     1242          ++job_counter;
     1243          return;
     1244        }
     1245
     1246      /* failure? */
     1247      if (rc)
     1248        {
     1249          child->pid = (pid_t)42424242;
     1250          child->status = rc << 8;
     1251          child->has_status = 1;
     1252          unblock_sigs();
     1253          return;
     1254        }
     1255
     1256      /* conditional check == true; kicking off a child (not kmk_builtin_*). */
     1257      argv = argv_spawn;
    12371258    }
    12381259#endif /* CONFIG_WITH_KMK_BUILTIN */
     
    15091530
    15101531  /* Free the storage used by the child's argument list.  */
     1532#ifdef KMK /* leak */
     1533 cleanup_argv:
     1534#endif
    15111535#ifndef VMS
    15121536  free (argv[0]);
     
    15191543  child->file->update_status = 2;
    15201544  notice_finished_file (child->file);
     1545#ifdef KMK /* fix leak */
     1546  goto cleanup_argv;
     1547#else
    15211548  return;
     1549#endif
    15221550}
    15231551
Note: See TracChangeset for help on using the changeset viewer.