diff --git a/include/agent/linux/get_user_count.h b/include/agent/linux/get_user_count.h index f80d58e39ac57645e344c4c2370c222d4618b7d3..05c82402daa991ab98076bfbdeeb753a52bb03f7 100644 --- a/include/agent/linux/get_user_count.h +++ b/include/agent/linux/get_user_count.h @@ -9,7 +9,9 @@ #include <signal.h> #include <stdio.h> #include <stdlib.h> -#include <cstring> +#include <string.h> +#include <pwd.h> +#include <grp.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/fcntl.h> @@ -17,6 +19,7 @@ #include <unistd.h> #include <utmp.h> #include <iostream> +#include <fstream> #include <set> diff --git a/src/linux/get_user_count.cpp b/src/linux/get_user_count.cpp index 7ffe91ec469bde6bd6fd3cb0f64f5d68e39e4f6f..c942ee4a544135f570e399723c5461ee23090bc7 100644 --- a/src/linux/get_user_count.cpp +++ b/src/linux/get_user_count.cpp @@ -473,6 +473,22 @@ static struct user_log * last_modified() { } int get_user_count() { + + /* The agent execution depends on the file '/var/log/wtmp', which is not + * present on some distros, such as OpenSUSE docker image. When this happens, + * this file is created and it's permissions setted. + */ + + std::string wtmp_path = "/var/log/wtmp"; + struct stat buffer; + if (stat(wtmp_path.c_str(), &buffer) != 0) { //file not exists + ofstream wtmp_file; + wtmp_file.open(wtmp_path.c_str()); + wtmp_file.close(); + chown(wtmp_path.c_str(), getpwnam("root")->pw_uid, getgrnam("tty")->gr_gid); + chmod(wtmp_path.c_str(), 664); + } + time_t rawtime; time(&rawtime);