From owner-freebsd-hackers@FreeBSD.ORG Tue Mar 23 14:27:57 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DBC871065675 for ; Tue, 23 Mar 2010 14:27:57 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id ACCC18FC1E for ; Tue, 23 Mar 2010 14:27:57 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 5FD4246B8D; Tue, 23 Mar 2010 10:27:57 -0400 (EDT) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPA id B99F08A025; Tue, 23 Mar 2010 10:27:56 -0400 (EDT) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Tue, 23 Mar 2010 10:00:58 -0400 User-Agent: KMail/1.12.1 (FreeBSD/7.3-CBSD-20100217; KDE/4.3.1; amd64; ; ) References: <86ocifcmew.fsf@ds4.des.no> In-Reply-To: <86ocifcmew.fsf@ds4.des.no> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <201003231000.58961.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Tue, 23 Mar 2010 10:27:56 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-1.7 required=4.2 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Dag-Erling =?utf-8?q?Sm=C3=B8rgrav?= , Dmitry Krivenok Subject: Re: Strange behavior of kernel module (output terminated) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Mar 2010 14:27:57 -0000 On Tuesday 23 March 2010 7:22:47 am Dag-Erling Sm=C3=B8rgrav wrote: > Dmitry Krivenok writes: > > /* The function called at load/unload. */ > > static int event_handler(struct module *module, int event, void *arg) > > { > > int e =3D 0; /* Error, 0 for normal return status */ > > switch (event) > > { > > case MOD_LOAD: > > uprintf("Hello FreeBSD kernel!\n"); >=20 > I'm not sure it's such a good idea to use uprintf() here. The event > handler can be called in non-process context. If you are doing a kldload post-boot it is actually done from some sort of= =20 process context. We run module handlers synchronously from the kldload(2)= =20 syscall. > > int i =3D 0; > > for(i =3D 0; i < 1000; i++) > > { > > uprintf("%3d ", i); > > if(! (i % 10) ) uprintf("\n"); > > } >=20 > (i % 10) is not a predicate. The test should be if (i % 10 =3D=3D 0). >=20 > If you want to work on FreeBSD, I recommend you get used to the > FreeBSD coding style; see 'man 9 style'. True, but that doesn't explain the behavior he sees. > > As you can see the loop was terminated after i=3D=3D466. I tried to > > load/unload the module many times but the last printed number was > > always 466. >=20 > You filled up a buffer somewhere... Does uprintf() require the caller to flush the output to the tty somehow? = If=20 so, that seems to be a bug. Nothing in the uprintf(9) manpage suggests tha= t=20 the output should be manually flushed. =2D-=20 John Baldwin