Signal Scan

I have a signal that blocks SIGINT and basically says: "Sorry, you cannot exit. \ N"

The problem is that this can happen during a scan.

When this happens during scanf, scanf accepts printf as input.

How can I do printf, which will make scanf basically press enter automatically. I don’t care that I have a bad contribution. I just want to programmatically end the scan with printf or something else.

process:

scanf ("receive material") -> User can enter material into.

-> SIGINT happens and goes to my handler.

-> Handler says "Blah blah blah" for the standard release.

-> Scanf took this blah blah blah and is waiting for more input.

How to make scanf complete when it returns (it doesn’t matter what it builds, I just want it to continue without user help).

EDIT: if I send two signals, then scanf will exit. I want to somehow emulate the scanf ending programmatically.

+1
source share
2 answers

Your question suggests that you are confused - or perhaps English is not your first language.

I have a signal that blocks SIGINT and basically says: "Sorry, you cannot exit. \ N"

, SIGINT. , "signal()" , sigaction() POSIX, .

, .

, 'this', -, , , . , , ; , . , SIGQUIT (, , ); , , , "kill -9 pid", .

f, scanf printf .

... , -, , 'printf()' ( , " " ) "scanf()"? ... - - , , .

printf, scanf . , . printf - .

- O/S ( POSIX.) 'scanf()'; . , , . "scanf()" . "scanf()" , , "sigsetjmp()" , "setjmp()", , "scanf()" ), 'siglongjmp()' :

sigjmp_buf trap;

int intermediary(int argument)
{
    if (sigsetjmp(trap) == 0)
    {
         function_calling_scanf(argument);
         return 0;  // Success
    }
    // Report failure
    return -1;
}

:

:

   scanf("get stuff") -> User is able to enter stuff in.

- > SIGINT .

- > "--" .

- > Scanf -- .

, scanf "--"? , .

, scanf ( , , , ).

sigsetjmp().

EDIT: , scanf . - scanf.

, "signal()" , , "sigaction()". "signal()" , , . 'sigaction()' ; (SIGINT) , . , , ( ).

+1

scanf, . read(2), -1 EINTR. Scanf . .

, QNX POSIX , scanf .

0

Source: https://habr.com/ru/post/1770563/


All Articles