Skip to content
Snippets Groups Projects
Commit f9ec80f9 authored by Felipe Shi Iu Wu's avatar Felipe Shi Iu Wu
Browse files

Issue #19: /var/log/wtmp creation

parent cdc5e66f
No related branches found
No related tags found
2 merge requests!51Merge development to master,!21Issue #19: /var/log/wtmp creation
Pipeline #
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <cstring> #include <string.h>
#include <pwd.h>
#include <grp.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/fcntl.h> #include <sys/fcntl.h>
...@@ -17,6 +19,7 @@ ...@@ -17,6 +19,7 @@
#include <unistd.h> #include <unistd.h>
#include <utmp.h> #include <utmp.h>
#include <iostream> #include <iostream>
#include <fstream>
#include <set> #include <set>
......
...@@ -473,6 +473,22 @@ static struct user_log * last_modified() { ...@@ -473,6 +473,22 @@ static struct user_log * last_modified() {
} }
int get_user_count() { 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_t rawtime;
time(&rawtime); time(&rawtime);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment