Changeset d7b399f for tests/meta/dumpable.cfa
- Timestamp:
- Jul 18, 2024, 11:01:28 PM (4 weeks ago)
- Branches:
- master
- Children:
- 3ee4a53
- Parents:
- e3260aa1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/meta/dumpable.cfa
re3260aa1 rd7b399f 32 32 void check_ulimit() { 33 33 struct rlimit rlp; 34 getrlimit(RLIMIT_CORE, &rlp );35 if (rlp.rlim_cur < 536870912) {34 getrlimit(RLIMIT_CORE, &rlp ); 35 if ( rlp.rlim_cur < 536870912 ) { 36 36 serr | "Soft core limit is less than ~500Mb: " | rlp.rlim_cur; 37 37 } 38 38 39 if (rlp.rlim_max < 536870912) {39 if ( rlp.rlim_max < 536870912 ) { 40 40 serr | "Hard core limit is less than ~500Mb: " | rlp.rlim_max; 41 41 } … … 46 46 char myExe[PATH_MAX]; 47 47 ssize_t n = readlink("/proc/self/exe", myExe, sizeof(myExe)); 48 if (n < 0 ) {49 perror("readlink(/proc/self/exe ) error");48 if (n < 0 ) { 49 perror("readlink(/proc/self/exe ) error"); 50 50 return 1; 51 51 } 52 52 myExe[n] = '\0'; 53 53 54 if (int r = access(myExe, F_OK); r != 0) serr | "Expected current executable does not exist!" | r | errno;55 if (int r = access(myExe, R_OK); r != 0) serr | "No read access for current executable" | r | errno;54 if ( int r = access(myExe, F_OK ); r != 0 ) serr | "Expected current executable does not exist!" | r | errno; 55 if ( int r = access(myExe, R_OK ); r != 0 ) serr | "No read access for current executable" | r | errno; 56 56 } 57 57 58 58 { 59 59 char myCwd[PATH_MAX]; 60 if (getcwd(myCwd, sizeof(myCwd )) == 0p) {60 if (getcwd(myCwd, sizeof(myCwd )) == 0p ) { 61 61 perror("getcwd() error"); 62 62 return; 63 63 } 64 64 65 if (access(myCwd, F_OK) != 0) serr | "Expected current working directory does not exist!";66 if (access(myCwd, R_OK) != 0) serr | "No read access for current working directory";67 if (access(myCwd, W_OK) != 0) serr | "No write access for current working directory";65 if ( access(myCwd, F_OK ) != 0 ) serr | "Expected current working directory does not exist!"; 66 if ( access(myCwd, R_OK ) != 0 ) serr | "No read access for current working directory"; 67 if ( access(myCwd, W_OK ) != 0 ) serr | "No write access for current working directory"; 68 68 } 69 69 } … … 71 71 void check_free_space() { 72 72 struct statvfs buf; 73 if (statvfs(".", &buf) != 0) {73 if ( statvfs(".", &buf ) != 0 ) { 74 74 perror("statvfs() error"); 75 75 return; … … 78 78 uint64_t avail = buf.f_bavail; 79 79 avail *= buf.f_bsize; 80 if (avail < 536870912_l64u) {80 if ( avail < 536870912_l64u ) { 81 81 serr | "Available diskspace is less than ~500Mb: " | avail; 82 82 } 83 83 84 if (buf.f_favail < 10) {84 if ( buf.f_favail < 10 ) { 85 85 serr | "Available inodes is less than 10: " | buf.f_favail; 86 86 } 87 87 88 if (buf.f_flag & ST_RDONLY) {88 if ( buf.f_flag & ST_RDONLY ) { 89 89 serr | "Filesystem is read only"; 90 90 } … … 93 93 void check_noconflict() { 94 94 char * name = "./core"; 95 if (access("./core", F_OK) == 0) serr | "A file of the core name ('" | name | "') already exists";95 if ( access("./core", F_OK ) == 0 ) serr | "A file of the core name ('" | name | "') already exists"; 96 96 } 97 97 98 98 void check_dumpflag() { 99 int r = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0 );100 if (r < 0) {101 perror("prctl(PR_GET_DUMPABLE ) error");99 int r = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0 ); 100 if ( r < 0 ) { 101 perror("prctl(PR_GET_DUMPABLE ) error"); 102 102 return; 103 103 } 104 104 105 if (r != 1) serr | "dumpable attribute not set to 1 \"(SUID_DUMP_USER, process is dumpable)\", was" | r;105 if ( r != 1 ) serr | "dumpable attribute not set to 1 \"(SUID_DUMP_USER, process is dumpable )\", was" | r; 106 106 } 107 107 108 108 void check_core_pattern() { 109 109 int ret; 110 int cp = open("/proc/sys/kernel/core_pattern", 0, O_RDONLY); 111 if(cp < 0) { 112 perror("open(/proc/sys/kernel/core_pattern, O_RDONLY) error"); 110 int cp = open("/proc/sys/kernel/core_pattern", 0, O_RDONLY ); 111 112 if ( cp < 0 ) { 113 perror( "open(/proc/sys/kernel/core_pattern, O_RDONLY ) error" ); 113 114 return; 114 } 115 } // if 115 116 116 117 try { … … 118 119 const int sz = sizeof("core\n"); 119 120 char buf[512]; 120 ret = read( cp, buf, 512);121 if (ret < 0) {122 perror( "first core pattern read error");121 ret = read( cp, buf, 512 ); 122 if ( ret < 0 ) { 123 perror( "core pattern read error" ); 123 124 return; 124 125 } 125 ret = strncmp( expected, buf, sz - 1);126 if (ret != 0) {126 ret = strncmp( expected, buf, sz - 1 ); 127 if ( ret != 0 ) { 127 128 serr | "/proc/sys/kernel/core_pattern does not contain 'core', was:" | nl | nl | buf | nl 128 129 | "Test script expect cores files to be dumped with name 'core' in current working directory." | nl 129 130 | "Apport is not supported, it should be deactivated in /etc/default/apport for the test suite to work with core dumps."; 130 131 return;132 131 } 132 } finally { 133 ret = close(cp ); 134 if ( ret < 0 ) perror("close(/proc/sys/kernel/core_pattern ) error"); 133 135 } 134 finally {135 ret = close(cp);136 if(ret < 0) perror("close(/proc/sys/kernel/core_pattern) error");137 }138 139 136 } 140 137 141 138 int main() { 142 139 check_ulimit(); 143 144 140 check_permission(); 145 146 141 check_free_space(); 147 148 142 check_noconflict(); 149 150 143 check_dumpflag(); 151 152 144 check_core_pattern(); 153 154 145 sout | "Done"; 155 146 }
Note: See TracChangeset
for help on using the changeset viewer.