Author Topic: Unsafe code in signal handler (linux version)  (Read 973 times)

0 Members and 1 Guest are viewing this topic.

Offline dmvn

  • Member
  • ***
  • Posts: 27
  • Karma: +3/-0
    • DMVN Educational Project
Unsafe code in signal handler (linux version)
« on: 07 December, 2013, 22:23:24 »
I'm now trying to make my hub working on new PtokaX 0.500, and I noticed some potential problems in source code (at least in UNIX part).

It's a known fact that signal handlers are restricted by set of calls that are safe inside them (referring to http://man7.org/linux/man-pages/man7/signal.7.html ).
In particular, malloc and pthread_mutex_lock are cannot be done in signal handlers.

But in current code there are two problems:
1) std::string is used in first line of SigHandler function (which implies use of malloc() ),
2) adding SHUTDOWN event to queue is of course wrapped by mutex, and this is unsafe too.

This may lead to deadlocks, coredumps on terminating process, etc.

I've noticed this because of another problem, which is under my investigation now: PtokaX freezes after running again on converted users base, but I had not found why.

PtokaX forum

Unsafe code in signal handler (linux version)
« on: 07 December, 2013, 22:23:24 »

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 475
  • Karma: +209/-22
  • PtokaX developer
Re: Unsafe code in signal handler (linux version)
« Reply #1 on: 07 December, 2013, 23:05:25 »
Thank you for report, it will be fixed in next release  ;)
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

PtokaX forum

Re: Unsafe code in signal handler (linux version)
« Reply #1 on: 07 December, 2013, 23:05:25 »