Re: pkg_add/pkg_delete: include PID in syslog messages

2012-05-28 Thread Lawrence Teo
On Mon, Mar 19, 2012 at 12:50:12PM +0100, Marc Espie wrote:
 On Wed, Mar 07, 2012 at 12:31:48AM -0500, Lawrence Teo wrote:
  This simple diff makes pkg_add and pkg_delete include their PID when
  logging to syslog. This is useful when trying to determine whether
  several packages were added (or removed) by the same pkg_add (or
  pkg_delete) process.
  
  Here is some sample output:
  
  Mar  3 22:15:17 obsd-amd64 pkg_add[3530]: Added nano-2.2.6 
  Mar  3 22:15:26 obsd-amd64 pkg_delete[21136]: Removed nano-2.2.6 
  Mar  3 22:16:51 obsd-amd64 pkg_add[30666]: Added redland-1.0.8p1 
  Mar  3 22:16:54 obsd-amd64 pkg_add[30666]: Added mozilla-dicts-en-GB-1.3 
  Mar  3 22:16:56 obsd-amd64 pkg_add[30666]: Added hunspell-1.2.12 
  Mar  3 22:23:22 obsd-amd64 pkg_add[30666]: Added libreoffice-3.4.5.2v0 
  Mar  3 23:33:23 obsd-amd64 pkg_add[5948]: Added kdiff3-0.9.96p1 
  
  Comments?
 
 The more I think about it, the more I fail to see the value.
 Consider that any pkg_add/pkg_delete that actually changes installed
 packages *will* lock the database anyways, so by nature, all relevant
 runs of pkg_add/pkg_delete will happen in sequence.
 
 Hence, there's totally no ambiguity in the log lines. If I remove the pids
 in there, I still have no trouble figuring out what happened.
 
 When I look at those logs, I usually have to look at the time anyways,
 so in the above case, figuring out that libreoffice and kdiff3 are
 different runs of pkg_add is not that hard...

Thank you for your comments.

If I remove the PIDs from the above logs, part of it would look like
this:

Mar  3 22:16:51 obsd-amd64 pkg_add: Added redland-1.0.8p1 
Mar  3 22:16:54 obsd-amd64 pkg_add: Added mozilla-dicts-en-GB-1.3 
Mar  3 22:16:56 obsd-amd64 pkg_add: Added hunspell-1.2.12 
Mar  3 22:23:22 obsd-amd64 pkg_add: Added libreoffice-3.4.5.2v0 

Just relying on those timestamps alone without PIDs, it looks like
redland, mozilla-dicts, and hunspell are part of the same run, while
libreoffice is a different run.

However, with PIDs it is clear that they are part of the same run, where
it so happened that it took almost 6.5 minutes to install the
libreoffice package on this machine:

Mar  3 22:16:51 obsd-amd64 pkg_add[30666]: Added redland-1.0.8p1 
Mar  3 22:16:54 obsd-amd64 pkg_add[30666]: Added mozilla-dicts-en-GB-1.3 
Mar  3 22:16:56 obsd-amd64 pkg_add[30666]: Added hunspell-1.2.12 
Mar  3 22:23:22 obsd-amd64 pkg_add[30666]: Added libreoffice-3.4.5.2v0 

 I won't say I can't be swayed, but you'll have to give me a concrete case
 where the pid offers some actual advantage over no pid.

My goal is to help the bleary-eyed sysadmin figure out what in the world
s/he did after working on a project all night long. :)  I think the
PIDs would help them answer questions like, Why did I install $PACKAGE
again? (where $PACKAGE could be hunspell in the above example).

Please let me know if you have any further thoughts and if you're ok
with the diff.  Since a long time has passed since your post on this
thread and I only managed to reply now, I have included my diff again
below.

Thank you,
Lawrence


Index: AddDelete.pm
===
RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/AddDelete.pm,v
retrieving revision 1.53
diff -u -p -r1.53 AddDelete.pm
--- AddDelete.pm9 Oct 2011 16:43:50 -   1.53
+++ AddDelete.pm4 Mar 2012 04:37:04 -
@@ -185,7 +185,7 @@ sub handle_options
$state-{loglevel} //= $state-config-value(loglevel) // 1;
if ($state-{loglevel}) {
require Sys::Syslog;
-   Sys::Syslog::openlog($state-{cmd}, nofatal);
+   Sys::Syslog::openlog($state-{cmd}, nofatal,pid);
}
 }



Re: pkg_add/pkg_delete: include PID in syslog messages

2012-05-28 Thread Stuart Henderson
On 2012/05/28 10:53, Lawrence Teo wrote:
 On Mon, Mar 19, 2012 at 12:50:12PM +0100, Marc Espie wrote:
  The more I think about it, the more I fail to see the value.
  Consider that any pkg_add/pkg_delete that actually changes installed
  packages *will* lock the database anyways, so by nature, all relevant
  runs of pkg_add/pkg_delete will happen in sequence.
  
  Hence, there's totally no ambiguity in the log lines. If I remove the pids
  in there, I still have no trouble figuring out what happened.
  
  When I look at those logs, I usually have to look at the time anyways,
  so in the above case, figuring out that libreoffice and kdiff3 are
  different runs of pkg_add is not that hard...
 
 Thank you for your comments.
 
 If I remove the PIDs from the above logs, part of it would look like
 this:
 
 Mar  3 22:16:51 obsd-amd64 pkg_add: Added redland-1.0.8p1 
 Mar  3 22:16:54 obsd-amd64 pkg_add: Added mozilla-dicts-en-GB-1.3 
 Mar  3 22:16:56 obsd-amd64 pkg_add: Added hunspell-1.2.12 
 Mar  3 22:23:22 obsd-amd64 pkg_add: Added libreoffice-3.4.5.2v0 
 
 Just relying on those timestamps alone without PIDs, it looks like
 redland, mozilla-dicts, and hunspell are part of the same run, while
 libreoffice is a different run.
 
 However, with PIDs it is clear that they are part of the same run, where
 it so happened that it took almost 6.5 minutes to install the
 libreoffice package on this machine:
 
 Mar  3 22:16:51 obsd-amd64 pkg_add[30666]: Added redland-1.0.8p1 
 Mar  3 22:16:54 obsd-amd64 pkg_add[30666]: Added mozilla-dicts-en-GB-1.3 
 Mar  3 22:16:56 obsd-amd64 pkg_add[30666]: Added hunspell-1.2.12 
 Mar  3 22:23:22 obsd-amd64 pkg_add[30666]: Added libreoffice-3.4.5.2v0 

