public inbox for linux-newbie@vger.kernel.org
 help / color / mirror / Atom feed
From: "Sergey V. Burchu" <sayd@joker.botik.ru>
To: linux-newbie@vger.kernel.org
Subject: hm.. again about writing to files from kernel
Date: Wed, 10 Sep 2003 03:33:03 +0400	[thread overview]
Message-ID: <20030909233303.GA21519@joker.botik.ru> (raw)

Hello.
I understand this question is asked again and again...
But I'm a newbie :)

But I want to tell I want to do:

I need info about traffic of every user on my linux box.
I looked through list of available software but ... :(

So I decided to make if myself. Main idea was quite simple:

When socket is created we can know uid of user who is trying to create
socket. So I have to add rx and tx counters to data structures and
simply count all incoming/outgoing data and when socket is closing
just to dump this info, for example to syslog. It works fine but my 
syslog grows up to some G... :( 
So I have to find a way to dump info which uses less disk space.
I think the best way is to dump directly to logfile and dump binary data,
for example some struct. 
So I needed a way to write to a file from inside kernel.
I wanted it configurable but I understand that it's not good to 
parse config inside kernel. So I use /proc:
Userspace program opens file for writing, gives FD to kernel through /proc 
and sleeps for a time. Inside kernel I use FD to locate "struct file" 
from "current" pointer and save it for feature use. 
So now I have a way to write to file: file->f_op->write(..) or 
generic_file_write(..).
I use it when socket is closed. It works.. for me without any oops.

But I wanted to improve this:
If my linux box crashs I lost some info from sockets what was
alive for a long period of time... Or I lost info from sockets in listening
state. So I wanted to do a periodical dump of info to my logfile.
So I used timer to do it. But timer_func is executed in another context
or something else ... so now I have a panic(). As I can see from oops 
it complains about schedule in interrupt. 

So my questions are:
Is my way of dumping correct? If yes where i can find a bug or ... If no 
where I can read about better way? Or tell me here...

Thanks! :)
-- 
	Burchu Sergey.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

                 reply	other threads:[~2003-09-09 23:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030909233303.GA21519@joker.botik.ru \
    --to=sayd@joker.botik.ru \
    --cc=linux-newbie@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox