[BusyBox] Re: BusyBox 0.45: tar.c and sh.c
Erik Andersen
andersen at lineo.com
Wed Jun 28 16:56:50 UTC 2000
On Wed Jun 28, 2000 at 12:19:04PM +0200, Marius Groeger wrote:
>
> Ok, here it is, finally. Its two patches, one to implement the "sh
> -c" option for popen support, the other to fix a bug in the tar code
> that would unlink existing local files upon "tvf".
Yikes!!! The tar bug you found is _awful_!!!!! Thank you for the fix!!!
Both patches applied. I am CC'ing this to the mailing list, as this bug
fix is very much of general interest.
/me dons a brown paper bag.
-Erik
--
Erik B. Andersen email: andersen at lineo.com
--This message was written using 73% post-consumer electrons--
Index: sh.c
===================================================================
RCS file: /home/elinos/CVS/sysgo/elinos/build/busybox/sh.c,v
retrieving revision 1.5
retrieving revision 1.9
diff -c -r1.5 -r1.9
*** sh.c 2000/06/23 16:14:48 1.5
--- sh.c 2000/06/23 17:12:32 1.9
***************
*** 133,138 ****
--- 133,139 ----
static const char shell_usage[] =
"sh [FILE]...\n"
+ "sh -c command [args]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nlash: The BusyBox command interpreter (shell).\n\n"
#endif
***************
*** 140,145 ****
--- 141,147 ----
static char cwd[1024];
static char *prompt = "# ";
+ static char *local_pending_command = NULL;
#ifdef BB_FEATURE_SH_COMMAND_EDITING
void win_changed(int sig)
***************
*** 225,232 ****
if (*cmd->progs[0].argv[0] == 'f') {
/* Make this job the foreground job */
! if (tcsetpgrp(0, job->pgrp))
! perror("tcsetpgrp");
jobList->fg = job;
}
--- 227,235 ----
if (*cmd->progs[0].argv[0] == 'f') {
/* Make this job the foreground job */
! /* suppress messages when run from /linuxrc mag at sysgo.de */
! if (tcsetpgrp(0, job->pgrp) && errno != ENOTTY)
! perror("tcsetpgrp");
jobList->fg = job;
}
***************
*** 411,416 ****
--- 414,430 ----
static int getCommand(FILE * source, char *command)
{
+ if (source == NULL) {
+ if (local_pending_command) {
+ /* a command specified (-c option): return it & mark it done */
+ strcpy(command, local_pending_command);
+ free(local_pending_command);
+ local_pending_command = NULL;
+ return 0;
+ }
+ return 1;
+ }
+
if (source == stdin) {
#ifdef BB_FEATURE_SH_COMMAND_EDITING
int len;
***************
*** 842,848 ****
jobList->fg = job;
/* move the new process group into the foreground */
! if (tcsetpgrp(0, newJob.pgrp))
perror("tcsetpgrp");
}
--- 856,863 ----
jobList->fg = job;
/* move the new process group into the foreground */
! /* suppress messages when run from /linuxrc mag at sysgo.de */
! if (tcsetpgrp(0, newJob.pgrp) && errno != ENOTTY)
perror("tcsetpgrp");
}
***************
*** 894,903 ****
--- 909,922 ----
char *nextCommand = NULL;
struct jobSet jobList = { NULL, NULL };
struct job newJob;
+ pid_t parent_pgrp;
int i;
int status;
int inBg;
+ /* save current owner of TTY so we can restore it on exit */
+ parent_pgrp = tcgetpgrp(0);
+
command = (char *) calloc(BUFSIZ, sizeof(char));
/* don't pay any attention to this signal; it just confuses
***************
*** 939,948 ****
removeJob(&jobList, jobList.fg);
jobList.fg = NULL;
-
- /* move the shell to the foreground */
- if (tcsetpgrp(0, getpid()))
- perror("tcsetpgrp");
}
} else {
/* the child was stopped */
--- 958,963 ----
***************
*** 958,970 ****
if (!jobList.fg) {
/* move the shell to the foreground */
! if (tcsetpgrp(0, getpid()))
! perror("tcsetpgrp");
}
}
}
free(command);
return 0;
}
--- 973,990 ----
if (!jobList.fg) {
/* move the shell to the foreground */
! /* suppress messages when run from /linuxrc mag at sysgo.de */
! if (tcsetpgrp(0, getpid()) && errno != ENOTTY)
! perror("tcsetpgrp");
}
}
}
free(command);
+ /* return controlling TTY back to parent process group before exiting */
+ if (tcsetpgrp(0, parent_pgrp))
+ perror("tcsetpgrp");
+
return 0;
}
***************
*** 973,981 ****
{
FILE *input = stdin;
- if (argc > 2) {
- usage(shell_usage);
- }
/* initialize the cwd */
getcwd(cwd, sizeof(cwd));
--- 993,998 ----
***************
*** 993,1005 ****
fprintf(stdout, "\n\nBusyBox v%s (%s) Built-in shell\n", BB_VER, BB_BT);
fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n");
} else {
! if (*argv[1]=='-') {
usage("sh\n\nlash -- the BusyBox LAme SHell (command interpreter)\n");
}
! input = fopen(argv[1], "r");
! if (!input) {
! fatalError("sh: Couldn't open file '%s': %s\n", argv[1],
! strerror(errno));
}
}
--- 1010,1042 ----
fprintf(stdout, "\n\nBusyBox v%s (%s) Built-in shell\n", BB_VER, BB_BT);
fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n");
} else {
! if (argv[1][0]=='-' && argv[1][1]=='c') {
! int i;
! local_pending_command = (char *) calloc(BUFSIZ, sizeof(char));
! if (local_pending_command == 0) {
! fatalError("sh: out of memory\n");
! }
! for(i=2; i<argc; i++)
! {
! if (strlen(local_pending_command) + strlen(argv[i]) >= BUFSIZ) {
! fatalError("sh: commands for -c option too long\n");
! }
! strcat(local_pending_command, argv[i]);
! if (i + 1 < argc)
! strcat(local_pending_command, " ");
! }
! input = NULL;
!
! }
! else if (argv[1][0]=='-') {
usage("sh\n\nlash -- the BusyBox LAme SHell (command interpreter)\n");
}
! else {
! input = fopen(argv[1], "r");
! if (!input) {
! fatalError("sh: Couldn't open file '%s': %s\n", argv[1],
! strerror(errno));
! }
}
}
Index: tar.c
===================================================================
RCS file: /home/elinos/CVS/sysgo/elinos/build/busybox/tar.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -c -r1.4 -r1.5
*** tar.c 2000/06/23 16:14:48 1.4
--- tar.c 2000/06/23 19:40:46 1.5
***************
*** 648,654 ****
}
/* Remove any clutter lying in our way */
! unlink( header.name);
/* If we got here, we can be certain we have a legitimate
* header to work with. So work with it. */
--- 648,655 ----
}
/* Remove any clutter lying in our way */
! if (extractFlag == TRUE) /* .. but only if we are extracting (as */
! unlink( header.name); /* opposed to listing) (rob at sysgo.de) */
/* If we got here, we can be certain we have a legitimate
* header to work with. So work with it. */
More information about the busybox
mailing list