get username from getlogin(), $LOGNAME, $USER, $LNAME, $USERNAME.
authorHuang Peng <shawn.p.huang@gmail.com>
Mon, 4 Aug 2008 13:04:48 +0000 (21:04 +0800)
committerHuang Peng <shawn.p.huang@gmail.com>
Mon, 4 Aug 2008 13:04:48 +0000 (21:04 +0800)
gtk2/ibusimclient.c
qt4/ibus-client.cpp

index 25b0686..939ce12 100644 (file)
@@ -204,7 +204,7 @@ _ibus_im_client_ibus_open (IBusIMClient *client)
     }
 #endif
     if (ibus_addr == NULL) {
-        gchar *display, *host, *id;
+        gchar *display, *host, *id, *username;
         display = g_strdup (g_getenv ("DISPLAY"));
         if (display != NULL) {
             id = host = display;
@@ -219,7 +219,18 @@ _ibus_im_client_ibus_open (IBusIMClient *client)
         else {
             host = id = "";
         }
-        ibus_addr = g_strdup_printf ("unix:path=/tmp/ibus-%s/ibus-%s-%s", getlogin (), host, id);
+        
+        username = getlogin();
+        if (username == NULL)
+            username = getenv("LOGNAME");
+        if (username == NULL)
+            username = getenv("USER");
+        if (username == NULL)
+            username = getenv("LNAME");
+        if (username == NULL)
+            username = getenv("USERNAME");
+
+        ibus_addr = g_strdup_printf ("unix:path=/tmp/ibus-%s/ibus-%s-%s", username, host, id);
         g_free (display);
     }
 
index 43ca50a..8b0aff2 100644 (file)
@@ -332,6 +332,7 @@ IBusClient::connectToBus ()
 {
        QString address;
        QString session;
+       QString username;
        QDBusConnection *connection = NULL;
 
        if (ibus != NULL)
@@ -339,7 +340,18 @@ IBusClient::connectToBus ()
 
        session = getenv ("DISPLAY");
        session.replace (":", "-");
-       address = QString("unix:path=/tmp/ibus-%1/ibus-%2").arg (getlogin(), session);
+       
+       username = getlogin ();
+       if (username.isNull ())
+               username = getenv ("LOGNAME");
+       if (username.isNull ())
+               username = getenv ("USER");
+       if (username.isNull ())
+               username = getenv ("LNAME");
+       if (username.isNull ())
+               username = getenv ("USERNAME");
+
+       address = QString("unix:path=/tmp/ibus-%1/ibus-%2").arg (username, session);
        connection = new QDBusConnection (
                QDBusConnection::connectToBus (
                        address,