From 406c3a3b7ddefbfadbae9ac1858a4b235c7e6cfd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 19 Feb 2015 08:41:15 -0600 Subject: apps/examples/ostest: Sample errno on returns from sem_timedwait(). Otherwise, intervening system calls my change the value of the reported errno. Noted by Juha Niskanen --- apps/examples/ostest/semtimed.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'apps/examples/ostest') diff --git a/apps/examples/ostest/semtimed.c b/apps/examples/ostest/semtimed.c index 447f97cc5..fc147aa06 100644 --- a/apps/examples/ostest/semtimed.c +++ b/apps/examples/ostest/semtimed.c @@ -1,7 +1,7 @@ /*********************************************************************** * apps/examples/ostest/semtimed.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -92,6 +92,7 @@ void semtimed_test(void) int prio_min; int prio_max; int prio_mid; + int errcode; pthread_attr_t attr; int status; @@ -106,7 +107,9 @@ void semtimed_test(void) abstime.tv_nsec = before.tv_nsec; printf("semtimed_test: Waiting for two second timeout\n"); - status = sem_timedwait(&sem, &abstime); + status = sem_timedwait(&sem, &abstime); + errcode = errno; + (void)clock_gettime(CLOCK_REALTIME, &after); if (status == OK) @@ -115,7 +118,6 @@ void semtimed_test(void) } else { - int errcode = errno; if (errcode == ETIMEDOUT) { printf("samwait_test: PASS\n"); @@ -192,12 +194,13 @@ void semtimed_test(void) abstime.tv_nsec = before.tv_nsec; printf("semtimed_test: Waiting for two second timeout\n"); - status = sem_timedwait(&sem, &abstime); + status = sem_timedwait(&sem, &abstime); + errcode = errno; + (void)clock_gettime(CLOCK_REALTIME, &after); if (status < 0) { - int errcode = errno; printf("semtimed_test: ERROR: sem_timedwait failed with: %d\n", errcode); } else -- cgit v1.2.3