[fpc-pascal] Re: Configuration file handling

Reinier Olislagers reinierolislagers at gmail.com
Sat Feb 16 09:37:34 CET 2013

On 16-2-2013 9:09, Sven Barth wrote:
> On 15.02.2013 23:54, Mark Morgan Lloyd wrote:
>> If multiple, related, programs running on unix (Linux, Solaris etc.)
>> refer to the same configuration file accessed via a TIniFile, is there
>> any recommended "good practice" to ensure that they don't try to update
>> it simultaneously?
>> In the case that I'm thinking of, I don't anticipate e.g. multiple
>> logins trying to write setup information at the same time. The more
>> risky case is if there are e.g. multiple daemons or apps trying to save
>> state when a UPS signals imminent shutdown.
> This might be for Windows, but I think this applies here as well:
> http://blogs.msdn.com/b/oldnewthing/archive/2004/11/22/267890.aspx

Security problems with world-writable files? Yes, that problem applies
to *nix as well but Mark has given no indication his config files are
world-writable. (Even if the logins Mark speaks of run under different
user accounts, there's such a thing as groups on *nix, too :) )

UPS shutdown: no experience with that - I'd expect the process to just
get a regular kill signal; perhaps the OS/UPS driver provides dbus (or
other messaging layer) notifications.

If the data is not that important, wouldn't a naive approach like a loop
- repeats say max 3x,
- tries to save the data,
- catching exceptions coming from TIniFile, then waiting a random small
amount of time
- giving up after those 3x

Obviously, this problem would be alleviated if you run under multiple
different accounts (normal applications) and properly save settings
somewhere in the user's ~ directory rather than a systemwide path (which
the FPC getconfig... forgot exactly supports).

More information about the fpc-pascal mailing list