If this is necessary at all, I'd honestly prefer log entries like
started update and finished update rather than logging PIDs.
It's unlikely of course, but PIDs are random, so you can't rely
on the PID alone to identify whether two log entries with a
certain PID are from the same run.

 My goal is to help the bleary-eyed sysadmin figure out what in the world
 s/he did after working on a project all night long. :)

This is certainly not restricted to pkg_add. I find sudo logs
quite useful for this.



Re: pkg_add/pkg_delete: include PID in syslog messages

2012-05-28 Thread Marc Espie
On Mon, May 28, 2012 at 10:53:15AM -0400, Lawrence Teo wrote:
 My goal is to help the bleary-eyed sysadmin figure out what in the world
 s/he did after working on a project all night long. :)  I think the
 PIDs would help them answer questions like, Why did I install $PACKAGE
 again? (where $PACKAGE could be hunspell in the above example).

Administrator forgot to turn on his brain.

In the above case, hunspell is a depency of libreoffice, so it was not
installed per se: it won't show up in pkg_info -m
and pkg_info -R will tell him what requires it.

(or hey, pkg_delete -nav will also tell him which packages won't be removed
because they're needed by something).



Re: pkg_add/pkg_delete: include PID in syslog messages

2012-03-19 Thread Marc Espie
On Wed, Mar 07, 2012 at 12:31:48AM -0500, Lawrence Teo wrote:
 This simple diff makes pkg_add and pkg_delete include their PID when
 logging to syslog. This is useful when trying to determine whether
 several packages were added (or removed) by the same pkg_add (or
 pkg_delete) process.
 
 Here is some sample output:
 
 Mar  3 22:15:17 obsd-amd64 pkg_add[3530]: Added nano-2.2.6 
 Mar  3 22:15:26 obsd-amd64 pkg_delete[21136]: Removed nano-2.2.6 
 Mar  3 22:16:51 obsd-amd64 pkg_add[30666]: Added redland-1.0.8p1 
 Mar  3 22:16:54 obsd-amd64 pkg_add[30666]: Added mozilla-dicts-en-GB-1.3 
 Mar  3 22:16:56 obsd-amd64 pkg_add[30666]: Added hunspell-1.2.12 
 Mar  3 22:23:22 obsd-amd64 pkg_add[30666]: Added libreoffice-3.4.5.2v0 
 Mar  3 23:33:23 obsd-amd64 pkg_add[5948]: Added kdiff3-0.9.96p1 
 
 Comments?

The more I think about it, the more I fail to see the value.
Consider that any pkg_add/pkg_delete that actually changes installed
packages *will* lock the database anyways, so by nature, all relevant
runs of pkg_add/pkg_delete will happen in sequence.

Hence, there's totally no ambiguity in the log lines. If I remove the pids
in there, I still have no trouble figuring out what happened.

When I look at those logs, I usually have to look at the time anyways,
so in the above case, figuring out that libreoffice and kdiff3 are
different runs of pkg_add is not that hard...

I won't say I can't be swayed, but you'll have to give me a concrete case
where the pid offers some actual advantage over no pid.



pkg_add/pkg_delete: include PID in syslog messages

2012-03-06 Thread Lawrence Teo
This simple diff makes pkg_add and pkg_delete include their PID when
logging to syslog. This is useful when trying to determine whether
several packages were added (or removed) by the same pkg_add (or
pkg_delete) process.

Here is some sample output:

Mar  3 22:15:17 obsd-amd64 pkg_add[3530]: Added nano-2.2.6 
Mar  3 22:15:26 obsd-amd64 pkg_delete[21136]: Removed nano-2.2.6 
Mar  3 22:16:51 obsd-amd64 pkg_add[30666]: Added redland-1.0.8p1 
Mar  3 22:16:54 obsd-amd64 pkg_add[30666]: Added mozilla-dicts-en-GB-1.3 
Mar  3 22:16:56 obsd-amd64 pkg_add[30666]: Added hunspell-1.2.12 
Mar  3 22:23:22 obsd-amd64 pkg_add[30666]: Added libreoffice-3.4.5.2v0 
Mar  3 23:33:23 obsd-amd64 pkg_add[5948]: Added kdiff3-0.9.96p1 

Comments?

Thanks,
Lawrence

Index: AddDelete.pm
===
RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/AddDelete.pm,v
retrieving revision 1.53
diff -u -p -r1.53 AddDelete.pm
--- AddDelete.pm9 Oct 2011 16:43:50 -   1.53
+++ AddDelete.pm4 Mar 2012 04:37:04 -
@@ -185,7 +185,7 @@ sub handle_options
$state-{loglevel} //= $state-config-value(loglevel) // 1;
if ($state-{loglevel}) {
require Sys::Syslog;
-   Sys::Syslog::openlog($state-{cmd}, nofatal);
+   Sys::Syslog::openlog($state-{cmd}, nofatal,pid);
}
 }