LinuxCNC / linuxcnc

LinuxCNC controls CNC machines. It can drive milling machines, lathes, 3d printers, laser cutters, plasma cutters, robot arms, hexapods, and more.
http://linuxcnc.org/
GNU General Public License v2.0
1.77k stars 1.14k forks source link

Check for correct return value after call to 'pthread_*' #2808

Closed havardAasen closed 2 months ago

havardAasen commented 8 months ago

According to man pages, calls to 'pthread_*' can return 'a nonzero value'. This means it can be both negative and positive, we have to check for both.

This commit includes the diff supplied in #2656 and also fixes the same mistake in other files. Fixes: #2656

cepelinas9000 commented 8 months ago

'pthread_*' functions do not set errno variable.

The error handling is incorrect, reading manuals (for example https://man7.org/linux/man-pages/man3/pthread_setschedparam.3.html) there where no mentioning settings errno. But there is macro which sets manually:

// in https://man7.org/linux/man-pages/man3/pthread_setschedparam.3.html example
#define handle_error_en(en, msg) \
               do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
havardAasen commented 8 months ago

Right, my bad. I'll update the patch, thanks.