After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 305399 - beagled.in magic
beagled.in magic
Status: RESOLVED FIXED
Product: beagle
Classification: Other
Component: General
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Beagle Bugs
Beagle Bugs
: 306543 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2005-05-25 07:08 UTC by Lukas Lipka
Modified: 2005-06-09 19:19 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Solution (2.41 KB, patch)
2005-06-02 21:37 UTC, Daniel Drake
committed Details | Review

Description Lukas Lipka 2005-05-25 07:08:34 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
Comment 1 Veerapuram Varadhan 2005-05-25 12:02:06 UTC
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.
Comment 2 Lukas Lipka 2005-05-25 13:59:31 UTC
Now that I tried it again, it doesnt occur anymore, but I havent changed
anything.  This is strange.
Comment 3 Joe Shaw 2005-06-02 18:40:08 UTC
I can duplicate this if I run "beagled --bg --help"
Comment 4 Wouter Bolsterlee (uws) 2005-06-02 19:11:29 UTC
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.
Comment 5 Joe Shaw 2005-06-02 19:30:31 UTC
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.
Comment 6 Daniel Drake 2005-06-02 21:37:58 UTC
Created attachment 47165 [details] [review]
Solution

How about something like this?
Comment 7 Joe Shaw 2005-06-02 22:11:52 UTC
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.
Comment 8 Daniel Drake 2005-06-02 22:40:40 UTC
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.
Comment 9 Joe Shaw 2005-06-03 02:18:59 UTC
Yeah, I guess "--help --bg" probably wouldn't come up.

The --fg thing could come up if the exec fails for some reason.
Comment 10 Daniel Drake 2005-06-05 13:35:05 UTC
*** Bug 306543 has been marked as a duplicate of this bug. ***
Comment 11 Daniel Drake 2005-06-06 19:24:29 UTC
Ok, checked this into CVS with an added "exit 1" after the foreground exec. Any
other problems?