You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Ben Collins-Sussman <su...@newton.collab.net> on 2001/01/26 05:48:20 UTC

stdout?

Hey Greg S. --

I notice that in log.c, the function run_cmd_in_directory() takes some
apr_file_t's to "hook up" to the child process -- one for input,
output, and error.

If I want to call this function and make the child process print to
plain old stdout, what's the proper procedure?  If I pass all NULLs
for the apr_file_t arguments, nothing is printed to stdout.  If I try
to do an apr_open (&outhandle, stdout, APR_WRITE, APR_OS_DEFAULT,
pool), and then pass *that* handle to run_cmd_in_directory(), I get a
generic apr error "no such file".

What am I missing here?

Re: stdout?

Posted by Ben Collins-Sussman <su...@newton.collab.net>.
Greg Stein <gs...@lyra.org> writes:

> On Fri, Jan 26, 2001 at 09:55:37AM -0600, Ben Collins-Sussman wrote:
> > Kevin Pilch-Bisson <ke...@pilch-bisson.net> writes:
> > 
> > > +  apr_os_file_t stdout_fileno = STDOUT_FILENO;
> > >
> > > +  status = apr_put_os_file (&outhandle, &stdout_fileno, pool);
> > 
> > Thanks, Kevin, this did the trick... `svn diff' works now! :)
> 
> I figured this one out after I posted the (ahem) "solution". I went in and
> fixed up the code so that you don't have to initialize outhandle to NULL any
> more.

Cool... right now Mike Pilato is sitting here trying to get rid of the
"unistd.h" dependency in client/diff.c, so it will compile on Win32.

Re: stdout?

Posted by Greg Stein <gs...@lyra.org>.
On Fri, Jan 26, 2001 at 09:55:37AM -0600, Ben Collins-Sussman wrote:
> Kevin Pilch-Bisson <ke...@pilch-bisson.net> writes:
> 
> > +  apr_os_file_t stdout_fileno = STDOUT_FILENO;
> >
> > +  status = apr_put_os_file (&outhandle, &stdout_fileno, pool);
> 
> Thanks, Kevin, this did the trick... `svn diff' works now! :)

I figured this one out after I posted the (ahem) "solution". I went in and
fixed up the code so that you don't have to initialize outhandle to NULL any
more.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: stdout?

Posted by Ben Collins-Sussman <su...@newton.collab.net>.
Kevin Pilch-Bisson <ke...@pilch-bisson.net> writes:

> +  apr_os_file_t stdout_fileno = STDOUT_FILENO;
>
> +  status = apr_put_os_file (&outhandle, &stdout_fileno, pool);

Thanks, Kevin, this did the trick... `svn diff' works now! :)

Re: stdout?

Posted by Kevin Pilch-Bisson <ke...@pilch-bisson.net>.
Okay, here is a patch, which just copies STDOUT_FILENO into a memory
address then passes the address of that memory.  It seems to work for
me.

Modified:   subversion/client/diff.c
Log:    Changed to use a copy of STDOUT_FILENO, so that we can take the
address of it.

Revision    Changes Path
1.1         +2 -1   subversion/client/diff.c

Index: diff.c
===================================================================
RCS file: /cvs/subversion/subversion/client/diff.c,v
retrieving revision 1.1
diff -u -p -r1.1 diff.c
--- diff.c	2001/01/26 14:21:06	1.1
+++ diff.c	2001/01/26 14:54:29
@@ -37,6 +37,7 @@ svn_cl__print_file_diff (svn_string_t *p
   svn_error_t *err;
   svn_string_t *pristine_copy_path;
   const char *args[5];
+  apr_os_file_t stdout_fileno = STDOUT_FILENO;
 
   apr_file_t *outhandle = NULL;
 
@@ -49,7 +50,7 @@ svn_cl__print_file_diff (svn_string_t *p
 
   /* Get an apr_file_t representing stdout, which is where we'll have
      the diff program print to. */
-  status = apr_put_os_file (&outhandle, (apr_os_file_t *) STDOUT_FILENO, pool);
+  status = apr_put_os_file (&outhandle, &stdout_fileno, pool);
   if (status)
     return svn_error_create (status, 0, NULL, pool,
                              "error: can't open handle to stdout");

On Fri, Jan 26, 2001 at 09:40:50AM -0500, Kevin Pilch-Bisson wrote:
> On Fri, Jan 26, 2001 at 08:37:57AM -0600, Ben Collins-Sussman wrote:
> > Kevin Pilch-Bisson <ke...@pilch-bisson.net> writes:
> >  
> > > Anyway try status = apr_put_os_file(&file, &STDOUT_FILENO, pool).  My
> > > guess is that your segfault was because you casted an int to a pointer,
> > > and then the filedes assignment dereferenced that pointer.
> > 
> > Uh, this won't compile.  You can't place an `&' in front of int, can you?
> > 
> >      diff.c:52: invalid lvalue in unary `&'
> > 
> > I can't find any reference to STDOUT_FILENO in apr, except in apr.hw,
> > which is a win32-specific file.  What the heck is this thing?  :)
> > 
> > Well, I checked in `svn diff' now, so somebody feel free to make
> > client/diff.c work correctly.  :)
> > ____________________________________________________________
> Well you can place an & in from for an int, but not in front of a
> literal, which is what STD_FILENO is since it is #defined.  I'll take a
> look at it, and let you know what I find.
> -- 
> >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Kevin Pilch-Bisson
> kevin@pilch-bisson.net
> http://www.pilch-bisson.net
> PGP Public Key At http://pgp.pilch-bisson.net



