Created
August 18, 2013 17:00
-
-
Save Cloudef/6262720 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* gcc `pkg-config --cflags --libs libsystemd-login` systemd-active-user.c -o systemd-active-user | |
* get current active user id that has process in 'foreground' according to documentation */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main(void) | |
{ | |
uid_t *uids = NULL, uactiveid = 0; | |
int i, num = sd_get_uids(&uids); | |
for (i = 0; i < num; ++i) { | |
char *state = NULL; | |
sd_uid_get_state(uids[i], &state); | |
if (!strcmp(state, "active")) uactiveid = uids[i]; | |
if (state) free(state); | |
} | |
if (uids) free(uids); | |
printf("%u\n", uactiveid); | |
return EXIT_SUCCESS; | |
} | |
/* vim: set ts=8 sw=4 tw=0 :*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment