From: Dmitry V. Levin Date: Sat, 4 Jul 2015 08:56:21 +0000 (+0000) Subject: time.c: move rtc ioctl parser to a separate file X-Git-Tag: v4.11~483 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=746db06d919694e5c32ab7d2369b31a55d4f503b;p=strace time.c: move rtc ioctl parser to a separate file * rtc.c: new file * Makefile.am (strace_SOURCES): Add it. * time.c (print_rtc, rtc_ioctl): Move to rtc.c. --- diff --git a/Makefile.am b/Makefile.am index e2a0f747..4790f325 100644 --- a/Makefile.am +++ b/Makefile.am @@ -90,6 +90,7 @@ strace_SOURCES = \ regs.h \ renameat.c \ resource.c \ + rtc.c \ sched.c \ scsi.c \ seccomp.c \ diff --git a/rtc.c b/rtc.c new file mode 100644 index 00000000..f72f98ab --- /dev/null +++ b/rtc.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2004 Ulrich Drepper + * Copyright (c) 2004 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "defs.h" +#include +#include + +static void +print_rtc(struct tcb *tcp, const struct rtc_time *rt) +{ + tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, " + "tm_mday=%d, tm_mon=%d, tm_year=%d, ", + rt->tm_sec, rt->tm_min, rt->tm_hour, + rt->tm_mday, rt->tm_mon, rt->tm_year); + if (!abbrev(tcp)) + tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}", + rt->tm_wday, rt->tm_yday, rt->tm_isdst); + else + tprints("...}"); +} + +int +rtc_ioctl(struct tcb *tcp, const unsigned int code, const long arg) +{ + switch (code) { + case RTC_ALM_SET: + case RTC_SET_TIME: + if (entering(tcp)) { + struct rtc_time rt; + if (umove(tcp, arg, &rt) < 0) + tprintf(", %#lx", arg); + else { + tprints(", "); + print_rtc(tcp, &rt); + } + } + break; + case RTC_ALM_READ: + case RTC_RD_TIME: + if (exiting(tcp)) { + struct rtc_time rt; + if (syserror(tcp) || umove(tcp, arg, &rt) < 0) + tprintf(", %#lx", arg); + else { + tprints(", "); + print_rtc(tcp, &rt); + } + } + break; + case RTC_IRQP_SET: + case RTC_EPOCH_SET: + if (entering(tcp)) + tprintf(", %lu", arg); + break; + case RTC_IRQP_READ: + case RTC_EPOCH_READ: + if (exiting(tcp)) + tprintf(", %lu", arg); + break; + case RTC_WKALM_SET: + if (entering(tcp)) { + struct rtc_wkalrm wk; + if (umove(tcp, arg, &wk) < 0) + tprintf(", %#lx", arg); + else { + tprintf(", {enabled=%d, pending=%d, ", + wk.enabled, wk.pending); + print_rtc(tcp, &wk.time); + tprints("}"); + } + } + break; + case RTC_WKALM_RD: + if (exiting(tcp)) { + struct rtc_wkalrm wk; + if (syserror(tcp) || umove(tcp, arg, &wk) < 0) + tprintf(", %#lx", arg); + else { + tprintf(", {enabled=%d, pending=%d, ", + wk.enabled, wk.pending); + print_rtc(tcp, &wk.time); + tprints("}"); + } + } + break; + default: + return 0; + } + return 1; +} diff --git a/time.c b/time.c index b30fd0f2..f315f5da 100644 --- a/time.c +++ b/time.c @@ -31,8 +31,6 @@ #include #include #include -#include -#include #ifndef UTIME_NOW #define UTIME_NOW ((1l << 30) - 1l) @@ -704,92 +702,6 @@ SYS_FUNC(timer_gettime) return 0; } -static void -print_rtc(struct tcb *tcp, const struct rtc_time *rt) -{ - tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, " - "tm_mday=%d, tm_mon=%d, tm_year=%d, ", - rt->tm_sec, rt->tm_min, rt->tm_hour, - rt->tm_mday, rt->tm_mon, rt->tm_year); - if (!abbrev(tcp)) - tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}", - rt->tm_wday, rt->tm_yday, rt->tm_isdst); - else - tprints("...}"); -} - -int -rtc_ioctl(struct tcb *tcp, const unsigned int code, long arg) -{ - switch (code) { - case RTC_ALM_SET: - case RTC_SET_TIME: - if (entering(tcp)) { - struct rtc_time rt; - if (umove(tcp, arg, &rt) < 0) - tprintf(", %#lx", arg); - else { - tprints(", "); - print_rtc(tcp, &rt); - } - } - break; - case RTC_ALM_READ: - case RTC_RD_TIME: - if (exiting(tcp)) { - struct rtc_time rt; - if (syserror(tcp) || umove(tcp, arg, &rt) < 0) - tprintf(", %#lx", arg); - else { - tprints(", "); - print_rtc(tcp, &rt); - } - } - break; - case RTC_IRQP_SET: - case RTC_EPOCH_SET: - if (entering(tcp)) - tprintf(", %lu", arg); - break; - case RTC_IRQP_READ: - case RTC_EPOCH_READ: - if (exiting(tcp)) - tprintf(", %lu", arg); - break; - case RTC_WKALM_SET: - if (entering(tcp)) { - struct rtc_wkalrm wk; - if (umove(tcp, arg, &wk) < 0) - tprintf(", %#lx", arg); - else { - tprintf(", {enabled=%d, pending=%d, ", - wk.enabled, wk.pending); - print_rtc(tcp, &wk.time); - tprints("}"); - } - } - break; - case RTC_WKALM_RD: - if (exiting(tcp)) { - struct rtc_wkalrm wk; - if (syserror(tcp) || umove(tcp, arg, &wk) < 0) - tprintf(", %#lx", arg); - else { - tprintf(", {enabled=%d, pending=%d, ", - wk.enabled, wk.pending); - print_rtc(tcp, &wk.time); - tprints("}"); - } - } - break; - default: - if (entering(tcp)) - tprintf(", %#lx", arg); - break; - } - return 1; -} - #include "xlat/timerfdflags.h" SYS_FUNC(timerfd)