By default, Bugzilla does not search the list of RESOLVED bugs.
You can force it to do so by putting the upper-case word ALL in front of your search query, e.g.: ALL tdelibs
We recommend searching for bugs this way, as you may discover that your bug has already been resolved and fixed in a later release.

Bug 888

Summary: kinit: fprintf(stderr, "tdeinit: PID %ld terminated.\n", (long) exit_pid);
Product: TDE Reporter: Darrell <darrella>
Component: tdelibsAssignee: Timothy Pearson <kb9vqf>
Status: RESOLVED FIXED    
Severity: minor CC: bugwatch, darrella, kb9vqf, michele.calgaro, slavek.banko
Priority: P1    
Version: R14.0.0 [Trinity]   
Hardware: Other   
OS: Other   
Compiler Version: TDE Version String:
Application Version: Application Name: kinit
Attachments: Patch to convert fprintf->kdDebug and comment out message
Patch to disable single fprintf message and nominal string cleanup

Description Darrell 2012-03-02 13:13:49 CST
This message is from tdelibs/kinit/kinit.cpp. They appear in the xession log.

The messages seem to be intended as debugging aids. Yet they lack information. The messages should include the process name too.

Like this:

PID 10804 (process name) terminated.

With that information the message might remain useful only to developers for debugging, but at least the message appears useful and informational to curious users.

Adding the process name adds professional polish.
Comment 1 Darrell 2013-05-23 17:36:51 CDT
Tim, as you recently have been fixing debugging messages, could you hack at this one too?
Comment 2 Darrell 2013-09-09 11:49:46 CDT
Considering recent patches that now invoke previously unseen kderror and kdwarning messages (bug report 1655, Commit 5354555 2013-08-26), addressing this bug report would be helpful toward debugging and resolving what has become too much stdout/stderr spew.

"PID xxxx terminated" provides no useful information. :-)

A more useful message:

PID xxxx terminated (process name/description).

Trivial note: the code is now located in tdelibs/tdeinit/tdeinit.cpp:1354.
Comment 3 Michele Calgaro 2013-11-21 07:26:18 CST
> PID xxxx terminated (process name/description).

AFAICT, that is not possible. The fprintf is called when waitpid returns a non-zero value, i.e. when a child process has been terminated.

  exit_pid = waitpid(-1, 0, WNOHANG);

At that point, the child process no longer exists, so it is not possible to get the process name for it. 
Perhaps I am wrong, but I also googled extensively and didn't find anything about this that I didn't already know.

One solution would be to store the process names and pids in a symbol table, but that would be to heavy to do since:
1) we would have to update the symbol table continuously to detect new child processes spawn and process terminated
2) each single update operation requires accessing a file in /proc/$pid/cmdline

Since the message is inside an #ifndef NDEBUG block, you could compile the NDEBUG option to hide the message (and several others as well).

If no one has anything else to say on this, I suggest we close this bug.
Comment 4 Darrell 2013-11-21 13:32:31 CST
Looks like the following snippet has existed since 3.5.10:

#ifndef NDEBUG
  fprintf(stderr, "kdeinit: PID %ld terminated.\n", (long) exit_pid);
#endif

I have a 3.5.10 virtual machine. I don't see these messages. The likely reason is the 3.5.10 packages never were built with debugging enabled and that makes sense.

I only saw the messages after I started participating in the Trinity project.

From a developer's perspective, building packages with debugging enabled makes much sense and is much needed. My problem with this particular message is the message provides nothing useful. Instead the message provides a lot of clutter spew in the user's xsession-error log.

If there is no method to reveal the process name, and I accept as much, then why don't we delete that three-line snippet from the code? Or, if the message is useful in certain development areas (I'd like to learn more), rather than use fprintf, use kdebug such that the message can be disabled using kdebugdialog?
Comment 5 Timothy Pearson 2013-11-21 14:37:43 CST
Let's change this to an appropriate kdDebug statement and comment out the resultant line for now.

Tim
Comment 6 Darrell 2013-11-21 15:04:52 CST
Okay. Michele, please let me attempt the patch and you approve. I need to learn. :-)
Comment 7 Darrell 2013-11-21 15:37:02 CST
Created attachment 1660 [details]
Patch to convert fprintf->kdDebug and comment out message

Michele, please provide a sanity check of the patch. I haven't yet tested. Thanks.
Comment 8 Michele Calgaro 2013-11-22 00:56:01 CST
Hi Darrell, I would suggest something like this:

#ifndef NDEBUG
  kdDebug() << "[tdeinit] PID " << (long) exit_pid << " terminated.\n" << endl;
#endif

No point to keep the old code commented, since we can trace that from GIT if we need. The code is not commented, since the debug message can be enable/disable by kdebugdialog.
Also please note the space before "terminated" that was missing.

In the same file there are several "#ifndef NDEBUG" blocks that use fprintf to write messages. For consistency, you should change all of them to kdDebug as well
Comment 9 Darrell 2013-11-22 11:09:40 CST
If all fprintf strings are converted to kdDebug:

* Why would we need '#ifndef NDEBUG' qualifiers? Should they be deleted?

* Currently kdDebug() is global whereas kdDebug(xxxx) provides a method to silence specific kdDebug messages. Which kdDebug(xxxx) code should be used?
Comment 10 Darrell 2013-11-22 11:15:49 CST
I don't want to tinker with converting the fprintf->kdDebug. We have bug 1710 to address that issue.
Comment 11 Michele Calgaro 2013-11-24 01:55:35 CST
(In reply to comment #9)
> If all fprintf strings are converted to kdDebug:
> 
> * Why would we need '#ifndef NDEBUG' qualifiers? Should they be deleted?
Good point! I should have thought of that too :(

> * Currently kdDebug() is global whereas kdDebug(xxxx) provides a method to
> silence specific kdDebug messages. Which kdDebug(xxxx) code should be used?
I am not on a TDE computer now, but I can check later (or tomorrow).

> I don't want to tinker with converting the fprintf->kdDebug. We have bug 1710
> to address that issue.
Then perhaps we could close this bug and just keep bug 1710 for this issue too.
I agree that fprintf->kdDebug conversions should be done in general and not limited to specific messages or files.
What do you think?
Comment 12 Darrell 2013-11-24 11:59:06 CST
To coordinate everybody's concerns, for closing this report I think we leave the fprintf as an fprintf and just comment out the message. Eventually we convert the fprintf to kdDebug in bug 1710.

I checked the 3.4.3 sources and this specific message existed then too. Been around a while.

When creating packages with debugging enabled, this specific message provides no value that I can see because there is no way to know the process name and there are no previous debug messages about the PID being started. That is, there is no way to coordinate the termination message with anything. Thus the message only adds spew noise rather than usefulness, which is my original concern.

Until working on bug 1710, the proposed patch would look like this:

// #ifndef NDEBUG
//   fprintf(stderr, "[tdeinit] PID %ld terminated.\n", (long) exit_pid);
// #endif

We reduce output spew noise. Sound acceptable?
Comment 13 Darrell 2013-11-24 15:14:36 CST
Created attachment 1668 [details]
Patch to disable single fprintf message and nominal string cleanup
Comment 14 Michele Calgaro 2013-11-24 22:39:07 CST
Looks good to me. 
At line 1353 I would just add a comment to say that the fprintf commented out may have to be reinstated when the fprintf -> kdDebug conversion is done.
Comment 15 Darrell 2013-11-24 23:14:47 CST
>At line 1353 I would just add a comment to say that the fprintf commented out
>may have to be reinstated when the fprintf -> kdDebug conversion is done.
Added. Patch pushed to git in commit 5dc0b354.

Thanks for the help!