2005-01-12 14:40:52

by sounak chakraborty

[permalink] [raw]
Subject: problem with syscall macro

i am writing a program which willcopy all the lines
from system log file /var/log/messages and put it in a
user log file
i am using syslog with syscall3 but when i am using
write system cal it is not able to write anything
do i have to add something more
i have added the syscall3 macro for write too
do i have to do it for open system call also
i am little bit confuse with the kernel-user mode
switching concept too
could you please help me out
thans
sounak



________________________________________________________________________
Yahoo! India Matrimony: Find your partner online. http://yahoo.shaadi.com/india-matrimony/


2005-01-12 14:57:43

by Jan-Benedict Glaw

[permalink] [raw]
Subject: Re: problem with syscall macro

On Wed, 2005-01-12 14:40:47 +0000, sounak chakraborty <[email protected]>
wrote in message <[email protected]>:
> i am writing a program which willcopy all the lines
> from system log file /var/log/messages and put it in a
> user log file

That's an easy task.

> i am using syslog with syscall3 but when i am using

Why do you want to use syslog with syscall3? syslogd and klogs will
prepare /var/log/messages for you, so you just need to read() it and
write() it to a different file.

> write system cal it is not able to write anything
> do i have to add something more
> i have added the syscall3 macro for write too

No need for that. You shouldn't fiddle directly with your operating
system's syscall interface. You should use libc's wrappers instead,
which will also correctly set errno and all the like.

> do i have to do it for open system call also
> i am little bit confuse with the kernel-user mode
> switching concept too

Actually, you don't need to know anything about Linux' internals, Linux'
syscall interface etc. You only need to know about the
POSIX/SuSv3/whatever interface the libc presents to userspace. If you
directly use system calls, you'll loose portability and need to fight
against stupid problems like this one.

> could you please help me out

The bottom line is that this isn't a kernel-related question, so you'd
probably ask on a C beginner's mailing list...

See:
man 2 open
man 2 close
man 2 read
man 2 write

MfG, JBG

--
Jan-Benedict Glaw [email protected] . +49-172-7608481 _ O _
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg _ _ O
fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak! O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));


Attachments:
(No filename) (1.78 kB)
signature.asc (189.00 B)
Digital signature
Download all attachments

2005-01-12 15:04:46

by linux-os

[permalink] [raw]
Subject: Re: problem with syscall macro

On Wed, 12 Jan 2005, sounak chakraborty wrote:

> i am writing a program which willcopy all the lines
> from system log file /var/log/messages and put it in a
> user log file
> i am using syslog with syscall3 but when i am using
> write system cal it is not able to write anything
> do i have to add something more
> i have added the syscall3 macro for write too
> do i have to do it for open system call also
> i am little bit confuse with the kernel-user mode
> switching concept too
> could you please help me out
> thans
> sounak
>

You are very confused. The "stuff" that comes from the
kernel, printk(), etc., is buffered by the kernel and
then read by user-mode code from /proc/kmsg.

But, once you read it, it's gone. Therefore there is
a procedure, int syslog(int type, char *buf, int buf_len);
that allows a user to read/manuiplate the logging
facility. `man syslog` will get you that information.
You do __not__ use _syscall3(). See the underscore in
the name? Things that begin with underscores are used by
the 'C' runtime library, not you directly.

#include <stdio.h>
#include <sys/syslog.h>
int main() {
char buf[0x2000];
syslog(3, buf, sizeof(buf));
puts(buf);
return 0;
}

Cheers,
Dick Johnson
Penguin : Linux version 2.6.10 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.