diff --git a/lib/libc/gen/exterr_cat_filenames.h b/lib/libc/gen/exterr_cat_filenames.h --- a/lib/libc/gen/exterr_cat_filenames.h +++ b/lib/libc/gen/exterr_cat_filenames.h @@ -11,6 +11,7 @@ [EXTERR_CAT_FILEDESC] = "kern/kern_descrip.c", [EXTERR_CAT_PROCEXIT] = "kern/kern_exit.c", [EXTERR_CAT_FORK] = "kern/kern_fork.c", + [EXTERR_CAT_TIME] = "kern/kern_time.c", [EXTERR_CAT_GENIO] = "kern/sys_generic.c", [EXTERR_CAT_VFSBIO] = "kern/vfs_bio.c", [EXTERR_CAT_INOTIFY] = "kern/vfs_inotify.c", diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -32,10 +32,12 @@ #include #include "opt_ktrace.h" +#define EXTERR_CATEGORY EXTERR_CAT_TIME #include #include #include #include +#include #include #include #include @@ -216,7 +218,7 @@ *clk_id = MAKE_THREAD_CPUCLOCK(tid); return (0); default: - return (EINVAL); + return (EXTERROR(EINVAL, "Invalid CPUCLOCK_WHICH %jd", which)); } } @@ -300,14 +302,14 @@ tid = clock_id & CPUCLOCK_ID_MASK; td2 = tdfind(tid, p->p_pid); if (td2 == NULL) - return (EINVAL); + return (EXTERROR(EINVAL, "Invalid thread id %jd", tid)); kern_thread_cputime(td2, ats); PROC_UNLOCK(td2->td_proc); } else { pid = clock_id & CPUCLOCK_ID_MASK; error = pget(pid, PGET_CANSEE, &p2); if (error != 0) - return (EINVAL); + return (EXTERROR(EINVAL, "Invalid process id %jd", pid)); kern_process_cputime(p2, ats); PROC_UNLOCK(p2); } @@ -381,7 +383,7 @@ break; default: if ((int)clock_id >= 0) - return (EINVAL); + return (EXTERROR(EINVAL, "Unknown clock id %jd", clock_id)); return (get_cputime(td, clock_id, ats)); } return (0); @@ -419,13 +421,13 @@ if ((error = priv_check(td, PRIV_CLOCK_SETTIME)) != 0) return (error); if (clock_id != CLOCK_REALTIME) - return (EINVAL); + return (EXTERROR(EINVAL, "clock_id %jd not CLOCK_REALTIME", clock_id)); if (!timespecvalid_interval(ats)) - return (EINVAL); + return (EXTERROR(EINVAL, "Invalid timespec")); if (!allow_insane_settime && (ats->tv_sec > 8000ULL * 365 * 24 * 60 * 60 || ats->tv_sec < utc_offset())) - return (EINVAL); + return (EXTERROR(EINVAL, "Insane clock jump")); /* XXX Don't convert nsec->usec and back */ TIMESPEC_TO_TIMEVAL(&atv, ats); error = settime(td, &atv); @@ -493,7 +495,7 @@ default: if ((int)clock_id < 0) goto cputime; - return (EINVAL); + return (EXTERROR(EINVAL, "clock_id %jd invalid", clock_id)); } return (0); } @@ -523,9 +525,9 @@ bool is_abs_real, precise; if (rqt->tv_nsec < 0 || rqt->tv_nsec >= NS_PER_SEC) - return (EINVAL); + return (EXTERROR(EINVAL, "rqt bad nanosecond %jd", rqt->tv_nsec)); if ((flags & ~TIMER_ABSTIME) != 0) - return (EINVAL); + return (EXTERROR(EINVAL, "Bad timer flags set %#jx", flags)); switch (clock_id) { case CLOCK_REALTIME: case CLOCK_TAI: @@ -562,7 +564,7 @@ return (ENOTSUP); case CLOCK_THREAD_CPUTIME_ID: default: - return (EINVAL); + return (EXTERROR(EINVAL, "clock_id %jd invalid", clock_id)); } do { ts = *rqt; @@ -743,7 +745,8 @@ if (tv) { if (tv->tv_usec < 0 || tv->tv_usec >= 1000000 || tv->tv_sec < 0) - return (EINVAL); + return (EXTERROR(EINVAL, "Bad timeval %jd %jd", + tv->tv_sec, tv->tv_usec)); error = settime(td, tv); } return (error); @@ -795,7 +798,7 @@ struct timeval ctv; if (which > ITIMER_PROF) - return (EINVAL); + return (EXTERROR(EINVAL, "Invalid itimer type %ju", which)); if (which == ITIMER_REAL) { /* @@ -863,19 +866,22 @@ return (kern_getitimer(td, which, oitv)); if (which > ITIMER_PROF) - return (EINVAL); + return (EXTERROR(EINVAL, "Invalid itimer type %ju", which)); #ifdef KTRACE if (KTRPOINT(td, KTR_STRUCT)) ktritimerval(aitv); #endif if (itimerfix(&aitv->it_value) || aitv->it_value.tv_sec > INT32_MAX / 2) - return (EINVAL); + return (EXTERROR(EINVAL, "Interval too large %jd", + aitv->it_value.tv_sec)); if (!timevalisset(&aitv->it_value)) timevalclear(&aitv->it_interval); else if (itimerfix(&aitv->it_interval) || aitv->it_interval.tv_sec > INT32_MAX / 2) - return (EINVAL); + return (EXTERROR(EINVAL, + "Interval too large for existing timer %jd", + aitv->it_interval.tv_sec)); if (which == ITIMER_REAL) { PROC_LOCK(p); @@ -1282,20 +1288,22 @@ int error; if (clock_id < 0 || clock_id >= MAX_CLOCKS) - return (EINVAL); + return (EXTERROR(EINVAL, "Invalid clock_id %jd", clock_id)); if (posix_clocks[clock_id].timer_create == NULL) - return (EINVAL); + return (EXTERROR(EINVAL, "Null posix clock %jd",clock_id)); if (evp != NULL) { if (evp->sigev_notify != SIGEV_NONE && evp->sigev_notify != SIGEV_SIGNAL && evp->sigev_notify != SIGEV_THREAD_ID) - return (EINVAL); + return (EXTERROR(EINVAL, "sigev_notify invalid %jd", + evp->sigev_notify)); if ((evp->sigev_notify == SIGEV_SIGNAL || evp->sigev_notify == SIGEV_THREAD_ID) && !_SIG_VALID(evp->sigev_signo)) - return (EINVAL); + return (EXTERROR(EINVAL, "signal number invalid %jd", + evp->sigev_notify)); } if (p->p_itimers == NULL) @@ -1420,7 +1428,7 @@ it = itimer_find(p, timerid); if (it == NULL) { PROC_UNLOCK(p); - return (EINVAL); + return (EXTERROR(EINVAL, "No itimer found id %jd", timerid)); } PROC_UNLOCK(p); @@ -1478,7 +1486,7 @@ PROC_LOCK(p); if (timer_id < 3 || (it = itimer_find(p, timer_id)) == NULL) { PROC_UNLOCK(p); - error = EINVAL; + error = EXTERROR(EINVAL, "No itimer found %jd", timer_id); } else { PROC_UNLOCK(p); itimer_enter(it); @@ -1519,7 +1527,7 @@ PROC_LOCK(p); if (timer_id < 3 || (it = itimer_find(p, timer_id)) == NULL) { PROC_UNLOCK(p); - error = EINVAL; + error = EXTERROR(EINVAL, "No itimer found %d", timer_id); } else { PROC_UNLOCK(p); itimer_enter(it); @@ -1553,7 +1561,7 @@ if (timer_id < 3 || (it = itimer_find(p, timer_id)) == NULL) { PROC_UNLOCK(p); - error = EINVAL; + error = EXTERROR(EINVAL, "No itimer found %jd", timer_id); } else { td->td_retval[0] = it->it_overrun_last; ITIMER_UNLOCK(it); @@ -1625,11 +1633,11 @@ val = *value; if (itimespecfix(&val.it_value)) - return (EINVAL); + return (EXTERROR(EINVAL, "Cannot fix itimer")); if (timespecisset(&val.it_value)) { if (itimespecfix(&val.it_interval)) - return (EINVAL); + return (EXTERROR(EINVAL, "Cannot fix interval")); } else { timespecclear(&val.it_interval); } diff --git a/sys/sys/exterr_cat.h b/sys/sys/exterr_cat.h --- a/sys/sys/exterr_cat.h +++ b/sys/sys/exterr_cat.h @@ -40,6 +40,7 @@ #define EXTERR_CAT_FORK 15 #define EXTERR_CAT_PROCEXIT 16 #define EXTERR_CAT_VMM 17 +#define EXTERR_CAT_TIME 18 #endif