Skip to contentSkip to conversation

problem with syscall macro

DISCUSSION sounak chakraborty 3 participants 3 messages Jan 12, 2005

lore
Share & tools
lore
#0 lore raw

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/

#1 lore raw

On Wed, 2005-01-12 14:40:47 +0000, sounak chakraborty <[email protected]> wrote in message <[email protected]>:

Quoted 3 lines

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.

Quoted 1 line

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.

Quoted 3 lines

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.

Quoted 3 lines

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.

Quoted 1 line

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

Signature · 4 lines
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));
#2 lore raw
In reply to sounak chakraborty
Quoted 5 lines · sounak chakraborty

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

Quoted 9 lines

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.