LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-28-2007, 07:25 PM   #1
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Rep: Reputation: 30
Angry problem in programming with inotify


Hello all, I would like to develop a pplication with inotify.
Now my code is stupid, but it does yet error.
When I try 'gcc myprogram.c -o myprogram' the output is:

/tmp/ccef8sAa.o(.text+0x1d): In function 'main':
:undefined reference to 'inotify_init'
collect2: ld retuned 1 exit status

It seems that it don't find inotify_init. I tried 'grep INOTIFY /boot/config' and output is:

CONFIG_INOTIFY=y
CONFIG_INOTIFY_USER=y

The command 'man inotify_init' return man page of above syscall.

What is the problem?
Is there someone that it can help me?

Thanks in advance,
Shift
 
Old 03-28-2007, 07:30 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
What version of glibc do you have?
Was it compiled with inotify support?
 
Old 03-28-2007, 08:00 PM   #3
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
Quote:
What version of glibc do you have?
I have a Slackware 11, then I suppose that I am using glibc-2.3.6.
Inotify.h did not present in /usr/include/sys, but I copied inotify.h from /usr/src/linux/fs


Quote:
Was it compiled with inotify support?
No, but I installed a precompiled kernel 2.6.18 provided with distribution (test26.s)
 
Old 03-28-2007, 08:44 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by shifter
No, but I installed a precompiled kernel 2.6.18 provided with distribution (test26.s)
If such is the case (i.e., your glibc has no built-in inotify support), you need to use the system calls directly. Your originally posted problem is a linking one and thus can be fixed if you identify your own inotify functions wrapping the linux system calls. E.g. (from inotify-syscalls.h):
Code:
#include <sys/syscall.h>

static inline int inotify_init (void)
{
	return syscall (__NR_inotify_init);
}

static inline int inotify_add_watch (int fd, const char *name, __u32 mask)
{
	return syscall (__NR_inotify_add_watch, fd, name, mask);
}

static inline int inotify_rm_watch (int fd, __u32 wd)
{
	return syscall (__NR_inotify_rm_watch, fd, wd);
}
And voila… no more undefined references.
 
Old 03-28-2007, 08:50 PM   #5
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
What are steps that I need to do exactly?
What I must add to code?

Thanks
 
Old 03-28-2007, 09:26 PM   #6
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by shifter
What are steps that I need to do exactly?
What I must add to code?

Thanks
You have a few options:
  • If you have a the file <sys/inotify-syscalls.h> in your include path, just include that file at the beginning of each source file you need it in.
  • Make your own inotify-syscalls.h header with the lines of the previous post (of course you need to surround the code with #ifndef _LINUX_INOTIFY_SYSCALLS_H\
    #define _LINUX_INOTIFY_SYSCALLS_H at the beginning and #endif at the end as is custom with C header files). Include it at the beginning of each source file you need it in.
  • Put the lines from the previous post at the beginning of each source file you need it in.
The important thing is to have the definitions of the wrapper functions (which will most likely be inlined anyway) visible to the rest of source, so they are not assumed by the compiler to reside in an external library (e.g., glibc), and so that the linker does not complain when they are not found in the aforementioned library.

Also, you might want to take a look at this (though it’s a bit old).
 
Old 03-30-2007, 05:28 AM   #7
gjo
Member
 
Registered: Aug 2004
Location: South India
Distribution: Fedora3,Xandros,WinXP
Posts: 53

Rep: Reputation: 15
check these also

sorry,it was a wrong thread...

Last edited by gjo; 04-04-2007 at 03:04 AM.
 
Old 03-30-2007, 08:32 AM   #8
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Are you sure you posted the above post in the correct thread?
 
Old 04-01-2007, 09:17 PM   #9
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
Exactly, what is __u32 in inotify?
The event->mask field in declared as __u32.
How can I to compare __u32 with an integer? for example '__u32 == IN_ACCESS'

Thanks in advance to help.
 
Old 04-01-2007, 10:42 PM   #10
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
Now my problem is the following:

if (event->mask & IN_ISDIR) printf("IS A DIRECTORY");

but gcc outputs 'error: dereferencing pointer to incomplete type'.
Now what is the problem????
I am despaired...

Last edited by shifter; 04-01-2007 at 10:44 PM.
 
Old 04-02-2007, 12:46 PM   #11
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by shifter
Exactly, what is __u32 in inotify?
The event->mask field in declared as __u32.
How can I to compare __u32 with an integer? for example '__u32 == IN_ACCESS'

Thanks in advance to help.
In case you did’t figure it out yet, __u32 is an unsigned 32-bit integer storage unit. It can be compared with a literal numeral value easily.

Quote:
Originally Posted by shifter
Now my problem is the following:

if (event->mask & IN_ISDIR) printf("IS A DIRECTORY");

but gcc outputs 'error: dereferencing pointer to incomplete type'.
Now what is the problem????
I am despaired...
In your code, is “event” a pointer to a struct inotify_event or is event itself a struct inotify_event? You can’t use pointer syntax with a struct (i.e., instead of “event->mask” try “event.mask”).
 
Old 04-02-2007, 08:20 PM   #12
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
Problem resolved, ...
The syntax is correct, but I did not declare correctly event structure.

event_inotify* event instead inotify_event*

Last edited by shifter; 04-02-2007 at 08:41 PM.
 
Old 06-21-2007, 06:14 PM   #13
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
Exist it a method for tracing if I make subdirectory into directory monitored with inotify (like IN_CREATE, IN_ATTRIB...)

Thanks to help in advance.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
udev and inotify aeruzcar Linux - General 3 03-24-2007 12:42 PM
Mounting Inotify? trscookie Linux - Software 1 12-19-2005 01:37 PM
inotify user instance limit??? brad182 Linux - Software 0 12-15-2005 05:41 PM
Is inotify worth it? aneel.d Linux - General 0 10-14-2005 10:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration