UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2006-07-04 07:59 PM

thinking
Member
Registered: 2005-09-15
Posts: 103

Re: how to reading config data on the fly?

[email protected]

i'm running a self written server, which should be able to read new config data on the fly

the idea behind this:
the problem i currently have, is logging
i have a bit logging in my server, but there are no log levels
so i thought about using something like apache (reading a config file with a logging level and then just use it)
but in the past few hours there have been some problems with my server and i thought: "a higher log level would be better now"
but this would mean, restart the server

one solution would be using a signal to tell the server something has changed (like SIGHUP)
well, it's a possibility (but it's not very elegant ;-) )

then i thought about /proc directory
for example if you change the value in /proc/sys/net/ipv4/ip_forward you cann disable/enable ip forwarding on the fly, not?

Q1: how can one (many would be better) process (processes) read a config file, which is reread if changed?
Q2: how does the kernel do this stuff with /proc?
Q3: is there a way to do it as smart as the kernel does (with /proc)?

i thought about using a named pipe in the file system
and every process who needs the value reads (using select();) from it
the problem: afaik, only one process get's notified for reading the new data
this means, i would need a one to many IPC

keep in mind, the primary goal was:
changing the log level of one (better would be many) process(es) on the fly without restarting the server
and that's what i will use it most

[email protected]

Offline

#2 2006-07-05 12:32 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: how to reading config data on the fly?

Offline

#3 2006-07-05 04:53 PM

thinking
Member
Registered: 2005-09-15
Posts: 103

Re: how to reading config data on the fly?

thx rob
inotify sounds interesting
but since i have an old kernel too
it won't work

but i think i will try F_NOTIFY using fcntl(); function
this only works with directories, afaik

well i think there is another problem with this
cause this method would reload the file everytime it gets changed

for someone like me, this would mean,
if the file is currently edited by an admin, and he saves the changes currently made, but need to continue and change some more values
the wrong values would be loaded
but i think i can do a workaround using a timestamp and waiting a few minutes after the change or just using signals

Offline

#4 2006-07-05 08:20 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: how to reading config data on the fly?

Yeah, that fcntl(F_NOTIFY) is the old, much maligned "dnotify" interface that
no one liked very much...

You know, I think you're really putting too much thought/effort into something that's
probably not going to be that useful very much, anyway...  I'd say you'd probably be
best off just going with the fairly standard method of making the user hit you with
SIGHUP if they want you to reload the config file...  (Yes, signals are ugly, but if
you're going to go with dnotify, you're stuck with a signal interface, anyway...)  That
way, you don't have to worry about situations like you mention, where a change is
incomplete, and the file might not be in a properly parsable state (or may parse as
something unintended)...  Lots of daemons behave this way (syslogd, Apache httpd,
etc.), so it's a fairly standard, expected thing...

Or, you don't really specify what the server is doing, but maybe it's feasable to add
a command to its normal protocol handling to do the log-level changing on the fly?
Then, you'd just have a normal client connect to it and do the changing...  Or, if it's
not a network server (or you don't want normal clients being able to change such
stuff), maybe have it listening on a separate Unix-domain socket for such messages
instead, and create a specialized client to connect to it that way and change the
level... *shrug*

Offline

#5 2006-07-06 10:06 AM

thinking
Member
Registered: 2005-09-15
Posts: 103

Re: how to reading config data on the fly?

Offline

#6 2006-07-06 11:12 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: how to reading config data on the fly?

The signal stuff, notifications on directories only, not knowing what changed, and being not portable more or less sums it up. But if yo're already using a signal to trigger the config reload then the signal stuff is fine, and just adding dotify support as an addon is easy enough.

Offline

#7 2006-07-06 01:44 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: how to reading config data on the fly?

Offline

#8 2006-07-06 06:57 PM

thinking
Member
Registered: 2005-09-15
Posts: 103

Re: how to reading config data on the fly?

lol
[email protected]

@i3839
F_NOTIFY not being "portable" means, that dnotify is portable?
on windows too?
i'm just asking cause of interest

Offline

#9 2006-07-06 07:20 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: how to reading config data on the fly?

F_NOTIFY and dnotify are synonym.

Dnotify/F_NOTIFY is Linux specific and won't work on other systems, because they don't have it. Most of the time they have something else which can achieve the same thing though, which again isn't portable to other systems either.

When I say other systems or "not portable" I have posix systems in mind. Windows is out of leage anyway considering portability, you should be happy if different releases are backward compatible. It doesn't even have fcntl() as far as I know. Windows isn't interesting.

If you need portable file notification then use something like fam or gamin, but hacking up system specific notification code is easy enough, if you don't do fancy things.

Offline

Board footer

Powered by FluxBB