1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>UNIX-specific utilities and integration</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="GLib Reference Manual">
<link rel="up" href="glib-utilities.html" title="GLib Utilities">
<link rel="prev" href="glib-Testing.html" title="Testing">
<link rel="next" href="glib-Windows-Compatibility-Functions.html" title="Windows Compatibility Functions">
<meta name="generator" content="GTK-Doc V1.19 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="glib-Testing.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GLib Reference Manual</th>
<td><a accesskey="n" href="glib-Windows-Compatibility-Functions.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts">
<a href="#glib-UNIX-specific-utilities-and-integration.synopsis" class="shortcut">Top</a>
|
<a href="#glib-UNIX-specific-utilities-and-integration.description" class="shortcut">Description</a>
</td></tr>
</table>
<div class="refentry">
<a name="glib-UNIX-specific-utilities-and-integration"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="glib-UNIX-specific-utilities-and-integration.top_of_page"></a>UNIX-specific utilities and integration</span></h2>
<p>UNIX-specific utilities and integration — pipes, signal handling</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<a name="glib-UNIX-specific-utilities-and-integration.synopsis"></a><h2>Synopsis</h2>
<pre class="synopsis">
#include <glib-unix.h>
#define <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#G-UNIX-ERROR:CAPS" title="G_UNIX_ERROR">G_UNIX_ERROR</a>
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#g-unix-open-pipe" title="g_unix_open_pipe ()">g_unix_open_pipe</a> (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> *fds</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> flags</code></em>,
<em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="struct GError"><span class="type">GError</span></a> **error</code></em>);
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#g-unix-set-fd-nonblocking" title="g_unix_set_fd_nonblocking ()">g_unix_set_fd_nonblocking</a> (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> fd</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a> nonblock</code></em>,
<em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="struct GError"><span class="type">GError</span></a> **error</code></em>);
<a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="returnvalue">guint</span></a> <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#g-unix-signal-add" title="g_unix_signal_add ()">g_unix_signal_add</a> (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> signum</code></em>,
<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSourceFunc" title="GSourceFunc ()"><span class="type">GSourceFunc</span></a> handler</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);
<a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="returnvalue">guint</span></a> <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#g-unix-signal-add-full" title="g_unix_signal_add_full ()">g_unix_signal_add_full</a> (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> priority</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> signum</code></em>,
<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSourceFunc" title="GSourceFunc ()"><span class="type">GSourceFunc</span></a> handler</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>,
<em class="parameter"><code><a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="type">GDestroyNotify</span></a> notify</code></em>);
<a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> * <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#g-unix-signal-source-new" title="g_unix_signal_source_new ()">g_unix_signal_source_new</a> (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> signum</code></em>);
<a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> (<a class="link" href="glib-UNIX-specific-utilities-and-integration.html#GUnixFDSourceFunc" title="GUnixFDSourceFunc ()">*GUnixFDSourceFunc</a>) (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> fd</code></em>,
<em class="parameter"><code><a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="type">GIOCondition</span></a> condition</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);
<a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="returnvalue">guint</span></a> <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#g-unix-fd-add" title="g_unix_fd_add ()">g_unix_fd_add</a> (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> fd</code></em>,
<em class="parameter"><code><a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="type">GIOCondition</span></a> condition</code></em>,
<em class="parameter"><code><a class="link" href="glib-UNIX-specific-utilities-and-integration.html#GUnixFDSourceFunc" title="GUnixFDSourceFunc ()"><span class="type">GUnixFDSourceFunc</span></a> function</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);
<a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="returnvalue">guint</span></a> <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#g-unix-fd-add-full" title="g_unix_fd_add_full ()">g_unix_fd_add_full</a> (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> priority</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> fd</code></em>,
<em class="parameter"><code><a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="type">GIOCondition</span></a> condition</code></em>,
<em class="parameter"><code><a class="link" href="glib-UNIX-specific-utilities-and-integration.html#GUnixFDSourceFunc" title="GUnixFDSourceFunc ()"><span class="type">GUnixFDSourceFunc</span></a> function</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>,
<em class="parameter"><code><a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="type">GDestroyNotify</span></a> notify</code></em>);
<a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> * <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#g-unix-fd-source-new" title="g_unix_fd_source_new ()">g_unix_fd_source_new</a> (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> fd</code></em>,
<em class="parameter"><code><a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="type">GIOCondition</span></a> condition</code></em>);
</pre>
</div>
<div class="refsect1">
<a name="glib-UNIX-specific-utilities-and-integration.description"></a><h2>Description</h2>
<p>
Most of GLib is intended to be portable; in contrast, this set of
functions is designed for programs which explicitly target UNIX,
or are using it to build higher level abstractions which would be
conditionally compiled if the platform matches G_OS_UNIX.
</p>
<p>
To use these functions, you must explicitly include the
"glib-unix.h" header.
</p>
</div>
<div class="refsect1">
<a name="glib-UNIX-specific-utilities-and-integration.details"></a><h2>Details</h2>
<div class="refsect2">
<a name="G-UNIX-ERROR:CAPS"></a><h3>G_UNIX_ERROR</h3>
<pre class="programlisting">#define G_UNIX_ERROR (g_unix_error_quark())
</pre>
<p>
Error domain for API in the "g_unix_" namespace. Note that there is
no exported enumeration mapping <code class="literal">errno</code>. Instead, all functions
ensure that <code class="literal">errno</code> is relevant. The code for all <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#G-UNIX-ERROR:CAPS" title="G_UNIX_ERROR"><span class="type">G_UNIX_ERROR</span></a> is
always <code class="literal">0</code>, and the error message is always
generated via <a class="link" href="glib-String-Utility-Functions.html#g-strerror" title="g_strerror ()"><code class="function">g_strerror()</code></a>.
</p>
<p>
It is expected that most code will not look at <code class="literal">errno</code> from these
APIs. Important cases where one would want to differentiate between
errors are already covered by existing cross-platform GLib API,
such as e.g. <a href="http://library.gnome.org/devel/gio/unstable/GFile.html"><span class="type">GFile</span></a> wrapping <code class="literal">ENOENT</code>. However, it is
provided for completeness, at least.
</p>
</div>
<hr>
<div class="refsect2">
<a name="g-unix-open-pipe"></a><h3>g_unix_open_pipe ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> g_unix_open_pipe (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> *fds</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> flags</code></em>,
<em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="struct GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>
Similar to the UNIX <code class="function">pipe()</code> call, but on modern systems like Linux
uses the <code class="function">pipe2()</code> system call, which atomically creates a pipe with
the configured flags. The only supported flag currently is
<code class="literal">FD_CLOEXEC</code>. If for example you want to configure
<code class="literal">O_NONBLOCK</code>, that must still be done separately with
<code class="function">fcntl()</code>.
</p>
<p>
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>This function does *not* take <code class="literal">O_CLOEXEC</code>, it takes
<code class="literal">FD_CLOEXEC</code> as if for <code class="function">fcntl()</code>; these are
different on Linux/glibc.</div>
<p>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>fds</code></em> :</span></p></td>
<td>Array of two integers</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>flags</code></em> :</span></p></td>
<td>Bitfield of file descriptor flags, see "man 2 fcntl"</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
<td>a <a class="link" href="glib-Error-Reporting.html#GError" title="struct GError"><span class="type">GError</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> on success, <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> if not (and errno will be set).</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.30</p>
</div>
<hr>
<div class="refsect2">
<a name="g-unix-set-fd-nonblocking"></a><h3>g_unix_set_fd_nonblocking ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> g_unix_set_fd_nonblocking (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> fd</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a> nonblock</code></em>,
<em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="struct GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>
Control the non-blocking state of the given file descriptor,
according to <em class="parameter"><code>nonblock</code></em>. On most systems this uses <code class="literal">O_NONBLOCK</code>, but
on some older ones may use <code class="literal">O_NDELAY</code>.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>fd</code></em> :</span></p></td>
<td>A file descriptor</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>nonblock</code></em> :</span></p></td>
<td>If <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a>, set the descriptor to be non-blocking</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
<td>a <a class="link" href="glib-Error-Reporting.html#GError" title="struct GError"><span class="type">GError</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if successful</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.30</p>
</div>
<hr>
<div class="refsect2">
<a name="g-unix-signal-add"></a><h3>g_unix_signal_add ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="returnvalue">guint</span></a> g_unix_signal_add (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> signum</code></em>,
<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSourceFunc" title="GSourceFunc ()"><span class="type">GSourceFunc</span></a> handler</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);</pre>
<p>
A convenience function for <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#g-unix-signal-source-new" title="g_unix_signal_source_new ()"><code class="function">g_unix_signal_source_new()</code></a>, which
attaches to the default <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a>. You can remove the watch
using <a class="link" href="glib-The-Main-Event-Loop.html#g-source-remove" title="g_source_remove ()"><code class="function">g_source_remove()</code></a>.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>signum</code></em> :</span></p></td>
<td>Signal number</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>handler</code></em> :</span></p></td>
<td>Callback</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
<td>Data for <em class="parameter"><code>handler</code></em>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>An ID (greater than 0) for the event source</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.30</p>
</div>
<hr>
<div class="refsect2">
<a name="g-unix-signal-add-full"></a><h3>g_unix_signal_add_full ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="returnvalue">guint</span></a> g_unix_signal_add_full (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> priority</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> signum</code></em>,
<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSourceFunc" title="GSourceFunc ()"><span class="type">GSourceFunc</span></a> handler</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>,
<em class="parameter"><code><a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="type">GDestroyNotify</span></a> notify</code></em>);</pre>
<p>
A convenience function for <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#g-unix-signal-source-new" title="g_unix_signal_source_new ()"><code class="function">g_unix_signal_source_new()</code></a>, which
attaches to the default <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a>. You can remove the watch
using <a class="link" href="glib-The-Main-Event-Loop.html#g-source-remove" title="g_source_remove ()"><code class="function">g_source_remove()</code></a>.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>priority</code></em> :</span></p></td>
<td>the priority of the signal source. Typically this will be in
the range between <a class="link" href="glib-The-Main-Event-Loop.html#G-PRIORITY-DEFAULT:CAPS" title="G_PRIORITY_DEFAULT"><span class="type">G_PRIORITY_DEFAULT</span></a> and <a class="link" href="glib-The-Main-Event-Loop.html#G-PRIORITY-HIGH:CAPS" title="G_PRIORITY_HIGH"><span class="type">G_PRIORITY_HIGH</span></a>.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>signum</code></em> :</span></p></td>
<td>Signal number</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>handler</code></em> :</span></p></td>
<td>Callback</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
<td>Data for <em class="parameter"><code>handler</code></em>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>notify</code></em> :</span></p></td>
<td>
<a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="type">GDestroyNotify</span></a> for <em class="parameter"><code>handler</code></em>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>An ID (greater than 0) for the event source
Rename to: g_unix_signal_add</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.30</p>
</div>
<hr>
<div class="refsect2">
<a name="g-unix-signal-source-new"></a><h3>g_unix_signal_source_new ()</h3>
<pre class="programlisting"><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> * g_unix_signal_source_new (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> signum</code></em>);</pre>
<p>
Create a <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> that will be dispatched upon delivery of the UNIX
signal <em class="parameter"><code>signum</code></em>. In GLib versions before 2.36, only
<code class="literal">SIGHUP</code>, <code class="literal">SIGINT</code>,
<code class="literal">SIGTERM</code> can be monitored. In GLib 2.36,
<code class="literal">SIGUSR1</code> and <code class="literal">SIGUSR2</code> were
added.
</p>
<p>
Note that unlike the UNIX default, all sources which have created a
watch will be dispatched, regardless of which underlying thread
invoked <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#g-unix-signal-source-new" title="g_unix_signal_source_new ()"><code class="function">g_unix_signal_source_new()</code></a>.
</p>
<p>
For example, an effective use of this function is to handle <code class="literal">SIGTERM</code>
cleanly; flushing any outstanding files, and then calling
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-loop-quit" title="g_main_loop_quit ()"><code class="function">g_main_loop_quit()</code></a>. It is not safe to do any of this a regular
UNIX signal handler; your handler may be invoked while <code class="function">malloc()</code> or
another library function is running, causing reentrancy if you
attempt to use it from the handler. None of the GLib/GObject API
is safe against this kind of reentrancy.
</p>
<p>
The interaction of this source when combined with native UNIX
functions like <code class="function">sigprocmask()</code> is not defined.
</p>
<p>
The source will not initially be associated with any <a class="link" href="glib-The-Main-Event-Loop.html#GMainContext" title="GMainContext"><span class="type">GMainContext</span></a>
and must be added to one with <a class="link" href="glib-The-Main-Event-Loop.html#g-source-attach" title="g_source_attach ()"><code class="function">g_source_attach()</code></a> before it will be
executed.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>signum</code></em> :</span></p></td>
<td>A signal number</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>A newly created <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a>
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.30</p>
</div>
<hr>
<div class="refsect2">
<a name="GUnixFDSourceFunc"></a><h3>GUnixFDSourceFunc ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> (*GUnixFDSourceFunc) (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> fd</code></em>,
<em class="parameter"><code><a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="type">GIOCondition</span></a> condition</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);</pre>
<p>
The type of functions to be called when a UNIX fd watch source
triggers.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>fd</code></em> :</span></p></td>
<td>the fd that triggered the event</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>condition</code></em> :</span></p></td>
<td>the IO conditions reported on <em class="parameter"><code>fd</code></em>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
<td>user data passed to <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#g-unix-fd-add" title="g_unix_fd_add ()"><code class="function">g_unix_fd_add()</code></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> if the source should be removed</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-unix-fd-add"></a><h3>g_unix_fd_add ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="returnvalue">guint</span></a> g_unix_fd_add (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> fd</code></em>,
<em class="parameter"><code><a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="type">GIOCondition</span></a> condition</code></em>,
<em class="parameter"><code><a class="link" href="glib-UNIX-specific-utilities-and-integration.html#GUnixFDSourceFunc" title="GUnixFDSourceFunc ()"><span class="type">GUnixFDSourceFunc</span></a> function</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);</pre>
<p>
Sets a function to be called when the IO condition, as specified by
<em class="parameter"><code>condition</code></em> becomes true for <em class="parameter"><code>fd</code></em>.
</p>
<p>
<em class="parameter"><code>function</code></em> will be called when the specified IO condition becomes
<a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a>. The function is expected to clear whatever event caused the
IO condition to become true and return <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> in order to be notified
when it happens again. If <em class="parameter"><code>function</code></em> returns <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> then the watch
will be cancelled.
</p>
<p>
The return value of this function can be passed to <a class="link" href="glib-The-Main-Event-Loop.html#g-source-remove" title="g_source_remove ()"><code class="function">g_source_remove()</code></a>
to cancel the watch at any time that it exists.
</p>
<p>
The source will never close the fd -- you must do it yourself.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>fd</code></em> :</span></p></td>
<td>a file descriptor</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>condition</code></em> :</span></p></td>
<td>IO conditions to watch for on <em class="parameter"><code>fd</code></em>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>function</code></em> :</span></p></td>
<td>a <span class="type">GPollFDFunc</span>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
<td>data to pass to <em class="parameter"><code>function</code></em>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the ID (greater than 0) of the event source</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.36</p>
</div>
<hr>
<div class="refsect2">
<a name="g-unix-fd-add-full"></a><h3>g_unix_fd_add_full ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="returnvalue">guint</span></a> g_unix_fd_add_full (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> priority</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> fd</code></em>,
<em class="parameter"><code><a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="type">GIOCondition</span></a> condition</code></em>,
<em class="parameter"><code><a class="link" href="glib-UNIX-specific-utilities-and-integration.html#GUnixFDSourceFunc" title="GUnixFDSourceFunc ()"><span class="type">GUnixFDSourceFunc</span></a> function</code></em>,
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>,
<em class="parameter"><code><a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="type">GDestroyNotify</span></a> notify</code></em>);</pre>
<p>
Sets a function to be called when the IO condition, as specified by
<em class="parameter"><code>condition</code></em> becomes true for <em class="parameter"><code>fd</code></em>.
</p>
<p>
This is the same as <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#g-unix-fd-add" title="g_unix_fd_add ()"><code class="function">g_unix_fd_add()</code></a>, except that it allows you to
specify a non-default priority and a provide a <a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="type">GDestroyNotify</span></a> for
<em class="parameter"><code>user_data</code></em>.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>priority</code></em> :</span></p></td>
<td>the priority of the source</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>fd</code></em> :</span></p></td>
<td>a file descriptor</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>condition</code></em> :</span></p></td>
<td>IO conditions to watch for on <em class="parameter"><code>fd</code></em>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>function</code></em> :</span></p></td>
<td>a <a class="link" href="glib-UNIX-specific-utilities-and-integration.html#GUnixFDSourceFunc" title="GUnixFDSourceFunc ()"><span class="type">GUnixFDSourceFunc</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
<td>data to pass to <em class="parameter"><code>function</code></em>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>notify</code></em> :</span></p></td>
<td>function to call when the idle is removed, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the ID (greater than 0) of the event source</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.36</p>
</div>
<hr>
<div class="refsect2">
<a name="g-unix-fd-source-new"></a><h3>g_unix_fd_source_new ()</h3>
<pre class="programlisting"><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="returnvalue">GSource</span></a> * g_unix_fd_source_new (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> fd</code></em>,
<em class="parameter"><code><a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="type">GIOCondition</span></a> condition</code></em>);</pre>
<p>
Creates a <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> to watch for a particular IO condition on a file
descriptor.
</p>
<p>
The source will never close the fd -- you must do it yourself.
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>fd</code></em> :</span></p></td>
<td>a file descriptor</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>condition</code></em> :</span></p></td>
<td>IO conditions to watch for on <em class="parameter"><code>fd</code></em>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the newly created <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a>
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.36</p>
</div>
</div>
</div>
<div class="footer">
<hr>
Generated by GTK-Doc V1.19</div>
</body>
</html>
|