D-Bus: dbus-sysdeps.c Source File

D-Bus 1.14.10

dbus-sysdeps.c
1/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2/* dbus-sysdeps.c Wrappers around system/libc features shared between UNIX and Windows (internal to D-Bus implementation)
3 *
4 * Copyright (C) 2002, 2003, 2006 Red Hat, Inc.
5 * Copyright (C) 2003 CodeFactory AB
6 *
7 * Licensed under the Academic Free License version 2.1
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 *
23 */
24
25#include <config.h>
26#include "dbus-internals.h"
27#include "dbus-sysdeps.h"
28#include "dbus-threads.h"
29#include "dbus-protocol.h"
30#include "dbus-string.h"
31#include "dbus-list.h"
32#include "dbus-misc.h"
33
34/* NOTE: If you include any unix/windows-specific headers here, you are probably doing something
35 * wrong and should be putting some code in dbus-sysdeps-unix.c or dbus-sysdeps-win.c.
36 *
37 * These are the standard ANSI C headers...
38 */
39#if HAVE_LOCALE_H
40#include <locale.h>
41#endif
42#include <stdlib.h>
43#include <string.h>
44#include <stdio.h>
45
46#ifdef HAVE_ERRNO_H
47#include <errno.h>
48#endif
49
50#ifdef DBUS_WIN
51 #include <stdlib.h>
52#elif (defined __APPLE__)
53# include <crt_externs.h>
54# define environ (*_NSGetEnviron())
55#elif HAVE_DECL_ENVIRON && defined(HAVE_UNISTD_H)
56# include <unistd.h>
57#else
58extern char **environ;
59#endif
60
61#ifdef DBUS_WIN
62#include "dbus-sockets-win.h"
63#else
64#include <arpa/inet.h>
65#include <netinet/in.h>
66#include <sys/socket.h>
67#endif
68
86void
87_dbus_abort (void)
88{
89 const char *s;
90
91 _dbus_print_backtrace ();
92
93 s = _dbus_getenv ("DBUS_BLOCK_ON_ABORT");
94 if (s && *s)
95 {
96 /* don't use _dbus_warn here since it can _dbus_abort() */
97 fprintf (stderr, " Process %lu sleeping for gdb attach\n", _dbus_pid_for_log ());
98 _dbus_sleep_milliseconds (1000 * 180);
99 }
100
101 abort ();
102 _dbus_exit (1); /* in case someone manages to ignore SIGABRT ? */
103}
104
123dbus_bool_t
124dbus_setenv (const char *varname,
125 const char *value)
126{
127 _dbus_assert (varname != NULL);
128
129 if (value == NULL)
130 {
131#ifdef HAVE_UNSETENV
132 unsetenv (varname);
133 return TRUE;
134#else
135 char *putenv_value;
136 size_t len;
137
138 len = strlen (varname);
139
140 /* Use system malloc to avoid memleaks that dbus_malloc
141 * will get upset about.
142 */
143
144 putenv_value = malloc (len + 2);
145 if (putenv_value == NULL)
146 return FALSE;
147
148 strcpy (putenv_value, varname);
149#if defined(DBUS_WIN)
150 strcat (putenv_value, "=");
151#endif
152
153 return (putenv (putenv_value) == 0);
154#endif
155 }
156 else
157 {
158#ifdef HAVE_SETENV
159 return (setenv (varname, value, TRUE) == 0);
160#else
161 char *putenv_value;
162 size_t len;
163 size_t varname_len;
164 size_t value_len;
165
166 varname_len = strlen (varname);
167 value_len = strlen (value);
168
169 len = varname_len + value_len + 1 /* '=' */ ;
170
171 /* Use system malloc to avoid memleaks that dbus_malloc
172 * will get upset about.
173 */
174
175 putenv_value = malloc (len + 1);
176 if (putenv_value == NULL)
177 return FALSE;
178
179 strcpy (putenv_value, varname);
180 strcpy (putenv_value + varname_len, "=");
181 strcpy (putenv_value + varname_len + 1, value);
182
183 return (putenv (putenv_value) == 0);
184#endif
185 }
186}
187
194const char*
195_dbus_getenv (const char *varname)
196{
197 /* Don't respect any environment variables if the current process is
198 * setuid. This is the equivalent of glibc's __secure_getenv().
199 */
200 if (_dbus_check_setuid ())
201 return NULL;
202 return getenv (varname);
203}
204
210dbus_bool_t
211_dbus_clearenv (void)
212{
213 dbus_bool_t rc = TRUE;
214
215#ifdef HAVE_CLEARENV
216 if (clearenv () != 0)
217 rc = FALSE;
218#else
219
220 if (environ != NULL)
221 environ[0] = NULL;
222#endif
223
224 return rc;
225}
226
235dbus_bool_t
236_dbus_split_paths_and_append (DBusString *dirs,
237 const char *suffix,
238 DBusList **dir_list)
239{
240 int start;
241 int i;
242 int len;
243 char *cpath;
244 DBusString file_suffix;
245
246 start = 0;
247 i = 0;
248
249 _dbus_string_init_const (&file_suffix, suffix);
250
251 len = _dbus_string_get_length (dirs);
252
253 while (_dbus_string_find (dirs, start, _DBUS_PATH_SEPARATOR, &i))
254 {
255 DBusString path;
256
257 if (!_dbus_string_init (&path))
258 goto oom;
259
260 if (!_dbus_string_copy_len (dirs,
261 start,
262 i - start,
263 &path,
264 0))
265 {
266 _dbus_string_free (&path);
267 goto oom;
268 }
269
270 _dbus_string_chop_white (&path);
271
272 /* check for an empty path */
273 if (_dbus_string_get_length (&path) == 0)
274 goto next;
275
276 if (!_dbus_concat_dir_and_file (&path,
277 &file_suffix))
278 {
279 _dbus_string_free (&path);
280 goto oom;
281 }
282
283 if (!_dbus_string_copy_data(&path, &cpath))
284 {
285 _dbus_string_free (&path);
286 goto oom;
287 }
288
289 if (!_dbus_list_append (dir_list, cpath))
290 {
291 _dbus_string_free (&path);
292 dbus_free (cpath);
293 goto oom;
294 }
295
296 next:
297 _dbus_string_free (&path);
298 start = i + 1;
299 }
300
301 if (start != len)
302 {
303 DBusString path;
304
305 if (!_dbus_string_init (&path))
306 goto oom;
307
308 if (!_dbus_string_copy_len (dirs,
309 start,
310 len - start,
311 &path,
312 0))
313 {
314 _dbus_string_free (&path);
315 goto oom;
316 }
317
318 if (!_dbus_concat_dir_and_file (&path,
319 &file_suffix))
320 {
321 _dbus_string_free (&path);
322 goto oom;
323 }
324
325 if (!_dbus_string_copy_data(&path, &cpath))
326 {
327 _dbus_string_free (&path);
328 goto oom;
329 }
330
331 if (!_dbus_list_append (dir_list, cpath))
332 {
333 _dbus_string_free (&path);
334 dbus_free (cpath);
335 goto oom;
336 }
337
338 _dbus_string_free (&path);
339 }
340
341 return TRUE;
342
343 oom:
344 _dbus_list_clear_full (dir_list, dbus_free);
345 return FALSE;
346}
347
362dbus_bool_t
363_dbus_string_append_int (DBusString *str,
364 long value)
365{
366 /* this calculation is from comp.lang.c faq */
367#define MAX_LONG_LEN ((sizeof (long) * 8 + 2) / 3 + 1) /* +1 for '-' */
368 int orig_len;
369 int i;
370 char *buf;
371
372 orig_len = _dbus_string_get_length (str);
373
374 if (!_dbus_string_lengthen (str, MAX_LONG_LEN))
375 return FALSE;
376
377 buf = _dbus_string_get_data_len (str, orig_len, MAX_LONG_LEN);
378
379 snprintf (buf, MAX_LONG_LEN, "%ld", value);
380
381 i = 0;
382 while (*buf)
383 {
384 ++buf;
385 ++i;
386 }
387
388 _dbus_string_shorten (str, MAX_LONG_LEN - i);
389
390 return TRUE;
391}
392
400dbus_bool_t
401_dbus_string_append_uint (DBusString *str,
402 unsigned long value)
403{
404 /* this is wrong, but definitely on the high side. */
405#define MAX_ULONG_LEN (MAX_LONG_LEN * 2)
406 int orig_len;
407 int i;
408 char *buf;
409
410 orig_len = _dbus_string_get_length (str);
411
412 if (!_dbus_string_lengthen (str, MAX_ULONG_LEN))
413 return FALSE;
414
415 buf = _dbus_string_get_data_len (str, orig_len, MAX_ULONG_LEN);
416
417 snprintf (buf, MAX_ULONG_LEN, "%lu", value);
418
419 i = 0;
420 while (*buf)
421 {
422 ++buf;
423 ++i;
424 }
425
426 _dbus_string_shorten (str, MAX_ULONG_LEN - i);
427
428 return TRUE;
429}
430
443dbus_bool_t
444_dbus_string_parse_int (const DBusString *str,
445 int start,
446 long *value_return,
447 int *end_return)
448{
449 long v;
450 const char *p;
451 char *end;
452
453 p = _dbus_string_get_const_data_len (str, start,
454 _dbus_string_get_length (str) - start);
455
456 end = NULL;
457 _dbus_set_errno_to_zero ();
458 v = strtol (p, &end, 0);
459 if (end == NULL || end == p || errno != 0)
460 return FALSE;
461
462 if (value_return)
463 *value_return = v;
464 if (end_return)
465 *end_return = start + (end - p);
466
467 return TRUE;
468}
469
482dbus_bool_t
483_dbus_string_parse_uint (const DBusString *str,
484 int start,
485 unsigned long *value_return,
486 int *end_return)
487{
488 unsigned long v;
489 const char *p;
490 char *end;
491
492 p = _dbus_string_get_const_data_len (str, start,
493 _dbus_string_get_length (str) - start);
494
495 end = NULL;
496 _dbus_set_errno_to_zero ();
497 v = strtoul (p, &end, 0);
498 if (end == NULL || end == p || errno != 0)
499 return FALSE;
500
501 if (value_return)
502 *value_return = v;
503 if (end_return)
504 *end_return = start + (end - p);
505
506 return TRUE;
507}
508
/* DBusString group */
510
524dbus_bool_t
525_dbus_generate_random_bytes_buffer (char *buffer,
526 int n_bytes,
527 DBusError *error)
528{
529 DBusString str;
530
531 if (!_dbus_string_init (&str))
532 {
533 _DBUS_SET_OOM (error);
534 return FALSE;
535 }
536
537 if (!_dbus_generate_random_bytes (&str, n_bytes, error))
538 {
539 _dbus_string_free (&str);
540 return FALSE;
541 }
542
543 _dbus_string_copy_to_buffer (&str, buffer, n_bytes);
544
545 _dbus_string_free (&str);
546 return TRUE;
547}
548
558dbus_bool_t
559_dbus_generate_random_ascii (DBusString *str,
560 int n_bytes,
561 DBusError *error)
562{
563 static const char letters[] =
564 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
565 int i;
566 int len;
567
568 if (!_dbus_generate_random_bytes (str, n_bytes, error))
569 return FALSE;
570
571 len = _dbus_string_get_length (str);
572 i = len - n_bytes;
573 while (i < len)
574 {
575 _dbus_string_set_byte (str, i,
576 letters[_dbus_string_get_byte (str, i) %
577 (sizeof (letters) - 1)]);
578
579 ++i;
580 }
581
582 _dbus_assert (_dbus_string_validate_ascii (str, len - n_bytes,
583 n_bytes));
584
585 return TRUE;
586}
587
598const char*
599_dbus_error_from_errno (int error_number)
600{
601 switch (error_number)
602 {
603 case 0:
604 return DBUS_ERROR_FAILED;
605
606#ifdef EPROTONOSUPPORT
607 case EPROTONOSUPPORT:
608 return DBUS_ERROR_NOT_SUPPORTED;
609#elif defined(WSAEPROTONOSUPPORT)
610 case WSAEPROTONOSUPPORT:
611 return DBUS_ERROR_NOT_SUPPORTED;
612#endif
613#ifdef EAFNOSUPPORT
614 case EAFNOSUPPORT:
615 return DBUS_ERROR_NOT_SUPPORTED;
616#elif defined(WSAEAFNOSUPPORT)
617 case WSAEAFNOSUPPORT:
618 return DBUS_ERROR_NOT_SUPPORTED;
619#endif
620#ifdef ENFILE
621 case ENFILE:
622 return DBUS_ERROR_LIMITS_EXCEEDED; /* kernel out of memory */
623#endif
624#ifdef EMFILE
625 case EMFILE:
626 return DBUS_ERROR_LIMITS_EXCEEDED;
627#endif
628#ifdef EACCES
629 case EACCES:
630 return DBUS_ERROR_ACCESS_DENIED;
631#endif
632#ifdef EPERM
633 case EPERM:
634 return DBUS_ERROR_ACCESS_DENIED;
635#endif
636#ifdef ENOBUFS
637 case ENOBUFS:
638 return DBUS_ERROR_NO_MEMORY;
639#endif
640#ifdef ENOMEM
641 case ENOMEM:
642 return DBUS_ERROR_NO_MEMORY;
643#endif
644#ifdef ECONNREFUSED
645 case ECONNREFUSED:
646 return DBUS_ERROR_NO_SERVER;
647#elif defined(WSAECONNREFUSED)
648 case WSAECONNREFUSED:
649 return DBUS_ERROR_NO_SERVER;
650#endif
651#ifdef ETIMEDOUT
652 case ETIMEDOUT:
653 return DBUS_ERROR_TIMEOUT;
654#elif defined(WSAETIMEDOUT)
655 case WSAETIMEDOUT:
656 return DBUS_ERROR_TIMEOUT;
657#endif
658#ifdef ENETUNREACH
659 case ENETUNREACH:
660 return DBUS_ERROR_NO_NETWORK;
661#elif defined(WSAENETUNREACH)
662 case WSAENETUNREACH:
663 return DBUS_ERROR_NO_NETWORK;
664#endif
665#ifdef EADDRINUSE
666 case EADDRINUSE:
667 return DBUS_ERROR_ADDRESS_IN_USE;
668#elif defined(WSAEADDRINUSE)
669 case WSAEADDRINUSE:
670 return DBUS_ERROR_ADDRESS_IN_USE;
671#endif
672#ifdef EEXIST
673 case EEXIST:
674 return DBUS_ERROR_FILE_EXISTS;
675#endif
676#ifdef ENOENT
677 case ENOENT:
678 return DBUS_ERROR_FILE_NOT_FOUND;
679#endif
680 default:
681 return DBUS_ERROR_FAILED;
682 }
683}
684
690const char*
691_dbus_error_from_system_errno (void)
692{
693 return _dbus_error_from_errno (errno);
694}
695
699void
700_dbus_set_errno_to_zero (void)
701{
702#ifdef DBUS_WINCE
703 SetLastError (0);
704#else
705 errno = 0;
706#endif
707}
708
713dbus_bool_t
714_dbus_get_is_errno_enomem (int e)
715{
716 return e == ENOMEM;
717}
718
723dbus_bool_t
724_dbus_get_is_errno_eintr (int e)
725{
726 return e == EINTR;
727}
728
733dbus_bool_t
734_dbus_get_is_errno_epipe (int e)
735{
736 return e == EPIPE;
737}
738
743dbus_bool_t
744_dbus_get_is_errno_etoomanyrefs (int e)
745{
746#ifdef ETOOMANYREFS
747 return e == ETOOMANYREFS;
748#else
749 return FALSE;
750#endif
751}
752
757const char*
758_dbus_strerror_from_errno (void)
759{
760 return _dbus_strerror (errno);
761}
762
769void
770_dbus_log (DBusSystemLogSeverity severity,
771 const char *msg,
772 ...)
773{
774 va_list args;
775
776 va_start (args, msg);
777
778 _dbus_logv (severity, msg, args);
779
780 va_end (args);
781}
782
783/*
784 * Try to convert the IPv4 or IPv6 address pointed to by
785 * sockaddr_pointer into a string.
786 *
787 * @param sockaddr_pointer A struct sockaddr_in or struct sockaddr_in6
788 * @param len The length of the struct pointed to by sockaddr_pointer
789 * @param string An array to write the address into
790 * @param string_len Length of string (should usually be at least INET6_ADDRSTRLEN)
791 * @param family_name Used to return "ipv4" or "ipv6", or NULL to ignore
792 * @param port Used to return the port number, or NULL to ignore
793 * @returns #FALSE with errno set if the address family was not understood
794 */
795dbus_bool_t
796_dbus_inet_sockaddr_to_string (const void *sockaddr_pointer,
797 size_t len,
798 char *string,
799 size_t string_len,
800 const char **family_name,
801 dbus_uint16_t *port,
802 DBusError *error)
803{
804 union
805 {
806 struct sockaddr sa;
807 struct sockaddr_storage storage;
808 struct sockaddr_in ipv4;
809 struct sockaddr_in6 ipv6;
810 } addr;
811 int saved_errno;
812
813 if (len > sizeof (addr))
814 return FALSE;
815
816 _DBUS_ZERO (addr);
817 memcpy (&addr, sockaddr_pointer, len);
818
819 switch (addr.sa.sa_family)
820 {
821 case AF_INET:
822 if (inet_ntop (AF_INET, &addr.ipv4.sin_addr, string, string_len) != NULL)
823 {
824 if (family_name != NULL)
825 *family_name = "ipv4";
826
827 if (port != NULL)
828 *port = ntohs (addr.ipv4.sin_port);
829
830 return TRUE;
831 }
832 else
833 {
834 saved_errno = _dbus_get_low_level_socket_errno ();
835 dbus_set_error (error, _dbus_error_from_errno (saved_errno),
836 "Failed to get identity of IPv4 socket: %s",
837 _dbus_strerror (saved_errno));
838 }
839
840 return FALSE;
841
842#ifdef AF_INET6
843 case AF_INET6:
844 if (inet_ntop (AF_INET6, &addr.ipv6.sin6_addr, string, string_len) != NULL)
845 {
846 if (family_name != NULL)
847 *family_name = "ipv6";
848
849 if (port != NULL)
850 *port = ntohs (addr.ipv6.sin6_port);
851
852 return TRUE;
853 }
854 else
855 {
856 saved_errno = _dbus_get_low_level_socket_errno ();
857 dbus_set_error (error, _dbus_error_from_errno (saved_errno),
858 "Failed to get identity of IPv6 socket: %s",
859 _dbus_strerror (saved_errno));
860 }
861
862 return FALSE;
863#endif
864
865 default:
866 dbus_set_error (error, DBUS_ERROR_FAILED,
867 "Failed to get identity of socket: unknown family");
868 return FALSE;
869 }
870}
871
872/*
873 * Format an error appropriate for saved_errno for the IPv4 or IPv6
874 * address pointed to by sockaddr_pointer of length sockaddr_len.
875 *
876 * @param error The error to set
877 * @param sockaddr_pointer A struct sockaddr_in or struct sockaddr_in6
878 * @param len The length of the struct pointed to by sockaddr_pointer
879 * @param description A prefix like "Failed to listen on socket"
880 * @param saved_errno The OS-level error number to use
881 */
882void
883_dbus_set_error_with_inet_sockaddr (DBusError *error,
884 const void *sockaddr_pointer,
885 size_t len,
886 const char *description,
887 int saved_errno)
888{
889 char string[INET6_ADDRSTRLEN];
890 dbus_uint16_t port;
891 const struct sockaddr *addr = sockaddr_pointer;
892
893 if (_dbus_inet_sockaddr_to_string (sockaddr_pointer, len,
894 string, sizeof (string), NULL, &port,
895 NULL))
896 {
897 dbus_set_error (error, _dbus_error_from_errno (saved_errno),
898 "%s \"%s\" port %u: %s",
899 description, string, port, _dbus_strerror (saved_errno));
900 }
901 else
902 {
903 dbus_set_error (error, _dbus_error_from_errno (saved_errno),
904 "%s <address of unknown family %d>: %s",
905 description, addr->sa_family,
906 _dbus_strerror (saved_errno));
907 }
908}
909
910void
911_dbus_combine_tcp_errors (DBusList **sources,
912 const char *summary,
913 const char *host,
914 const char *port,
915 DBusError *dest)
916{
917 DBusString message = _DBUS_STRING_INIT_INVALID;
918
919 if (_dbus_list_length_is_one (sources))
920 {
921 /* If there was exactly one error, just use it */
922 dbus_move_error (_dbus_list_get_first (sources), dest);
923 }
924 else
925 {
926 DBusList *iter;
927 const char *name = NULL;
928
929 /* If there was more than one error, concatenate all the
930 * errors' diagnostic messages, and use their common error
931 * name, or DBUS_ERROR_FAILED if more than one name is
932 * represented */
933 if (!_dbus_string_init (&message))
934 {
935 _DBUS_SET_OOM (dest);
936 goto out;
937 }
938
939 for (iter = _dbus_list_get_first_link (sources);
940 iter != NULL;
941 iter = _dbus_list_get_next_link (sources, iter))
942 {
943 DBusError *error = iter->data;
944
945 if (name == NULL)
946 {
947 /* no error names known yet, try to use this one */
948 name = error->name;
949 }
950 else if (strcmp (name, error->name) != 0)
951 {
952 /* errors of two different names exist, reconcile by
953 * using FAILED */
954 name = DBUS_ERROR_FAILED;
955 }
956
957 if ((_dbus_string_get_length (&message) > 0 &&
958 !_dbus_string_append (&message, "; ")) ||
959 !_dbus_string_append (&message, error->message))
960 {
961 _DBUS_SET_OOM (dest);
962 goto out;
963 }
964 }
965
966 if (name == NULL)
967 name = DBUS_ERROR_FAILED;
968
969 dbus_set_error (dest, name, "%s to \"%s\":%s (%s)",
970 summary, host ? host : "*", port,
971 _dbus_string_get_const_data (&message));
972 }
973
974out:
975 _dbus_string_free (&message);
976}
977
980/* tests in dbus-sysdeps-util.c */
dbus_move_error
void dbus_move_error(DBusError *src, DBusError *dest)
Moves an error src into dest, freeing src and overwriting dest.
Definition dbus-errors.c:279
dbus_set_error
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
Definition dbus-errors.c:354
_dbus_get_is_errno_epipe
dbus_bool_t _dbus_get_is_errno_epipe(int e)
See if errno is EPIPE.
Definition dbus-sysdeps.c:734
_dbus_get_is_errno_etoomanyrefs
dbus_bool_t _dbus_get_is_errno_etoomanyrefs(int e)
See if errno is ETOOMANYREFS.
Definition dbus-sysdeps.c:744
_dbus_assert
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
Definition dbus-internals.h:153
_dbus_log
void _dbus_log(DBusSystemLogSeverity severity, const char *msg,...)
Log a message to the system log file (e.g.
Definition dbus-sysdeps.c:770
_dbus_error_from_errno
const char * _dbus_error_from_errno(int error_number)
Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.
Definition dbus-sysdeps.c:599
_dbus_generate_random_ascii
dbus_bool_t _dbus_generate_random_ascii(DBusString *str, int n_bytes, DBusError *error)
Generates the given number of random bytes, where the bytes are chosen from the alphanumeric ASCII su...
Definition dbus-sysdeps.c:559
_dbus_error_from_system_errno
const char * _dbus_error_from_system_errno(void)
Converts the current system errno value into a DBusError name.
Definition dbus-sysdeps.c:691
_dbus_strerror_from_errno
const char * _dbus_strerror_from_errno(void)
Get error message from errno.
Definition dbus-sysdeps.c:758
_dbus_get_is_errno_eintr
dbus_bool_t _dbus_get_is_errno_eintr(int e)
See if errno is EINTR.
Definition dbus-sysdeps.c:724
_DBUS_ZERO
#define _DBUS_ZERO(object)
Sets all bits in an object to zero.
Definition dbus-internals.h:194
_dbus_set_errno_to_zero
void _dbus_set_errno_to_zero(void)
Assign 0 to the global errno variable.
Definition dbus-sysdeps.c:700
_dbus_get_is_errno_enomem
dbus_bool_t _dbus_get_is_errno_enomem(int e)
See if errno is ENOMEM.
Definition dbus-sysdeps.c:714
_dbus_generate_random_bytes_buffer
dbus_bool_t _dbus_generate_random_bytes_buffer(char *buffer, int n_bytes, DBusError *error)
Fills n_bytes of the given buffer with random bytes.
Definition dbus-sysdeps.c:525
_dbus_list_get_first_link
DBusList * _dbus_list_get_first_link(DBusList **list)
Gets the first link in the list.
Definition dbus-list.c:595
_dbus_list_length_is_one
dbus_bool_t _dbus_list_length_is_one(DBusList **list)
Check whether length is exactly one.
Definition dbus-list.c:811
_dbus_list_clear_full
void _dbus_list_clear_full(DBusList **list, DBusFreeFunction function)
Free every link and every element in the list.
Definition dbus-list.c:568
_dbus_list_get_first
void * _dbus_list_get_first(DBusList **list)
Gets the first data in the list.
Definition dbus-list.c:640
_dbus_list_append
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
Definition dbus-list.c:271
_dbus_list_get_next_link
#define _dbus_list_get_next_link(list, link)
Gets the next link in the list, or NULL if there are no more links.
Definition dbus-list.h:119
NULL
#define NULL
A null pointer, defined appropriately for C or C++.
Definition dbus-macros.h:49
TRUE
#define TRUE
Expands to "1".
Definition dbus-macros.h:39
FALSE
#define FALSE
Expands to "0".
Definition dbus-macros.h:42
dbus_free
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition dbus-memory.c:692
dbus_setenv
dbus_bool_t dbus_setenv(const char *varname, const char *value)
Wrapper for setenv().
Definition dbus-sysdeps.c:124
DBUS_ERROR_TIMEOUT
#define DBUS_ERROR_TIMEOUT
Certain timeout errors, possibly ETIMEDOUT on a socket.
Definition dbus-protocol.h:387
DBUS_ERROR_NOT_SUPPORTED
#define DBUS_ERROR_NOT_SUPPORTED
Requested operation isn't supported (like ENOSYS on UNIX).
Definition dbus-protocol.h:373
DBUS_ERROR_ADDRESS_IN_USE
#define DBUS_ERROR_ADDRESS_IN_USE
Can't bind a socket since its address is in use (i.e.
Definition dbus-protocol.h:391
DBUS_ERROR_ACCESS_DENIED
#define DBUS_ERROR_ACCESS_DENIED
Security restrictions don't allow doing what you're trying to do.
Definition dbus-protocol.h:377
DBUS_ERROR_NO_SERVER
#define DBUS_ERROR_NO_SERVER
Unable to connect to server (probably caused by ECONNREFUSED on a socket).
Definition dbus-protocol.h:381
DBUS_ERROR_FILE_EXISTS
#define DBUS_ERROR_FILE_EXISTS
Existing file and the operation you're using does not silently overwrite.
Definition dbus-protocol.h:399
DBUS_ERROR_LIMITS_EXCEEDED
#define DBUS_ERROR_LIMITS_EXCEEDED
Some limited resource is exhausted.
Definition dbus-protocol.h:375
DBUS_ERROR_NO_NETWORK
#define DBUS_ERROR_NO_NETWORK
No network access (probably ENETUNREACH on a socket).
Definition dbus-protocol.h:389
DBUS_ERROR_FAILED
#define DBUS_ERROR_FAILED
A generic error; "something went wrong" - see the error message for more.
Definition dbus-protocol.h:359
DBUS_ERROR_NO_MEMORY
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
Definition dbus-protocol.h:361
DBUS_ERROR_FILE_NOT_FOUND
#define DBUS_ERROR_FILE_NOT_FOUND
Missing file.
Definition dbus-protocol.h:397
_dbus_string_append
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
Definition dbus-string.c:966
_dbus_string_init
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition dbus-string.c:182
_dbus_string_init_const
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition dbus-string.c:197
_dbus_string_append_int
dbus_bool_t _dbus_string_append_int(DBusString *str, long value)
Appends an integer to a DBusString.
Definition dbus-sysdeps.c:363
_dbus_string_find
dbus_bool_t _dbus_string_find(const DBusString *str, int start, const char *substr, int *found)
Finds the given substring in the string, returning TRUE and filling in the byte index where the subst...
Definition dbus-string.c:1664
_dbus_string_get_data_len
char * _dbus_string_get_data_len(DBusString *str, int start, int len)
Gets a sub-portion of the raw character buffer from the string.
Definition dbus-string.c:521
_dbus_string_free
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as _DBUS_STRING_IN...
Definition dbus-string.c:278
_dbus_string_shorten
void _dbus_string_shorten(DBusString *str, int length_to_remove)
Makes a string shorter by the given number of bytes.
Definition dbus-string.c:811
_dbus_string_copy_data
dbus_bool_t _dbus_string_copy_data(const DBusString *str, char **data_return)
Copies the data from the string into a char*.
Definition dbus-string.c:703
_dbus_string_parse_uint
dbus_bool_t _dbus_string_parse_uint(const DBusString *str, int start, unsigned long *value_return, int *end_return)
Parses an unsigned integer contained in a DBusString.
Definition dbus-sysdeps.c:483
_dbus_string_lengthen
dbus_bool_t _dbus_string_lengthen(DBusString *str, int additional_length)
Makes a string longer by the given number of bytes.
Definition dbus-string.c:791
_dbus_string_parse_int
dbus_bool_t _dbus_string_parse_int(const DBusString *str, int start, long *value_return, int *end_return)
Parses an integer contained in a DBusString.
Definition dbus-sysdeps.c:444
_dbus_string_validate_ascii
dbus_bool_t _dbus_string_validate_ascii(const DBusString *str, int start, int len)
Checks that the given range of the string is valid ASCII with no nul bytes.
Definition dbus-string.c:2536
_dbus_string_append_uint
dbus_bool_t _dbus_string_append_uint(DBusString *str, unsigned long value)
Appends an unsigned integer to a DBusString.
Definition dbus-sysdeps.c:401
_dbus_string_chop_white
void _dbus_string_chop_white(DBusString *str)
Deletes leading and trailing whitespace.
Definition dbus-string.c:2049
_dbus_string_copy_len
dbus_bool_t _dbus_string_copy_len(const DBusString *source, int start, int len, DBusString *dest, int insert_at)
Like _dbus_string_copy(), but can copy a segment from the middle of the source string.
Definition dbus-string.c:1435
_dbus_string_copy_to_buffer
void _dbus_string_copy_to_buffer(const DBusString *str, char *buffer, int avail_len)
Copies the contents of a DBusString into a different buffer.
Definition dbus-string.c:728
_dbus_logv
void _dbus_logv(DBusSystemLogSeverity severity, const char *msg, va_list args)
Log a message to the system log file (e.g.
Definition dbus-sysdeps-unix.c:5023
_dbus_pid_for_log
unsigned long _dbus_pid_for_log(void)
The only reason this is separate from _dbus_getpid() is to allow it on Windows for logging but not fo...
Definition dbus-sysdeps-unix.c:3008
_dbus_clearenv
dbus_bool_t _dbus_clearenv(void)
Wrapper for clearenv().
Definition dbus-sysdeps.c:211
_dbus_exit
void _dbus_exit(int code)
Exit the process, returning the given value.
Definition dbus-sysdeps-unix.c:3475
_dbus_getenv
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
Definition dbus-sysdeps.c:195
_dbus_check_setuid
dbus_bool_t _dbus_check_setuid(void)
NOTE: If you modify this function, please also consider making the corresponding change in GLib.
Definition dbus-sysdeps-unix.c:4817
_dbus_sleep_milliseconds
void _dbus_sleep_milliseconds(int milliseconds)
Sleeps the given number of milliseconds.
Definition dbus-sysdeps-unix.c:3376
_dbus_generate_random_bytes
dbus_bool_t _dbus_generate_random_bytes(DBusString *str, int n_bytes, DBusError *error)
Generates the given number of securely random bytes, using the best mechanism we can come up with.
Definition dbus-sysdeps-unix.c:3406
_dbus_abort
void _dbus_abort(void)
Aborts the program with SIGABRT (dumping core).
Definition dbus-sysdeps.c:87
_dbus_concat_dir_and_file
dbus_bool_t _dbus_concat_dir_and_file(DBusString *dir, const DBusString *next_component)
Appends the given filename to the given directory.
Definition dbus-sysdeps-unix.c:3331
_dbus_split_paths_and_append
dbus_bool_t _dbus_split_paths_and_append(DBusString *dirs, const char *suffix, DBusList **dir_list)
Split paths into a list of char strings.
Definition dbus-sysdeps.c:236
_dbus_print_backtrace
void _dbus_print_backtrace(void)
On GNU libc systems, print a crude backtrace to stderr.
Definition dbus-sysdeps-unix.c:3676
DBusError
Object representing an exception.
Definition dbus-errors.h:49
DBusError::name
const char * name
public error name field
Definition dbus-errors.h:50
DBusError::message
const char * message
public error message field
Definition dbus-errors.h:51
DBusList
A node in a linked list.
Definition dbus-list.h:35
DBusList::data
void * data
Data stored at this element.
Definition dbus-list.h:38
DBusString
Definition dbus-string.h:43