#define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include static int calls=0; static int camera_fd(int fd){char name[64],target[256];snprintf(name,sizeof(name),"/proc/self/fd/%d",fd);ssize_t n=readlink(name,target,sizeof(target)-1);if(n<0)return 0;target[n]=0;return strcmp(target,"/dev/video5")==0;} static long long now_ms(void){struct timespec t;clock_gettime(CLOCK_MONOTONIC,&t);return (long long)t.tv_sec*1000+t.tv_nsec/1000000;} static void marker(const char *s){ssize_t ignored=write(2,s,strlen(s));(void)ignored;} static int should_stall(void){ static long long since=0;static int phase=0,resumed=0; if(!getenv("VAP_TEST_STALL"))return 0; if(phase==0){if(++calls<60)return 0;phase=1;since=now_ms();marker("TEST_STALL_ACTIVE\n");} if(phase==1&&getenv("VAP_TEST_RECOVER")&&now_ms()-since>=4200){phase=2;marker("TEST_CAMERA_RECOVERED\n");return 0;} if(phase==2){if(++resumed<30)return 0;phase=3;marker("TEST_STALL_SECOND\n");} return phase==1||phase==3; } int poll(struct pollfd *fds,nfds_t count,int timeout){static int(*real_poll)(struct pollfd*,nfds_t,int);if(!real_poll)real_poll=dlsym(RTLD_NEXT,"poll");for(nfds_t i=0;iflags|=V4L2_BUF_FLAG_ERROR;return rc;} errno=strcmp(kind,"device_error")==0?ENODEV:EIO;return -1; } return real_ioctl(fd,request,arg); }