forked from jackburton79/inventory-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsersRoster.cpp
More file actions
39 lines (31 loc) · 760 Bytes
/
Copy pathUsersRoster.cpp
File metadata and controls
39 lines (31 loc) · 760 Bytes
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
36
37
38
39
/*
* LoggedUsers.cpp
*
* Created on: 15/lug/2013
* Author: Stefano Ceccherini
*/
#include "UsersRoster.h"
#include "Support.h"
#include <ctime>
#include <utmpx.h>
UsersRoster::UsersRoster()
{
setutxent();
struct utmpx* record = NULL;
while ((record = getutxent()) != NULL) {
if (record->ut_type == USER_PROCESS) {
user_entry entry;
entry.login = record->ut_user;
time_t loginTime = record->ut_tv.tv_sec;
entry.logintime = loginTime;
struct tm timeInfoStruct;
struct tm* timeinfo = localtime_r(&loginTime, &timeInfoStruct);
char timeString[64];
strftime(timeString, sizeof(timeString), "%a %b %d %R", timeinfo);
entry.logintimestring = timeString;
fItems.push_back(entry);
}
}
endutxent();
Rewind();
}