2 #include <sys/select.h>
13 int main(int argc,char *argv[])
15 FILE *fp = NULL, *fp_in = NULL;
16 FILE *out_fp = NULL, *diff_fp = NULL;
19 printf("usage: vsys_conctest <slicename>\n");
22 const char topcmd[IMAPIG];
23 const char top_in_file[IMAPIG];
25 int fd_in = -1, fd_out;
29 struct timeval tv={.tv_sec=5,.tv_usec=0};
31 sprintf("%s/vsys/test.out",argv[1]);
32 sprintf("%s/vsys/test.in",argv[1]);
33 while (count < 200000) {
39 printf("(%d)", count);fflush(stdout);
40 if ((fd_out = open(topcmd, O_RDONLY | O_NONBLOCK)) < 0) {
41 fprintf(stderr, "error executing top\n");
46 while ((fd_in = open(top_in_file, O_WRONLY| O_NONBLOCK)) < 0) {
47 fprintf(stderr, "Waiting for %s (%s)\n", top_in_file,strerror(errno));
52 if ((flag = fcntl(fd_out, F_GETFL)) == -1) {
53 printf("fcntl get failed\n");
59 if ((flag2 = fcntl(fd_in, F_GETFL)) == -1) {
60 printf("fcntl get failed\n");
68 FD_SET(fd_out, &readSet);
71 res = select(fd_out + 1, &readSet, NULL, NULL, NULL);
74 if (errno == EINTR || errno == EAGAIN) {
78 fprintf(stderr,"select failed errno=%d errstr=%s\n", errno, strerror(errno));
81 break; /* we're done */
85 if (fcntl(fd_out, F_SETFL, flag & ~O_NONBLOCK) == -1) {
86 printf("fcntl set failed\n");
92 if ((flag = fcntl(fd_out, F_GETFL)) == -1) {
93 printf("fcntl get failed\n");
100 if (fcntl(fd_in, F_SETFL, flag2 & ~O_NONBLOCK) == -1) {
101 printf("fcntl set failed\n");
106 if ((flag2 = fcntl(fd_in, F_GETFL)) == -1) {
107 printf("fcntl get failed\n");
112 if (flag & O_NONBLOCK == 0) {
113 printf("fd_out still nonblocking\n");
117 if (flag & O_NONBLOCK == 0) {
118 printf("fd_in still nonblocking\n");
121 if ((fp = fdopen(fd_out, "r")) == NULL) {
122 printf("fdopen failed\n");
126 while (fgets(buf, sizeof(buf), fp) != NULL) {
131 printf("Test returned different results - run again to verify\n");
140 printf("test successful.\n");