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

Revert "Merge branch 'issue/17' into 'development'"

This reverts merge request !19
parent c3c3485e
No related branches found
No related tags found
1 merge request!51Merge development to master
Pipeline #
......@@ -38,8 +38,6 @@ struct utmplist *utmplist = NULL;
char *ufile; /* Filename of this file */
time_t lastdate; /* Last date we've seen */
struct tm * timeinfo;
set<string> users;
char yesterday[7], today[7];
/*
* Read one utmp entry, return in new format.
......@@ -128,11 +126,17 @@ static int uread(FILE *fp, struct utmp *u, int *quit) {
return 1;
}
static void list(struct utmp *p, time_t t, int what) {
/*
* Show one line of information on screen
*/
static struct user_log *list(struct utmp *p, time_t t, int what) {
time_t tmp;
struct user_log * u = (struct user_log *)malloc(sizeof(struct user_log));
char login[25], logout[25], month[3];
/*
* Calculate times
*/
tmp = (time_t)p->ut_time;
timeinfo = gmtime(&tmp); // NOLINT(runtime/threadsafe_fn)
strftime(month, 3, "%m", timeinfo);
......@@ -140,10 +144,10 @@ static void list(struct utmp *p, time_t t, int what) {
snprintf(u->user, sizeof(u->user), p->ut_name, 0);
snprintf(login, sizeof(login), ctime(&tmp), 0);
u->login[0] = login[22];
u->login[1] = login[23];
u->login[2] = month[0];
u->login[3] = month[1];
u->login[0] = login[22];
u->login[1] = login[23];
u->login[4] = login[8] == ' '?'0':login[8];
u->login[5] = login[9];
u->login[6] = '\0';
......@@ -169,16 +173,7 @@ static void list(struct utmp *p, time_t t, int what) {
u->logout[6] = '\0';
break;
}
if (!strcmp(u->logout, yesterday)) {
users.insert(u->user);
} else if (!strcmp(u->login, yesterday)) {
users.insert(u->user);
} else if (( strcmp(u->login, yesterday) &&
strcmp(u->login, today)) && (!strcmp(u->logout, today) ||
!strcmp(u->logout, "999999"))) {
users.insert(u->user);
}
return u;
}
static struct user_log * last_modified() {
......@@ -310,7 +305,9 @@ static struct user_log * last_modified() {
/* Show it */
if (c == 0) {
quit = 0;
list(&ut, p->ut.ut_time, R_NORMAL);
u = list(&ut, p->ut.ut_time, R_NORMAL);
v = u;
v->next = NULL;
c = 1;
}
if (p->next) p->next->prev = p->prev;
......@@ -335,7 +332,9 @@ static struct user_log * last_modified() {
c = R_PHANTOM;
quit = 0;
list(&ut, lastboot, c);
u = list(&ut, lastboot, c);
v = u;
v->next = NULL;
}
/* FALLTHRU */
......@@ -421,7 +420,11 @@ static struct user_log * last_modified() {
/* Show it */
if (c == 0) {
quit = 0;
list(&ut, p->ut.ut_time, R_NORMAL);
w = list(&ut, p->ut.ut_time, R_NORMAL);
c = 1;
v->next = w;
w->next = NULL;
v = w;
}
if (p->next) p->next->prev = p->prev;
if (p->prev)
......@@ -445,7 +448,10 @@ static struct user_log * last_modified() {
c = R_PHANTOM;
quit = 0;
list(&ut, lastboot, c);
w = list(&ut, lastboot, c);
v->next = w;
w->next = NULL;
v = w;
}
/* FALLTHRU */
......@@ -470,12 +476,16 @@ static struct user_log * last_modified() {
}
fclose(fp);
return u;
}
int get_user_count() {
last_modified();
struct user_log * u = last_modified();
struct user_log * i;
time_t rawtime;
char yesterday[7], today[7];
set<string> users;
time(&rawtime);
timeinfo = localtime(&rawtime); // NOLINT(runtime/threadsafe_fn)
......@@ -487,5 +497,18 @@ int get_user_count() {
strftime(yesterday, 7, "%y%m%d", timeinfo);
yesterday[6] = '\0';
for (i = u; i; i = u) {
if (!strcmp(i->logout, yesterday)) {
users.insert(i->user);
} else if (!strcmp(i->login, yesterday)) {
users.insert(i->user);
} else if (( strcmp(i->login, yesterday) &&
strcmp(i->login, today)) && (!strcmp(i->logout, today) ||
!strcmp(i->logout, "999999"))) {
users.insert(i->user);
}
u = i->next;
free(i);
}
return users.size();
}
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