- Timestamp:
- Dec 1, 2007 12:22:28 AM (17 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/job.c
r1164 r1290 1211 1211 { 1212 1212 int rc; 1213 char **argv_spawn = NULL; 1213 1214 char **p2 = argv; 1214 while (*p2 && strncmp (*p2, "kmk_builtin_", sizeof("kmk_builtin_") - 1))1215 1216 assert (*p2);1215 while (*p2 && strncmp (*p2, "kmk_builtin_", sizeof("kmk_builtin_") - 1)) 1216 p2++; 1217 assert (*p2); 1217 1218 set_command_state (child->file, cs_running); 1219 child->pid = 0; 1218 1220 if (p2 != argv) 1219 rc = kmk_builtin_command(*p2);1221 rc = kmk_builtin_command (*p2, &argv_spawn, &child->pid); 1220 1222 else 1221 {1223 { 1222 1224 int argc = 1; 1223 1225 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 1227 1230 #ifndef VMS 1228 1231 free (argv[0]); 1229 1232 free ((char *) argv); 1230 1233 #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; 1237 1258 } 1238 1259 #endif /* CONFIG_WITH_KMK_BUILTIN */ … … 1509 1530 1510 1531 /* Free the storage used by the child's argument list. */ 1532 #ifdef KMK /* leak */ 1533 cleanup_argv: 1534 #endif 1511 1535 #ifndef VMS 1512 1536 free (argv[0]); … … 1519 1543 child->file->update_status = 2; 1520 1544 notice_finished_file (child->file); 1545 #ifdef KMK /* fix leak */ 1546 goto cleanup_argv; 1547 #else 1521 1548 return; 1549 #endif 1522 1550 } 1523 1551 -
trunk/src/kmk/kmkbuiltin.c
r1162 r1290 29 29 #include <stdio.h> 30 30 #include <ctype.h> 31 #include <assert.h> 31 32 #ifdef _MSC_VER 32 33 # include <io.h> … … 39 40 #endif 40 41 41 int kmk_builtin_command(const char *pszCmd )42 int kmk_builtin_command(const char *pszCmd, char ***ppapszArgvToSpawn, pid_t *pPidSpawned) 42 43 { 43 44 int argc; … … 151 152 */ 152 153 if (!*pszCmd) 153 rc = kmk_builtin_command_parsed(argc, argv );154 rc = kmk_builtin_command_parsed(argc, argv, ppapszArgvToSpawn, pPidSpawned); 154 155 else 155 156 rc = 1; … … 163 164 164 165 165 int kmk_builtin_command_parsed(int argc, char **argv )166 int kmk_builtin_command_parsed(int argc, char **argv, char ***ppapszArgvToSpawn, pid_t *pPidSpawned) 166 167 { 167 168 const char *pszCmd = argv[0]; … … 194 195 else if (!strcmp(pszCmd, "kDepIDB")) 195 196 rc = kmk_builtin_kDepIDB(argc, argv, environ); 196 else if (!strcmp(pszCmd, "ln"))197 rc = kmk_builtin_ln(argc, argv, environ);198 197 else if (!strcmp(pszCmd, "mkdir")) 199 198 rc = kmk_builtin_mkdir(argc, argv, environ); 200 199 else if (!strcmp(pszCmd, "mv")) 201 200 rc = kmk_builtin_mv(argc, argv, environ); 201 /*else if (!strcmp(pszCmd, "redirect")) 202 rc = kmk_builtin_redirect(argc, argv, environ, pPidSpawned);*/ 202 203 else if (!strcmp(pszCmd, "rm")) 203 204 rc = kmk_builtin_rm(argc, argv, environ); 204 205 else if (!strcmp(pszCmd, "rmdir")) 205 206 rc = kmk_builtin_rmdir(argc, argv, environ); 207 /*else if (!strcmp(pszCmd, "test")) 208 rc = kmk_builtin_test(argc, argv, environ, ppapszArgvToSpawn);*/ 206 209 /* rarely used commands: */ 207 210 else if (!strcmp(pszCmd, "cp")) 208 211 rc = kmk_builtin_cp(argc, argv, environ); 212 else if (!strcmp(pszCmd, "ln")) 213 rc = kmk_builtin_ln(argc, argv, environ); 209 214 else if (!strcmp(pszCmd, "md5sum")) 210 215 rc = kmk_builtin_md5sum(argc, argv, environ); … … 218 223 return 1; 219 224 } 225 226 /* 227 * Cleanup. 228 */ 220 229 g_progname = "kmk"; /* paranoia, make sure it's not pointing at a freed argv[0]. */ 221 230 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 222 258 return rc; 223 259 } -
trunk/src/kmk/kmkbuiltin.h
r1183 r1290 25 25 */ 26 26 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 35 int kmk_builtin_command(const char *pszCmd, char ***ppapszArgvToSpawn, pid_t *pPidSpawned); 36 int kmk_builtin_command_parsed(int argc, char **argv, char ***ppapszArgvToSpawn, pid_t *pPidSpawned); 29 37 30 38 extern int kmk_builtin_append(int argc, char **argv, char **envp);
Note:
See TracChangeset
for help on using the changeset viewer.