Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
a5ee1669
Commit
a5ee1669
authored
Oct 19, 2010
by
mattijs
Browse files
ENH: fileMonitor : continue if inotify_init failed
parent
82eedb5b
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/OSspecific/POSIX/fileMonitor.C
View file @
a5ee1669
...
...
@@ -39,7 +39,7 @@ Class
#else
# include <sys/inotify.h>
# include <sys/ioctl.h>
# include <errno.h>
# define EVENT_SIZE ( sizeof (struct inotify_event) )
# define EVENT_LEN (EVENT_SIZE + 16)
# define EVENT_BUF_LEN ( 1024 * EVENT_LEN )
...
...
@@ -144,7 +144,7 @@ namespace Foam
#else
//- File descriptor for the inotify instance
int
fd
;
int
inotifyFd_
;
//- Current watchIDs and corresponding directory id
DynamicList
<
label
>
dirWatches_
;
...
...
@@ -153,23 +153,39 @@ namespace Foam
//- initialise inotify
inline
fileMonitorWatcher
(
const
label
sz
=
20
)
:
fd
(
inotify_init
()),
inotifyFd_
(
inotify_init
()),
dirWatches_
(
sz
),
dirFiles_
(
sz
)
{}
{
if
(
inotifyFd_
<
0
)
{
WarningIn
(
"fileMonitorWatcher(const label)"
)
<<
"Failed allocating an inotify descriptor : "
<<
string
(
strerror
(
errno
))
<<
endl
<<
" Please increase the number of allowable "
<<
"inotify instances"
<<
endl
<<
" (/proc/sys/fs/inotify/max_user_instances on Linux)"
<<
endl
<<
" Continuing without additional file monitoring."
<<
endl
;
}
}
//- remove all watches
inline
~
fileMonitorWatcher
()
{
forAll
(
dirWatches_
,
i
)
if
(
inotifyFd_
>=
0
)
{
if
(
dirWatches_
[
i
]
>=
0
)
forAll
(
dirWatches_
,
i
)
{
if
(
inotify_rm_watch
(
fd
,
int
(
dirWatches_
[
i
]
))
)
if
(
dirWatches_
[
i
]
>=
0
)
{
WarningIn
(
"fileMonitor::~fileMonitor()"
)
<<
"Failed deleting directory watch "
<<
dirWatches_
[
i
]
<<
endl
;
if
(
inotify_rm_watch
(
inotifyFd_
,
int
(
dirWatches_
[
i
])))
{
WarningIn
(
"fileMonitor::~fileMonitor()"
)
<<
"Failed deleting directory watch "
<<
dirWatches_
[
i
]
<<
endl
;
}
}
}
}
...
...
@@ -177,10 +193,15 @@ namespace Foam
inline
bool
addWatch
(
const
label
watchFd
,
const
fileName
&
fName
)
{
if
(
inotifyFd_
<
0
)
{
return
false
;
}
// Add/retrieve watch on directory containing file
label
dirWatchID
=
inotify_add_watch
(
fd
,
inotifyFd_
,
fName
.
path
().
c_str
(),
IN_CLOSE_WRITE
);
...
...
@@ -189,7 +210,8 @@ namespace Foam
{
FatalErrorIn
(
"addWatch(const label, const fileName&)"
)
<<
"Failed adding watch "
<<
watchFd
<<
" to directory "
<<
fName
<<
" to directory "
<<
fName
<<
" due to "
<<
string
(
strerror
(
errno
))
<<
exit
(
FatalError
);
}
...
...
@@ -209,6 +231,11 @@ namespace Foam
inline
bool
removeWatch
(
const
label
watchFd
)
{
if
(
inotifyFd_
<
0
)
{
return
false
;
}
dirWatches_
[
watchFd
]
=
-
1
;
return
true
;
}
...
...
@@ -263,11 +290,11 @@ void Foam::fileMonitor::checkFiles() const
fd_set
fdSet
;
// Add notify descriptor to select fd_set
FD_ZERO
(
&
fdSet
);
FD_SET
(
watcher_
->
fd
,
&
fdSet
);
FD_SET
(
watcher_
->
inotifyFd_
,
&
fdSet
);
int
ready
=
select
(
watcher_
->
fd
+
1
,
// num filedescriptors in fdSet
watcher_
->
inotifyFd_
+
1
,
// num filedescriptors in fdSet
&
fdSet
,
// fdSet with only inotifyFd
NULL
,
// No writefds
NULL
,
// No errorfds
...
...
@@ -280,15 +307,15 @@ void Foam::fileMonitor::checkFiles() const
<<
"Problem in issuing select."
<<
abort
(
FatalError
);
}
else
if
(
FD_ISSET
(
watcher_
->
fd
,
&
fdSet
))
else
if
(
FD_ISSET
(
watcher_
->
inotifyFd_
,
&
fdSet
))
{
// Read events
ssize_t
nBytes
=
read
(
watcher_
->
fd
,
buffer
,
EVENT_BUF_LEN
);
ssize_t
nBytes
=
read
(
watcher_
->
inotifyFd_
,
buffer
,
EVENT_BUF_LEN
);
if
(
nBytes
<
0
)
{
FatalErrorIn
(
"fileMonitor::updateStates(const fileName&)"
)
<<
"read of "
<<
watcher_
->
fd
<<
"read of "
<<
watcher_
->
inotifyFd_
<<
" failed with "
<<
label
(
nBytes
)
<<
abort
(
FatalError
);
}
...
...
@@ -364,6 +391,7 @@ Foam::label Foam::fileMonitor::addWatch(const fileName& fName)
label
watchFd
;
label
sz
=
freeWatchFds_
.
size
();
if
(
sz
)
{
watchFd
=
freeWatchFds_
[
sz
-
1
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment