GNOME Bugzilla – Bug 305399
beagled.in magic
Last modified: 2005-06-09 19:19:35 UTC
The shell code below causes that if you use a command-line argument to beagled which exits immedietly (such as --help) you will recieve the message that the daemon exited with errors. Any shell script guru around? # If beagled (in --bg mode) has exited with some errors, we need # to inform the users about the same. This 500 milli-seconds sleep # is to wait for the daemon to start and exit, in case of errors ;) # Fixes http://bugzilla.gnome.org/show_bug.cgi?id=171975 sleep 0.5 BEAGLED_PID=`pidof -s $PROCESS_NAME` if [ x$BEAGLED_PID == x ] && [ $fg -ne 1 ]; then echo "Beagle Daemon exited with errors. See ~/.beagle/Log/current-Beagle for more details." fi
I don't think so because before the abovesaid shellcode, the following will get executed. if [ $fg -eq 1 ]; then exec -a $PROCESS_NAME $CMDLINE else exec -a $PROCESS_NAME $CMDLINE & fi So, depending upon the "--fg" or "--bg" flag the process will be exec'ed. IINW, the "--help" flag is handled within the "exec'ed" process and exits with a success status and hence the shell code in question will not output that the daemon exited with errors in case of "--help" and other "handled" flags. Correct me if I am wrong.
Now that I tried it again, it doesnt occur anymore, but I havent changed anything. This is strange.
I can duplicate this if I run "beagled --bg --help"
GNU Coding Standards dictate that --help should exit() with a succesful status: --help This option should output brief documentation for how to invoke the program, on standard output, then exit successfully. Other options and arguments should be ignored once this is seen, and the program should not perform its normal function.
Yeah, this doesn't really have anything to do with the exit status; --bg just invokes beagled in the background, and there's a timer to see if it's still running. With --help it will have exited before the timer expires. The whole system is pretty broken; but daemonizing in the standard Unix way doesn't work very well for mono.
Created attachment 47165 [details] [review] Solution How about something like this?
It still wouldn't work in the case of "beagled --help --bg", because $fg_user would be reset to 0. It's a fairly minor thing to fix, and probably the right approach overall. The "ps -p $!" thing won't work in the case of --fg, so you'd have to add a test back for whether we're running in the foreground and OR them together.
Yes, "--help --bg" wouldn't work right, but thats just silly anyway.. When you use --fg, beagled is run in the foreground through exec. exec _replaces_ the current shell (i.e. the beagled script) so whatever is below that will never get called in that situation.
Yeah, I guess "--help --bg" probably wouldn't come up. The --fg thing could come up if the exec fails for some reason.
*** Bug 306543 has been marked as a duplicate of this bug. ***
Ok, checked this into CVS with an added "exit 1" after the foreground exec. Any other problems?