Josh Posted May 18, 2021 Share Posted May 18, 2021 Just making a simple timer is unbelievably complicated and the documentation example can't even run without crashing: Quote Unable to open 'sigprocmask.c': Unable to read file '/build/glibc-eX1tMB/glibc-2.31/sysdeps/unix/sysv/linux/sigprocmask.c' (Error: Unable to resolve non-existing file '/build/glibc-eX1tMB/glibc-2.31/sysdeps/unix/sysv/linux/sigprocmask.c'). #include <stdint.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <signal.h> #include <time.h> #define CLOCKID CLOCK_REALTIME #define SIG SIGRTMIN #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \ } while (0) static void print_siginfo(siginfo_t *si) { timer_t *tidp; int orr; tidp = (timer_t*)si->si_value.sival_ptr; printf(" sival_ptr = %p; ", si->si_value.sival_ptr); printf(" *sival_ptr = %#jx\n", (uintmax_t) *tidp); orr = timer_getoverrun(*tidp); if (orr == -1) errExit("timer_getoverrun"); else printf(" overrun count = %d\n", orr); } static void handler(int sig, siginfo_t *si, void *uc) { /* Note: calling printf() from a signal handler is not safe (and should not be done in production programs), since printf() is not async-signal-safe; see signal-safety(7). Nevertheless, we use printf() here as a simple way of showing that the handler was called. */ printf("Caught signal %d\n", sig); print_siginfo(si); signal(sig, SIG_IGN); } int main(int argc, char *argv[]) { long long msecs = 500; timer_t timerid; struct sigevent sev; struct itimerspec its; long long freq_nanosecs; sigset_t mask; struct sigaction sa; /* Establish handler for timer signal. */ printf("Establishing handler for signal %d\n", SIG); sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = handler; sigemptyset(&sa.sa_mask); if (sigaction(SIG, &sa, NULL) == -1) errExit("sigaction"); /* Block timer signal temporarily. */ printf("Blocking signal %d\n", SIG); sigemptyset(&mask); sigaddset(&mask, SIG); if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) errExit("sigprocmask"); /* Create the timer. */ sev.sigev_notify = SIGEV_SIGNAL; sev.sigev_signo = SIG; sev.sigev_value.sival_ptr = &timerid; if (timer_create(CLOCKID, &sev, &timerid) == -1) errExit("timer_create"); printf("timer ID is %#jx\n", (uintmax_t) timerid); /* Start the timer. */ freq_nanosecs = msecs * 1000000; its.it_value.tv_sec = freq_nanosecs / 1000000000; its.it_value.tv_nsec = freq_nanosecs % 1000000000; its.it_interval.tv_sec = its.it_value.tv_sec; its.it_interval.tv_nsec = its.it_value.tv_nsec; if (timer_settime(timerid, 0, &its, NULL) == -1) errExit("timer_settime"); /* Sleep for a while; meanwhile, the timer may expire multiple times. */ printf("Sleeping for 5 seconds\n"); sleep(5); /* Unlock the timer signal, so that timer notification can be delivered. */ printf("Unblocking signal %d\n", SIG); if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1) errExit("sigprocmask"); exit(EXIT_SUCCESS); } Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted May 18, 2021 Author Share Posted May 18, 2021 The problem is that GDB is stopping every time any signal is received. Very not wanted. https://github.com/microsoft/vscode-cpptools/issues/7546 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Ma-Shell Posted May 18, 2021 Share Posted May 18, 2021 (edited) You can change GDB's behaviour: https://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_38.html Something like handle SIG33 nostop noprint pass should do the trick (whereas SIG33 should correspond to SIGRTMIN). Just put any commands for disabling signals into your .gdbinit file. Edited May 18, 2021 by Ma-Shell formatting 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted May 18, 2021 Author Share Posted May 18, 2021 Ah okay, the .gdbinit file has to be in the home directory, and then it will work. Thanks! Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Ma-Shell Posted May 20, 2021 Share Posted May 20, 2021 Yeah, basically every file starting with a dot belongs into the home directory because the starting dot is basically the Linux way of hiding files and that folder ist the only place where you would want to hide the files because otherwise they clutter your home directory (like on Windows your Documents-directory which is completely unusable for me because every program puts their data there) Quote Link to comment Share on other sites More sharing options...
aiaf Posted May 26, 2021 Share Posted May 26, 2021 Home directory is the usual place to store program configurations for the user ( hidden .filename also .directoryname). Thats why gdb looks there. Also every directory has this: . = current directory .. = parent directory Quote I made this with Leadwerks/UAK: Structura | Stacky Desktop Edition Website: Binary Station Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.