linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* writing logfile
@ 2003-02-25 10:57 Mat Harris
  2003-02-25 11:38 ` Elias Athanasopoulos
  0 siblings, 1 reply; 14+ messages in thread
From: Mat Harris @ 2003-02-25 10:57 UTC (permalink / raw)
  To: linux-c-programming

[-- Attachment #1: Type: text/plain, Size: 598 bytes --]

WARNING: Newbie ALERT!!!

I am trying to write three functions to plugin to my app. They are defined 
in log.h and are used for opening, writing to, and closing a logfile. I have
attached log.h.

My questions are: How do I tell fopen to create if not there or append if
it is? I seem to get an error either way. 

And: Why does the fputs cause a segfault? Is there a better way of doing it?
I know I do not understand types and casting very well so I may have it
totally wrong.

Thanks

-- 
Mat Harris			OpenGPG Public Key ID: C37D57D9
mat.harris@genestate.com	www.genestate.com	

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: writing logfile
  2003-02-25 10:57 writing logfile Mat Harris
@ 2003-02-25 11:38 ` Elias Athanasopoulos
  2003-02-25 12:49   ` Mat Harris
  0 siblings, 1 reply; 14+ messages in thread
From: Elias Athanasopoulos @ 2003-02-25 11:38 UTC (permalink / raw)
  To: Mat Harris; +Cc: linux-c-programming

On Tue, Feb 25, 2003 at 10:57:40AM +0000, Mat Harris wrote:
> in log.h and are used for opening, writing to, and closing a logfile. I have
> attached log.h.

You don't.

> My questions are: How do I tell fopen to create if not there or append if
> it is? I seem to get an error either way. 

This is explained in details in fopen(3).

> And: Why does the fputs cause a segfault? Is there a better way of doing it?
> I know I do not understand types and casting very well so I may have it
> totally wrong.

fputs() is not designed to segfault; you most probably use it wrong. You
have to show parts of your code to get at least a hint.

Elias

-- 
University of Athens			I bet the human brain 
Physics Department				is a kludge --Marvin Minsky 

	

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: writing logfile
  2003-02-25 11:38 ` Elias Athanasopoulos
@ 2003-02-25 12:49   ` Mat Harris
  2003-02-25 13:09     ` William N. Zanatta
                       ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Mat Harris @ 2003-02-25 12:49 UTC (permalink / raw)
  To: Elias Athanasopoulos; +Cc: linux-c-programming


