Browse Source

Fixing a bug due to getlogin() in syntribos

The bug is due to the fact that sometimes when using os.getlogin(),
Python is calling the system getlogin() function and returns a strerror
"No such file or dir", thus failing to get the login name.

Change-Id: I4156325d7435c69943b2bb736bd1ec7b4d060db4
Closes-Bug: #1640850
tags/0.3.0^0
Rahul Nair 2 years ago
parent
commit
a2f1d7c222
1 changed files with 9 additions and 1 deletions
  1. 9
    1
      syntribos/utils/env.py

+ 9
- 1
syntribos/utils/env.py View File

@@ -14,6 +14,7 @@
14 14
 import datetime
15 15
 import logging
16 16
 import os
17
+import pwd
17 18
 import shutil
18 19
 import sys
19 20
 
@@ -42,7 +43,13 @@ def get_user_home_root():
42 43
     global FOLDER
43 44
     user = os.environ.get("SUDO_USER")
44 45
     if not user:
45
-        user = os.getlogin() or os.environ.get("USER")
46
+        try:
47
+            user = os.environ.get("USER") or os.getlogin()
48
+        except OSError as e:
49
+            # Refer https://mail.python.org/pipermail/python-bugs-list/
50
+            # 2002-July/012691.html
51
+            LOG.error("Exception thrown in : {}".format(e))
52
+            user = pwd.getpwuid(os.getuid())[0]
46 53
     home_path = "~{0}/{1}".format(user, FOLDER)
47 54
     return expand_path(home_path)
48 55
 
@@ -62,6 +69,7 @@ def get_venv_root():
62 69
 
63 70
 def get_syntribos_root():
64 71
     """This determines the proper path to use as syntribos' root directory."""
72
+    path = ""
65 73
     custom_root = CONF.syntribos.custom_root
66 74
 
67 75
     if custom_root:

Loading…
Cancel
Save