-- 
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Kevin Pilch-Bisson
kevin@pilch-bisson.net
http://www.pilch-bisson.net
PGP Public Key At http://pgp.pilch-bisson.net

Re: stdout?

Posted by Kevin Pilch-Bisson <ke...@pilch-bisson.net>.
On Fri, Jan 26, 2001 at 08:37:57AM -0600, Ben Collins-Sussman wrote:
> Kevin Pilch-Bisson <ke...@pilch-bisson.net> writes:
>  
> > Anyway try status = apr_put_os_file(&file, &STDOUT_FILENO, pool).  My
> > guess is that your segfault was because you casted an int to a pointer,
> > and then the filedes assignment dereferenced that pointer.
> 
> Uh, this won't compile.  You can't place an `&' in front of int, can you?
> 
>      diff.c:52: invalid lvalue in unary `&'
> 
> I can't find any reference to STDOUT_FILENO in apr, except in apr.hw,
> which is a win32-specific file.  What the heck is this thing?  :)
> 
> Well, I checked in `svn diff' now, so somebody feel free to make
> client/diff.c work correctly.  :)
> ____________________________________________________________
Well you can place an & in from for an int, but not in front of a
literal, which is what STD_FILENO is since it is #defined.  I'll take a
look at it, and let you know what I find.
-- 
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Kevin Pilch-Bisson
kevin@pilch-bisson.net
http://www.pilch-bisson.net
PGP Public Key At http://pgp.pilch-bisson.net

Re: stdout?

Posted by Ben Collins-Sussman <su...@newton.collab.net>.
Kevin Pilch-Bisson <ke...@pilch-bisson.net> writes:
 
> Anyway try status = apr_put_os_file(&file, &STDOUT_FILENO, pool).  My
> guess is that your segfault was because you casted an int to a pointer,
> and then the filedes assignment dereferenced that pointer.

Uh, this won't compile.  You can't place an `&' in front of int, can you?

     diff.c:52: invalid lvalue in unary `&'

I can't find any reference to STDOUT_FILENO in apr, except in apr.hw,
which is a win32-specific file.  What the heck is this thing?  :)

Well, I checked in `svn diff' now, so somebody feel free to make
client/diff.c work correctly.  :)

Re: stdout?

Posted by Kevin Pilch-Bisson <ke...@pilch-bisson.net>.
Okay, here I am replying to my own messages, which I didn't even manage
to send to the list.