[-- Attachment #1.1: Type: text/plain, Size: 1058 bytes --]

sorry, did my special trick of not attaching the file. here it is

On Tue, Feb 25, 2003 at 01:38:10 +0200, Elias Athanasopoulos wrote:
> On Tue, Feb 25, 2003 at 10:57:40AM +0000, Mat Harris wrote:
> > in log.h and are used for opening, writing to, and closing a logfile. I have
> > attached log.h.
> 
> You don't.
> 
> > My questions are: How do I tell fopen to create if not there or append if
> > it is? I seem to get an error either way. 
> 
> This is explained in details in fopen(3).
> 
> > And: Why does the fputs cause a segfault? Is there a better way of doing it?
> > I know I do not understand types and casting very well so I may have it
> > totally wrong.
> 
> fputs() is not designed to segfault; you most probably use it wrong. You
> have to show parts of your code to get at least a hint.
> 
> Elias
> 
> -- 
> University of Athens			I bet the human brain 
> Physics Department				is a kludge --Marvin Minsky 
> 
> 	

-- 
Mat Harris			OpenGPG Public Key ID: C37D57D9
mat.harris@genestate.com	www.genestate.com	

[-- Attachment #1.2: log.h --]
[-- Type: text/plain, Size: 457 bytes --]

int open_log()
{
  char logfile[4096];
  int loghandle;

  strcpy(logfile, WEBROOT);
  strcat(logfile, "/logs/access.log");

  loghandle = open(logfile, O_CREAT);

  if (loghandle < 0)
    {
      fprintf(stderr, "Couldn't open logfile: %s\n", logfile);
      exit(1);
    }
  else
    {
      return loghandle;
    }
}

void close_log(int loghandle)
{
  close(loghandle);
}

void write_log(int loghandle, char string[1024])
{
  fputs(string, loghandle);
}

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: writing logfile
  2003-02-25 12:49   ` Mat Harris
@ 2003-02-25 13:09     ` William N. Zanatta
  2003-02-25 13:11       ` Mat Harris
  2003-02-25 14:10       ` Elias Athanasopoulos
  2003-02-25 14:18     ` Elias Athanasopoulos
  2003-02-26  1:09     ` Glynn Clements
  2 siblings, 2 replies; 14+ messages in thread
From: William N. Zanatta @ 2003-02-25 13:09 UTC (permalink / raw)
  To: Mat Harris; +Cc: Elias Athanasopoulos, linux-c-programming


   Wow it is a mess! Time to get the old book, sit down and read some 
more...

   You are opening a file through open() which returns an integer 
representation of the file descriptor and trying to write on it through 
fputs() which writes to a file descriptor represented by a FILE pointer.

   That's your answer. You are using the wrong functions.

   You may either change your code to work with integers, open(), read() 
  write() and close() or make it use FILE *, fopen(), fread() (...), 
fputs() (...) and fclose(). It is up to you and will depends on the kind 
of application you're writing.

   Each of the ways of file manipulation has advantages and/or 
disadvantages. You should seek for something about that over the net.

   ">   loghandle = open(logfile, O_CREAT);"

   Maybe I'm wrong, but I think this previous call just creates a file 
and doesn't make it available for reading/writing in any way. Is that 
right brothers???

   william

-- 
Perl combines all of the worst aspects of BASIC, C and line noise.
                 -- Keith Packard


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: writing logfile
  2003-02-25 13:09     ` William N. Zanatta
@ 2003-02-25 13:11       ` Mat Harris
  2003-02-25 14:10       ` Elias Athanasopoulos
  1 sibling, 0 replies; 14+ messages in thread
From: Mat Harris @ 2003-02-25 13:11 UTC (permalink / raw)
  To: William N. Zanatta; +Cc: Elias Athanasopoulos, linux-c-programming

[-- Attachment #1: Type: text/plain, Size: 1444 bytes --]

i thought it was something along those lines. so i need to do dot-to-dot
with the functions. i will read up on that in a mo

On Tue, Feb 25, 2003 at 10:09:37 -0300, William N. Zanatta wrote:
> 
>    Wow it is a mess! Time to get the old book, sit down and read some 
> more...
> 
>    You are opening a file through open() which returns an integer 
> representation of the file descriptor and trying to write on it through 
> fputs() which writes to a file descriptor represented by a FILE pointer.
> 
>    That's your answer. You are using the wrong functions.
> 
>    You may either change your code to work with integers, open(), read() 
>   write() and close() or make it use FILE *, fopen(), fread() (...), 
> fputs() (...) and fclose(). It is up to you and will depends on the kind 
> of application you're writing.
> 
>    Each of the ways of file manipulation has advantages and/or 
> disadvantages. You should seek for something about that over the net.
> 
>    ">   loghandle = open(logfile, O_CREAT);"
> 
>    Maybe I'm wrong, but I think this previous call just creates a file 
> and doesn't make it available for reading/writing in any way. Is that 
> right brothers???
> 
>    william
> 
> -- 
> Perl combines all of the worst aspects of BASIC, C and line noise.
>                  -- Keith Packard

-- 
Mat Harris			OpenGPG Public Key ID: C37D57D9
mat.harris@genestate.com	www.genestate.com	

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: writing logfile
  2003-02-25 13:09     ` William N. Zanatta
  2003-02-25 13:11       ` Mat Harris
@ 2003-02-25 14:10       ` Elias Athanasopoulos
  1 sibling, 0 replies; 14+ messages in thread
From: Elias Athanasopoulos @ 2003-02-25 14:10 UTC (permalink / raw)
  To: William N. Zanatta; +Cc: Mat Harris, linux-c-programming

On Tue, Feb 25, 2003 at 10:09:37AM -0300, William N. Zanatta wrote:
>    ">   loghandle = open(logfile, O_CREAT);"
> 
>    Maybe I'm wrong, but I think this previous call just creates a file 
> and doesn't make it available for reading/writing in any way. Is that 
> right brothers???

I think it will create it and open it in read-only mode, since O_RDONLY
is defined as 0 and thus O_RDONLY | O_CREAT equals to O_CREAT.

It is quite missleading, though, so feeding open() explicitly with the
flags it asks is the right thing to do, IMHO.

Elias

-- 
University of Athens			I bet the human brain 
Physics Department				is a kludge --Marvin Minsky 

	

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: writing logfile
  2003-02-25 12:49   ` Mat Harris
  2003-02-25 13:09     ` William N. Zanatta
@ 2003-02-25 14:18     ` Elias Athanasopoulos
  2003-02-26  1:09     ` Glynn Clements
  2 siblings, 0 replies; 14+ messages in thread
From: Elias Athanasopoulos @ 2003-02-25 14:18 UTC (permalink / raw)
  To: Mat Harris; +Cc: linux-c-programming

On Tue, Feb 25, 2003 at 12:49:37PM +0000, Mat Harris wrote:
> void write_log(int loghandle, char string[1024])
> {
>   fputs(string, loghandle);
> }

You should compiling with -Wall. This will save you a lot and help you
find out your errors. 

Remember: a warning is a virtual error, which can break the balance 
conservation of the application for a small period of time, allowed by 
the uncertainty principle, enough to make the application segfault. :-)

Elias

-- 
University of Athens			I bet the human brain 
Physics Department				is a kludge --Marvin Minsky 

	

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: writing logfile
  2003-02-25 12:49   ` Mat Harris
  2003-02-25 13:09     ` William N. Zanatta
  2003-02-25 14:18     ` Elias Athanasopoulos
@ 2003-02-26  1:09     ` Glynn Clements
  2003-02-26  9:25       ` Mat Harris
  2 siblings, 1 reply; 14+ messages in thread
From: Glynn Clements @ 2003-02-26  1:09 UTC (permalink / raw)
  To: Mat Harris; +Cc: Elias Athanasopoulos, linux-c-programming


Mat Harris wrote:

>   loghandle = open(logfile, O_CREAT);

This should probably be:

   loghandle = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0600);

You may also wish to use the O_SYNC flag, to force data to be written
to disk immediately (so that it isn't lost if the system crashes or
the power fails).

As William pointed out, if you open the file with open(), you need to
use write() to write data to the file. Alternatively, you could use
fopen() and fputs(), but fopen() doesn't give you as much control
(e.g. you can't set the permissions or the O_SYNC flag on creation).

Also, you can create an ANSI stream (a "FILE *") from a descriptor
using fdopen(), and you can get the descriptor for an ANSI stream
using fileno(). But you need to be careful about accessing a file
using both methods (which basically means that you need to understand
how the two relate to each other).

-- 
Glynn Clements <glynn.clements@virgin.net>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: writing logfile
  2003-02-26  1:09     ` Glynn Clements
@ 2003-02-26  9:25       ` Mat Harris
  2003-02-26 10:09         ` Jan-Benedict Glaw
  0 siblings, 1 reply; 14+ messages in thread
From: Mat Harris @ 2003-02-26  9:25 UTC (permalink / raw)
  To: Glynn Clements; +Cc: Elias Athanasopoulos, linux-c-programming


[-- Attachment #1.1: Type: text/plain, Size: 1487 bytes --]

ok i have modified it to use open, write, and close> Now tho I am getting
garbage written to the logfile. Evidently i have made an error with types
or there is confusion between writing a text string and writing raw bits.

i have attached the modified code.

Thanks for all your help so far people :)

On Wed, Feb 26, 2003 at 01:09:12 +0000, Glynn Clements wrote:
> 
> Mat Harris wrote:
> 
> >   loghandle = open(logfile, O_CREAT);
> 
> This should probably be:
> 
>    loghandle = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0600);
> 
> You may also wish to use the O_SYNC flag, to force data to be written
> to disk immediately (so that it isn't lost if the system crashes or
> the power fails).
> 
> As William pointed out, if you open the file with open(), you need to
> use write() to write data to the file. Alternatively, you could use
> fopen() and fputs(), but fopen() doesn't give you as much control
> (e.g. you can't set the permissions or the O_SYNC flag on creation).
> 
> Also, you can create an ANSI stream (a "FILE *") from a descriptor
> using fdopen(), and you can get the descriptor for an ANSI stream
> using fileno(). But you need to be careful about accessing a file
> using both methods (which basically means that you need to understand
> how the two relate to each other).
> 
> -- 
> Glynn Clements <glynn.clements@virgin.net>

-- 
Mat Harris			OpenGPG Public Key ID: C37D57D9
mat.harris@genestate.com	www.genestate.com	

[-- Attachment #1.2: log.h --]
[-- Type: text/plain, Size: 552 bytes --]

int open_log()
{
  char logfile[4096];
  int loghandle;

  strcpy(logfile, WEBROOT);
  strcat(logfile, "/logs/access.log");

  loghandle = open(logfile, O_WRONLY | O_CREAT | O_APPEND | O_SYNC, 0600);

  if (loghandle < 0)
    {
      fprintf(stderr, "Couldn't open logfile: %s\n", logfile);
      exit(1);
    }
  else
    {
      return loghandle;
    }
}

void close_log(int loghandle)
{
  close(loghandle);
}

void write_log(int loghandle, char string[1024])
{
  printf("requested file: %s\n", string);
  write(loghandle, string, sizeof(string));
}

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: writing logfile
  2003-02-26  9:25       ` Mat Harris
@ 2003-02-26 10:09         ` Jan-Benedict Glaw
  2003-02-26 10:18           ` Mat Harris
  0 siblings, 1 reply; 14+ messages in thread
From: Jan-Benedict Glaw @ 2003-02-26 10:09 UTC (permalink / raw)
  To: linux-c-programming

[-- Attachment #1: Type: text/plain, Size: 1660 bytes --]

On Wed, 2003-02-26 09:25:02 +0000, Mat Harris <mat.harris@genestate.com>
wrote in message <20030226092502.A12697@genestate.com>:
> ok i have modified it to use open, write, and close> Now tho I am getting
> garbage written to the logfile. Evidently i have made an error with types
> or there is confusion between writing a text string and writing raw bits.

Despite some other shortages, try it this way:

> On Wed, Feb 26, 2003 at 01:09:12 +0000, Glynn Clements wrote:
> int open_log()
> {
>   char logfile[4096];
>   int loghandle;
> 
>   strcpy(logfile, WEBROOT);
>   strcat(logfile, "/logs/access.log");

logfile *may* be too short. This is asking for trouble!

>   loghandle = open(logfile, O_WRONLY | O_CREAT | O_APPEND | O_SYNC, 0600);
> 
>   if (loghandle < 0)
>     {
>       fprintf(stderr, "Couldn't open logfile: %s\n", logfile);
>       exit(1);
>     }
>   else
>     {
>       return loghandle;
>     }
> }
> 
> void close_log(int loghandle)
> {
>   close(loghandle);
> }
> 
> void write_log(int loghandle, char string[1024])

void
write_log(int loghandle, char *string)

> {

if(!string)
	return;

>   printf("requested file: %s\n", string);
>   write(loghandle, string, sizeof(string));
	write(loghandle, string, strlen(string));
	write(loghandle, "\n", strlen("\n"));
> }

MfG, JBG

-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
    fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
       ret = do_actions((curr | FREE_SPEECH) && ~(IRAQ_WAR_2 | DRM | TCPA);

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: writing logfile
  2003-02-26 10:09         ` Jan-Benedict Glaw
@ 2003-02-26 10:18           ` Mat Harris
  2003-02-26 19:45             ` Glynn Clements
  0 siblings, 1 reply; 14+ messages in thread
From: Mat Harris @ 2003-02-26 10:18 UTC (permalink / raw)
  To: linux-c-programming


[-- Attachment #1.1: Type: text/plain, Size: 2429 bytes --]

ok and now i am getting something weird. when I try to log a successful
request, and then make the request again, it ands to the previous printf
message and prints it again so it repeats all the previous messages again
and again. Also, the garbage in the logfile is the beginning of my webroot
"/home....". I do not know what is going on here.

I have attached all my work so far. PS Please don't tell me about re-inventing
the wheel, this is just for experimentation :)

On Wed, Feb 26, 2003 at 11:09:15 +0100, Jan-Benedict Glaw wrote:
> On Wed, 2003-02-26 09:25:02 +0000, Mat Harris <mat.harris@genestate.com>
> wrote in message <20030226092502.A12697@genestate.com>:
> > ok i have modified it to use open, write, and close> Now tho I am getting
> > garbage written to the logfile. Evidently i have made an error with types
> > or there is confusion between writing a text string and writing raw bits.
> 
> Despite some other shortages, try it this way:
> 
> > On Wed, Feb 26, 2003 at 01:09:12 +0000, Glynn Clements wrote:
> > int open_log()
> > {
> >   char logfile[4096];
> >   int loghandle;
> > 
> >   strcpy(logfile, WEBROOT);
> >   strcat(logfile, "/logs/access.log");
> 
> logfile *may* be too short. This is asking for trouble!
> 
> >   loghandle = open(logfile, O_WRONLY | O_CREAT | O_APPEND | O_SYNC, 0600);
> > 
> >   if (loghandle < 0)
> >     {
> >       fprintf(stderr, "Couldn't open logfile: %s\n", logfile);
> >       exit(1);
> >     }
> >   else
> >     {
> >       return loghandle;
> >     }
> > }
> > 
> > void close_log(int loghandle)
> > {
> >   close(loghandle);
> > }
> > 
> > void write_log(int loghandle, char string[1024])
> 
> void
> write_log(int loghandle, char *string)
> 
> > {
> 
> if(!string)
> 	return;
> 
> >   printf("requested file: %s\n", string);
> >   write(loghandle, string, sizeof(string));
> 	write(loghandle, string, strlen(string));
> 	write(loghandle, "\n", strlen("\n"));
> > }
> 
> MfG, JBG
> 
> -- 
>    Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
>    "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
>     fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
>        ret = do_actions((curr | FREE_SPEECH) && ~(IRAQ_WAR_2 | DRM | TCPA);



-- 
Mat Harris			OpenGPG Public Key ID: C37D57D9
mat.harris@genestate.com	www.genestate.com	

[-- Attachment #1.2: webserver.tar.gz --]
[-- Type: application/x-gzip, Size: 15524 bytes --]

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: writing logfile
  2003-02-26 10:18           ` Mat Harris
@ 2003-02-26 19:45             ` Glynn Clements
  2003-02-27 10:04               ` Mat Harris
  0 siblings, 1 reply; 14+ messages in thread
From: Glynn Clements @ 2003-02-26 19:45 UTC (permalink / raw)
  To: Mat Harris; +Cc: linux-c-programming


Mat Harris wrote:

> ok and now i am getting something weird. when I try to log a successful
> request, and then make the request again, it ands to the previous printf
> message and prints it again so it repeats all the previous messages again
> and again. Also, the garbage in the logfile is the beginning of my webroot
> "/home....". I do not know what is going on here.

Line 52 of webserver.c:

>	  strcat(logmsg, filename);

should be

	  strcpy(logmsg, filename);

Also:

> #include "log.h" /* logging functions */

Don't use #include for actual code. Put it in a separate .c file and
compile it separately.

> void write_log(int loghandle, char *string)
> {
>   write(loghandle, string, sizeof(string));
> }

   write(loghandle, string, strlen(string));

Applying sizeof() to a "char *" will return the size of the pointer
(typically 4 on a 32-bit system, 8 on a 64-bit system), not the length
of the string to which it points.

-- 
Glynn Clements <glynn.clements@virgin.net>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: writing logfile
  2003-02-26 19:45             ` Glynn Clements
@ 2003-02-27 10:04               ` Mat Harris
  2003-02-27 10:32                 ` SOLVED: " Mat Harris
  0 siblings, 1 reply; 14+ messages in thread
From: Mat Harris @ 2003-02-27 10:04 UTC (permalink / raw)
  To: linux-c-programming

[-- Attachment #1: Type: text/plain, Size: 1717 bytes --]

ok, thanks guys for the help with my webserver, the loggin works fine and now
I have remembered about extern void etc I have put the functions to compile
seperateley as suggested.

Just one more thing tho, the logmessage is getting printed to the client's
browser after any html content has been transferred and I can't see where it
is happening. I have put a tarball of the whole thing at

http://www.genestate.com/~matthewh/debug/

thanks again.

On Wed, Feb 26, 2003 at 07:45:07 +0000, Glynn Clements wrote:
> 
> Mat Harris wrote:
> 
> > ok and now i am getting something weird. when I try to log a successful
> > request, and then make the request again, it ands to the previous printf
> > message and prints it again so it repeats all the previous messages again
> > and again. Also, the garbage in the logfile is the beginning of my webroot
> > "/home....". I do not know what is going on here.
> 
> Line 52 of webserver.c:
> 
> >	  strcat(logmsg, filename);
> 
> should be
> 
> 	  strcpy(logmsg, filename);
> 
> Also:
> 
> > #include "log.h" /* logging functions */
> 
> Don't use #include for actual code. Put it in a separate .c file and
> compile it separately.
> 
> > void write_log(int loghandle, char *string)
> > {
> >   write(loghandle, string, sizeof(string));
> > }
> 
>    write(loghandle, string, strlen(string));
> 
> Applying sizeof() to a "char *" will return the size of the pointer
> (typically 4 on a 32-bit system, 8 on a 64-bit system), not the length
> of the string to which it points.
> 
> -- 
> Glynn Clements <glynn.clements@virgin.net>

-- 
Mat Harris			OpenGPG Public Key ID: C37D57D9
mat.harris@genestate.com	www.genestate.com	

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* SOLVED: Re: writing logfile
  2003-02-27 10:04               ` Mat Harris
@ 2003-02-27 10:32                 ` Mat Harris
  0 siblings, 0 replies; 14+ messages in thread
From: Mat Harris @ 2003-02-27 10:32 UTC (permalink / raw)
  To: linux-c-programming

[-- Attachment #1: Type: text/plain, Size: 2116 bytes --]

it's alright, i was closing the logfile inside the connection loop so it was 
printing to a null filehandle and got confused.

On Thu, Feb 27, 2003 at 10:04:15 +0000, Mat Harris wrote:
> ok, thanks guys for the help with my webserver, the loggin works fine and now
> I have remembered about extern void etc I have put the functions to compile
> seperateley as suggested.
> 
> Just one more thing tho, the logmessage is getting printed to the client's
> browser after any html content has been transferred and I can't see where it
> is happening. I have put a tarball of the whole thing at
> 
> http://www.genestate.com/~matthewh/debug/
> 
> thanks again.
> 
> On Wed, Feb 26, 2003 at 07:45:07 +0000, Glynn Clements wrote:
> > 
> > Mat Harris wrote:
> > 
> > > ok and now i am getting something weird. when I try to log a successful
> > > request, and then make the request again, it ands to the previous printf
> > > message and prints it again so it repeats all the previous messages again
> > > and again. Also, the garbage in the logfile is the beginning of my webroot
> > > "/home....". I do not know what is going on here.
> > 
> > Line 52 of webserver.c:
> > 
> > >	  strcat(logmsg, filename);
> > 
> > should be
> > 
> > 	  strcpy(logmsg, filename);
> > 
> > Also:
> > 
> > > #include "log.h" /* logging functions */
> > 
> > Don't use #include for actual code. Put it in a separate .c file and
> > compile it separately.
> > 
> > > void write_log(int loghandle, char *string)
> > > {
> > >   write(loghandle, string, sizeof(string));
> > > }
> > 
> >    write(loghandle, string, strlen(string));
> > 
> > Applying sizeof() to a "char *" will return the size of the pointer
> > (typically 4 on a 32-bit system, 8 on a 64-bit system), not the length
> > of the string to which it points.
> > 
> > -- 
> > Glynn Clements <glynn.clements@virgin.net>
> 
> -- 
> Mat Harris			OpenGPG Public Key ID: C37D57D9
> mat.harris@genestate.com	www.genestate.com	



-- 
Mat Harris			OpenGPG Public Key ID: C37D57D9
mat.harris@genestate.com	www.genestate.com	

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2003-02-27 10:32 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-25 10:57 writing logfile Mat Harris
2003-02-25 11:38 ` Elias Athanasopoulos
2003-02-25 12:49   ` Mat Harris
2003-02-25 13:09     ` William N. Zanatta
2003-02-25 13:11       ` Mat Harris
2003-02-25 14:10       ` Elias Athanasopoulos
2003-02-25 14:18     ` Elias Athanasopoulos
2003-02-26  1:09     ` Glynn Clements
2003-02-26  9:25       ` Mat Harris
2003-02-26 10:09         ` Jan-Benedict Glaw
2003-02-26 10:18           ` Mat Harris
2003-02-26 19:45             ` Glynn Clements
2003-02-27 10:04               ` Mat Harris
2003-02-27 10:32                 ` SOLVED: " Mat Harris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).