At root process running,how to get user logged on use C++?Linux/Mac
I've program running as root and call another program to run(A).
I want A run as user logged on.I've used command: su - 'username' -c A,
or in A main function,i've called: setuid(current_uid_logged).
But i don't know what the way to get user-name logged on or uid in root process.
Any ways that i tried: getenv("USERNAME") or getlogin() always return root account.
I've confused with getlogin(),my program is running when kernel start and wait for user login(i've a thread to wait a Finder process(Mac OSX) running to detect user logged on),
wait 10seconds and call getlogin() but sometime,it's returned root but can be return user login.I think Finder process is running when user logged on.But when i call my app to run with sudo command,getlogin() always returns current user logged on.
How to do exactly.
Thanks so much.
Regards
At root process running,how to get user logged on use C++?Linux/Mac
===

I've program running as root and call another program to run(A).
I want A run as user logged on.I've used command: su - 'username' -c A,
or in A main function,i've called: setuid(current_uid_logged).
But i don't know what the way to get user-name logged on or uid in root process.
Any ways that i tried: getenv("USERNAME") or getlogin() always return root account.
I've confused with getlogin(),my program is running when kernel start and wait for user login(i've a thread to wait a Finder process(Mac OSX) running to detect user logged on),
wait 10seconds and call getlogin() but sometime,it's returned root but can be return user login.I think Finder process is running when user logged on.But when i call my app to run with sudo command,getlogin() always returns current user logged on.
How to do exactly.
Thanks so much.
Regards