2 #include <sys/select.h>
12 FILE *fp = NULL, *fp_in = NULL;
13 FILE *out_fp = NULL, *diff_fp = NULL;
14 const char* topcmd = "feg/test.out";
15 const char* top_in_file = "feg/test.in";
17 int fd_in = -1, fd_out;
21 struct timeval tv={.tv_sec=5,.tv_usec=0};
23 while (count < 10000) {
28 printf("(%d)", count);
30 if ((fd_out = open(topcmd, O_RDONLY | O_NONBLOCK)) < 0) {
31 fprintf(stderr, "error executing top\n");
35 if ((fd_in = open(top_in_file, O_WRONLY)) < 0) {
36 fprintf(stderr, "error opening %s\n", top_in_file);
40 if ((flag = fcntl(fd_out, F_GETFL)) == -1) {
41 printf("fcntl get failed\n");
46 FD_SET(fd_out, &readSet);
48 res = select(fd_out + 1, &readSet, NULL, NULL, &tv);
50 printf("select failed: %d,%s\n",fd_out,strerror(errno));
54 if (fcntl(fd_out, F_SETFL, flag & ~O_NONBLOCK) == -1) {
55 printf("fcntl set failed\n");
59 if ((flag = fcntl(fd_out, F_GETFL)) == -1) {
60 printf("fcntl get failed\n");
64 if (flag & O_NONBLOCK == 0) {
65 printf("fd_out still nonblocking\n");
69 if ((fp = fdopen(fd_out, "r")) == NULL) {
70 printf("fdopen failed\n");
74 if ((out_fp = fopen("/tmp/vsys_passwd_test", "w")) == NULL) {
75 printf("could not create tmp file for test\n");
79 while (fgets(buf, sizeof(buf), fp) != NULL) {
80 fprintf(out_fp, "%s",buf);
86 if ((diff_fp = popen("/usr/bin/diff -u /tmp/vsys_passwd_test /etc/passwd","r")) == NULL) {
87 printf("Could not diff results\n");
91 while (fgets(buf, sizeof(buf), diff_fp) != NULL) {
96 printf("Test returned different results - run again to verify\n");
106 printf("test successful.\n");