int main(int argc, char** argv) { pthread_t threadid; struct timespec tsDelay; // Primitive argument parsing. if (argc > 1) s_debug = 1; print_thread_id("main: "); { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = &SignalHandler; sigemptyset(&sa.sa_mask); sigaction(SIGALRM, &sa, 0); } pthread_create(&threadid, 0, thread_func, 0); // Wait until the thread is inside clock_nanosleep(). tsDelay.tv_sec = 0; tsDelay.tv_nsec = 20 * 1000 * 1000; nanosleep(&tsDelay, 0); // And send SIGALRM to the thread. pthread_kill(threadid, SIGALRM); pthread_join(threadid, 0); return 0; }
int main(int argc, char** argv) { pthread_t threadid; struct timespec tsDelay; if (argc > 1) s_debug = 1; print_thread_id("main: "); { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = &SignalHandler; sigemptyset(&sa.sa_mask); sigaction(SIGALRM, &sa, 0); } if (pthread_create(&threadid, 0, thread_func, 0) != 0) { fprintf(stderr, "Thread creation failed\n"); return 1; } tsDelay.tv_sec = 0; tsDelay.tv_nsec = 20 * 1000 * 1000; nanosleep(&tsDelay, 0); pthread_kill(threadid, SIGALRM); pthread_join(threadid, 0); return 0; }
void* thread_func(void* thread_arg) { print_thread_id("thread: "); sleep(10); //assert(result < 0 && errno == EINTR); return 0; }
void* thread_func(void* thread_arg) { print_thread_id("thread: "); sleep(10); return 0; }
static void SignalHandler(const int iSignal) { print_thread_id("Signal was delivered to "); }
/* Format trace of user ta. Inline with kernel ta */ void trace_printf(const char *function, int line, int level, bool level_ok, const char *fmt, ...) { va_list ap; char buf[MAX_PRINT_SIZE]; size_t boffs = 0; int res; int thread_id; if (level_ok && level > trace_level) return; /* Print the type of message */ res = snprintk(buf, sizeof(buf), "%c/", trace_level_to_string(level, level_ok)); if (res < 0) return; boffs += res; /* Print the location, i.e., TEE core or TA */ res = snprintk(buf + boffs, sizeof(buf) - boffs, "%s:", trace_ext_prefix); if (res < 0) return; boffs += res; /* Print the Thread ID */ if (level_ok && !(BIT(level) & CFG_MSG_LONG_PREFIX_MASK)) thread_id = -1; else thread_id = trace_ext_get_thread_id(); res = print_thread_id(buf + boffs, sizeof(buf) - boffs, thread_id); if (res < 0) return; boffs += res; /* Print the function and line */ if (level_ok && !(BIT(level) & CFG_MSG_LONG_PREFIX_MASK)) function = NULL; if (function) { res = snprintk(buf + boffs, sizeof(buf) - boffs, "%s:%d ", function, line); if (res < 0) return; boffs += res; } va_start(ap, fmt); res = vsnprintk(buf + boffs, sizeof(buf) - boffs, fmt, ap); va_end(ap); if (res > 0) boffs += res; if (boffs >= (sizeof(buf) - 1)) boffs = sizeof(buf) - 2; buf[boffs] = '\n'; while (boffs && buf[boffs] == '\n') boffs--; boffs++; buf[boffs + 1] = '\0'; trace_ext_puts(buf); }