keyboard input intercept

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RJ45

    keyboard input intercept

    Hello,
    I am writing a shell in C.
    I need to intercept Signals like CTRL+C or CTRL+D
    and set to ignore them. This is on Unix, using gcc.
    my goal is to avoid users escaping the shell with SIGINT
    SIGQUIT signals using keyboard input.
    Anyone could give me a little hint ?

    thanks

    Rick

  • Ben Pfaff

    #2
    Re: keyboard input intercept

    RJ45 <rj45@NOSPAMsla cknet.comwrites :
    I am writing a shell in C.
    I need to intercept Signals like CTRL+C or CTRL+D
    and set to ignore them. This is on Unix, using gcc.
    my goal is to avoid users escaping the shell with SIGINT
    SIGQUIT signals using keyboard input.
    Anyone could give me a little hint ?
    I'd recommend comp.unix.progr ammer as a place where you're likely
    to get better answers to this question.
    --
    Peter Seebach on C99:
    "[F]or the most part, features were added, not removed. This sounds
    great until you try to carry a full-sized printout of the standard
    around for a day."

    Comment

    • santosh

      #3
      Re: keyboard input intercept

      RJ45 wrote:
      Hello,
      I am writing a shell in C.
      I need to intercept Signals like CTRL+C or CTRL+D
      and set to ignore them. This is on Unix, using gcc.
      my goal is to avoid users escaping the shell with SIGINT
      SIGQUIT signals using keyboard input.
      Anyone could give me a little hint ?
      >
      thanks
      >
      Rick
      Yes, methods are available to do this, but you should ask in a group
      for your system or atleast comp.unix.progr ammer, since it is system
      specific. Standard C itself only provides rudimentary facilities for
      signal handling, but your system's C library will most likely provide
      more facilities to accomplish what you want.

      Comment

      • Kenny McCormack

        #4
        Re: keyboard input intercept

        In article <slrneugmpc.nif .rj45@slacknet. com>,
        RJ45 <rj45@NOSPAMsla cknet.comwrote:
        >Hello,
        >I am writing a shell in C.
        >I need to intercept Signals like CTRL+C or CTRL+D
        >and set to ignore them. This is on Unix, using gcc.
        >my goal is to avoid users escaping the shell with SIGINT
        >SIGQUIT signals using keyboard input.
        >Anyone could give me a little hint ?
        Let me be the first to say:

        Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

        Useful clc-related links:





        However, I will point out, as a small hint, that ^C and ^D *aren't*
        "signals". Grasping fully the implications of this will help greatly in
        solving your underlying problem.

        Comment

        • Kenny McCormack

          #5
          Re: keyboard input intercept

          In article <1172857020.529 340.316940@h3g2 000cwc.googlegr oups.com>,
          santosh <santosh.k83@gm ail.comwrote:
          >RJ45 wrote:
          >Hello,
          >I am writing a shell in C.
          >I need to intercept Signals like CTRL+C or CTRL+D
          >and set to ignore them. This is on Unix, using gcc.
          >my goal is to avoid users escaping the shell with SIGINT
          >SIGQUIT signals using keyboard input.
          >Anyone could give me a little hint ?
          >>
          >thanks
          >>
          >Rick
          >
          >Yes, methods are available to do this, but you should ask in a group
          >for your system or atleast comp.unix.progr ammer, since it is system
          >specific. Standard C itself only provides rudimentary facilities for
          >signal handling, but your system's C library will most likely provide
          >more facilities to accomplish what you want.
          But, as I pointed out, signal handling doesn't have anything to do with
          it; *keyboard* handling does. I.e., OP certainly meant to write:

          I need to intercept keys like CTRL+C or CTRL+D ...

          Comment

          • santosh

            #6
            Re: keyboard input intercept

            Kenny McCormack wrote:
            In article <1172857020.529 340.316940@h3g2 000cwc.googlegr oups.com>,
            santosh <santosh.k83@gm ail.comwrote:
            RJ45 wrote:
            Hello,
            I am writing a shell in C.
            I need to intercept Signals like CTRL+C or CTRL+D
            and set to ignore them. This is on Unix, using gcc.
            my goal is to avoid users escaping the shell with SIGINT
            SIGQUIT signals using keyboard input.
            Anyone could give me a little hint ?
            >
            thanks
            >
            Rick
            Yes, methods are available to do this, but you should ask in a group
            for your system or atleast comp.unix.progr ammer, since it is system
            specific. Standard C itself only provides rudimentary facilities for
            signal handling, but your system's C library will most likely provide
            more facilities to accomplish what you want.
            >
            But, as I pointed out, signal handling doesn't have anything to do with
            it; *keyboard* handling does. I.e., OP certainly meant to write:
            >
            I need to intercept keys like CTRL+C or CTRL+D ...
            Since he's trying to intercept key sequences for the purpose of signal
            handling, it would be more portable to use the system's signal
            handling facilities than attempting to manually interpret key
            sequences as signals. The key sequences can vary from system to
            system, but the signal types and method of handling are likely to be
            more or less the same.

            Also only few of the possible signals are mapped to keyboard
            sequences. What if a signal is sent from another process, instead of
            the user? Inspite of all this, some signals like SIGKILL can't be
            ignored.

            If the OP's shell's response to signals is not canonical for the
            concerned platform, then potential users are likely to get annoyed
            with his programme.

            Comment

            • GMM50

              #7
              Re: keyboard input intercept

              On Mar 2, 12:13 pm, RJ45 <r...@NOSPAMsla cknet.comwrote:
              Hello,
              I am writing a shell in C.
              I need to intercept Signals like CTRL+C or CTRL+D
              and set to ignore them. This is on Unix, using gcc.
              my goal is to avoid users escaping the shell with SIGINT
              SIGQUIT signals using keyboard input.
              Anyone could give me a little hint ?
              >
              thanks
              >
              Rick
              If you are working on a PC, those key sequences are interperated in
              the keyboard handler most likely a dll.
              I've done some easy rewrites to just see if a key was pressed. Turbo
              C 3.x had Kbhit() function that reported if a key was hit.

              I suspect WinXP and beyond have further removed you from the hardware.

              gm

              Comment

              • santosh

                #8
                Re: keyboard input intercept

                GMM50 wrote:
                On Mar 2, 12:13 pm, RJ45 <r...@NOSPAMsla cknet.comwrote:
                Hello,
                I am writing a shell in C.
                I need to intercept Signals like CTRL+C or CTRL+D
                and set to ignore them. This is on Unix, using gcc.
                my goal is to avoid users escaping the shell with SIGINT
                SIGQUIT signals using keyboard input.
                Anyone could give me a little hint ?

                thanks

                Rick
                >
                If you are working on a PC, those key sequences are interperated in
                the keyboard handler most likely a dll.
                Key sequences have nothing to do with signals. The fact that a few
                keys are mapped to some common signals doesn't mean a program has to
                mess around with the raw keyboard input to handle signals.
                I've done some easy rewrites to just see if a key was pressed. Turbo
                C 3.x had Kbhit() function that reported if a key was hit.
                Proper signal handling must also take into account signals received
                from other processes.
                I suspect WinXP and beyond have further removed you from the hardware.
                There's no need to do keyboard handling to implement response to
                signals, not for an ordinary application anyway.

                Comment

                • Keith Thompson

                  #9
                  Re: keyboard input intercept

                  "santosh" <santosh.k83@gm ail.comwrites:
                  GMM50 wrote:
                  >On Mar 2, 12:13 pm, RJ45 <r...@NOSPAMsla cknet.comwrote:
                  Hello,
                  I am writing a shell in C.
                  I need to intercept Signals like CTRL+C or CTRL+D
                  and set to ignore them. This is on Unix, using gcc.
                  my goal is to avoid users escaping the shell with SIGINT
                  SIGQUIT signals using keyboard input.
                  Anyone could give me a little hint ?
                  >>
                  >If you are working on a PC, those key sequences are interperated in
                  >the keyboard handler most likely a dll.
                  I think you mean if you're working under MS Windows (PCs can, and
                  often do, run other operating systems). The OP specifically said he's
                  using Unix, which doesn't have DLLs (at least not by that name).
                  Key sequences have nothing to do with signals. The fact that a few
                  keys are mapped to some common signals doesn't mean a program has to
                  mess around with the raw keyboard input to handle signals.
                  <OT>
                  On Unix-like systems, if a program doesn't perform any system-specific
                  actions, then typing Control-C will most likely cause a SIGINT signal
                  to be delivered to the current program.

                  The OP can either (a) use signal() (or some system-specific function
                  like sigaction()) to set up a handler for the signal, or (b) do some
                  system-specific stuff to reconfigure the system so that Control-C is
                  treated as an ordinary character.

                  The signal-handling method is probably simplest, since it leaves it up
                  to the OS (and the user's settings) to determine which characters send
                  which signals.
                  </OT>

                  The details are, of course, system-specific; I suggest asking in a
                  comp.unix.progr ammer -- but check <http://www.faqs.org/faqs/unix-faq/>
                  first.

                  --
                  Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                  San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
                  "We must do something. This is something. Therefore, we must do this."
                  -- Antony Jay and Jonathan Lynn, "Yes Minister"

                  Comment

                  Working...