Bug 61180

Summary: [RFE] nash execve call redirect stdout
Product: [Retired] Red Hat Linux Reporter: Matt Domsch <matt_domsch>
Component: mkinitrdAssignee: Matt Wilson <msw>
Status: CLOSED RAWHIDE QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: low    
Version: 7.3CC: ewt
Target Milestone: ---Keywords: FutureFeature
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2002-03-14 21:59:50 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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)