Subject: bin/15769: usbhidaction exits after first command if relative path is used for config file
To: None <gnats-bugs@gnats.netbsd.org>
From: None <kivinen@ssh.fi>
List: netbsd-bugs
Date: 03/01/2002 00:05:04
>Number:         15769
>Category:       bin
>Synopsis:       usbhidaction exits after first command if relative path is used for config file
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Feb 28 14:08:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Tero Kivinen
>Release:        NetBSD 1.5ZA
>Organization:
SSH Communications Security
>Environment:
System: NetBSD haste.acr.fi 1.5ZA NetBSD 1.5ZA (HASTE) #11: Thu Feb 28 02:29:30 EET 2002 ztk@haste.acr.fi:/usr/src/sys/arch/i386/compile/HASTE i386
Architecture: i386
Machine: i386
>Description:

	If I start "usbhidaction -f 0 -c msxpkbd.hidctl" then it will
	only execute one operation from the config file and exit
	immediately after that. If I use "usbhidaction -f 0 -c
	/u/kivinen/msxpkbd.hidctl" then it will work normally. Also if I
	use "usbhidaction -d -f 0 -c msxpkbd.hidctl" or "usbhidaction
	-v -f 0 -c msxpkbd.hidctl" then it also works.

	Usbhidaction will exit after first command if I am running it
	as a deamon AND the config file path was given as relative
	path. The reason is that when usbhidaction is run as daemon it
	does daemon(0, 0) call, and that will do chdir("/"). When the
	first command is executed then the main loop will immediately
	try to reparse the config file because the global variable
	reparse is initialized to 1. Now because the chdir the
	parse_conf does not find the config file and instead of simply
	reporting that to the upper layer (which would then ignore the
	reparse and continue with old data) it calls err(1, "%s",
	conf) which now exits WITHOUT any error messages (as we are
	running as daemon, which means that the error messages to
	stdout/stderr are lost). 

>How-To-Repeat:

	Run "usbhidaction -f 0 -c config" and try to do two operations. 

>Fix:

	There are several things to fix.

	1) usbhidaction should print out errors to syslog instead of
	stderr, if running as daemon.

	2) usbhidaction should not reparse the config file immediately
	when it starts, only after receiving sigint (i.e change "int
	reparse = 1;" to "int reparse = 0;").

	3) usbhidaction should try to convert the config file name to
	absolute path before doing the daemon (i.e do getcwd and
	prepend that to the config file name if it does not start with /). 
>Release-Note:
>Audit-Trail:
>Unformatted:
 Last update Feb 27 2002