According to the Linux kernel code, we know that the sigqueue is
allocated and queue the signal to it's list by the system call
rt_sigqueueinfo(2) which called by sigqueue(3) in this test code.
Meanwhile, if the signal is queued, it increase the user's sigpending
field. Then if it going to queue another signal, it read the rlimit of
the sigpending from the task's signal->rlim[] member and compare with
the user's current sigpending number.
So, it's the issue. The user who is running this code may have other
pending signals before this, and actually it does.

This patch read the pending signal's number from the /proc/<pid>/status
and minus it. Eliminate the impact of other pending signals.

Signed-off-by: Wanlong Gao <[email protected]>
Signed-off-by: Peng Haitao <[email protected]>
---
 .../conformance/interfaces/sigqueue/9-1.c          |   62 ++++++++++++++++++--
 1 files changed, 57 insertions(+), 5 deletions(-)

diff --git 
a/testcases/open_posix_testsuite/conformance/interfaces/sigqueue/9-1.c 
b/testcases/open_posix_testsuite/conformance/interfaces/sigqueue/9-1.c
index 6320384..a96d194 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigqueue/9-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigqueue/9-1.c
@@ -29,17 +29,69 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <string.h>
+#include <fcntl.h>
 #include "posixtest.h"
 
 void myhandler(int signo, siginfo_t *info, void *context) {
        printf ("Inside Handler\n");
 }
 
+void get_sigpending(int pid, long *current)
+{
+       int fd, len;
+       char procdir[128] = "";
+       char line[1024] = "";
+       char *pos, *pos2, *sig;
+
+       snprintf(procdir, sizeof(procdir) - 1, "/proc/%d/status", pid);
+       procdir[sizeof(procdir) - 1] = '\0';
+
+       fd = open(procdir, O_RDONLY);
+       if (fd == -1) {
+               perror("Can't open the proc file");
+               return;
+       }
+
+       len = read(fd, line, sizeof(line) - 1);
+       close(fd);
+
+       if (len <= 0) {
+               perror("Read file error");
+               return;
+       } else {
+               line[len] = '\0';
+       }
+
+       pos = strstr(line, "SigQ:");
+       if (pos == NULL) {
+               printf("Can't find the SigQ: string.\n");
+               return;
+       }
+
+       pos2 = strchr(pos, '\n');
+       if (pos2 == NULL) {
+               printf("Can't get the position of the newline character.\n");
+               return;
+       }
+
+       sig = pos;
+       sig[pos2 - pos] = '\0';
+       sig = strrchr(sig, '\t');
+       if (sig == NULL) {
+               printf("Can't find the tab character.\n");
+               return;
+       }
+
+       if (sscanf(sig, "%ld", current) != 1)
+               perror("Can't get the current value");
+}
+
 int main()
 {
 
-       int pid, i;
-       long syslimit;
+       int pid;
+       long curr, syslimit;
        union sigval value;
        struct sigaction act;
 
@@ -63,8 +115,8 @@ int main()
                        " not a bug.\n");
                return PTS_PASS;
        }
-
-       for (i=0; i<syslimit; i++) {
+       get_sigpending(pid, &curr);
+       for (; curr < syslimit; curr++) {
                if (sigqueue(pid, SIGTOTEST, value) != 0) {
                        printf("Test UNRESOLVED: call to sigqueue did not 
return success\n");
                        return PTS_UNRESOLVED;
@@ -81,4 +133,4 @@ int main()
        }
 
        return PTS_PASS;
-}
\ No newline at end of file
+}
-- 
1.7.6


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to