VirtualBox

Changeset 1290 in kBuild for trunk/src


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

Allow builtins to spawn and schedule spawning.

Location:
trunk/src/kmk
Files:
3 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
  • trunk/src/kmk/kmkbuiltin.c

    r1162 r1290  
    2929#include <stdio.h>
    3030#include <ctype.h>
     31#include <assert.h>
    3132#ifdef _MSC_VER
    3233# include <io.h>
     
    3940#endif
    4041
    41 int kmk_builtin_command(const char *pszCmd)
     42int kmk_builtin_command(const char *pszCmd, char ***ppapszArgvToSpawn, pid_t *pPidSpawned)
    4243{
    4344    int         argc;
     
    151152     */
    152153    if (!*pszCmd)
    153         rc = kmk_builtin_command_parsed(argc, argv);
     154        rc = kmk_builtin_command_parsed(argc, argv, ppapszArgvToSpawn, pPidSpawned);
    154155    else
    155156        rc = 1;
     
    163164
    164165
    165 int kmk_builtin_command_parsed(int argc, char **argv)
     166int kmk_builtin_command_parsed(int argc, char **argv, char ***ppapszArgvToSpawn, pid_t *pPidSpawned)
    166167{
    167168    const char *pszCmd = argv[0];
     
    194195    else if (!strcmp(pszCmd, "kDepIDB"))
    195196        rc = kmk_builtin_kDepIDB(argc, argv, environ);
    196     else if (!strcmp(pszCmd, "ln"))
    197         rc = kmk_builtin_ln(argc, argv, environ);
    198197    else if (!strcmp(pszCmd, "mkdir"))
    199198        rc = kmk_builtin_mkdir(argc, argv, environ);
    200199    else if (!strcmp(pszCmd, "mv"))
    201200        rc = kmk_builtin_mv(argc, argv, environ);
     201    /*else if (!strcmp(pszCmd, "redirect"))
     202        rc = kmk_builtin_redirect(argc, argv, environ, pPidSpawned);*/
    202203    else if (!strcmp(pszCmd, "rm"))
    203204        rc = kmk_builtin_rm(argc, argv, environ);
    204205    else if (!strcmp(pszCmd, "rmdir"))
    205206        rc = kmk_builtin_rmdir(argc, argv, environ);
     207    /*else if (!strcmp(pszCmd, "test"))
     208        rc = kmk_builtin_test(argc, argv, environ, ppapszArgvToSpawn);*/
    206209    /* rarely used commands: */
    207210    else if (!strcmp(pszCmd, "cp"))
    208211        rc = kmk_builtin_cp(argc, argv, environ);
     212    else if (!strcmp(pszCmd, "ln"))
     213        rc = kmk_builtin_ln(argc, argv, environ);
    209214    else if (!strcmp(pszCmd, "md5sum"))
    210215        rc = kmk_builtin_md5sum(argc, argv, environ);
     
    218223        return 1;
    219224    }
     225
     226    /*
     227     * Cleanup.
     228     */
    220229    g_progname = "kmk";                 /* paranoia, make sure it's not pointing at a freed argv[0]. */
    221230    umask(iumask);
     231
     232
     233    /*
     234     * If we've executed a conditional test or something that wishes to execute
     235     * some child process, check if the child is a kmk_builtin thing. We recurse
     236     * here, both because I'm lazy and because it's easier to debug a problem then
     237     * (the call stack shows what's been going on).
     238     */
     239    if (    !rc
     240        &&  *ppapszArgvToSpawn
     241        &&  !strncmp(**ppapszArgvToSpawn, "kmk_builtin_", sizeof("kmk_builtin_") - 1))
     242    {
     243        char **argv_new = *ppapszArgvToSpawn;
     244        int argc_new = 1;
     245        while (argv_new[argc_new])
     246          argc_new++;
     247
     248        assert(argv_new[0] != argv[0]);
     249        assert(!*pPidSpawned);
     250
     251        *ppapszArgvToSpawn = NULL;
     252        rc = kmk_builtin_command_parsed (argc_new, argv_new, ppapszArgvToSpawn, pPidSpawned);
     253
     254        free (argv_new[0]);
     255        free (argv_new);
     256    }
     257
    222258    return rc;
    223259}
  • trunk/src/kmk/kmkbuiltin.h

    r1183 r1290  
    2525 */
    2626
    27 int kmk_builtin_command(const char *pszCmd);
    28 int kmk_builtin_command_parsed(int argc, char **argv);
     27#ifdef _MSC_VER
     28# ifndef pid_t /* see config.h.win */
     29#  define pid_t int
     30# endif
     31#else
     32# include <sys/types.h>
     33#endif
     34
     35int kmk_builtin_command(const char *pszCmd, char ***ppapszArgvToSpawn, pid_t *pPidSpawned);
     36int kmk_builtin_command_parsed(int argc, char **argv, char ***ppapszArgvToSpawn, pid_t *pPidSpawned);
    2937
    3038extern int kmk_builtin_append(int argc, char **argv, char **envp);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette