LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Launching UI in logged in user context (https://www.linuxquestions.org/questions/linux-newbie-8/launching-ui-in-logged-in-user-context-735478/)

logforlinux 06-25-2009 02:28 AM

Launching UI in logged in user context
 
Hi,

I am running Red Hat Linux 4. I have a program that gets started everytime when system gets up. The program runs with root privileges. In this program, I want to find who is currently logged in. What I want to do is to start the User interface process in logged in user mode.


e.g.

int main(int c, char *[]){

char *loggedUser = getenv("USER");

//Based on loggedUser value; execute further
return 0;
}


Consider the following scenario;
1. Start the system,
2. Program will get loaded with root privilege,
3. logged in to the system with 'test' user (i.e. non -root),
4. command getenv("USER"), returns 'null' value, How come?
5. if root logs in, then getenv("USER") returns 'root'


Is there any why to find who is currently logged within a process which is started by root?

Fantasio 06-26-2009 11:03 AM

First of all, why you process runs under root ? It should use it's own user or the connected user.

logforlinux 06-28-2009 11:45 PM

The process must run under root as it needs some root privileges.

chrism01 06-29-2009 12:40 AM

What about the 'who' cmd ?

logforlinux 06-29-2009 11:52 PM

Got it...

I am using 'w -ih'/'who'


All times are GMT -5. The time now is 04:30 AM.