Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Mar 2010 10:00:58 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-hackers@freebsd.org
Cc:        Dag-Erling =?utf-8?q?Sm=C3=B8rgrav?= <des@des.no>, Dmitry Krivenok <krivenok.dmitry@gmail.com>
Subject:   Re: Strange behavior of kernel module (output terminated)
Message-ID:  <201003231000.58961.jhb@freebsd.org>
In-Reply-To: <86ocifcmew.fsf@ds4.des.no>
References:  <da48cf211003230218n56794f0bs27eef860efc0da3e@mail.gmail.com> <86ocifcmew.fsf@ds4.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday 23 March 2010 7:22:47 am Dag-Erling Sm=C3=B8rgrav wrote:
> Dmitry Krivenok <krivenok.dmitry@gmail.com> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003231000.58961.jhb>