diff options
author | Ron Yorston <rmy@pobox.com> | 2018-12-03 08:54:48 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-12-03 08:54:48 +0000 |
commit | 6f586b168b2fd8da3da821418464c5ac0e83cd0b (patch) | |
tree | c83d822aa034cf5aba79edc7005e74095f8d822a | |
parent | db74f7020d4a0aadc78b93ddeae4d7fe49dafebf (diff) | |
download | busybox-w32-6f586b168b2fd8da3da821418464c5ac0e83cd0b.tar.gz busybox-w32-6f586b168b2fd8da3da821418464c5ac0e83cd0b.tar.bz2 busybox-w32-6f586b168b2fd8da3da821418464c5ac0e83cd0b.zip |
ash: improvements to forkshell debug
If forkshell_print is passed a NULL file pointer it opens and
closes a local one.
Add the pid to the output file name so forkshell_print can be
called from both parent and child.
-rw-r--r-- | shell/ash.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/shell/ash.c b/shell/ash.c index 0c564ed04..d23c22248 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -379,8 +379,11 @@ static struct forkshell* forkshell_prepare(struct forkshell *fs); | |||
379 | static void forkshell_init(const char *idstr); | 379 | static void forkshell_init(const char *idstr); |
380 | static void forkshell_child(struct forkshell *fs); | 380 | static void forkshell_child(struct forkshell *fs); |
381 | static void sticky_free(void *p); | 381 | static void sticky_free(void *p); |
382 | #define free(p) sticky_free(p) | 382 | # define free(p) sticky_free(p) |
383 | static void spawn_forkshell(struct job *jp, struct forkshell *fs, int mode); | 383 | static void spawn_forkshell(struct job *jp, struct forkshell *fs, int mode); |
384 | # if FORKSHELL_DEBUG | ||
385 | static void forkshell_print(FILE *fp0, struct forkshell *fs, char **notes); | ||
386 | # endif | ||
384 | #endif | 387 | #endif |
385 | 388 | ||
386 | /* ============ Hash table sizes. Configurable. */ | 389 | /* ============ Hash table sizes. Configurable. */ |
@@ -15540,16 +15543,26 @@ forkshell_copy(struct forkshell *fs, struct forkshell *new) | |||
15540 | 15543 | ||
15541 | #if FORKSHELL_DEBUG | 15544 | #if FORKSHELL_DEBUG |
15542 | /* fp and notes can each be NULL */ | 15545 | /* fp and notes can each be NULL */ |
15543 | static void forkshell_print(FILE *fp, struct forkshell *fs, char **notes) | 15546 | static void |
15547 | forkshell_print(FILE *fp0, struct forkshell *fs, char **notes) | ||
15544 | { | 15548 | { |
15549 | FILE *fp; | ||
15545 | void *lfuncblock; | 15550 | void *lfuncblock; |
15546 | char *lfuncstring; | 15551 | char *lfuncstring; |
15547 | char **lnodeptr; | 15552 | char **lnodeptr; |
15548 | char *s; | 15553 | char *s; |
15549 | int count; | 15554 | int count; |
15550 | 15555 | ||
15551 | if (fp == NULL && (fp=fopen("fs.out", "w")) == NULL) | 15556 | if (fp0 != NULL) { |
15552 | return; | 15557 | fp = fp0; |
15558 | } | ||
15559 | else { | ||
15560 | char name[32]; | ||
15561 | |||
15562 | sprintf(name, "fs_%d.out", getpid()); | ||
15563 | if ((fp=fopen(name, "w")) == NULL) | ||
15564 | return; | ||
15565 | } | ||
15553 | 15566 | ||
15554 | fprintf(fp, "size %d = %d + %d*%d + %d + %d\n", fs->size, | 15567 | fprintf(fp, "size %d = %d + %d*%d + %d + %d\n", fs->size, |
15555 | (int)sizeof(struct forkshell), fs->nodeptrcount, | 15568 | (int)sizeof(struct forkshell), fs->nodeptrcount, |
@@ -15600,6 +15613,9 @@ static void forkshell_print(FILE *fp, struct forkshell *fs, char **notes) | |||
15600 | ++count; | 15613 | ++count; |
15601 | } | 15614 | } |
15602 | fprintf(fp, "--- %d strings ---\n", count); | 15615 | fprintf(fp, "--- %d strings ---\n", count); |
15616 | |||
15617 | if (fp0 == NULL) | ||
15618 | fclose(fp); | ||
15603 | } | 15619 | } |
15604 | #endif | 15620 | #endif |
15605 | 15621 | ||
@@ -15613,6 +15629,7 @@ forkshell_prepare(struct forkshell *fs) | |||
15613 | SECURITY_ATTRIBUTES sa; | 15629 | SECURITY_ATTRIBUTES sa; |
15614 | #if FORKSHELL_DEBUG | 15630 | #if FORKSHELL_DEBUG |
15615 | void *fb0; | 15631 | void *fb0; |
15632 | char name[32]; | ||
15616 | FILE *fp; | 15633 | FILE *fp; |
15617 | #endif | 15634 | #endif |
15618 | 15635 | ||
@@ -15656,7 +15673,8 @@ forkshell_prepare(struct forkshell *fs) | |||
15656 | new->old_base = new; | 15673 | new->old_base = new; |
15657 | new->hMapFile = h; | 15674 | new->hMapFile = h; |
15658 | #if FORKSHELL_DEBUG | 15675 | #if FORKSHELL_DEBUG |
15659 | if ((fp=fopen("fs.out", "w")) != NULL) { | 15676 | sprintf(name, "fs_%d.out", getpid()); |
15677 | if ((fp=fopen(name, "w")) != NULL) { | ||
15660 | int i; | 15678 | int i; |
15661 | 15679 | ||
15662 | /* perform some sanity checks on pointers */ | 15680 | /* perform some sanity checks on pointers */ |