@@ -646,16 +646,20 @@ void timeout_negative(const char* command) {
646
646
recv (fd, msg_timeout.buf , sizeof (msg_timeout), 0 ) > 0 ;
647
647
}
648
648
649
- alarm_timeout =
650
- alarm ((old_alarm <= 0 ) ? old_alarm
651
- : (old_alarm > (1 + 3 - alarm_wrap))
652
- ? old_alarm - 3 + alarm_wrap
653
- : 2 );
649
+ if (old_alarm > 0 ) {
650
+ unsigned int time_spent = 3 - alarm_wrap;
651
+ if (old_alarm > time_spent + 1 ) {
652
+ old_alarm -= time_spent;
653
+ } else {
654
+ old_alarm = 2 ;
655
+ }
656
+ }
657
+ alarm_timeout = alarm (old_alarm);
654
658
sigaction (SIGALRM, &old_sigaction, nullptr );
655
659
656
660
close (fd);
657
661
658
- if (! content_wrap && ! alarm_wrap && content_timeout && alarm_timeout) {
662
+ if (content_wrap && alarm_wrap && content_timeout && alarm_timeout) {
659
663
break ;
660
664
}
661
665
}
@@ -710,8 +714,8 @@ TEST(logd, timeout) {
710
714
// A few tries to get it right just in case wrap kicks in due to
711
715
// content providers being active during the test.
712
716
int i = 5 ;
713
- log_time now (android_log_clockid ());
714
- now .tv_sec -= 30 ; // reach back a moderate period of time
717
+ log_time start (android_log_clockid ());
718
+ start .tv_sec -= 30 ; // reach back a moderate period of time
715
719
716
720
while (--i) {
717
721
int fd = socket_local_client (" logdr" , ANDROID_SOCKET_NAMESPACE_RESERVED,
@@ -726,7 +730,7 @@ TEST(logd, timeout) {
726
730
std::string ask = android::base::StringPrintf (
727
731
" dumpAndClose lids=0,1,2,3,4,5 timeout=6 start=%" PRIu32
728
732
" .%09" PRIu32,
729
- now .tv_sec , now .tv_nsec );
733
+ start .tv_sec , start .tv_nsec );
730
734
731
735
struct sigaction ignore, old_sigaction;
732
736
memset (&ignore, 0 , sizeof (ignore));
@@ -756,11 +760,15 @@ TEST(logd, timeout) {
756
760
recv (fd, msg_timeout.buf , sizeof (msg_timeout), 0 ) > 0 ;
757
761
}
758
762
759
- alarm_timeout =
760
- alarm ((old_alarm <= 0 ) ? old_alarm
761
- : (old_alarm > (1 + 3 - alarm_wrap))
762
- ? old_alarm - 3 + alarm_wrap
763
- : 2 );
763
+ if (old_alarm > 0 ) {
764
+ unsigned int time_spent = 3 - alarm_wrap;
765
+ if (old_alarm > time_spent + 1 ) {
766
+ old_alarm -= time_spent;
767
+ } else {
768
+ old_alarm = 2 ;
769
+ }
770
+ }
771
+ alarm_timeout = alarm (old_alarm);
764
772
sigaction (SIGALRM, &old_sigaction, nullptr );
765
773
766
774
close (fd);
@@ -773,23 +781,23 @@ TEST(logd, timeout) {
773
781
// active _or_ inactive during the test.
774
782
if (content_timeout) {
775
783
log_time msg (msg_timeout.entry .sec , msg_timeout.entry .nsec );
776
- if (msg < now ) {
784
+ if (msg < start ) {
777
785
fprintf (stderr, " %u.%09u < %u.%09u\n " , msg_timeout.entry .sec ,
778
- msg_timeout.entry .nsec , (unsigned )now .tv_sec ,
779
- (unsigned )now .tv_nsec );
786
+ msg_timeout.entry .nsec , (unsigned )start .tv_sec ,
787
+ (unsigned )start .tv_nsec );
780
788
_exit (-1 );
781
789
}
782
- if (msg > now ) {
783
- now = msg;
784
- now .tv_sec += 30 ;
785
- msg = log_time (android_log_clockid ());
786
- if (now > msg ) {
787
- now = msg ;
788
- --now .tv_sec ;
790
+ if (msg > start ) {
791
+ start = msg;
792
+ start .tv_sec += 30 ;
793
+ log_time now = log_time (android_log_clockid ());
794
+ if (start > now ) {
795
+ start = now ;
796
+ --start .tv_sec ;
789
797
}
790
798
}
791
799
} else {
792
- now .tv_sec -= 120 ; // inactive, reach further back!
800
+ start .tv_sec -= 120 ; // inactive, reach further back!
793
801
}
794
802
}
795
803
@@ -802,8 +810,8 @@ TEST(logd, timeout) {
802
810
}
803
811
804
812
if (content_wrap || !content_timeout) {
805
- fprintf (stderr, " now =%" PRIu32 " .%09" PRIu32 " \n " , now .tv_sec ,
806
- now .tv_nsec );
813
+ fprintf (stderr, " start =%" PRIu32 " .%09" PRIu32 " \n " , start .tv_sec ,
814
+ start .tv_nsec );
807
815
}
808
816
809
817
EXPECT_TRUE (written);
0 commit comments