2 #include <sys/select.h>
11 FILE *fp = NULL, *fp_in = NULL;
12 FILE *out_fp = NULL, *diff_fp = NULL;
13 const char* topcmd = "/vservers/pl_netflow/vsys/test.out";
14 const char* top_in_file = "/vservers/pl_netflow/vsys/test.in";
16 int fd_in = -1, fd_out;
20 struct timeval tv={.tv_sec=5,.tv_usec=0};
29 if ((fd_out = open(topcmd, O_RDONLY | O_NONBLOCK)) < 0) {
30 fprintf(stderr, "error executing top\n");
33 if ((fd_in = open(top_in_file, O_WRONLY)) < 0) {
34 fprintf(stderr, "error opening %s\n", top_in_file);
38 if ((flag = fcntl(fd_out, F_GETFL)) == -1) {
39 printf("fcntl get failed\n");
44 FD_SET(fd_out, &readSet);
46 res = select(fd_out + 1, &readSet, NULL, NULL, &tv);
48 printf("select failed\n");
52 if (fcntl(fd_out, F_SETFL, flag & ~O_NONBLOCK) == -1) {
53 printf("fcntl set failed\n");
57 if ((flag = fcntl(fd_out, F_GETFL)) == -1) {
58 printf("fcntl get failed\n");
62 if (flag & O_NONBLOCK == 0) {
63 printf("fd_out still nonblocking\n");
67 if ((fp = fdopen(fd_out, "r")) == NULL) {
68 printf("fdopen failed\n");
72 if ((out_fp = fopen("/tmp/vsys_passwd_test", "w")) == NULL) {
73 printf("could not create tmp file for test\n");
77 while (fgets(buf, sizeof(buf), fp) != NULL) {
78 fprintf(out_fp, "%s",buf);
84 if ((diff_fp = popen("/usr/bin/diff -u /tmp/vsys_passwd_test /etc/passwd","r")) == NULL) {
85 printf("Could not diff results\n");
89 while (fgets(buf, sizeof(buf), diff_fp) != NULL) {
94 printf("Test returned different results - run again to verify\n");
103 printf("test successful.\n");