Unix Programming - POSIX Mistake: rewinddir returns no errors!

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > February 2007 > POSIX Mistake: rewinddir returns no errors!





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author POSIX Mistake: rewinddir returns no errors!
unix_fan

2007-02-22, 7:19 am

What is the best way to poll a directory for the arrival of files?

The OpenGroup
(http://www.opengroup.org/onlinepubs...sh/readdir.html)
says:

If a file is removed from or added to the directory after the most
recent call to opendir() or rewinddir(), whether a subsequent call to
readdir() returns an entry for that file is unspecified.

This would seem to identify rewinddir() as a reliable
synchronization point - a place where the system re-scans the directory on
the disk.

But rewinddir() doesn't return any error messages!

That would imply that no disk I/O is necessary.

This seems to me to be a specification bug. Is that correct?

A related question - what is the cost of an opendir()? If rewinddir()
really does check in with the disk, then what is the cost difference
between opendir() and rewinddir()?

Maybe I'll just use closedir()/opendir() to be safe (but that seems
unfortunate).

Spoon

2007-02-22, 7:19 am

unix_fan wrote:

> What is the best way to poll a directory for the arrival of files?


What is _your_ definition of "the best way" ?

The most portable?
The most efficient in terms of processing ressources?
The easiest to write?
Something else?

> The OpenGroup
> (http://www.opengroup.org/onlinepubs...sh/readdir.html)
> says:


This spec is more recent:
http://www.opengroup.org/onlinepubs...ns/readdir.html

In Linux, you might want to take a look at inotify.

cf. Documentation/filesystems/inotify.txt
http://lxr.free-electrons.com/sourc...ems/inotify.txt

"Inotify is a file change notification system and a replacement for
dnotify. Inotify fixes numerous shortcomings in dnotify and introduces
several new features including multiple file events, one-shot support,
and unmount notification."

Regards.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com