118
ibus_get_socket_folder (void)
120
static gchar *folder = NULL;
122
if (folder == NULL) {
123
const gchar *session = ibus_get_session_id ();
124
if (session && session[0] != '\0') {
125
folder = g_strdup_printf ("/tmp/ibus-%s-%s",
126
ibus_get_user_name (), session);
129
folder = g_strdup_printf ("/tmp/ibus-%s",
130
ibus_get_user_name ());
137
121
ibus_get_socket_path (void)
139
123
static gchar *path = NULL;
200
181
ibus_get_address (void)
202
const gchar *address = NULL;
183
static gchar *address = NULL;
203
185
static gchar buffer[1024];
189
if (address != NULL) {
206
194
/* get address from evn variable */
207
address = g_getenv ("IBUS_ADDRESS");
195
address = g_strdup (g_getenv ("IBUS_ADDRESS"));
211
200
/* read address from ~/.config/ibus/bus/soketfile */
212
201
pf = fopen (ibus_get_socket_path (), "r");
216
206
while (!feof (pf)) {
217
207
gchar *p = buffer;
218
208
if (fgets (buffer, sizeof (buffer), pf) == NULL)
211
/* skip comment line */
222
if (strncmp (p, "IBUS_ADDRESS=", sizeof ("IBUS_ADDRESS=") - 1) != 0)
224
address = p + sizeof ("IBUS_ADDRESS=") - 1;
225
for (p = (gchar *)address; *p != '\n' && *p != '\0'; p++);
214
/* parse IBUS_ADDRESS */
215
if (strncmp (p, "IBUS_ADDRESS=", sizeof ("IBUS_ADDRESS=") - 1) == 0) {
216
address = p + sizeof ("IBUS_ADDRESS=") - 1;
217
for (p = (gchar *)address; *p != '\n' && *p != '\0'; p++);
220
address = g_strdup (address);
224
/* parse IBUS_DAEMON_PID */
225
if (strncmp (p, "IBUS_DAEMON_PID=", sizeof ("IBUS_DAEMON_PID=") - 1) == 0) {
226
pid = atoi(p + sizeof ("IBUS_DAEMON_PID=") - 1);
233
if (pid == -1 || kill (pid, 0) != 0) {
243
248
g_mkdir_with_parents (path, 0700);
251
g_unlink (ibus_get_socket_path ());
246
252
pf = fopen (ibus_get_socket_path (), "w");
247
253
g_return_if_fail (pf != NULL);
249
fprintf (pf, "# This file is created by ibus-daemon, please do not modify it\n");
250
fprintf (pf, "IBUS_ADDRESS=%s\n", address);
256
"# This file is created by ibus-daemon, please do not modify it\n"
258
"IBUS_DAEMON_PID=%ld\n",
259
address, (glong) getpid ());