Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
kernel module programming question
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
Clansman
Tux's lil' helper
Tux's lil' helper


Joined: 10 Jan 2004
Posts: 140

PostPosted: Thu Oct 14, 2004 1:20 pm    Post subject: kernel module programming question Reply with quote

hi everyone,

not sure if i'd post here or in kernel & hardware. can't harm putting it here.

i made a very simple kernel module that creates a /proc file and it counts the number of accesses to itself.

the problem is that the counter gets incremented by steps of 2 or 3 instead of 1.

i mean catting the file once i get counter value=1, then catting it again i get counter value=4 and so on...

stracing the "cat /proc/new/info" results in 1 open of the file and one read. still those are 2 accesses and not 3. to be sure i made a program that just opens and closes the file to see if the counter got updated. it didn't...

what could be happening here?

thanks.
[]
Back to top
View user's profile Send private message
Athas
Guru
Guru


Joined: 04 Sep 2003
Posts: 394
Location: Brøndby, Denmark

PostPosted: Thu Oct 14, 2004 1:43 pm    Post subject: Reply with quote

If you could post some code, it would be great.
_________________
Emacs-optimized danish console keymap - My .emacs
Climacs - next generation Emacs.
Back to top
View user's profile Send private message
Clansman
Tux's lil' helper
Tux's lil' helper


Joined: 10 Jan 2004
Posts: 140

PostPosted: Thu Oct 14, 2004 2:39 pm    Post subject: Reply with quote

feedback :D

ok, i could post the entire code but that would be big. i'd start by the read_proc function:

Code:

/*
 * read_proc function
 *
 */
static int hackalot_proc_info (char *page,char **start,off_t off,int count,int *eof,void *data)
{
   int size;
   /* just print information */
   size=sprintf(page, "%s %d %s\n",HACKALOT_INFO_D1,counter,HACKALOT_INFO_D2);
   if(size>0)
      ++counter;
   return(size);
}


right now it's a bit different. the counter variable is properly locked via atomic operations and the size>0 check is no longer. it doesn't make a difference.
still the behaviour is not the expected.

thanks.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum