Attached is a small patch to NGIRCd CVS that writes the daemons pid to a file (Default: /var/run/ngircd/ngircd.pid).
The pidfile can be changed via the -P <pidfile> or --pidfile <pidfile> options.
The getpid.sh script included with ngircd does not work on FreeBSD 5.3-Stable (ps needs -ax switches). Also, the sample configuration file says 'one port, separated with ";"' ( the given example uses the correct "," seperator).
Thanks, Florian
Hi Florian!
Attached is a small patch to NGIRCd CVS that writes the daemons pid to a file (Default: /var/run/ngircd/ngircd.pid).
Your approach won't work when using the REHASH command or sending the daemon a SIGHUP: ngIRCd forks a new process which possibly doesn't run with root privileges and/or chroot()'ed. The the pid-file can't be written.
A possible solution should be (untested):
in main(): - open/create pid file with before dropping privileges and remember its file handle, - unlink the file. - call Write_Pidfile() inside the main loop. - close the file before exiting.
Write_Pidfile() should truncate the pid file (ftruncate) and write the PID into it. It shouldn't open and close it.
The getpid.sh script included with ngircd does not work on FreeBSD 5.3-Stable (ps needs -ax switches).
Hm, this script is only intended to be used by the "test suite" and I thought(!) that I tested it on FreeBSD 5 ... I'll re-test it.
Also, the sample configuration file says 'one port, separated with ";"' ( the given example uses the correct "," seperator).
Thanks, fixed in CVS-HEAD.
Regards Alex
Alexander Barton alex@barton.de wrote:
Your approach won't work when using the REHASH command or sending the daemon a SIGHUP: ngIRCd forks a new process which possibly doesn't run with root privileges and/or chroot()'ed. The the pid-file can't be written.
# ps awux | grep ircd ircd 36023 0.0 0.1 2912 2580 ?? Ss Sun10AM 0:37.29 /usr/local/sbin/ngircd root 57004 0.0 0.0 1516 856 p0 RL+ 2:03PM 0:00.00 grep ircd # kill -HUP 36023 # ps awux | grep ircd ircd 36023 0.0 0.1 2912 2580 ?? Ss Sun10AM 0:37.31 /usr/local/sbin/ngircd root 57009 0.0 0.0 1516 692 p0 RL+ 2:04PM 0:00.00 grep ircd
It _DOES_ reread the config file, though (i changed the motd) I looked at the code... NGIRCd_SignalRestart is set to FALSE just at the beginning of the main loop int ngircd.c (around line 236 or so)... Hmmm... Why would you want it to fork()?
(everything is the same for /REHASH)
A possible solution should be (untested):
in main():
- open/create pid file with before dropping privileges
Yes, i thought about this. This would also eliminate the need to have a writeable file in the chroot. (So yes, I agree my patch is not optimal ;-) )
- unlink the file.
- call Write_Pidfile() inside the main loop.
- close the file before exiting.
I don't understand... Why would i need a pid file that i can't see from the outside of the process? (FreeBSD startup scripts would need a "permanent" pid in order to work properly i.e.:
# /usr/local/etc/rc.d/ngircd.sh status ngircd is running as pid 36023.
Thanks, Florian
Hi Florian!
It _DOES_ reread the config file, though (i changed the motd) I looked at the code... NGIRCd_SignalRestart is set to FALSE just at the beginning of the main loop int ngircd.c (around line 236 or so)... Hmmm... Why would you want it to fork()?
(everything is the same for /REHASH)
Ah, yes ... I meant RESTART ...
When ngIRCd (re-)starts it forks a child process to detach itself off the console and "go to background".
<alex@Alex-PC:~> $ ps ax|grep ngircd 15373 ? Ss 0:00 /opt/ngircd/HEAD/sbin/ngircd 17214 pts/3 R+ 0:00 grep ngircd *** Connect, become IRC operator and issue RESTART command ... *** <alex@Alex-PC:~> $ ps ax|grep ngircd 17246 ? Ss 0:00 /opt/ngircd/HEAD/sbin/ngircd 17267 pts/3 S+ 0:00 grep ngircd
A possible solution should be (untested):
in main():
- open/create pid file with before dropping privileges
Yes, i thought about this. This would also eliminate the need to have a writeable file in the chroot. (So yes, I agree my patch is not optimal ;-) )
;-)
- unlink the file.
- call Write_Pidfile() inside the main loop.
- close the file before exiting.
I don't understand... Why would i need a pid file that i can't see from the outside of the process?
Right, this is nonsense. Until now I thought that the directory entry is removed not until the file is closed. But this is wrong, the unlink() can only be done when ngIRCd shuts down.
Regards Alex
Alexander Barton alex@barton.de wrote:
Ah, yes ... I meant RESTART ...
Ok, forget the other mail I sent, then 8-)
I'll see if I can redo the pidfile patch without changing too much. (It might take a few days, though)
Thanks, Florian
Florian Westphal westphal@foo.fh-furtwangen.de wrote:
I looked at the code...
... but not careful enough...
NGIRCd_SignalRestart is set to FALSE just at the beginning of the main loop
... but this seems completely irrelevant ...
From what i could piece together: ngircd gets SIGHUP, sighandler sets NGIRCd_SignalRehash = TRUE.
Conn_Handler() (in conn.c) checks: if( NGIRCd_SignalRehash ) NGIRCd_Rehash( );
ngircd.c: NGIRCd_Rehash() calls Conn_{Exit,INIT}Listeners( )... and sets NGIRCd_SignalRehash back to FALSE.