Changeset d7b399f


Ignore:
Timestamp:
Jul 18, 2024, 11:01:28 PM (3 hours ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Parents:
e3260aa1
Message:

formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/meta/dumpable.cfa

    re3260aa1 rd7b399f  
    3232void check_ulimit() {
    3333        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 ) {
    3636                serr | "Soft core limit is less than ~500Mb: " | rlp.rlim_cur;
    3737        }
    3838
    39         if(rlp.rlim_max < 536870912) {
     39        if ( rlp.rlim_max < 536870912 ) {
    4040                serr | "Hard core limit is less than ~500Mb: " | rlp.rlim_max;
    4141        }
     
    4646                char myExe[PATH_MAX];
    4747                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");
    5050                        return 1;
    5151                }
    5252                myExe[n] = '\0';
    5353
    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;
    5656        }
    5757
    5858        {
    5959                char myCwd[PATH_MAX];
    60                 if (getcwd(myCwd, sizeof(myCwd)) == 0p) {
     60                if (getcwd(myCwd, sizeof(myCwd )) == 0p ) {
    6161                        perror("getcwd() error");
    6262                        return;
    6363                }
    6464
    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";
    6868        }
    6969}
     
    7171void check_free_space() {
    7272        struct statvfs buf;
    73         if(statvfs(".", &buf) != 0) {
     73        if ( statvfs(".", &buf ) != 0 ) {
    7474                perror("statvfs() error");
    7575                return;
     
    7878        uint64_t avail = buf.f_bavail;
    7979        avail *= buf.f_bsize;
    80         if(avail < 536870912_l64u) {
     80        if ( avail < 536870912_l64u ) {
    8181                serr | "Available diskspace is less than ~500Mb: " | avail;
    8282        }
    8383
    84         if(buf.f_favail < 10) {
     84        if ( buf.f_favail < 10 ) {
    8585                serr | "Available inodes is less than 10: " | buf.f_favail;
    8686        }
    8787
    88         if(buf.f_flag & ST_RDONLY) {
     88        if ( buf.f_flag & ST_RDONLY ) {
    8989                serr | "Filesystem is read only";
    9090        }
     
    9393void check_noconflict() {
    9494        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";
    9696}
    9797
    9898void 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");
    102102                return;
    103103        }
    104104
    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;
    106106}
    107107
    108108void check_core_pattern() {
    109109        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" );
    113114                return;
    114         }
     115        } // if
    115116
    116117        try {
     
    118119                const int sz = sizeof("core\n");
    119120                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" );
    123124                        return;
    124125                }
    125                 ret = strncmp(expected, buf, sz - 1);
    126                 if(ret != 0) {
     126                ret = strncmp( expected, buf, sz - 1 );
     127                if ( ret != 0 ) {
    127128                        serr | "/proc/sys/kernel/core_pattern does not contain 'core', was:" | nl | nl | buf | nl
    128129                             | "Test script expect cores files to be dumped with name 'core' in current working directory." | nl
    129130                             | "Apport is not supported, it should be deactivated in /etc/default/apport for the test suite to work with core dumps.";
    130 
    131                         return;
    132131                }
     132        } finally {
     133                ret = close(cp );
     134                if ( ret < 0 ) perror("close(/proc/sys/kernel/core_pattern ) error");
    133135        }
    134         finally {
    135                 ret = close(cp);
    136                 if(ret < 0) perror("close(/proc/sys/kernel/core_pattern) error");
    137         }
    138 
    139136}
    140137
    141138int main() {
    142139        check_ulimit();
    143 
    144140        check_permission();
    145 
    146141        check_free_space();
    147 
    148142        check_noconflict();
    149 
    150143        check_dumpflag();
    151 
    152144        check_core_pattern();
    153 
    154145        sout | "Done";
    155146}
Note: See TracChangeset for help on using the changeset viewer.