2

It seems, that the getlogin() function is not working when called from the Linux subsystem on Windows (it always returns null).

This leads to two questions:

  • Is there a working alternative?
  • Is it possible to determine if we are on a "normal" Linux or a "Windows Linux" like stated here?
3
  • It's not a system call. It relies on a login, specifically a utmp record, I guess your WSL is not bothering to set that up when you open a WSL window. getlogin is probably working correctly, it's just telling you there is no utmp record :-P. If you want some alternative, you need to explain exactly what behaviour you want.
    – sourcejedi
    Commented May 11, 2019 at 14:27
  • @sourcejedi You're right. Somewhere else, I read that this utmp record doesn't exist (which seems to produce some more problems). I just need an easy way to display the username of the user who started the process.
    – TimSch
    Commented May 11, 2019 at 14:40
  • good start. Is it a set-uid process, or does it run with the same UID as the process that exec()'d it ? Do you want sudo my-program to show root ?
    – sourcejedi
    Commented May 11, 2019 at 14:55

1 Answer 1

1

Assuming you are still running as the same user: getuid() then resolve it to a user name.

https://stackoverflow.com/questions/39157675/how-to-get-linux-user-id-by-user-name

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .