title: How to get the logged on user from a process running as root?
body: <p>I have a program running as root and call another program to run(A).</p>
  <p>I want A to run when the user logs on. I've used command: <code>su - 'username' -c A</code>,</p>
  <p>or in the A main function, I've called: <code>setuid(current_uid_logged)</code>.</p>
  <p>But I don't know the way to get the user-name of the logged on user, or the uid in the root process.</p>
  <p>Ways that I've tried: <code>getenv(&quot;USERNAME&quot;)</code> or <code>getlogin()</code> always return <code>root</code> account.</p>
  <p>I've confused with <code>getlogin()</code>, my program is running when kernel start and wait for user login (I have a thread to wait a Finder process (Mac OSX) running to detect user logged on), wait 10 seconds and call <code>getlogin()</code> but sometime, it returned <code>root</code> but can return user login. I think Finder process is running when user logged on.</p>
  <p>But when I call my app to run with <code>sudo</code> command, <code>getlogin()</code> always returns current user logged on.</p>
  <p>How do I do this?</p>