From owner-svn-src-all@FreeBSD.ORG Mon Feb 9 23:28:38 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1FF62DAF; Mon, 9 Feb 2015 23:28:38 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9BC09CB; Mon, 9 Feb 2015 23:28:37 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id t19NSRqr019482 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 10 Feb 2015 01:28:27 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua t19NSRqr019482 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id t19NSQ9F019481; Tue, 10 Feb 2015 01:28:26 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 10 Feb 2015 01:28:26 +0200 From: Konstantin Belousov To: Rui Paulo Subject: Re: svn commit: r278479 - in head: etc sys/kern Message-ID: <20150209232826.GJ42409@kib.kiev.ua> References: <201502092313.t19NDpoS083043@svn.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201502092313.t19NDpoS083043@svn.freebsd.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Feb 2015 23:28:38 -0000 On Mon, Feb 09, 2015 at 11:13:51PM +0000, Rui Paulo wrote: > Author: rpaulo > Date: Mon Feb 9 23:13:50 2015 > New Revision: 278479 > URL: https://svnweb.freebsd.org/changeset/base/278479 > > Log: > Notify devd(8) when a process crashed. > > This change implements a notification (via devctl) to userland when > the kernel produces coredumps after a process has crashed. > devd can then run a specific command to produce a human readable crash > report. The command is most usually a helper that runs gdb/lldb > commands on the file/coredump pair. It's possible to use this > functionality for implementing automatic generation of crash reports. > > devd(8) will be notified of the full path of the binary that crashed and > the full path of the coredump file. Arguably, there should be a knob, probably sysctl, to turn the functionality off. I definitely do not want this on crash boxes used for userspace debugging. Even despite the example handler is inactive. > > Modified: > head/etc/devd.conf > head/sys/kern/kern_sig.c > > Modified: head/etc/devd.conf > ============================================================================== > --- head/etc/devd.conf Mon Feb 9 23:04:30 2015 (r278478) > +++ head/etc/devd.conf Mon Feb 9 23:13:50 2015 (r278479) > @@ -325,4 +325,16 @@ notify 100 { > action "/usr/sbin/automount -c"; > }; > > +# Handle userland coredumps. > +# This commented out handler makes it possible to run an > +# automated debugging session after the core dump is generated. > +# Replace action with a proper coredump handler, but be aware that > +# it will run with elevated privileges. > +notify 10 { > + match "system" "kernel"; > + match "subsystem" "signal"; > + match "type" "coredump"; > + action "logger $comm $core"; > +}; > + > */ > > Modified: head/sys/kern/kern_sig.c > ============================================================================== > --- head/sys/kern/kern_sig.c Mon Feb 9 23:04:30 2015 (r278478) > +++ head/sys/kern/kern_sig.c Mon Feb 9 23:13:50 2015 (r278479) > @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); > #include > #include > #include > +#include > #include > #include > #include > @@ -3237,6 +3238,9 @@ coredump(struct thread *td) > void *rl_cookie; > off_t limit; > int compress; > + char *data = NULL; > + size_t len; > + char *fullpath, *freepath = NULL; > > #ifdef COMPRESS_USER_CORES > compress = compress_user_cores; > @@ -3322,9 +3326,36 @@ close: > error1 = vn_close(vp, FWRITE, cred, td); > if (error == 0) > error = error1; > + else > + goto out; > + /* > + * Notify the userland helper that a process triggered a core dump. > + * This allows the helper to run an automated debugging session. > + */ > + len = MAXPATHLEN * 2 + 5 /* comm= */ + 5 /* core= */ + 1; It is much cleaner to use static const char arrays for the names, and use sizeof() - 1 instead of hard-coding commented constants. > + data = malloc(len, M_TEMP, M_NOWAIT); Why is this allocation M_NOWAIT ? > + if (data == NULL) > + goto out; > + if (vn_fullpath_global(td, p->p_textvp, &fullpath, &freepath) != 0) > + goto out; > + snprintf(data, len, "comm=%s", fullpath); > + if (freepath != NULL) { > + free(freepath, M_TEMP); Checks for NULL pointer before free(9) are redundant. > + freepath = NULL; > + } > + if (vn_fullpath_global(td, vp, &fullpath, &freepath) != 0) > + goto out; > + snprintf(data, len, "%s core=%s", data, fullpath); This is weird, and highly depends on the implementation details, supplying the same string as target and source. IMO strcat(9) is enough there. > + devctl_notify("kernel", "signal", "coredump", data); > + free(name, M_TEMP); > +out: > #ifdef AUDIT > audit_proc_coredump(td, name, error); > #endif > + if (freepath != NULL) > + free(freepath, M_TEMP); > + if (data != NULL) > + free(data, M_TEMP); > free(name, M_TEMP); > return (error); > }