diff options
author | Ron Yorston <rmy@pobox.com> | 2020-06-20 12:13:36 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-06-20 12:13:36 +0100 |
commit | 327445bbbd6afa8ff164717206ad7635873b4bcc (patch) | |
tree | 5a369f89693cd7c19999c7642992982b4c9c6cac | |
parent | 6f8b2f4508610e9bd443f60535cc06df653f3c83 (diff) | |
download | busybox-w32-327445bbbd6afa8ff164717206ad7635873b4bcc.tar.gz busybox-w32-327445bbbd6afa8ff164717206ad7635873b4bcc.tar.bz2 busybox-w32-327445bbbd6afa8ff164717206ad7635873b4bcc.zip |
ash: reduce forkshell block size for FS_OPENHERE
When handling FS_OPENHERE the forkshell data block only needs to
contain the forkshell structure and the here document. Omit
everything else.
Update forkshell_print() for this case.
-rw-r--r-- | shell/ash.c | 83 |
1 files changed, 50 insertions, 33 deletions
diff --git a/shell/ash.c b/shell/ash.c index beadca68c..d84eaec88 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -16047,6 +16047,10 @@ forkshell_size(struct forkshell *fs) | |||
16047 | { | 16047 | { |
16048 | struct datasize ds = {0, 0}; | 16048 | struct datasize ds = {0, 0}; |
16049 | 16049 | ||
16050 | ds.funcstringsize += align_len(fs->path); | ||
16051 | if (fs->fpid == FS_OPENHERE) | ||
16052 | return ds; | ||
16053 | |||
16050 | ds = globals_var_size(ds, ash_ptr_to_globals_var); | 16054 | ds = globals_var_size(ds, ash_ptr_to_globals_var); |
16051 | ds = globals_misc_size(ds, ash_ptr_to_globals_misc); | 16055 | ds = globals_misc_size(ds, ash_ptr_to_globals_misc); |
16052 | ds = cmdtable_size(ds, cmdtable); | 16056 | ds = cmdtable_size(ds, cmdtable); |
@@ -16056,7 +16060,6 @@ forkshell_size(struct forkshell *fs) | |||
16056 | 16060 | ||
16057 | ds.funcblocksize = calcsize(ds.funcblocksize, fs->n); | 16061 | ds.funcblocksize = calcsize(ds.funcblocksize, fs->n); |
16058 | ds = argv_size(ds, fs->argv); | 16062 | ds = argv_size(ds, fs->argv); |
16059 | ds.funcstringsize += align_len(fs->path); | ||
16060 | 16063 | ||
16061 | #if MAX_HISTORY | 16064 | #if MAX_HISTORY |
16062 | if (line_input_state) { | 16065 | if (line_input_state) { |
@@ -16070,6 +16073,12 @@ static void | |||
16070 | forkshell_copy(struct forkshell *fs, struct forkshell *new) | 16073 | forkshell_copy(struct forkshell *fs, struct forkshell *new) |
16071 | { | 16074 | { |
16072 | memcpy(new, fs, sizeof(struct forkshell)); /* non-pointer stuff */ | 16075 | memcpy(new, fs, sizeof(struct forkshell)); /* non-pointer stuff */ |
16076 | |||
16077 | new->path = nodeckstrdup(fs->path); | ||
16078 | SAVE_PTR(new->path, xasprintf("path '%s'", fs->path ?: "NULL"), FREE); | ||
16079 | if (fs->fpid == FS_OPENHERE) | ||
16080 | return; | ||
16081 | |||
16073 | new->gvp = globals_var_copy(ash_ptr_to_globals_var); | 16082 | new->gvp = globals_var_copy(ash_ptr_to_globals_var); |
16074 | new->gmp = globals_misc_copy(ash_ptr_to_globals_misc); | 16083 | new->gmp = globals_misc_copy(ash_ptr_to_globals_misc); |
16075 | new->cmdtable = cmdtable_copy(cmdtable); | 16084 | new->cmdtable = cmdtable_copy(cmdtable); |
@@ -16084,10 +16093,8 @@ forkshell_copy(struct forkshell *fs, struct forkshell *new) | |||
16084 | 16093 | ||
16085 | new->n = copynode(fs->n); | 16094 | new->n = copynode(fs->n); |
16086 | new->argv = argv_copy(fs->argv); | 16095 | new->argv = argv_copy(fs->argv); |
16087 | new->path = nodeckstrdup(fs->path); | 16096 | SAVE_PTR2( new->n, "n", NO_FREE, |
16088 | SAVE_PTR3( new->n, "n", NO_FREE, | 16097 | new->argv, "argv", NO_FREE); |
16089 | new->argv, "argv", NO_FREE, | ||
16090 | new->path, xasprintf("path '%s'", fs->path ?: "NULL"), FREE); | ||
16091 | 16098 | ||
16092 | #if MAX_HISTORY | 16099 | #if MAX_HISTORY |
16093 | if (line_input_state) { | 16100 | if (line_input_state) { |
@@ -16141,41 +16148,47 @@ forkshell_print(FILE *fp0, struct forkshell *fs, const char **notes) | |||
16141 | lfuncstring = (char *)lfuncblock + fs->funcblocksize; | 16148 | lfuncstring = (char *)lfuncblock + fs->funcblocksize; |
16142 | lrelocate = (char *)lfuncstring + fs->funcstringsize; | 16149 | lrelocate = (char *)lfuncstring + fs->funcstringsize; |
16143 | 16150 | ||
16144 | size_gvp = (int)((char *)fs->gmp-(char *)fs->gvp); | 16151 | /* funcblocksize is zero for FS_OPENHERE */ |
16145 | size_gmp = (int)((char *)fs->cmdtable-(char *)fs->gmp); | 16152 | if (fs->funcblocksize != 0) { |
16153 | size_gvp = (int)((char *)fs->gmp-(char *)fs->gvp); | ||
16154 | size_gmp = (int)((char *)fs->cmdtable-(char *)fs->gmp); | ||
16146 | #if ENABLE_ASH_ALIAS && MAX_HISTORY | 16155 | #if ENABLE_ASH_ALIAS && MAX_HISTORY |
16147 | size_cmdtable = (int)((char *)fs->atab-(char *)fs->cmdtable); | 16156 | size_cmdtable = (int)((char *)fs->atab-(char *)fs->cmdtable); |
16148 | if (fs->history) { | 16157 | if (fs->history) { |
16149 | size_atab = (int)((char *)fs->history-(char *)fs->atab); | 16158 | size_atab = (int)((char *)fs->history-(char *)fs->atab); |
16150 | size_history = (int)(lfuncstring-(char *)fs->history); | 16159 | size_history = (int)(lfuncstring-(char *)fs->history); |
16151 | } | 16160 | } |
16152 | else { | 16161 | else { |
16162 | size_atab = (int)(lfuncstring-(char *)fs->atab); | ||
16163 | size_history = 0; | ||
16164 | } | ||
16165 | #elif ENABLE_ASH_ALIAS | ||
16166 | size_cmdtable = (int)((char *)fs->atab-(char *)fs->cmdtable); | ||
16153 | size_atab = (int)(lfuncstring-(char *)fs->atab); | 16167 | size_atab = (int)(lfuncstring-(char *)fs->atab); |
16154 | size_history = 0; | 16168 | size_history = 0; |
16155 | } | ||
16156 | #elif ENABLE_ASH_ALIAS | ||
16157 | size_cmdtable = (int)((char *)fs->atab-(char *)fs->cmdtable); | ||
16158 | size_atab = (int)(lfuncstring-(char *)fs->atab); | ||
16159 | size_history = 0; | ||
16160 | #elif MAX_HISTORY | 16169 | #elif MAX_HISTORY |
16161 | size_atab = 0; | 16170 | size_atab = 0; |
16162 | if (fs->history) { | 16171 | if (fs->history) { |
16163 | size_cmdtable = (int)((char *)fs->history-(char *)fs->cmdtable); | 16172 | size_cmdtable = (int)((char *)fs->history-(char *)fs->cmdtable); |
16164 | size_history = (int)(lfuncstring-(char *)fs->history); | 16173 | size_history = (int)(lfuncstring-(char *)fs->history); |
16165 | } | 16174 | } |
16166 | else { | 16175 | else { |
16176 | size_cmdtable = (int)(lfuncstring-(char *)fs->cmdtable); | ||
16177 | size_history = 0; | ||
16178 | } | ||
16179 | #else | ||
16167 | size_cmdtable = (int)(lfuncstring-(char *)fs->cmdtable); | 16180 | size_cmdtable = (int)(lfuncstring-(char *)fs->cmdtable); |
16181 | size_atab = 0; | ||
16168 | size_history = 0; | 16182 | size_history = 0; |
16169 | } | ||
16170 | #else | ||
16171 | size_cmdtable = (int)(lfuncstring-(char *)fs->cmdtable); | ||
16172 | size_atab = 0; | ||
16173 | size_history = 0; | ||
16174 | #endif | 16183 | #endif |
16175 | total = size_gvp + size_gmp + size_cmdtable + size_atab + size_history; | 16184 | total = size_gvp + size_gmp + size_cmdtable + size_atab + size_history; |
16176 | fprintf(fp, "funcblocksize %6d = %d + %d + %d + %d + %d = %d\n\n", | 16185 | fprintf(fp, "funcblocksize %6d = %d + %d + %d + %d + %d = %d\n\n", |
16177 | fs->funcblocksize, size_gvp, size_gmp, size_cmdtable, | 16186 | fs->funcblocksize, size_gvp, size_gmp, size_cmdtable, |
16178 | size_atab, size_history, total); | 16187 | size_atab, size_history, total); |
16188 | } | ||
16189 | else { | ||
16190 | fprintf(fp, "\n"); | ||
16191 | } | ||
16179 | 16192 | ||
16180 | fprintf(fp, "%s\n\n", fsname[fs->fpid]); | 16193 | fprintf(fp, "%s\n\n", fsname[fs->fpid]); |
16181 | fprintf(fp, "--- relocate ---\n"); | 16194 | fprintf(fp, "--- relocate ---\n"); |
@@ -16334,6 +16347,9 @@ forkshell_init(const char *idstr) | |||
16334 | } | 16347 | } |
16335 | } | 16348 | } |
16336 | 16349 | ||
16350 | if (fs->fpid == FS_OPENHERE) | ||
16351 | goto end; | ||
16352 | |||
16337 | /* Now fix up stuff that can't be transferred */ | 16353 | /* Now fix up stuff that can't be transferred */ |
16338 | for (i = 0; i < CMDTABLESIZE; i++) { | 16354 | for (i = 0; i < CMDTABLESIZE; i++) { |
16339 | struct tblentry *e = fs->cmdtable[i]; | 16355 | struct tblentry *e = fs->cmdtable[i]; |
@@ -16386,6 +16402,7 @@ forkshell_init(const char *idstr) | |||
16386 | else { | 16402 | else { |
16387 | SetConsoleCtrlHandler(ctrl_handler, TRUE); | 16403 | SetConsoleCtrlHandler(ctrl_handler, TRUE); |
16388 | } | 16404 | } |
16405 | end: | ||
16389 | forkshell_child(fs); | 16406 | forkshell_child(fs); |
16390 | } | 16407 | } |
16391 | 16408 | ||