|
54 | 54 | #include <evalfunction.h>
|
55 | 55 | #include <json-utils.h>
|
56 | 56 | #include <unix.h> /* GetCurrentUserName() */
|
| 57 | +#include <glob_lib.h> |
57 | 58 |
|
58 | 59 | #ifdef HAVE_ZONE_H
|
59 | 60 | # include <zone.h>
|
@@ -3059,6 +3060,43 @@ static void GetCPUInfo(EvalContext *ctx)
|
3059 | 3060 | count = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
3060 | 3061 | #endif
|
3061 | 3062 |
|
| 3063 | +#ifdef __linux__ |
| 3064 | + int package_id = 0, max_package_id = 0; |
| 3065 | + char buffer[CF_SMALLBUF] = ""; |
| 3066 | + StringSet *package_id_files = GlobFileList("/sys/devices/system/cpu/cpu*/topology/physical_package_id"); |
| 3067 | + StringSetIterator it = StringSetIteratorInit(package_id_files); |
| 3068 | + const char *file = NULL; |
| 3069 | + |
| 3070 | + while ((file = StringSetIteratorNext(&it))) |
| 3071 | + { |
| 3072 | + int f = open(file, O_RDONLY); |
| 3073 | + if (f == -1) |
| 3074 | + continue; |
| 3075 | + ssize_t n_read = FullRead(f, buffer, sizeof(buffer)); |
| 3076 | + if (n_read < 1) |
| 3077 | + continue; |
| 3078 | + if (sscanf(buffer, "%d", &package_id) == 1) |
| 3079 | + { |
| 3080 | + if (package_id > max_package_id) |
| 3081 | + max_package_id = package_id; |
| 3082 | + } |
| 3083 | + } |
| 3084 | + max_package_id++; |
| 3085 | + StringSetDestroy(package_id_files); |
| 3086 | + |
| 3087 | + if (max_package_id == 1) |
| 3088 | + { |
| 3089 | + snprintf(buffer, CF_SMALLBUF, "%d_cpusocket", max_package_id); |
| 3090 | + } |
| 3091 | + else |
| 3092 | + { |
| 3093 | + snprintf(buffer, CF_SMALLBUF, "%d_cpusockets", max_package_id); |
| 3094 | + } |
| 3095 | + EvalContextClassPutHard(ctx, buffer, "source=agent,derived-from=sys.cpusockets"); |
| 3096 | + snprintf(buffer, CF_SMALLBUF, "%d", max_package_id); |
| 3097 | + EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_SYS, "cpusockets", buffer, CF_DATA_TYPE_STRING, "inventory,source=agent,attribute_name=CPU sockets"); |
| 3098 | +#endif |
| 3099 | + |
3062 | 3100 | #if defined(HAVE_SYS_SYSCTL_H) && defined(HW_NCPU)
|
3063 | 3101 | // BSD-derived platforms
|
3064 | 3102 | int mib[2] = { CTL_HW, HW_NCPU };
|
|
0 commit comments