From owner-svn-src-head@FreeBSD.ORG Tue Jun 9 05:29:39 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 602C57D; Tue, 9 Jun 2015 05:29:39 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail105.syd.optusnet.com.au (mail105.syd.optusnet.com.au [211.29.132.249]) by mx1.freebsd.org (Postfix) with ESMTP id 269021934; Tue, 9 Jun 2015 05:29:38 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from c211-30-166-197.carlnfd1.nsw.optusnet.com.au (c211-30-166-197.carlnfd1.nsw.optusnet.com.au [211.30.166.197]) by mail105.syd.optusnet.com.au (Postfix) with ESMTPS id 063FA1045B8D; Tue, 9 Jun 2015 15:29:34 +1000 (AEST) Date: Tue, 9 Jun 2015 15:29:33 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Ed Maste cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r284157 - head/sys/kern In-Reply-To: <201506081607.t58G78EF092855@svn.freebsd.org> Message-ID: <20150609151112.F935@besplex.bde.org> References: <201506081607.t58G78EF092855@svn.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=XMDNMlVE c=1 sm=1 tr=0 a=KA6XNC2GZCFrdESI5ZmdjQ==:117 a=PO7r1zJSAAAA:8 a=kj9zAlcOel0A:10 a=JzwRw_2MAAAA:8 a=2NAtd3wyzpZ6avZ3ys4A:9 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Jun 2015 05:29:39 -0000 On Mon, 8 Jun 2015, Ed Maste wrote: > Log: > Add user facing errors for exceeding process memory limits > > Previously the process terminating with SIGABRT at startup was the > only notification. I don't like this. Errrors in syscalls should be reported by returning an error code, not by spamming the user's terminal. > Modified: head/sys/kern/imgact_elf.c > ============================================================================== > --- head/sys/kern/imgact_elf.c Mon Jun 8 15:24:24 2015 (r284156) > +++ head/sys/kern/imgact_elf.c Mon Jun 8 16:07:07 2015 (r284157) > ... > @@ -755,11 +755,14 @@ __CONCAT(exec_, __elfN(imgact))(struct i > if ((hdr->e_phoff > PAGE_SIZE) || > (u_int)hdr->e_phentsize * hdr->e_phnum > PAGE_SIZE - hdr->e_phoff) { > /* Only support headers in first page for now */ > + uprintf("Program headers not in the first page\n"); > return (ENOEXEC); > } > - phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff); > - if (!aligned(phdr, Elf_Addr)) > + phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff); > + if (!aligned(phdr, Elf_Addr)) { > + uprintf("Unaligned program headers\n"); > return (ENOEXEC); > + } > n = 0; > baddr = 0; > for (i = 0; i < hdr->e_phnum; i++) { Also, the spam doesn't even include much useful info, like the program or interpreter name. It can be difficult to tell where the error was for nested interpreters. Most of the old uprintf()s for exec failures are similarly deficient. In this file: X uprintf("elf_load_section: truncated ELF file\n"); X uprintf("ELF binary type \"%u\" not known.\n", This one also has style bugs (bogus quoting of a number, and termination with a period). X uprintf("ELF interpreter %s not found\n", interp); This one at least prints the interpreter name. I use the following partial fixes: X diff -u2 imgact_elf.c~ imgact_elf.c X --- imgact_elf.c~ Sat Jun 5 16:50:05 2004 X +++ imgact_elf.c Sat Jun 5 16:51:25 2004 X @@ -694,6 +693,6 @@ X brand_info = __elfN(get_brandinfo)(hdr, interp); X if (brand_info == NULL) { X - uprintf("ELF binary type \"%u\" not known.\n", X - hdr->e_ident[EI_OSABI]); X + uprintf("%s: ELF binary type \"%u\" not known.\n", X + imgp->stringbase, hdr->e_ident[EI_OSABI]); X error = ENOEXEC; X goto fail; X @@ -828,5 +827,6 @@ X &imgp->entry_addr, sv->sv_pagesize); X if (error != 0) { X - uprintf("ELF interpreter %s not found\n", interp); X + uprintf("%s: ELF interpreter %s not found\n", X + imgp->stringbase, interp); X goto fail; X } The message should be printed by the application, but there is a problem getting enough details for interpreters. Most applications learned to use the err() family for printing error messages long ago, so they don't forget to print the program name like these uprintfs, but the interpreter name is hard to print outside of the kernel. Bruce