Mercurial > projects > xwrited
annotate main.c @ 6:c2ddd2f977d1
Add Indonesian translation
author | Guido Berhoerster <guido+xwrited@berhoerster.name> |
---|---|
date | Sun, 27 Apr 2014 23:12:06 +0200 |
parents | 0907cc7064d4 |
children | fd2e275436a4 |
rev | line source |
---|---|
0
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
1 /* |
1
0907cc7064d4
Add support for newer glib versions
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
0
diff
changeset
|
2 * Copyright (C) 2014 Guido Berhoerster <guido+xwrited@berhoerster.name> |
0
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
3 * |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
4 * Permission is hereby granted, free of charge, to any person obtaining |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
5 * a copy of this software and associated documentation files (the |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
6 * "Software"), to deal in the Software without restriction, including |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
7 * without limitation the rights to use, copy, modify, merge, publish, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
8 * distribute, sublicense, and/or sell copies of the Software, and to |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
9 * permit persons to whom the Software is furnished to do so, subject to |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
10 * the following conditions: |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
11 * |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
12 * The above copyright notice and this permission notice shall be included |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
13 * in all copies or substantial portions of the Software. |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
14 * |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
22 */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
23 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
24 #define _XOPEN_SOURCE 600 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
25 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
26 #include <stdio.h> |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
27 #include <stdlib.h> |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
28 #include <string.h> |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
29 #include <unistd.h> |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
30 #include <fcntl.h> |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
31 #include <sys/stat.h> |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
32 #include <signal.h> |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
33 #include <errno.h> |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
34 #include <locale.h> |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
35 #include <libintl.h> |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
36 #include <glib.h> |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
37 #include <glib/gi18n.h> |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
38 #include <libnotify/notify.h> |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
39 #include "xwrited-debug.h" |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
40 #include "xwrited-unique.h" |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
41 #include "xwrited-utmp.h" |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
42 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
43 enum { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
44 PIPE_R_FD = 0, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
45 PIPE_W_FD |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
46 }; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
47 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
48 static int signal_pipe_fd[2] = { -1, -1 }; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
49 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
50 static void |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
51 on_signal(int signo) |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
52 { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
53 int old_errno = errno; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
54 ssize_t n; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
55 sigset_t sigset; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
56 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
57 /* try to read unread signals from the pipe and add the new one to it */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
58 n = read(signal_pipe_fd[PIPE_R_FD], &sigset, sizeof (sigset)); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
59 if ((n == -1) || ((size_t)n < sizeof (sigset))) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
60 sigemptyset(&sigset); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
61 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
62 sigaddset(&sigset, signo); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
63 write(signal_pipe_fd[PIPE_W_FD], &sigset, sizeof (sigset)); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
64 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
65 errno = old_errno; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
66 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
67 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
68 static gboolean |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
69 signal_read_cb(GIOChannel *source, GIOCondition cond, gpointer user_data) |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
70 { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
71 GMainLoop *loop = (GMainLoop *)user_data; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
72 sigset_t sigset; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
73 sigset_t old_sigset; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
74 GIOStatus status; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
75 gsize n; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
76 GError *error = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
77 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
78 /* |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
79 * deal with pending signals previously received in the signal handler, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
80 * try to read a sigset from the pipe, avoid partial reads by blocking |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
81 * all signals during the read operation |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
82 */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
83 sigfillset(&sigset); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
84 sigprocmask(SIG_BLOCK, &sigset, &old_sigset); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
85 status = g_io_channel_read_chars(source, (gchar *)&sigset, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
86 sizeof (sigset), &n, &error); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
87 sigprocmask(SIG_SETMASK, &old_sigset, NULL); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
88 if (status != G_IO_STATUS_NORMAL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
89 if (status != G_IO_STATUS_AGAIN) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
90 if (error != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
91 g_critical("failed to read from signal pipe: " |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
92 "%s", error->message); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
93 g_error_free(error); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
94 g_main_loop_quit(loop); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
95 } else { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
96 g_critical("failed to read from signal pipe"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
97 g_main_loop_quit(loop); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
98 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
99 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
100 } else if (n != sizeof (sigset)) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
101 g_critical("short read from signal pipe"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
102 g_main_loop_quit(loop); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
103 } else { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
104 if ((sigismember(&sigset, SIGINT) == 1) || |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
105 (sigismember(&sigset, SIGTERM) == 1) || |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
106 (sigismember(&sigset, SIGQUIT) == 1) || |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
107 (sigismember(&sigset, SIGHUP) == 1)) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
108 g_debug("received signal, exiting"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
109 g_main_loop_quit(loop); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
110 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
111 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
112 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
113 return (TRUE); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
114 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
115 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
116 static gboolean |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
117 send_notification(GString *raw_str, GMainLoop *loop) |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
118 { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
119 gboolean retval = FALSE; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
120 GString *utf8_str = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
121 gchar *startp = raw_str->str; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
122 gchar *endp; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
123 GRegex *regex = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
124 GError *error = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
125 gchar *body = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
126 GList *capabilities = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
127 gchar *tmp; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
128 NotifyNotification *notification = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
129 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
130 utf8_str = g_string_sized_new(raw_str->len); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
131 while (!g_utf8_validate(startp, raw_str->str + raw_str->len - |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
132 startp, (const gchar **)&endp)) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
133 g_string_append_len(utf8_str, startp, endp - startp); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
134 /* |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
135 * replace each byte that does not belong to a UTF-8-encoded |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
136 * character with the Unicode REPLACEMENT CHARACTER (U+FFFD) |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
137 */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
138 g_string_append(utf8_str, "\357\277\275"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
139 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
140 startp = endp + ((endp < raw_str->str + raw_str->len) ? 1 : 0); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
141 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
142 g_string_append_len(utf8_str, startp, raw_str->str + raw_str->len - |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
143 startp); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
144 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
145 /* remove any CR, BEL and trailing space and tabs */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
146 regex = g_regex_new("([\r\a]+|[ \t\r\a]+$)", G_REGEX_MULTILINE, 0, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
147 &error); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
148 if (error != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
149 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
150 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
151 body = g_regex_replace_literal(regex, utf8_str->str, -1, 0, "", 0, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
152 &error); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
153 if (error != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
154 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
155 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
156 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
157 /* |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
158 * skip empty messages or messages only consisting of whitespace and |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
159 * control characters |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
160 */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
161 if ((strlen(body) == 0) || |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
162 !g_regex_match_simple("[^[:space:][:cntrl:]]", body, 0, 0)) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
163 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
164 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
165 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
166 /* |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
167 * if the notification daemon supports markup the message needs to be |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
168 * escaped |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
169 */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
170 capabilities = notify_get_server_caps(); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
171 if (g_list_find_custom(capabilities, "body-markup", |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
172 (GCompareFunc)strcmp) != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
173 tmp = g_markup_escape_text(body, -1); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
174 g_free(body); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
175 body = tmp; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
176 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
177 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
178 /* show notification */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
179 notification = notify_notification_new(_("Message received"), |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
180 body, "utilities-terminal" |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
181 #if !defined(NOTIFY_VERSION_MINOR) || \ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
182 (NOTIFY_VERSION_MAJOR == 0 && NOTIFY_VERSION_MINOR < 7) |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
183 , NULL |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
184 #endif |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
185 ); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
186 if (notification == NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
187 g_critical("failed to create a notification object"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
188 g_main_loop_quit(loop); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
189 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
190 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
191 notify_notification_set_timeout(notification, NOTIFY_EXPIRES_NEVER); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
192 retval = notify_notification_show(notification, NULL); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
193 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
194 out: |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
195 if (notification != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
196 g_object_unref(G_OBJECT(notification)); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
197 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
198 if (capabilities != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
199 g_list_free_full(capabilities, g_free); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
200 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
201 g_free(body); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
202 if (regex != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
203 g_regex_unref(regex); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
204 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
205 if (utf8_str != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
206 g_string_free(utf8_str, TRUE); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
207 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
208 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
209 return (retval); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
210 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
211 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
212 static gboolean |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
213 master_pty_read_cb(GIOChannel *source, GIOCondition cond, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
214 gpointer user_data) |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
215 { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
216 GMainLoop *loop = (GMainLoop *)user_data; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
217 gchar buf[BUFSIZ]; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
218 GString *raw_str = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
219 GIOStatus status; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
220 gsize buf_len; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
221 GError *error = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
222 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
223 if ((cond & G_IO_IN) || (cond & G_IO_PRI)) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
224 raw_str = g_string_sized_new(BUFSIZ); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
225 /* read message from master pty */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
226 while ((status = g_io_channel_read_chars(source, buf, BUFSIZ, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
227 &buf_len, &error)) == G_IO_STATUS_NORMAL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
228 if (buf_len > 0) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
229 g_debug("read %" G_GSSIZE_FORMAT " bytes from " |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
230 "master pty", buf_len); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
231 g_string_append_len(raw_str, buf, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
232 (gssize)buf_len); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
233 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
234 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
235 if (error != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
236 g_critical("failed to read from master pty: %s", |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
237 error->message); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
238 g_error_free(error); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
239 g_main_loop_quit(loop); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
240 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
241 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
242 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
243 if (!send_notification(raw_str, loop)) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
244 g_warning("failed to send notification"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
245 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
246 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
247 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
248 if ((cond & G_IO_ERR) || (cond & G_IO_HUP)) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
249 g_critical("connection to master pty broken"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
250 g_main_loop_quit(loop); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
251 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
252 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
253 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
254 out: |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
255 if (raw_str != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
256 g_string_free(raw_str, TRUE); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
257 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
258 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
259 return (TRUE); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
260 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
261 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
262 int |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
263 main(int argc, char *argv[]) |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
264 { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
265 int status = EXIT_FAILURE; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
266 GMainLoop *loop = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
267 GError *error = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
268 XWritedUnique *app = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
269 GOptionContext *context = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
270 struct sigaction sigact; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
271 GIOChannel *signal_channel = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
272 GIOChannel *master_pty_channel = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
273 int masterfd = -1; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
274 int slavefd = -1; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
275 char *slave_name = NULL; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
276 gboolean vflag = FALSE; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
277 gboolean dflag = FALSE; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
278 const GOptionEntry options[] = { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
279 { "debug", 'd', 0, G_OPTION_ARG_NONE, &dflag, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
280 N_("Show extra debugging information"), NULL }, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
281 { "version", 'V', 0, G_OPTION_ARG_NONE, &vflag, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
282 N_("Print the current version and exit"), NULL }, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
283 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, 0 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
284 }; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
285 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
286 setlocale(LC_ALL, ""); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
287 bindtextdomain(PACKAGE, LOCALEDIR); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
288 bind_textdomain_codeset(PACKAGE, "UTF-8"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
289 textdomain(PACKAGE); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
290 |
1
0907cc7064d4
Add support for newer glib versions
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
0
diff
changeset
|
291 #if !GLIB_CHECK_VERSION(2, 35, 0) |
0907cc7064d4
Add support for newer glib versions
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
0
diff
changeset
|
292 /* deprecated in glib >= 2.35 */ |
0
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
293 g_type_init(); |
1
0907cc7064d4
Add support for newer glib versions
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
0
diff
changeset
|
294 #endif |
0
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
295 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
296 context = g_option_context_new("- display write and wall messages as " |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
297 "desktop notifications"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
298 g_option_context_add_main_entries(context, options, PACKAGE); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
299 g_option_context_set_translation_domain(context, PACKAGE); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
300 g_option_context_parse(context, &argc, &argv, &error); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
301 if (error != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
302 g_printerr("%s.\n", error->message); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
303 g_error_free(error); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
304 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
305 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
306 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
307 xwrited_debug_init(dflag); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
308 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
309 if (vflag) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
310 g_print("%s %s\n", PACKAGE, VERSION); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
311 status = EXIT_SUCCESS; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
312 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
313 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
314 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
315 app = xwrited_unique_new("org.guido-berhoerster.code.xwrited"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
316 if (app == NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
317 g_critical("failed to initialize application"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
318 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
319 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
320 if (!xwrited_unique_is_unique(app)) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
321 g_printerr(_("xwrited is already running in this session.\n")); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
322 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
323 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
324 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
325 if (!notify_init(APP_NAME)) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
326 g_critical("failed to initialize libnotify"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
327 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
328 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
329 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
330 loop = g_main_loop_new(NULL, FALSE); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
331 if (loop == NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
332 g_critical("failed to create main loop"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
333 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
334 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
335 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
336 /* open master pty */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
337 masterfd = posix_openpt(O_RDWR | O_NOCTTY); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
338 if (masterfd == -1) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
339 g_critical("failed to open master pty: %s", g_strerror(errno)); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
340 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
341 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
342 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
343 /* create slave pty */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
344 if ((grantpt(masterfd) == -1) || (unlockpt(masterfd) == -1)) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
345 g_critical("failed to create slave pty: %s", g_strerror(errno)); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
346 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
347 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
348 slave_name = ptsname(masterfd); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
349 if (slave_name == NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
350 g_critical("failed to obtain name of slave pty"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
351 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
352 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
353 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
354 /* |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
355 * keep an open fd around order to prevent closing the master fd when |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
356 * receiving an EOF |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
357 */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
358 slavefd = open(slave_name, O_RDWR); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
359 if (slavefd == -1) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
360 g_critical("failed to open slave pty: %s", g_strerror(errno)); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
361 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
362 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
363 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
364 /* create a GIOChannel for monitoring the master pty for messages */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
365 master_pty_channel = g_io_channel_unix_new(masterfd); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
366 g_io_channel_set_flags(master_pty_channel, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
367 g_io_channel_get_flags(master_pty_channel) | G_IO_FLAG_NONBLOCK, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
368 &error); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
369 if (error != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
370 g_critical("failed set flags on the master pty channel: %s", |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
371 error->message); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
372 g_error_free(error); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
373 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
374 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
375 if (!g_io_add_watch(master_pty_channel, G_IO_IN | G_IO_PRI | G_IO_HUP | |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
376 G_IO_ERR, master_pty_read_cb, loop)) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
377 g_critical("failed to add watch on signal channel"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
378 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
379 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
380 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
381 /* create pipe for delivering signals to a listener in the main loop */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
382 if (pipe(signal_pipe_fd) == -1) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
383 g_critical("failed to create signal pipe: %s", |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
384 g_strerror(errno)); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
385 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
386 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
387 if (fcntl(signal_pipe_fd[PIPE_W_FD], F_SETFL, O_NONBLOCK) == -1) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
388 g_critical("failed to set flags on signal pipe: %s", |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
389 g_strerror(errno)); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
390 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
391 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
392 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
393 /* create GIO channel for reading from the signal_pipe */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
394 signal_channel = g_io_channel_unix_new(signal_pipe_fd[PIPE_R_FD]); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
395 g_io_channel_set_encoding(signal_channel, NULL, &error); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
396 if (error != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
397 g_critical("failed to set binary encoding for signal channel: " |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
398 "%s", error->message); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
399 g_error_free(error); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
400 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
401 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
402 g_io_channel_set_buffered(signal_channel, FALSE); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
403 g_io_channel_set_flags(signal_channel, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
404 g_io_channel_get_flags(signal_channel) | G_IO_FLAG_NONBLOCK, |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
405 &error); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
406 if (error != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
407 g_critical("failed set flags on signal channel: %s", |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
408 error->message); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
409 g_error_free(error); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
410 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
411 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
412 if (g_io_add_watch(signal_channel, G_IO_IN | G_IO_PRI | G_IO_HUP | |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
413 G_IO_ERR, signal_read_cb, loop) == 0) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
414 g_critical("failed to add watch on the signal channel"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
415 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
416 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
417 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
418 /* set up signal handler */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
419 sigact.sa_handler = on_signal; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
420 sigact.sa_flags = SA_RESTART; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
421 sigemptyset(&sigact.sa_mask); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
422 if ((sigaction(SIGINT, &sigact, NULL) < 0) || |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
423 (sigaction(SIGTERM, &sigact, NULL) < 0) || |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
424 (sigaction(SIGQUIT, &sigact, NULL) < 0) || |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
425 (sigaction(SIGHUP, &sigact, NULL) < 0)) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
426 g_critical("failed to set up signal handler"); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
427 goto out; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
428 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
429 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
430 xwrited_utmp_add_entry(masterfd); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
431 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
432 /* main loop */ |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
433 g_main_loop_run(loop); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
434 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
435 xwrited_utmp_remove_entry(masterfd); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
436 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
437 status = EXIT_SUCCESS; |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
438 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
439 out: |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
440 if (context != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
441 g_option_context_free(context); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
442 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
443 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
444 if (signal_channel != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
445 g_io_channel_shutdown(signal_channel, FALSE, NULL); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
446 g_io_channel_unref(signal_channel); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
447 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
448 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
449 if (signal_pipe_fd[PIPE_R_FD] != -1) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
450 close(signal_pipe_fd[PIPE_R_FD]); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
451 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
452 if (signal_pipe_fd[PIPE_W_FD] != -1) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
453 close(signal_pipe_fd[PIPE_W_FD]); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
454 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
455 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
456 if (master_pty_channel != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
457 g_io_channel_shutdown(master_pty_channel, FALSE, NULL); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
458 g_io_channel_unref(master_pty_channel); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
459 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
460 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
461 if (slavefd != -1) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
462 close(slavefd); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
463 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
464 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
465 if (masterfd != -1) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
466 close(masterfd); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
467 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
468 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
469 if (app != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
470 g_object_unref(app); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
471 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
472 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
473 if (loop != NULL) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
474 g_main_loop_unref(loop); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
475 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
476 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
477 if (notify_is_initted()) { |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
478 notify_uninit(); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
479 } |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
480 |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
481 exit(status); |
52694b49dcc4
Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff
changeset
|
482 } |