mirror of https://github.com/i3/i3lock.git
getting current user with whoami like function rather than from env variable
parent
ec9a5f638b
commit
a3839aa69f
16
i3lock.c
16
i3lock.c
|
@ -8,6 +8,7 @@
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
@ -658,8 +659,18 @@ static void raise_loop(xcb_window_t window) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* whoami(void) {
|
||||||
|
uid_t uid = geteuid();
|
||||||
|
struct passwd *pw = getpwuid(uid);
|
||||||
|
if (pw) {
|
||||||
|
return pw->pw_name;
|
||||||
|
} else {
|
||||||
|
errx(EXIT_FAILURE, "Username not known!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
char *username;
|
char *username = whoami();
|
||||||
char *image_path = NULL;
|
char *image_path = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
struct pam_conv conv = {conv_callback, NULL};
|
struct pam_conv conv = {conv_callback, NULL};
|
||||||
|
@ -684,9 +695,6 @@ int main(int argc, char *argv[]) {
|
||||||
{NULL, no_argument, NULL, 0}
|
{NULL, no_argument, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
if ((username = getenv("USER")) == NULL)
|
|
||||||
errx(EXIT_FAILURE, "USER environment variable not set, please set it.\n");
|
|
||||||
|
|
||||||
char *optstring = "hvnbdc:p:ui:teI:f";
|
char *optstring = "hvnbdc:p:ui:teI:f";
|
||||||
while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) {
|
while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) {
|
||||||
switch (o) {
|
switch (o) {
|
||||||
|
|
Loading…
Reference in New Issue