`whoami`: revert "`whoami`: misc improvements, including...".

This reverts commit 8a2afdc33a.
so apparently `getlogin()` returns the user the process is running under, and when it is called when you are in a sudoed bash, it returns the login username instead of root.
as you may be able to guess, that is not exactly intended behaviour.
master
Drake 3 years ago
parent 9eb02a4954
commit 23bc854b51

@ -13,13 +13,16 @@ Available arguments:
*/
int main(int argc, char** argv) {
char * username = getlogin(); //a fucking ai came up with this. a fucking ai. A FUCKING AI
uid_t userid = geteuid();
char * username = getpwuid(userid)->pw_name;
if (argc == 1) {
printf("%s\n", username);
return 0;
} else {
for (int i = 0; i < argc; i++) {
char* arg = argv[i];
/*printf(arg);
printf(" ");*/
if (!strcmp(arg, "--help")) {
char* help =
"Drake's Epic Coreutils (working title) "
@ -36,7 +39,7 @@ int main(int argc, char** argv) {
printf(DRAKECU_VERSION);
return 0;
} else if (!strcmp(arg, "--uid")) {
printf("%d\n", (int)geteuid());
printf("%d\n", (int)userid);
return 0;
}
}

Loading…
Cancel
Save