annotate main.c @ 11:fd2e275436a4

Display error messages and free errors
author Guido Berhoerster <guido+xwrited@berhoerster.name>
date Mon, 16 Mar 2015 19:58:21 +0100
parents 0907cc7064d4
children 6440ba6e3466
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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) {
11
fd2e275436a4 Display error messages and free errors
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents: 1
diff changeset
149 g_critical("failed to create regex object: %s",
fd2e275436a4 Display error messages and free errors
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents: 1
diff changeset
150 error->message);
fd2e275436a4 Display error messages and free errors
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents: 1
diff changeset
151 g_error_free(error);
0
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
152 goto out;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
153 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
154 body = g_regex_replace_literal(regex, utf8_str->str, -1, 0, "", 0,
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
155 &error);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
156 if (error != NULL) {
11
fd2e275436a4 Display error messages and free errors
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents: 1
diff changeset
157 g_critical("failed to replace control and space characters: "
fd2e275436a4 Display error messages and free errors
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents: 1
diff changeset
158 "%s", error->message);
fd2e275436a4 Display error messages and free errors
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents: 1
diff changeset
159 g_error_free(error);
0
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
160 goto out;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
161 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
162
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
163 /*
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
164 * skip empty messages or messages only consisting of whitespace and
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
165 * control characters
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 ((strlen(body) == 0) ||
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
168 !g_regex_match_simple("[^[:space:][:cntrl:]]", body, 0, 0)) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
169 goto out;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
170 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
171
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
172 /*
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
173 * if the notification daemon supports markup the message needs to be
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
174 * escaped
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
175 */
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
176 capabilities = notify_get_server_caps();
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
177 if (g_list_find_custom(capabilities, "body-markup",
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
178 (GCompareFunc)strcmp) != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
179 tmp = g_markup_escape_text(body, -1);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
180 g_free(body);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
181 body = tmp;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
182 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
183
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
184 /* show notification */
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
185 notification = notify_notification_new(_("Message received"),
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
186 body, "utilities-terminal"
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
187 #if !defined(NOTIFY_VERSION_MINOR) || \
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
188 (NOTIFY_VERSION_MAJOR == 0 && NOTIFY_VERSION_MINOR < 7)
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
189 , NULL
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
190 #endif
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
191 );
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
192 if (notification == NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
193 g_critical("failed to create a notification object");
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
194 g_main_loop_quit(loop);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
195 goto out;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
196 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
197 notify_notification_set_timeout(notification, NOTIFY_EXPIRES_NEVER);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
198 retval = notify_notification_show(notification, NULL);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
199
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
200 out:
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
201 if (notification != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
202 g_object_unref(G_OBJECT(notification));
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
203 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
204 if (capabilities != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
205 g_list_free_full(capabilities, g_free);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
206 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
207 g_free(body);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
208 if (regex != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
209 g_regex_unref(regex);
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 if (utf8_str != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
212 g_string_free(utf8_str, TRUE);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
213 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
214
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
215 return (retval);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
216 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
217
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
218 static gboolean
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
219 master_pty_read_cb(GIOChannel *source, GIOCondition cond,
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
220 gpointer user_data)
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
221 {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
222 GMainLoop *loop = (GMainLoop *)user_data;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
223 gchar buf[BUFSIZ];
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
224 GString *raw_str = NULL;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
225 GIOStatus status;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
226 gsize buf_len;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
227 GError *error = NULL;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
228
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
229 if ((cond & G_IO_IN) || (cond & G_IO_PRI)) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
230 raw_str = g_string_sized_new(BUFSIZ);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
231 /* read message from master pty */
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
232 while ((status = g_io_channel_read_chars(source, buf, BUFSIZ,
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
233 &buf_len, &error)) == G_IO_STATUS_NORMAL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
234 if (buf_len > 0) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
235 g_debug("read %" G_GSSIZE_FORMAT " bytes from "
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
236 "master pty", buf_len);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
237 g_string_append_len(raw_str, buf,
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
238 (gssize)buf_len);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
239 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
240 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
241 if (error != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
242 g_critical("failed to read from master pty: %s",
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
243 error->message);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
244 g_error_free(error);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
245 g_main_loop_quit(loop);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
246 goto out;
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
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
249 if (!send_notification(raw_str, loop)) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
250 g_warning("failed to send notification");
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
251 }
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 if ((cond & G_IO_ERR) || (cond & G_IO_HUP)) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
255 g_critical("connection to master pty broken");
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
256 g_main_loop_quit(loop);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
257 goto out;
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
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
260 out:
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
261 if (raw_str != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
262 g_string_free(raw_str, TRUE);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
263 }
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 return (TRUE);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
266 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
267
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
268 int
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
269 main(int argc, char *argv[])
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
270 {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
271 int status = EXIT_FAILURE;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
272 GMainLoop *loop = NULL;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
273 GError *error = NULL;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
274 XWritedUnique *app = NULL;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
275 GOptionContext *context = NULL;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
276 struct sigaction sigact;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
277 GIOChannel *signal_channel = NULL;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
278 GIOChannel *master_pty_channel = NULL;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
279 int masterfd = -1;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
280 int slavefd = -1;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
281 char *slave_name = NULL;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
282 gboolean vflag = FALSE;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
283 gboolean dflag = FALSE;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
284 const GOptionEntry options[] = {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
285 { "debug", 'd', 0, G_OPTION_ARG_NONE, &dflag,
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
286 N_("Show extra debugging information"), NULL },
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
287 { "version", 'V', 0, G_OPTION_ARG_NONE, &vflag,
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
288 N_("Print the current version and exit"), NULL },
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
289 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, 0 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
290 };
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
291
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
292 setlocale(LC_ALL, "");
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
293 bindtextdomain(PACKAGE, LOCALEDIR);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
294 bind_textdomain_codeset(PACKAGE, "UTF-8");
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
295 textdomain(PACKAGE);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
296
1
0907cc7064d4 Add support for newer glib versions
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents: 0
diff changeset
297 #if !GLIB_CHECK_VERSION(2, 35, 0)
0907cc7064d4 Add support for newer glib versions
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents: 0
diff changeset
298 /* deprecated in glib >= 2.35 */
0
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
299 g_type_init();
1
0907cc7064d4 Add support for newer glib versions
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents: 0
diff changeset
300 #endif
0
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
301
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
302 context = g_option_context_new("- display write and wall messages as "
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
303 "desktop notifications");
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
304 g_option_context_add_main_entries(context, options, PACKAGE);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
305 g_option_context_set_translation_domain(context, PACKAGE);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
306 g_option_context_parse(context, &argc, &argv, &error);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
307 if (error != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
308 g_printerr("%s.\n", error->message);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
309 g_error_free(error);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
310 goto out;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
311 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
312
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
313 xwrited_debug_init(dflag);
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 if (vflag) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
316 g_print("%s %s\n", PACKAGE, VERSION);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
317 status = EXIT_SUCCESS;
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
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
321 app = xwrited_unique_new("org.guido-berhoerster.code.xwrited");
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
322 if (app == NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
323 g_critical("failed to initialize application");
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
324 goto out;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
325 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
326 if (!xwrited_unique_is_unique(app)) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
327 g_printerr(_("xwrited is already running in this session.\n"));
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
328 goto out;
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
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
331 if (!notify_init(APP_NAME)) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
332 g_critical("failed to initialize libnotify");
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 loop = g_main_loop_new(NULL, FALSE);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
337 if (loop == NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
338 g_critical("failed to create main loop");
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
339 goto out;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
340 }
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 /* open master pty */
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
343 masterfd = posix_openpt(O_RDWR | O_NOCTTY);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
344 if (masterfd == -1) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
345 g_critical("failed to open master 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
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
349 /* create slave pty */
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
350 if ((grantpt(masterfd) == -1) || (unlockpt(masterfd) == -1)) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
351 g_critical("failed to create slave pty: %s", g_strerror(errno));
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
352 goto out;
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 slave_name = ptsname(masterfd);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
355 if (slave_name == NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
356 g_critical("failed to obtain name of slave pty");
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
357 goto out;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
358 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
359
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
360 /*
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
361 * 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
362 * receiving an EOF
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 slavefd = open(slave_name, O_RDWR);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
365 if (slavefd == -1) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
366 g_critical("failed to open slave pty: %s", g_strerror(errno));
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
367 goto out;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
368 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
369
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
370 /* create a GIOChannel for monitoring the master pty for messages */
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
371 master_pty_channel = g_io_channel_unix_new(masterfd);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
372 g_io_channel_set_flags(master_pty_channel,
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
373 g_io_channel_get_flags(master_pty_channel) | G_IO_FLAG_NONBLOCK,
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
374 &error);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
375 if (error != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
376 g_critical("failed set flags on the master pty channel: %s",
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
377 error->message);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
378 g_error_free(error);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
379 goto out;
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 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
382 G_IO_ERR, master_pty_read_cb, loop)) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
383 g_critical("failed to add watch on signal channel");
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
384 goto out;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
385 }
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 /* create pipe for delivering signals to a listener in the main loop */
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
388 if (pipe(signal_pipe_fd) == -1) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
389 g_critical("failed to create signal pipe: %s",
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
390 g_strerror(errno));
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
391 goto out;
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 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
394 g_critical("failed to set flags on signal pipe: %s",
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
395 g_strerror(errno));
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
396 goto out;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
397 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
398
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
399 /* create GIO channel for reading from the signal_pipe */
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
400 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
401 g_io_channel_set_encoding(signal_channel, NULL, &error);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
402 if (error != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
403 g_critical("failed to set binary encoding for signal channel: "
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
404 "%s", error->message);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
405 g_error_free(error);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
406 goto out;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
407 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
408 g_io_channel_set_buffered(signal_channel, FALSE);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
409 g_io_channel_set_flags(signal_channel,
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
410 g_io_channel_get_flags(signal_channel) | G_IO_FLAG_NONBLOCK,
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
411 &error);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
412 if (error != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
413 g_critical("failed set flags on signal channel: %s",
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
414 error->message);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
415 g_error_free(error);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
416 goto out;
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 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
419 G_IO_ERR, signal_read_cb, loop) == 0) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
420 g_critical("failed to add watch on the signal channel");
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
421 goto out;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
422 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
423
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
424 /* set up signal handler */
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
425 sigact.sa_handler = on_signal;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
426 sigact.sa_flags = SA_RESTART;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
427 sigemptyset(&sigact.sa_mask);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
428 if ((sigaction(SIGINT, &sigact, NULL) < 0) ||
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
429 (sigaction(SIGTERM, &sigact, NULL) < 0) ||
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
430 (sigaction(SIGQUIT, &sigact, NULL) < 0) ||
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
431 (sigaction(SIGHUP, &sigact, NULL) < 0)) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
432 g_critical("failed to set up signal handler");
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
433 goto out;
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
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
436 xwrited_utmp_add_entry(masterfd);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
437
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
438 /* main loop */
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
439 g_main_loop_run(loop);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
440
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
441 xwrited_utmp_remove_entry(masterfd);
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 status = EXIT_SUCCESS;
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
444
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
445 out:
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
446 if (context != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
447 g_option_context_free(context);
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
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
450 if (signal_channel != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
451 g_io_channel_shutdown(signal_channel, FALSE, NULL);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
452 g_io_channel_unref(signal_channel);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
453 }
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 if (signal_pipe_fd[PIPE_R_FD] != -1) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
456 close(signal_pipe_fd[PIPE_R_FD]);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
457 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
458 if (signal_pipe_fd[PIPE_W_FD] != -1) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
459 close(signal_pipe_fd[PIPE_W_FD]);
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
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
462 if (master_pty_channel != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
463 g_io_channel_shutdown(master_pty_channel, FALSE, NULL);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
464 g_io_channel_unref(master_pty_channel);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
465 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
466
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
467 if (slavefd != -1) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
468 close(slavefd);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
469 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
470
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
471 if (masterfd != -1) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
472 close(masterfd);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
473 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
474
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
475 if (app != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
476 g_object_unref(app);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
477 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
478
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
479 if (loop != NULL) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
480 g_main_loop_unref(loop);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
481 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
482
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
483 if (notify_is_initted()) {
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
484 notify_uninit();
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
485 }
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
486
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
487 exit(status);
52694b49dcc4 Initial revision
Guido Berhoerster <guido+xwrited@berhoerster.name>
parents:
diff changeset
488 }