I'm having trouble getting an ap_popenf() to work under WIN32.  It appears
to return an invalid file descriptor.  This does not happen with the UNIX
machines I've tested.

I'm using Apache 1.3.22, installed from .MSI on WIN32.

Under BSD, output is written to the file "output.txt" as expected. 

Under Windows, the file is created, no output is written, and the module 
displays "Bad file descriptor".

Any assistance would be appreciated.  Here is the code; see my comments
inline:

-- cut here --

#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"

#include <limits.h>
#include <stdlib.h>
#include <errno.h>

#ifdef _WIN32
 #include <windows.h>
 #include <io.h>
#endif

/* Initialize the log file */
static void init_config_log(server_rec *s, pool *p)
{
   int fd, nbytes;
   char *fname = ap_server_root_relative (p, "output.txt");

   /* XXX WIN32: the following will create the file, but the descriptor 
    *            returned is invalid. 
    */
   if ((fd = ap_popenf(p,  fname, O_WRONLY|O_APPEND| O_CREAT, 0666)) < 0) {
       fprintf (stderr, "httpd: could not open %s.\n", fname);
       perror("open");
       exit( EXIT_FAILURE );
   }

   /* XXX WIN32: the following will open the file, and allow the write,
    *            however, there is no way to close the descriptor when the 
    *            module is unloaded.  or is there?
    */

   /*
   if ((fd = open( fname, O_WRONLY | O_APPEND | O_CREAT, 0666 )) < 0) {
       fprintf (stderr, "httpd: could not open %s.\n", fname);
       perror("open");
       exit( EXIT_FAILURE );
   }
    */

   /* Dump the FD */
   fprintf(stderr, "fd: %d\n", fd );

   /* Write a test string */
   nbytes = write( fd, "test\n", strlen(" test\n" ));

   /* If the write failed, mention it */
   if ( nbytes < 0 )  fprintf(stderr, "ERROR: %s\n", strerror( errno ));
}

/* Apache Module Dispatch */
module MODULE_VAR_EXPORT test_module =
{
       STANDARD_MODULE_STUFF,
       init_config_log,            /* initializer */
       NULL,                       /* create per-dir config */
       NULL,                       /* merge per-dir config */
       NULL,                       /* server config */
       NULL,                       /* merge server config */
       NULL,                       /* command table */
       NULL,                       /* handlers */
       NULL,                       /* filename translation */
       NULL,                       /* check_user_id */
       NULL,                       /* check auth */
       NULL,                       /* check access */
       NULL,                       /* type_checker */
       NULL,                       /* fixups */
       NULL,                       /* logger */
       NULL,                       /* header parser */
       NULL,                       /* child_init */
       NULL,                       /* child_exit */
       NULL                        /* post read-request */
};

-- cut here --

- Rob

--
Robert Mooney ([EMAIL PROTECTED])
www: http://www.aboveground.cx/~rjmooney/ 

Reply via email to