From 0ab1b0de25216ac895d0760389a9cfa7e30da5e8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 28 Aug 2014 17:00:24 -0600 Subject: [PATCH] nuttx/sched: Remove explicit references to errno. That is a problem from within the kernel for certain configurations --- sched/clock/clock_gettimeofday.c | 2 +- sched/environ/env_putenv.c | 2 +- sched/environ/env_setenv.c | 2 +- sched/errno/Make.defs | 2 +- sched/pthread/pthread_setschedprio.c | 5 +++-- sched/sched/sched_setparam.c | 4 ++-- sched/sched/sched_setpriority.c | 2 +- sched/sched/sched_setscheduler.c | 4 ++-- sched/semaphore/sem_destroy.c | 2 +- sched/task/task_posixspawn.c | 4 ++-- sched/task/task_spawn.c | 4 ++-- sched/task/task_spawnparms.c | 8 ++++---- sched/timer/timer_create.c | 6 +++--- sched/timer/timer_getoverrun.c | 2 +- sched/timer/timer_settime.c | 2 +- 15 files changed, 26 insertions(+), 25 deletions(-) diff --git a/sched/clock/clock_gettimeofday.c b/sched/clock/clock_gettimeofday.c index 46db6e6982..22a58d052a 100644 --- a/sched/clock/clock_gettimeofday.c +++ b/sched/clock/clock_gettimeofday.c @@ -93,7 +93,7 @@ int gettimeofday(struct timeval *tp, void *tzp) #ifdef CONFIG_DEBUG if (!tp) { - errno = EINVAL; + set_errno(EINVAL); return ERROR; } #endif diff --git a/sched/environ/env_putenv.c b/sched/environ/env_putenv.c index 74120f7af8..e0a69bf936 100644 --- a/sched/environ/env_putenv.c +++ b/sched/environ/env_putenv.c @@ -113,7 +113,7 @@ int putenv(FAR const char *string) return ret; errout: - errno = ret; + set_errno(ret); return ERROR; } diff --git a/sched/environ/env_setenv.c b/sched/environ/env_setenv.c index c00efb3049..e78cc8c89a 100644 --- a/sched/environ/env_setenv.c +++ b/sched/environ/env_setenv.c @@ -197,7 +197,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) errout_with_lock: sched_unlock(); errout: - errno = ret; + set_errno(ret); return ERROR; } diff --git a/sched/errno/Make.defs b/sched/errno/Make.defs index 481b398123..b96d49bee1 100644 --- a/sched/errno/Make.defs +++ b/sched/errno/Make.defs @@ -35,7 +35,7 @@ ERRNO_SRCS = errno_getptr.c -ifeq ($(CONFIG_NUTTX_KERNEL),y) +ifeq ($(CONFIG_LIB_SYSCALL),y) ERRNO_SRCS += errno_get.c errno_set.c endif diff --git a/sched/pthread/pthread_setschedprio.c b/sched/pthread/pthread_setschedprio.c index 4d8c6c7317..ff0536b3a6 100644 --- a/sched/pthread/pthread_setschedprio.c +++ b/sched/pthread/pthread_setschedprio.c @@ -104,7 +104,7 @@ int pthread_setschedprio(pthread_t thread, int prio) /* Set the errno to some non-zero value (failsafe) */ - errno = EINVAL; + set_errno(EINVAL); /* Call sched_setparam() to change the priority */ @@ -114,7 +114,8 @@ int pthread_setschedprio(pthread_t thread, int prio) { /* If sched_setparam() fails, return the errno */ - ret = errno; + ret = get_errno(); } + return ret; } diff --git a/sched/sched/sched_setparam.c b/sched/sched/sched_setparam.c index 2d954a23b7..74da23035a 100644 --- a/sched/sched/sched_setparam.c +++ b/sched/sched/sched_setparam.c @@ -115,7 +115,7 @@ int sched_setparam(pid_t pid, const struct sched_param *param) if (!param) { - errno = EINVAL; + set_errno(EINVAL); return ERROR; } @@ -142,7 +142,7 @@ int sched_setparam(pid_t pid, const struct sched_param *param) { /* No task with this pid was found */ - errno = ESRCH; + set_errno(ESRCH); sched_unlock(); return ERROR; } diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c index ab2b0ec8e2..177148a3a4 100644 --- a/sched/sched/sched_setpriority.c +++ b/sched/sched/sched_setpriority.c @@ -112,7 +112,7 @@ int sched_setpriority(FAR struct tcb_s *tcb, int sched_priority) if (sched_priority < SCHED_PRIORITY_MIN || sched_priority > SCHED_PRIORITY_MAX) { - errno = EINVAL; + set_errno(EINVAL); return ERROR; } diff --git a/sched/sched/sched_setscheduler.c b/sched/sched/sched_setscheduler.c index 62aa9cac22..d70e24f704 100644 --- a/sched/sched/sched_setscheduler.c +++ b/sched/sched/sched_setscheduler.c @@ -122,7 +122,7 @@ int sched_setscheduler(pid_t pid, int policy, if (policy != SCHED_FIFO) #endif { - errno = EINVAL; + set_errno(EINVAL); return ERROR; } @@ -138,7 +138,7 @@ int sched_setscheduler(pid_t pid, int policy, tcb = sched_gettcb(pid); if (!tcb) { - errno = ESRCH; + set_errno(ESRCH); return ERROR; } diff --git a/sched/semaphore/sem_destroy.c b/sched/semaphore/sem_destroy.c index 790fe3ee48..c4b0fc2169 100644 --- a/sched/semaphore/sem_destroy.c +++ b/sched/semaphore/sem_destroy.c @@ -120,7 +120,7 @@ int sem_destroy (FAR sem_t *sem) } else { - errno = -EINVAL; + set_errno(EINVAL); return ERROR; } } diff --git a/sched/task/task_posixspawn.c b/sched/task/task_posixspawn.c index 2973cb544d..5a831b95ab 100644 --- a/sched/task/task_posixspawn.c +++ b/sched/task/task_posixspawn.c @@ -132,7 +132,7 @@ static int posix_spawn_exec(FAR pid_t *pidp, FAR const char *path, pid = exec(path, (FAR char * const *)argv, symtab, nsymbols); if (pid < 0) { - ret = errno; + ret = get_errno(); sdbg("ERROR: exec failed: %d\n", ret); goto errout; } @@ -403,7 +403,7 @@ int posix_spawn(FAR pid_t *pid, FAR const char *path, ret = sched_getparam(0, ¶m); if (ret < 0) { - int errcode = errno; + int errcode = get_errno(); sdbg("ERROR: sched_getparam failed: %d\n", errcode); spawn_semgive(&g_spawn_parmsem); diff --git a/sched/task/task_spawn.c b/sched/task/task_spawn.c index bc0eef13fb..2f556120fd 100644 --- a/sched/task/task_spawn.c +++ b/sched/task/task_spawn.c @@ -152,7 +152,7 @@ static int task_spawn_exec(FAR pid_t *pidp, FAR const char *name, pid = TASK_CREATE(name, priority, stacksize, entry, argv); if (pid < 0) { - ret = errno; + ret = get_errno(); sdbg("ERROR: TASK_CREATE failed: %d\n", ret); goto errout; } @@ -395,7 +395,7 @@ int task_spawn(FAR pid_t *pid, FAR const char *name, main_t entry, ret = sched_getparam(0, ¶m); if (ret < 0) { - int errcode = errno; + int errcode = get_errno(); sdbg("ERROR: sched_getparam failed: %d\n", errcode); spawn_semgive(&g_spawn_parmsem); diff --git a/sched/task/task_spawnparms.c b/sched/task/task_spawnparms.c index 7a8cad6c48..20a02d083c 100644 --- a/sched/task/task_spawnparms.c +++ b/sched/task/task_spawnparms.c @@ -108,7 +108,7 @@ static inline int spawn_dup2(FAR struct spawn_dup2_file_action_s *action) ret = dup2(action->fd1, action->fd2); if (ret < 0) { - int errcode = errno; + int errcode = get_errno(); sdbg("ERROR: dup2 failed: %d\n", errcode); return errcode; @@ -130,7 +130,7 @@ static inline int spawn_open(FAR struct spawn_open_file_action_s *action) fd = open(action->path, action->oflags, action->mode); if (fd < 0) { - ret = errno; + ret = get_errno(); sdbg("ERROR: open failed: %d\n", ret); } @@ -147,7 +147,7 @@ static inline int spawn_open(FAR struct spawn_open_file_action_s *action) ret = dup2(fd, action->fd); if (ret < 0) { - ret = errno; + ret = get_errno(); sdbg("ERROR: dup2 failed: %d\n", ret); } @@ -184,7 +184,7 @@ void spawn_semtake(FAR sem_t *sem) do { ret = sem_wait(sem); - ASSERT(ret == 0 || errno == EINTR); + ASSERT(ret == 0 || get_errno() == EINTR); } while (ret != 0); } diff --git a/sched/timer/timer_create.c b/sched/timer/timer_create.c index 71a83546fc..3c1a4c1d3a 100644 --- a/sched/timer/timer_create.c +++ b/sched/timer/timer_create.c @@ -184,7 +184,7 @@ int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timer if (!timerid || clockid != CLOCK_REALTIME) { - errno = EINVAL; + set_errno(EINVAL); return ERROR; } @@ -193,7 +193,7 @@ int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timer wdog = wd_create(); if (!wdog) { - errno = EAGAIN; + set_errno(EAGAIN); return ERROR; } @@ -202,7 +202,7 @@ int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timer ret = timer_allocate(); if (!ret) { - errno = EAGAIN; + set_errno(EAGAIN); return ERROR; } diff --git a/sched/timer/timer_getoverrun.c b/sched/timer/timer_getoverrun.c index aa8eab3aa0..c0a34c33ab 100644 --- a/sched/timer/timer_getoverrun.c +++ b/sched/timer/timer_getoverrun.c @@ -104,7 +104,7 @@ int timer_getoverrun(timer_t timerid) { - errno = ENOSYS; + set_errno(ENOSYS); return ERROR; } diff --git a/sched/timer/timer_settime.c b/sched/timer/timer_settime.c index 716d05caf6..1039a1fa7f 100644 --- a/sched/timer/timer_settime.c +++ b/sched/timer/timer_settime.c @@ -304,7 +304,7 @@ int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value if (!timer || !value) { - errno = EINVAL; + set_errno(EINVAL); return ERROR; }