Changeset 7f9df7b9 in mainline for uspace/lib/posix/src/signal.c
- Timestamp:
- 2018-01-22T22:42:57Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7a08c70
- Parents:
- e0f47f5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/src/signal.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "posix/signal.h" 39 36 #include "internal/common.h" … … 61 58 static LIST_INITIALIZE(_signal_queue); 62 59 63 static posix_sigset_t _signal_mask = 0;60 static sigset_t _signal_mask = 0; 64 61 65 62 #define DEFAULT_HANDLER { .sa_handler = SIG_DFL, \ … … 67 64 68 65 /* Actions associated with each signal number. */ 69 static struct posix_sigaction _signal_actions[_TOP_SIGNAL + 1] = {66 static struct sigaction _signal_actions[_TOP_SIGNAL + 1] = { 70 67 DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 71 68 DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, … … 111 108 case SIGILL: 112 109 case SIGSEGV: 113 p osix_psignal(signo, "Hardware exception raised by user code");110 psignal(signo, "Hardware exception raised by user code"); 114 111 abort(); 115 112 case SIGSYS: … … 124 121 case SIGTTIN: 125 122 case SIGTTOU: 126 p osix_psignal(signo, "Unsupported signal caught");123 psignal(signo, "Unsupported signal caught"); 127 124 abort(); 128 125 case SIGCHLD: … … 164 161 * @return Always returns zero. 165 162 */ 166 int posix_sigemptyset(posix_sigset_t *set)163 int sigemptyset(sigset_t *set) 167 164 { 168 165 assert(set != NULL); … … 178 175 * @return Always returns zero. 179 176 */ 180 int posix_sigfillset(posix_sigset_t *set)177 int sigfillset(sigset_t *set) 181 178 { 182 179 assert(set != NULL); … … 193 190 * @return Always returns zero. 194 191 */ 195 int posix_sigaddset(posix_sigset_t *set, int signo)192 int sigaddset(sigset_t *set, int signo) 196 193 { 197 194 assert(set != NULL); … … 208 205 * @return Always returns zero. 209 206 */ 210 int posix_sigdelset(posix_sigset_t *set, int signo)207 int sigdelset(sigset_t *set, int signo) 211 208 { 212 209 assert(set != NULL); … … 223 220 * @return 1 if the signal is in the set, 0 otherwise. 224 221 */ 225 int posix_sigismember(const posix_sigset_t *set, int signo)222 int sigismember(const sigset_t *set, int signo) 226 223 { 227 224 assert(set != NULL); … … 239 236 * @param oact 240 237 */ 241 static void _sigaction_unsafe(int sig, const struct posix_sigaction *restrict act,242 struct posix_sigaction *restrict oact)238 static void _sigaction_unsafe(int sig, const struct sigaction *restrict act, 239 struct sigaction *restrict oact) 243 240 { 244 241 if (oact != NULL) { 245 242 memcpy(oact, &_signal_actions[sig], 246 sizeof(struct posix_sigaction));243 sizeof(struct sigaction)); 247 244 } 248 245 249 246 if (act != NULL) { 250 247 memcpy(&_signal_actions[sig], act, 251 sizeof(struct posix_sigaction));248 sizeof(struct sigaction)); 252 249 } 253 250 } … … 263 260 * @return -1 with errno set on failure, 0 on success. 264 261 */ 265 int posix_sigaction(int sig, const struct posix_sigaction *restrict act,266 struct posix_sigaction *restrict oact)262 int sigaction(int sig, const struct sigaction *restrict act, 263 struct sigaction *restrict oact) 267 264 { 268 265 if (sig > _TOP_SIGNAL || (act != NULL && … … 273 270 274 271 if (sig > _TOP_CATCHABLE_SIGNAL) { 275 p osix_psignal(sig,272 psignal(sig, 276 273 "WARNING: registering handler for a partially" 277 274 " or fully unsupported signal. This handler may only be" … … 294 291 * @return SIG_ERR on failure, original handler on success. 295 292 */ 296 void (* posix_signal(int sig, void (*func)(int)))(int)297 { 298 struct posix_sigaction new = {293 void (*signal(int sig, void (*func)(int)))(int) 294 { 295 struct sigaction new = { 299 296 .sa_handler = func, 300 297 .sa_mask = 0, … … 302 299 .sa_sigaction = NULL 303 300 }; 304 struct posix_sigaction old;305 if ( posix_sigaction(sig, func == NULL ? NULL : &new, &old) == 0) {301 struct sigaction old; 302 if (sigaction(sig, func == NULL ? NULL : &new, &old) == 0) { 306 303 return old.sa_handler; 307 304 } else { … … 313 310 link_t link; 314 311 int signo; 315 posix_siginfo_t siginfo;312 siginfo_t siginfo; 316 313 } signal_queue_item; 317 314 … … 322 319 * @param siginfo Additional information about the signal. 323 320 */ 324 static void _queue_signal(int signo, posix_siginfo_t *siginfo)321 static void _queue_signal(int signo, siginfo_t *siginfo) 325 322 { 326 323 assert(signo >= 0 && signo <= _TOP_SIGNAL); … … 330 327 link_initialize(&(item->link)); 331 328 item->signo = signo; 332 memcpy(&item->siginfo, siginfo, sizeof( posix_siginfo_t));329 memcpy(&item->siginfo, siginfo, sizeof(siginfo_t)); 333 330 list_append(&(item->link), &_signal_queue); 334 331 } … … 343 340 * blocked. 344 341 */ 345 static int _raise_sigaction(int signo, posix_siginfo_t *siginfo)342 static int _raise_sigaction(int signo, siginfo_t *siginfo) 346 343 { 347 344 assert(signo >= 0 && signo <= _TOP_SIGNAL); … … 350 347 fibril_mutex_lock(&_signal_mutex); 351 348 352 struct posix_sigaction action = _signal_actions[signo];353 354 if ( posix_sigismember(&_signal_mask, signo) ||349 struct sigaction action = _signal_actions[signo]; 350 351 if (sigismember(&_signal_mask, signo) || 355 352 action.sa_handler == SIG_HOLD) { 356 353 _queue_signal(signo, siginfo); … … 364 361 365 362 if ((action.sa_flags & SA_RESETHAND) && signo != SIGILL && signo != SIGTRAP) { 366 _signal_actions[signo] = (struct posix_sigaction) DEFAULT_HANDLER;363 _signal_actions[signo] = (struct sigaction) DEFAULT_HANDLER; 367 364 } 368 365 … … 394 391 list_get_instance(iterator, signal_queue_item, link); 395 392 396 if (! posix_sigismember(&_signal_mask, item->signo) &&393 if (!sigismember(&_signal_mask, item->signo) && 397 394 _signal_actions[item->signo].sa_handler != SIG_HOLD) { 398 395 list_remove(&(item->link)); … … 411 408 * @return -1 with errno set on failure, 0 on success. 412 409 */ 413 int posix_raise(int sig)410 int raise(int sig) 414 411 { 415 412 if (sig >= 0 && sig <= _TOP_SIGNAL) { 416 posix_siginfo_t siginfo = {413 siginfo_t siginfo = { 417 414 .si_signo = sig, 418 415 .si_code = SI_USER … … 433 430 * action, invalid signal number, lack of permissions, etc.), 0 on success. 434 431 */ 435 int posix_kill(posix_pid_t pid, int signo)432 int kill(pid_t pid, int signo) 436 433 { 437 434 if (pid < 1) { … … 446 443 } 447 444 448 if (pid == (p osix_pid_t) task_get_id()) {449 return posix_raise(signo);445 if (pid == (pid_t) task_get_id()) { 446 return raise(signo); 450 447 } 451 448 … … 471 468 * @return -1 on failure, 0 on success (see kill()). 472 469 */ 473 int posix_killpg(posix_pid_t pid, int sig)470 int killpg(pid_t pid, int sig) 474 471 { 475 472 assert(pid > 1); 476 return posix_kill(-pid, sig);473 return kill(-pid, sig); 477 474 } 478 475 … … 483 480 * @param message String to output alongside human-readable signal description. 484 481 */ 485 void p osix_psiginfo(const posix_siginfo_t *pinfo, const char *message)482 void psiginfo(const siginfo_t *pinfo, const char *message) 486 483 { 487 484 assert(pinfo != NULL); 488 p osix_psignal(pinfo->si_signo, message);485 psignal(pinfo->si_signo, message); 489 486 // TODO: print si_code 490 487 } … … 496 493 * @param message String to output alongside human-readable signal description. 497 494 */ 498 void p osix_psignal(int signum, const char *message)499 { 500 char *sigmsg = posix_strsignal(signum);495 void psignal(int signum, const char *message) 496 { 497 char *sigmsg = strsignal(signum); 501 498 if (message == NULL || *message == '\0') { 502 499 fprintf(stderr, "%s\n", sigmsg); … … 514 511 * @return 0 success, errorcode on failure. 515 512 */ 516 int posix_thread_sigmask(int how, const posix_sigset_t *restrict set,517 posix_sigset_t *restrict oset)513 int thread_sigmask(int how, const sigset_t *restrict set, 514 sigset_t *restrict oset) 518 515 { 519 516 fibril_mutex_lock(&_signal_mutex); … … 554 551 * @return 0 on success, -1 with errno set on failure. 555 552 */ 556 int posix_sigprocmask(int how, const posix_sigset_t *restrict set,557 posix_sigset_t *restrict oset)558 { 559 int result = posix_thread_sigmask(how, set, oset);553 int sigprocmask(int how, const sigset_t *restrict set, 554 sigset_t *restrict oset) 555 { 556 int result = thread_sigmask(how, set, oset); 560 557 if (result != 0) { 561 558 errno = result;
Note:
See TracChangeset
for help on using the changeset viewer.