summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@users.noreply.github.com>2015-01-06 08:34:35 +0100
committerMichael Stapelberg <stapelberg@users.noreply.github.com>2015-01-06 08:34:35 +0100
commit3898f75672dd2318d836ccfab06ed00fa3c39558 (patch)
treef032f76f75b73e0484bb2d2e6e121b239d1f11c3
parentec9a5f638b5aeaadc4f57356169b568f86d6f3d4 (diff)
parent665ce3e215b9b47a251b4433fe776d42072d9e9b (diff)
Merge pull request #3 from stibi/whoami
getting current user with whoami like function rather than from env variable
-rw-r--r--i3lock.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/i3lock.c b/i3lock.c
index 71b02ee..942781a 100644
--- a/i3lock.c
+++ b/i3lock.c
@@ -8,6 +8,8 @@
*/
#include <stdio.h>
#include <stdlib.h>
+#include <pwd.h>
+#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>
@@ -659,6 +661,7 @@ static void raise_loop(xcb_window_t window) {
}
int main(int argc, char *argv[]) {
+ struct passwd *pw;
char *username;
char *image_path = NULL;
int ret;
@@ -684,8 +687,10 @@ int main(int argc, char *argv[]) {
{NULL, no_argument, NULL, 0}
};
- if ((username = getenv("USER")) == NULL)
- errx(EXIT_FAILURE, "USER environment variable not set, please set it.\n");
+ if ((pw = getpwuid(getuid())) == NULL)
+ err(EXIT_FAILURE, "getpwuid() failed");
+ if ((username = pw->pw_name) == NULL)
+ errx(EXIT_FAILURE, "pw->pw_name is NULL.\n");
char *optstring = "hvnbdc:p:ui:teI:f";
while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) {