I'm sorting a utmp file by ut_time. Right now, I have something like the following:
Now, how I qsort ut_time in utmp if I had a structure like the following:Code:#define MAX_USERS 10 struct utmp info[MAX_USERS]; int compare (const void *a, const void *b) { const struct utmp *ma = a; const struct utmp *mb = b; int32_t time1, time2; time1 = ma->ut_time; time2 = mb->ut_time; if(time1 < time2) return -1; else if(time1 > time2) return 1; else return 0; } void print_session(void) { int i; for(i=0; i < counter; i++) printf("name: %s, tty: %s\n", info[i].ut_name, info[i].ut_line); } void find_sessions_to_kill(void){ qsort(info, counter, sizeof(struct utmp), compare ); print_session(); kill_sessions(); }
I would assume ut_time would be found byCode:typedef struct { uid_t uid; /*From the uid I can get the pid*/ dev_t dev; struct utmp in_users; }uinfo_t; uinfo_t uinfo[MAX_USERS];
Code:uinfo.in_users.ut_time



LinkBack URL
About LinkBacks


