Don't crash if UID is not found in pw database
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 16 Feb 2015 13:24:56 +0000 (15:24 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 16 Feb 2015 14:53:10 +0000 (16:53 +0200)
We just don't set the HOME env variable in that case.

Change-Id: Ieab00d21d61e7e001dc3c04ef1d618e9d8c455d3
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
obs_service_gbp_utils/__init__.py

index 5e64a0e763256bd48ce29c0ce33b072e061cf3d5..c0cea1e62339bc1264af7f2642a91da7302b4ade 100644 (file)
@@ -64,12 +64,15 @@ def _demoted_child_call(uid, gid, ret_data_q, func):
     if uid and uid > 0:
         try:
             os.setresuid(uid, uid, uid)
-            # Set environment
-            os.environ['HOME'] = pwd.getpwuid(uid).pw_dir
         except OSError as err:
             ret_data_q.put(GbpServiceError("Setting UID (%s) failed: %s" %
                                            (uid, err)))
             sys.exit(_RET_FORK_ERR)
+        try:
+            # Set environment
+            os.environ['HOME'] = pwd.getpwuid(uid).pw_dir
+        except KeyError:
+            pass
     # Call the function
     try:
         # Func must be a callable without arguments