From: Robert W. <ro...@us...> - 2003-04-01 16:43:32
|
I applied this patch to the CVS tree. FYI, I've seen the error you speak of on machines where the /proc/sys/kernel/msgmni is set too high. - Robbie Robert V. Williamson <ro...@us...> Linux Test Project IBM Linux Technology Center Phone: (512) 838-9295 T/L: 678-9295 Fax: (512) 838-4603 Web: http://ltp.sourceforge.net IRC: #ltp on freenode.irc.net ==================== "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." -Albert Einstein Dan Kegel <dk...@ix...> To: ltp <ltp...@li...> Sent by: cc: ltp...@li...ur Subject: [LTP] More trouble in msgctl08, msgctl09 ceforge.net 03/28/2003 03:44 PM I noticed that msgctl0[89] both do if (system("ipcs -q | wc -l > used")==-1){ tst_resm(TBROK,"Could not calculate used message queues"); but this doesn't properly detect an error if the ipcs command is not present. Also, there was an undocumented constant '4' in the following code, which turns out to be the number of lines of header in the output of ipcs. The following patch should fix both issues for msgctl08 & 9. I don't know if these are good tests; I'm just cleaning up a problem I ran into. In fact, I kind of wonder about them. On my Debian 3.0 system (a dual Pentium 4 Xeon), I often see: msgctl09 0 WARN : Fork failure in first child of child group 6 msgctl09 0 WARN : Fork failure in first child of child group 4 msgctl09 1 FAIL : Child exit status = 4 both before and after my change. - Dan --- ltp-20030306/testcases/kernel/syscalls/ipc/msgctl/msgctl08.c.old Fri Mar 28 13:23:32 2003 +++ ltp-20030306/testcases/kernel/syscalls/ipc/msgctl/msgctl08.c Fri Mar 28 13:36:46 2003 @@ -382,17 +382,57 @@ { } +#define BUFSIZE 512 + +/** Get the number of message queues already in use */ +static int get_used_msgqueues() +{ + FILE *f; + int used_queues; + char buff[BUFSIZE]; + + f = popen("ipcs -q", "r"); + if (!f) { + tst_resm(TBROK,"Could not run 'ipcs' to calculate used message queues"); + tst_exit(); + } + /* FIXME: Start at -4 because ipcs prints four lines of header */ + for (used_queues = -4; fgets(buff, BUFSIZE, f); used_queues++) + ; + fclose(f); + if (used_queues < 0) { + tst_resm(TBROK,"Could not read output of 'ipcs' to calculate used message queues"); + tst_exit(); + } + return used_queues; +} + +/** Get the max number of message queues allowed on system */ +static int get_max_msgqueues() +{ + FILE *f; + char buff[BUFSIZE]; + + /* Get the max number of message queues allowed on system */ + f = fopen("/proc/sys/kernel/msgmni", "r"); + if (!f){ + tst_resm(TBROK,"Could not open /proc/sys/kernel/msgmni"); + tst_exit(); + } + if (!fgets(buff, BUFSIZE, f)) { + tst_resm(TBROK,"Could not read /proc/sys/kernel/msgmni"); + tst_exit(); + } + fclose(f); + return atoi(buff); +} + /*************************************************************** * setup() - performs all ONE TIME setup for this test. *****************************************************************/ void setup() { -#define BUFSIZE 512 - FILE* f; - char buff[BUFSIZE]; - int used_queues; - tst_tmpdir(); /* You will want to enable some signal handling so you can capture @@ -408,24 +448,7 @@ */ TEST_PAUSE; - /* Get the max number of message queues allowed on system */ - f = fopen("/proc/sys/kernel/msgmni", "r"); - if (!f){ - tst_resm(TBROK,"Could not open /proc/sys/kernel/msgmni"); - tst_exit(); - } - fgets(buff, BUFSIZE, f); - fclose(f); - MSGMNI = atoi(buff); - if (system("ipcs -q | wc -l > used")==-1){ - tst_resm(TBROK,"Could not calculate used message queues"); - tst_exit(); - } - f = fopen("used","r"); - fgets(buff, BUFSIZE, f); - used_queues = atoi(buff); - MSGMNI = MSGMNI - (used_queues - 4); - fclose(f); + MSGMNI = get_max_msgqueues() - get_used_msgqueues(); if (MSGMNI <= 0){ tst_resm(TBROK,"Max number of message queues already used, cannot create more."); cleanup(); --- ltp-20030306/testcases/kernel/syscalls/ipc/msgctl/msgctl09.c.old Fri Mar 28 12:00:01 2003 +++ ltp-20030306/testcases/kernel/syscalls/ipc/msgctl/msgctl09.c Fri Mar 28 13:36:56 2003 @@ -545,17 +545,58 @@ kill(wkidarray[i], SIGTERM); } } + +#define BUFSIZE 512 + +/** Get the number of message queues already in use */ +static int get_used_msgqueues() +{ + FILE *f; + int used_queues; + char buff[BUFSIZE]; + + f = popen("ipcs -q", "r"); + if (!f) { + tst_resm(TBROK,"Could not run 'ipcs' to calculate used message queues"); + tst_exit(); + } + /* FIXME: Start at -4 because ipcs prints four lines of header */ + for (used_queues = -4; fgets(buff, BUFSIZE, f); used_queues++) + ; + fclose(f); + if (used_queues < 0) { + tst_resm(TBROK,"Could not read output of 'ipcs' to calculate used message queues"); + tst_exit(); + } + return used_queues; +} + +/** Get the max number of message queues allowed on system */ +static int get_max_msgqueues() +{ + FILE *f; + char buff[BUFSIZE]; + + /* Get the max number of message queues allowed on system */ + f = fopen("/proc/sys/kernel/msgmni", "r"); + if (!f){ + tst_resm(TBROK,"Could not open /proc/sys/kernel/msgmni"); + tst_exit(); + } + if (!fgets(buff, BUFSIZE, f)) { + tst_resm(TBROK,"Could not read /proc/sys/kernel/msgmni"); + tst_exit(); + } + fclose(f); + return atoi(buff); +} + /*************************************************************** * setup() - performs all ONE TIME setup for this test. *****************************************************************/ void setup() { -#define BUFSIZE 512 - FILE* f; - char buff[BUFSIZE]; - int used_queues; - tst_tmpdir(); /* You will want to enable some signal handling so you can capture * unexpected signals like SIGSEGV. @@ -570,24 +611,7 @@ */ TEST_PAUSE; - /* Get the max number of message queues allowed on system */ - f = fopen("/proc/sys/kernel/msgmni", "r"); - if (!f){ - tst_resm(TBROK,"Could not open /proc/sys/kernel/msgmni"); - tst_exit(); - } - fgets(buff, BUFSIZE, f); - fclose(f); - MSGMNI = atoi(buff); - if (system("ipcs -q | wc -l > used")==-1){ - tst_resm(TBROK,"Could not calculate used message queues"); - tst_exit(); - } - f = fopen("used","r"); - fgets(buff, BUFSIZE, f); - used_queues = atoi(buff); - MSGMNI = MSGMNI - (used_queues - 4); - fclose(f); + MSGMNI = get_max_msgqueues() - get_used_msgqueues(); if (MSGMNI <= 0){ tst_resm(TBROK,"Max number of message queues already used, cannot create more."); cleanup(); |