Re: Problem with lp.h

Richard Gooch (rgooch@atnf.csiro.au)
Mon, 17 May 1999 09:40:40 +1000


Patrick Jordan writes:
>
>
> The file include/linux/lp.h seems to have code in it, related to wait
> queues, that should be available only to the kernel, but is not hidden
> from user-space programs.
>
> In my case, util-linux-2.9r failed to compile until I made the change
> shown in the patch below (thanks rgooch).
>
> Note, I am a beginner at this (my first post to this list!) - the
> patch included below worked for me but is PROBABLY NOT CORRECT. I am
> posting here so the appropriate maintainer can check it.
>
> Patrick.
>
> diff -urN linux-clean/include/linux/lp.h linux/include/linux/lp.h
> --- linux-clean/include/linux/lp.h Sun May 16 14:04:59 1999
> +++ linux/include/linux/lp.h Sun May 16 20:50:47 1999
> @@ -123,10 +123,12 @@
> unsigned int runchars;
> struct lp_stats stats;
> #endif
> +#ifdef __KERNEL__
> wait_queue_head_t wait_q;
> unsigned int last_error;
> volatile unsigned int irq_detected:1;
> volatile unsigned int irq_missed:1;
> +#endif
> };

You want to be careful here. What you've done is modify the size and
content of a structure. If this structure is only used inside the
kernel, that's fine. However, if the structure is shared between
kernel and user space (say for an ioctl()), you're rooted. The same
goes for adding or moving structure members, of course.

In this case, a quick scan of the kernel sources doesn't reveal that
"struct lp_struct" is "exported" to user space, so your change is
fine, as far as it goes. But since the structure doesn't appear to be
exported to user space, you may as well put the #ifdef around the
whole structure declaration. That way, if any user space code is silly
enough to refer to that structure, it will refuse to compile, rather
than generating an incompatible binary.

Even better, put the #ifdef __KERNEL__ around all the stuff in lp.h
that doesn't seem to be needed in user space. That way you can make a
small contribution to cleaning up the current mess.

Regards,

Richard....

P.S. I told you it isn't worth the effort to build everything...

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/