Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How to do ioctl?

by morgon (Deacon)
on May 16, 2014 at 00:49 UTC ( #1086228=note: print w/ replies, xml ) Need Help??


in reply to How to do ioctl?

I have now tried to following which does what I want:

use Inline "C"; open my $dev, "<", "/dev/input/event14" or die $!; grab($dev->fileno, 1); __END__ __C__ #include <linux/input.h> void grab(int fd, int act) { int r = ioctl(fd, EVIOCGRAB, act); printf("grab: %d\n", r); }
But it seems silly to me to resort to C just to issue an ioctl-call.

Does anybody know how to do this in pure Perl?


Comment on Re: How to do ioctl?
Download Code
Re^2: How to do ioctl?
by Anonymous Monk on May 16, 2014 at 02:08 UTC
    What number is EVIOCGRAB? What does Inline think it is, and what does input.ph think it is?
      Good point.

      I've tried the following:

      printf("ph: %u\n", EVIOCGRAB()); open my $dev, "<", "/dev/input/event7" or die $!; grab($dev->fileno, 1); __END__ __C__ #include <linux/input.h> void grab(int fd, int act) { printf("c: %u\n", EVIOCGRAB); int r = ioctl(fd, EVIOCGRAB, act); printf("grab: %d\n", r); }
      And sure enough it prints:

      ph: 1073759632
      c: 1074021776

      So for whatever reason there is a mismatch.

      If I don't use the .ph-files but simply do ioctl $dev, 1074021776, 1;it works.

      So it seems the problem lies with h2ph....

      The way I generated the phs was I went to /usr/include and from there I issued "h2ph -a -d <some output-dir> linux/input.h"

      Was that the wrong way to do it? And is it normal that I have to do that on my own (as I said I installed via perlbrew and there were no .phs generated then?

      But at least I know how to do it now...

        Good point.

        :) thats why its on every checklist :)

        Was that the wrong way to do it?

        Nope, but it doesn't compile the c header it merely parses so there are https://metacpan.org/pod/h2ph#BUGS ... its old :)

        And is it normal that I have to do that on my own (as I said I installed via perlbrew and there were no .phs generated then?

        Yes, absolutely, h2ph just doesn't happen when building perl ... IIRC it didn't even as far back as 5.6.1

        The alternatives seem to be h2ph h2xs ExtUtils::Constant C::Scan::Constants ExtUtils::H2PM

        I like the ones that use a compiler to get the real number ...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1086228]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2014-12-26 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls