Questions tagged [async-safe]

10 questions
23
votes
4 answers

Print int from signal handler using write or async-safe functions

I want to print a number into log or to a terminal using write (or any async-safe function) inside a signal handler. I would prefer not to use buffered I/O. Is there an easy and recommended way to do that ? For example in place of printf, below I…
user648129
13
votes
4 answers

I need a list of Async-Signal-Safe Functions from glibc

Non syscall's wrappers but something like snprintf(), dprintf()
vitaly.v.ch
  • 2,485
  • 4
  • 26
  • 36
6
votes
2 answers

Is it always unsafe when I call a non-async-safe function from a signal handler?

I am just figuring out whether I can call a non-async-safe function in a signal handler. Quotes from Linux man page signal(7): If a signal interrupts the execution of an unsafe function, and handler calls an unsafe function, then the behavior of…
StrikeW
  • 501
  • 1
  • 4
  • 11
5
votes
3 answers

Is there a way to test whether I'm in a signal handler?

I'm having to work on a logging module that can be called from various places in a large project. The problem I have is that sometimes the module may be called from code executed inside a signal handler. Normally, the logging module includes time…
Jay Walker
  • 399
  • 1
  • 10
4
votes
3 answers

Is read-only access to a vector (vector::operator[] and vector::size()) asynchronous-safe?

My program needs to perform read-only access to the contents of a vector in a signal handler for SIGINT. (The alternative is to use a fixed-size array of fixed-length C strings.) The program is designed to run in a POSIX environment. Are…
bwDraco
  • 2,514
  • 2
  • 33
  • 38
2
votes
3 answers

The usage of sig_atomic_t in linux signal mask function

I was recently studying the book named Advanced Linux Programming and I ran into this question: The book said you should use sig_atomic_t variable type to be sure that if you set a global flag or counter in a signal handler function, context switch…
Amir Zadeh
  • 3,481
  • 2
  • 26
  • 47
1
vote
1 answer

Why only async-safe functions should be called from a signal handler?

I understand that, from a signal handler function sigaction() I should only call those functions that are "async-safe". But why is so?
Asif
  • 664
  • 1
  • 7
  • 14
1
vote
2 answers

How to manage a shared POSIX semaphore with async signals in a multithreaded application

I've to write a thread-safe library that uses a POSIX semaphore (used as a mutex with initial value = 1) for sync. I found some problems to correctly manage async signals. I've an application that links against this static library and the…
MirkoBanchi
  • 2,173
  • 5
  • 35
  • 52
0
votes
2 answers

Do functions which are not defined as async-safe, such as mmap(2), effect other async-safe functions called in signal handler?

I am making a library which gets injected into processes and redefines some of functions, such as open(2) to do some tasks before calling real open(2). My library would call mmap(2). As open(2) is async safe, is it possible that someone using the…
Mihir Luthra
  • 6,059
  • 3
  • 14
  • 39
0
votes
1 answer

Reading the MP3 IDV2 tag size

I am trying to read the size of a ID3V2 tag. my code is supposed to be storing the the first header which contains the identification, version, flags and size in this struct. The code freads from bit 0 to bit 9 and stores it here typedef struct { …