@@ -806,9 +806,10 @@ TEST(PortSysinfoTest, sysinfo_test_sysinfo_set_limit_CORE_FILE)
806
806
{
807
807
OMRPORT_ACCESS_FROM_OMRPORT (portTestEnv->getPortLibrary ());
808
808
const char *testName = " omrsysinfo_test_sysinfo_set_limit_FILE_DESCRIPTORS" ;
809
- intptr_t rc = - 1 ;
809
+ uint32_t rc = OMRPORT_LIMIT_UNKNOWN ;
810
810
uint64_t originalSoftLimit = 0 ;
811
811
uint64_t finalSoftLimit = 0 ;
812
+ uint64_t softSetToHardLimit = 0 ;
812
813
uint64_t originalHardLimit = 0 ;
813
814
uint64_t currentLimit = 0 ;
814
815
const uint64_t descriptorLimit = 256 ;
@@ -822,6 +823,7 @@ TEST(PortSysinfoTest, sysinfo_test_sysinfo_set_limit_CORE_FILE)
822
823
reportTestExit (OMRPORTLIB, testName);
823
824
return ;
824
825
}
826
+ portTestEnv->log (LEVEL_ERROR, " originalSoftLimit=%llu\n " , originalSoftLimit);
825
827
finalSoftLimit = originalSoftLimit;
826
828
827
829
rc = omrsysinfo_set_limit (OMRPORT_RESOURCE_FILE_DESCRIPTORS, descriptorLimit);
@@ -854,18 +856,54 @@ TEST(PortSysinfoTest, sysinfo_test_sysinfo_set_limit_CORE_FILE)
854
856
reportTestExit (OMRPORTLIB, testName);
855
857
return ;
856
858
}
859
+ portTestEnv->log (LEVEL_ERROR, " originalHardLimit=%llu\n " , originalHardLimit);
860
+
861
+ /* set soft limit to hard limit */
862
+ rc = omrsysinfo_set_limit (OMRPORT_RESOURCE_FILE_DESCRIPTORS, originalHardLimit);
863
+ if (0 != rc) {
864
+ outputErrorMessage (PORTTEST_ERROR_ARGS, " omrsysinfo_set_limit soft = hard FAILED rc=%d\n " , rc);
865
+ reportTestExit (OMRPORTLIB, testName);
866
+ return ;
867
+ }
868
+
869
+ /* get new soft limit */
870
+ rc = omrsysinfo_get_limit (OMRPORT_RESOURCE_FILE_DESCRIPTORS, &softSetToHardLimit);
871
+ if (OMRPORT_LIMIT_UNKNOWN == rc) {
872
+ outputErrorMessage (PORTTEST_ERROR_ARGS, " omrsysinfo_get_limit FAILED: OMRPORT_LIMIT_UNKNOWN\n " );
873
+ reportTestExit (OMRPORTLIB, testName);
874
+ return ;
875
+ }
876
+ portTestEnv->log (LEVEL_ERROR, " soft set to hard limit=%llu\n " , softSetToHardLimit);
877
+
878
+ /* set soft limit to old value */
879
+ rc = omrsysinfo_set_limit (OMRPORT_RESOURCE_FILE_DESCRIPTORS, originalSoftLimit);
880
+ if (0 != rc) {
881
+ outputErrorMessage (PORTTEST_ERROR_ARGS, " omrsysinfo_set_limit reset soft FAILED rc=%d\n " , rc);
882
+ reportTestExit (OMRPORTLIB, testName);
883
+ return ;
884
+ }
885
+
886
+ rc = omrsysinfo_get_limit (OMRPORT_RESOURCE_FILE_DESCRIPTORS | OMRPORT_LIMIT_HARD, ¤tLimit);
887
+ if (currentLimit != originalHardLimit) {
888
+ outputErrorMessage (PORTTEST_ERROR_ARGS, " omrsysinfo_get_limit FAILED: hard limit changed\n " );
889
+ reportTestExit (OMRPORTLIB, testName);
890
+ return ;
891
+ }
857
892
858
893
/* lowering the hard limit is irreversible unless privileged */
859
894
if (0 != geteuid ()) { /* normal user */
860
895
/* setting the hard limit from unlimited to a finite value has unpredictable results:
861
896
* the actual value may be much smaller than requested.
862
- * In that case, just try setting it to the same value.
897
+ * In that case, just try setting it to its current value (softSetToHardLimit) or a value slightly lower.
898
+ * Ensure that we don't try to set the hard limit to a value less than the current soft limit
899
+ * (i.e. originalSoftLimit).
863
900
*/
864
- uint64_t newHardLimit = (OMRPORT_LIMIT_UNLIMITED == rc) ? originalHardLimit: originalHardLimit - 1 ;
901
+ uint64_t newHardLimit = ((OMRPORT_LIMIT_UNLIMITED == rc) || (originalSoftLimit == softSetToHardLimit))
902
+ ? softSetToHardLimit: softSetToHardLimit - 1 ;
865
903
866
904
rc = omrsysinfo_set_limit (OMRPORT_RESOURCE_FILE_DESCRIPTORS | OMRPORT_LIMIT_HARD, newHardLimit);
867
905
if (0 != rc) {
868
- outputErrorMessage (PORTTEST_ERROR_ARGS, " omrsysinfo_set_limit set hard limit FAILED rc=%d\n " , rc);
906
+ outputErrorMessage (PORTTEST_ERROR_ARGS, " omrsysinfo_set_limit set hard limit=%lld FAILED rc=%d\n " , rc, newHardLimit );
869
907
reportTestExit (OMRPORTLIB, testName);
870
908
return ;
871
909
}
0 commit comments