coreadm and %d

Coreadm(1m) has a really nice feature that can be used to restrict coredumps that are collected to just the one from the system. Typically I'm not interested in a global core file from and application that someone is developing so I would like to limit the cores to just those created by programs that are delivered as part of solaris.

So if you use %d as part of the pattern it will expand to the name of the directory where the binary lives. If the directory does not exist then no core file.

So in this example if /usr/bin/ls were to dump core (not that it does) using this setup:

# coreadm
     global core file pattern: /var/cores/%d/%f.%p.%u
     global core file content: default
       init core file pattern: core
       init core file content: default
            global core dumps: enabled
       per-process core dumps: enabled
      global setid core dumps: disabled
 per-process setid core dumps: disabled
     global core dump logging: enabled
#

The global core only gets dumped if /var/cores/usr/bin exists.

The down side of this is that not all the executables you may be interested in are in /usr/bin or other obvious locations so they could fail to dump core as the directory does not yet exist.

So I knocked together this little script to create all the directories that I will ever need:

nawk '$2 == "f" { printf("file %s\\n", $1) }'  /var/sadm/install/contents |\\
ksh -p |\\
nawk 'function dirname(path) {
        len= length(path);
        for (n = 1 ; index(substr(path, len - (1+ n), n), "/") == 0; n++) ;

        return(substr(path, 1,  len - (2+ n)));
}
/ELF.\*executable/ {
        x[dirname($1)]=1
}
END {
        for (y in x ) {
                printf("test -d /var/cores%s || mkdir -p /var/cores%s\\n",
                        y, y)
        }
}' | ksh -x

My suspicion is that there is probably a better way. So let me know.

Tags:

Comments:

Post a Comment:
Comments are closed for this entry.
About

This is the old blog of Chris Gerhard. It has mostly moved to http://chrisgerhard.wordpress.com

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today