Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a program in /home/me/bin/foo, typically compiled from :

// includes
#define PATHNAME "/home/me/bin/bar.txt"

int main ()
   FILE* f;
   f = fopen(PATHNAME, "wb"); // I skip the possible error for freshness

   fputs(getenv("HOME"), f);


   return 0;

When I run the program from the directory in non-privileges user mode, the file bar.txt is created with /home/me written inside, that works fine..

.. until now my upstart configuration file in /etc/init looks like the following :

start on started tty2
exec /home/me/bin/foo

when I restart tty2, the file /home/me/bin/bar.txt is well created but nothing is written inside.

I've tried to write something else than getenv("HOME"), like a basic string but still nothing.

Why is that happening ? what should I do ?

update.1 : After few hours I just noticed that my pointer to the file was not handled properly.. Anyway except that little misunderstanding, that changes didn't solve my problem. I still have nothing in the file when I write getenv("HOME"). Why ? the process is executed as the root and getenv("HOME") is intended to write at least '/root'

share|improve this question

Commands executed by Upstart do not have a HOME environment variable.

I used upstart-socket-bridge on an unrelated project to print the environment variables (u-s-b adds a few special variables)


description "upstart-socket-bridge test"
start on socket PROTO=inet PORT=34567 ADDR=
setuid my_username
exec /bin/sh /tmp/socket-server


date > $outfile            # Timestamp
printenv >> $outfile
exit 0

Trigger the job:

$ nc localhost 34567

And the output list of environment variables looks like:

$ cat /tmp/outfile
Wed Dec 11 07:23:50 CST 2013
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.