Skip to content
Snippets Groups Projects
Commit 52e95241 authored by Diego Giovane Pasqualin's avatar Diego Giovane Pasqualin
Browse files

Merge branch 'issue/19' into 'development'


Issue #19: /var/log/wtmp creation

Signed-off-by: default avatarFelipe Shi Iu Wu <felipeshiwu@gmail.com>

See merge request !21
parents cdc5e66f f9ec80f9
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 @@
#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>
......
......@@ -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);
......
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