Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
openfoam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
openfoam
Commits
a5ee1669
Commit
a5ee1669
authored
14 years ago
by
mattijs
Browse files
Options
Downloads
Patches
Plain Diff
ENH: fileMonitor : continue if inotify_init failed
parent
82eedb5b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/OSspecific/POSIX/fileMonitor.C
+45
-17
45 additions, 17 deletions
src/OSspecific/POSIX/fileMonitor.C
with
45 additions
and
17 deletions
src/OSspecific/POSIX/fileMonitor.C
+
45
−
17
View file @
a5ee1669
...
@@ -39,7 +39,7 @@ Class
...
@@ -39,7 +39,7 @@ Class
#else
#else
# include <sys/inotify.h>
# include <sys/inotify.h>
# include <sys/ioctl.h>
# include <sys/ioctl.h>
# include <errno.h>
# define EVENT_SIZE ( sizeof (struct inotify_event) )
# define EVENT_SIZE ( sizeof (struct inotify_event) )
# define EVENT_LEN (EVENT_SIZE + 16)
# define EVENT_LEN (EVENT_SIZE + 16)
# define EVENT_BUF_LEN ( 1024 * EVENT_LEN )
# define EVENT_BUF_LEN ( 1024 * EVENT_LEN )
...
@@ -144,7 +144,7 @@ namespace Foam
...
@@ -144,7 +144,7 @@ namespace Foam
#else
#else
//- File descriptor for the inotify instance
//- File descriptor for the inotify instance
int
fd
;
int
inotifyFd_
;
//- Current watchIDs and corresponding directory id
//- Current watchIDs and corresponding directory id
DynamicList
<
label
>
dirWatches_
;
DynamicList
<
label
>
dirWatches_
;
...
@@ -153,23 +153,39 @@ namespace Foam
...
@@ -153,23 +153,39 @@ namespace Foam
//- initialise inotify
//- initialise inotify
inline
fileMonitorWatcher
(
const
label
sz
=
20
)
inline
fileMonitorWatcher
(
const
label
sz
=
20
)
:
:
fd
(
inotify_init
()),
inotifyFd_
(
inotify_init
()),
dirWatches_
(
sz
),
dirWatches_
(
sz
),
dirFiles_
(
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
//- remove all watches
inline
~
fileMonitorWatcher
()
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()"
)
if
(
inotify_rm_watch
(
inotifyFd_
,
int
(
dirWatches_
[
i
])))
<<
"Failed deleting directory watch "
{
<<
dirWatches_
[
i
]
<<
endl
;
WarningIn
(
"fileMonitor::~fileMonitor()"
)
<<
"Failed deleting directory watch "
<<
dirWatches_
[
i
]
<<
endl
;
}
}
}
}
}
}
}
...
@@ -177,10 +193,15 @@ namespace Foam
...
@@ -177,10 +193,15 @@ namespace Foam
inline
bool
addWatch
(
const
label
watchFd
,
const
fileName
&
fName
)
inline
bool
addWatch
(
const
label
watchFd
,
const
fileName
&
fName
)
{
{
if
(
inotifyFd_
<
0
)
{
return
false
;
}
// Add/retrieve watch on directory containing file
// Add/retrieve watch on directory containing file
label
dirWatchID
=
inotify_add_watch
label
dirWatchID
=
inotify_add_watch
(
(
fd
,
inotifyFd_
,
fName
.
path
().
c_str
(),
fName
.
path
().
c_str
(),
IN_CLOSE_WRITE
IN_CLOSE_WRITE
);
);
...
@@ -189,7 +210,8 @@ namespace Foam
...
@@ -189,7 +210,8 @@ namespace Foam
{
{
FatalErrorIn
(
"addWatch(const label, const fileName&)"
)
FatalErrorIn
(
"addWatch(const label, const fileName&)"
)
<<
"Failed adding watch "
<<
watchFd
<<
"Failed adding watch "
<<
watchFd
<<
" to directory "
<<
fName
<<
" to directory "
<<
fName
<<
" due to "
<<
string
(
strerror
(
errno
))
<<
exit
(
FatalError
);
<<
exit
(
FatalError
);
}
}
...
@@ -209,6 +231,11 @@ namespace Foam
...
@@ -209,6 +231,11 @@ namespace Foam
inline
bool
removeWatch
(
const
label
watchFd
)
inline
bool
removeWatch
(
const
label
watchFd
)
{
{
if
(
inotifyFd_
<
0
)
{
return
false
;
}
dirWatches_
[
watchFd
]
=
-
1
;
dirWatches_
[
watchFd
]
=
-
1
;
return
true
;
return
true
;
}
}
...
@@ -263,11 +290,11 @@ void Foam::fileMonitor::checkFiles() const
...
@@ -263,11 +290,11 @@ void Foam::fileMonitor::checkFiles() const
fd_set
fdSet
;
fd_set
fdSet
;
// Add notify descriptor to select fd_set
// Add notify descriptor to select fd_set
FD_ZERO
(
&
fdSet
);
FD_ZERO
(
&
fdSet
);
FD_SET
(
watcher_
->
fd
,
&
fdSet
);
FD_SET
(
watcher_
->
inotifyFd_
,
&
fdSet
);
int
ready
=
select
int
ready
=
select
(
(
watcher_
->
fd
+
1
,
// num filedescriptors in fdSet
watcher_
->
inotifyFd_
+
1
,
// num filedescriptors in fdSet
&
fdSet
,
// fdSet with only inotifyFd
&
fdSet
,
// fdSet with only inotifyFd
NULL
,
// No writefds
NULL
,
// No writefds
NULL
,
// No errorfds
NULL
,
// No errorfds
...
@@ -280,15 +307,15 @@ void Foam::fileMonitor::checkFiles() const
...
@@ -280,15 +307,15 @@ void Foam::fileMonitor::checkFiles() const
<<
"Problem in issuing select."
<<
"Problem in issuing select."
<<
abort
(
FatalError
);
<<
abort
(
FatalError
);
}
}
else
if
(
FD_ISSET
(
watcher_
->
fd
,
&
fdSet
))
else
if
(
FD_ISSET
(
watcher_
->
inotifyFd_
,
&
fdSet
))
{
{
// Read events
// 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
)
if
(
nBytes
<
0
)
{
{
FatalErrorIn
(
"fileMonitor::updateStates(const fileName&)"
)
FatalErrorIn
(
"fileMonitor::updateStates(const fileName&)"
)
<<
"read of "
<<
watcher_
->
fd
<<
"read of "
<<
watcher_
->
inotifyFd_
<<
" failed with "
<<
label
(
nBytes
)
<<
" failed with "
<<
label
(
nBytes
)
<<
abort
(
FatalError
);
<<
abort
(
FatalError
);
}
}
...
@@ -364,6 +391,7 @@ Foam::label Foam::fileMonitor::addWatch(const fileName& fName)
...
@@ -364,6 +391,7 @@ Foam::label Foam::fileMonitor::addWatch(const fileName& fName)
label
watchFd
;
label
watchFd
;
label
sz
=
freeWatchFds_
.
size
();
label
sz
=
freeWatchFds_
.
size
();
if
(
sz
)
if
(
sz
)
{
{
watchFd
=
freeWatchFds_
[
sz
-
1
];
watchFd
=
freeWatchFds_
[
sz
-
1
];
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment