File: linux.proc.cpuinfo.code

package info (click to toggle)
librpc-xml-perl 0.82-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 1,352 kB
  • sloc: perl: 9,665; xml: 3,020; makefile: 17
file content (35 lines) | stat: -rw-r--r-- 882 bytes parent folder | download | duplicates (9)
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
31
32
33
34
35
###############################################################################
#
#   Sub Name:       linux_proc_cpuinfo
#
#   Description:    Read the /proc/cpuinfo on a Linux server and return a
#                   STRUCT with the information.
#
#   Arguments:      None.
#
#   Returns:        hashref
#
###############################################################################
sub linux_proc_sysinfo
{
    use strict;

    my (%cpuinfo, $line, $key, $value);
    local *F;

    open(F, '/proc/cpuinfo') or
        return RPC::XML::fault->new(501, "Cannot open /proc/cpuinfo: $!");

    while (defined($line = <F>))
    {
        chomp $line;
        next if ($line =~ /^\s*$/);

        ($key, $value) = split(/\s+:\s+/, $line, 2);
        $key =~ s/ /_/g;
        $cpuinfo{$key} = ($key eq 'flags') ? [ split(/ /, $value) ] : $value;
    }
    close(F);

    \%cpuinfo;
}