Bug 61180 - [RFE] nash execve call redirect stdout
Summary: [RFE] nash execve call redirect stdout
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: mkinitrd
Version: 7.3
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
Assignee: Matt Wilson
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-03-14 21:59 UTC by Matt Domsch
Modified: 2007-03-27 03:51 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Enhancement
Doc Text:
Clone Of:
Environment:
Last Closed: 2002-03-14 21:59:50 UTC
Embargoed:


Attachments (Terms of Use)

Description Matt Domsch 2002-03-14 21:59:46 UTC
Description of Problem:
(ultra low priority enhancement request)

nash can redirect stdout on 'echo' commands, but cannot do so for execve'd 
apps.  Occasionally it's nice to be able to do this, e.g. the kernel starts 
fine, begins running the initrd fine, but hangs while loading a module.  It can 
be handy to stick static apps in the initrd to run before those insmods (like 
say, 'mptable'.

Patch provided against 3.3.4-3 is untested (testing mode keeps getting in the 
way), but I believe it's correct, and would appreciate a review.


Version-Release number of selected component (if applicable):
3.3.4-3


diff -urNp --exclude-from=/home/mdomsch/excludes mkinitrd-3.3.4.orig/nash/nash.c
 mkinitrd-3.3.4/nash/nash.c
--- mkinitrd-3.3.4.orig/nash/nash.c     Wed Jan 16 14:15:39 2002
+++ mkinitrd-3.3.4/nash/nash.c  Thu Mar 14 15:47:35 2002
@@ -212,6 +212,7 @@ int otherCommand(char * bin, char * cmd,
     const static char * sysPath = PATH;
     const char * pathStart;
     const char * pathEnd;
+    FILE *outFile = NULL;

     nextArg = args;

@@ -255,6 +256,13 @@ int otherCommand(char * bin, char * cmd,
     } else {
        if (!doFork || !(pid = fork())) {
            /* child */
+           if ((nextArg - args >= 2) && !strcmp(*(nextArg - 2), ">")) {
+                   outFile = freopen(*(nextArg - 1), "a", stdout);
+                   if (outFile) {
+                           *(nextArg - 2) = NULL;
+                           *(nextArg - 1) = NULL;
+                   }
+           }
            execve(args[0], args, env);
            printf("ERROR: failed in exec of %s\n", args[0]);
            return 1;

Comment 1 Erik Troan 2002-05-21 02:15:45 UTC
anything for you matt ;-)

it's in 3.3.11 (via a slightly different patch)

Comment 2 Matt Domsch 2002-05-21 02:48:50 UTC
Thanks Erik!  I know my patch didn't quite work - hope it wasn't too much 
trouble to make it do the right thing.


Comment 3 Erik Troan 2002-05-21 02:58:50 UTC
nah, it was easy enough

fwiw, you can test nash out by giving it "--force" on the command line, which
overrides test mode. this was broken recently, but it's fixed in CVS (along
with the other change you wanted)


Note You need to log in before you can comment on or make changes to this bug.