On Fri, Jan 26, 2001 at 09:16:36AM -0500, Kevin Pilch-Bisson wrote:
> On Fri, Jan 26, 2001 at 08:15:52AM -0600, Ben Collins-Sussman wrote:
> > Greg Stein <gs...@lyra.org> writes:
> > 
> > > #include <unistd.h>
> > > #include <apr_portable.h>
> > > 
> > > {
> > >     apr_file_t *file = NULL;  /* ### grumble. NULL needed... */
> > >     
> > >     status = apr_put_os_file(&file, STDOUT_FILENO, pool);
> > >     return file;
> > > }
> > > 
> > > There ya go! :-)
> > > 
> > > The put_os thing is os-specific, so it isn't portable.
> > > 
> > 
> > Hmmm, I get a compile warning that arg 2 is implicitly converting an
> > integer to a pointer.  If I cast it in place ((apr_os_file_t *)
> > STDOUT_FILENO),  then it compiles fine, but I get a segfault right in
> > the middle of apr_put_os_file()!
> 
> 
> It sounds to me like it is a file descriptor versuse FILE * problem,
> but that is just a guess of the top of my head.
> > 
> > (Specifically, in file_io/unix/open.c, line 227 where it tries to set
> > ->filedes).
> As in you are giving it a file descriptor, but it is treating it like a
> FILE *.  Try just passing it stdout instead of STDOUT_FILENO.
> 
After actually looking at the APR stuff, instead of just spouting off
the top of my head, apr_os_file_t is typefef'd to int.  This means that
I think you need to be passing &STDOUT_FILENO.  The reason it is a
poiner is that some other OSes (Windows Notably), have structs as the
native file type.

Anyway try status = apr_put_os_file(&file, &STDOUT_FILENO, pool).  My
guess is that your segfault was because you casted an int to a pointer,
and then the filedes assignment dereferenced that pointer.

Once again, sorry for not thinking before I hit send, and sorry for
missing the list.
-- 
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Kevin Pilch-Bisson
kevin@pilch-bisson.net
http://www.pilch-bisson.net
PGP Public Key At http://pgp.pilch-bisson.net

Re: stdout?

Posted by Ben Collins-Sussman <su...@newton.collab.net>.
Kevin Pilch-Bisson <ke...@pilch-bisson.net> writes:

> > (Specifically, in file_io/unix/open.c, line 227 where it tries to set
> > ->filedes).
> As in you are giving it a file descriptor, but it is treating it like a
> FILE *.  Try just passing it stdout instead of STDOUT_FILENO.

Yeah, passing `stdout' removed the segfault, but now nothing happens.
I still don't see the diff command printing anything to stdout.  Hm.

Re: stdout?

Posted by Ben Collins-Sussman <su...@newton.collab.net>.
Greg Stein <gs...@lyra.org> writes:

> #include <unistd.h>
> #include <apr_portable.h>
> 
> {
>     apr_file_t *file = NULL;  /* ### grumble. NULL needed... */
>     
>     status = apr_put_os_file(&file, STDOUT_FILENO, pool);
>     return file;
> }
> 
> There ya go! :-)
> 
> The put_os thing is os-specific, so it isn't portable.
> 

Hmmm, I get a compile warning that arg 2 is implicitly converting an
integer to a pointer.  If I cast it in place ((apr_os_file_t *)
STDOUT_FILENO),  then it compiles fine, but I get a segfault right in
the middle of apr_put_os_file()!

(Specifically, in file_io/unix/open.c, line 227 where it tries to set
->filedes).

Also:  what do you mean by your last sentence?  How can something in
APR, a portability layer, be non-portable? :)  I mean, we're talking
about grabbing stdout, which is an ANSI C thing, no?

Re: stdout?

Posted by Greg Stein <gs...@lyra.org>.
On Thu, Jan 25, 2001 at 11:48:20PM -0600, Ben Collins-Sussman wrote:
> 
> Hey Greg S. --
> 
> I notice that in log.c, the function run_cmd_in_directory() takes some
> apr_file_t's to "hook up" to the child process -- one for input,
> output, and error.
> 
> If I want to call this function and make the child process print to
> plain old stdout, what's the proper procedure?  If I pass all NULLs
> for the apr_file_t arguments, nothing is printed to stdout.  If I try
> to do an apr_open (&outhandle, stdout, APR_WRITE, APR_OS_DEFAULT,
> pool), and then pass *that* handle to run_cmd_in_directory(), I get a
> generic apr error "no such file".
> 
> What am I missing here?

#include <unistd.h>
#include <apr_portable.h>

{
    apr_file_t *file = NULL;  /* ### grumble. NULL needed... */
    
    status = apr_put_os_file(&file, STDOUT_FILENO, pool);
    return file;
}

There ya go! :-)

The put_os thing is os-specific, so it isn't portable.

[ and no, don't ask me why apr_portable is the non-portable crap. ]

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/