D-Bus  1.13.7
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
58 extern 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 
86 void
88 {
89  const char *s;
90 
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 
124 dbus_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 
194 const 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 
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 
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 
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 
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 
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;
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 
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;
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 
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 
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 
598 const 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:
609 #elif defined(WSAEPROTONOSUPPORT)
610  case WSAEPROTONOSUPPORT:
612 #endif
613 #ifdef EAFNOSUPPORT
614  case EAFNOSUPPORT:
616 #elif defined(WSAEAFNOSUPPORT)
617  case WSAEAFNOSUPPORT:
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:
627 #endif
628 #ifdef EACCES
629  case EACCES:
631 #endif
632 #ifdef EPERM
633  case EPERM:
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:
668 #elif defined(WSAEADDRINUSE)
669  case WSAEADDRINUSE:
671 #endif
672 #ifdef EEXIST
673  case EEXIST:
674  return DBUS_ERROR_FILE_EXISTS;
675 #endif
676 #ifdef ENOENT
677  case ENOENT:
679 #endif
680  default:
681  return DBUS_ERROR_FAILED;
682  }
683 }
684 
690 const char*
692 {
693  return _dbus_error_from_errno (errno);
694 }
695 
699 void
701 {
702 #ifdef DBUS_WINCE
703  SetLastError (0);
704 #else
705  errno = 0;
706 #endif
707 }
708 
715 {
716  return e == ENOMEM;
717 }
718 
725 {
726  return e == EINTR;
727 }
728 
735 {
736  return e == EPIPE;
737 }
738 
745 {
746 #ifdef ETOOMANYREFS
747  return e == ETOOMANYREFS;
748 #else
749  return FALSE;
750 #endif
751 }
752 
757 const char*
759 {
760  return _dbus_strerror (errno);
761 }
762 
769 void
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  */
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:
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  */
882 void
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 
910 void
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 
974 out:
975  _dbus_string_free (&message);
976 }
977 
980 /* tests in dbus-sysdeps-util.c */
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:952
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
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:714
#define DBUS_ERROR_FILE_NOT_FOUND
Missing file.
#define DBUS_ERROR_FILE_EXISTS
Existing file and the operation you&#39;re using does not silently overwrite.
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_bool_t _dbus_string_append_uint(DBusString *str, unsigned long value)
Appends an unsigned integer to a DBusString.
Definition: dbus-sysdeps.c:401
const char * message
public error message field
Definition: dbus-errors.h:51
#define NULL
A null pointer, defined appropriately for C or C++.
#define DBUS_ERROR_TIMEOUT
Certain timeout errors, possibly ETIMEDOUT on a socket.
void _dbus_abort(void)
Aborts the program with SIGABRT (dumping core).
Definition: dbus-sysdeps.c:87
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:777
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition: dbus-memory.c:703
dbus_bool_t _dbus_list_length_is_one(DBusList **list)
Check whether length is exactly one.
Definition: dbus-list.c:811
#define DBUS_ERROR_NOT_SUPPORTED
Requested operation isn&#39;t supported (like ENOSYS on UNIX).
dbus_bool_t _dbus_string_append_int(DBusString *str, long value)
Appends an integer to a DBusString.
Definition: dbus-sysdeps.c:363
void _dbus_string_chop_white(DBusString *str)
Deletes leading and trailing whitespace.
Definition: dbus-string.c:2006
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
void * data
Data stored at this element.
Definition: dbus-list.h:38
dbus_bool_t _dbus_check_setuid(void)
NOTE: If you modify this function, please also consider making the corresponding change in GLib...
void _dbus_list_clear_full(DBusList **list, DBusFreeFunction function)
Free every link and every element in the list.
Definition: dbus-list.c:568
dbus_bool_t _dbus_concat_dir_and_file(DBusString *dir, const DBusString *next_component)
Appends the given filename to the given directory.
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:507
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:175
void _dbus_string_shorten(DBusString *str, int length_to_remove)
Makes a string shorter by the given number of bytes.
Definition: dbus-string.c:797
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:1621
void * _dbus_list_get_first(DBusList **list)
Gets the first data in the list.
Definition: dbus-list.c:640
#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
dbus_bool_t _dbus_get_is_errno_etoomanyrefs(int e)
See if errno is ETOOMANYREFS.
Definition: dbus-sysdeps.c:744
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_bool_t _dbus_clearenv(void)
Wrapper for clearenv().
Definition: dbus-sysdeps.c:211
#define DBUS_ERROR_NO_SERVER
Unable to connect to server (probably caused by ECONNREFUSED on a socket).
dbus_bool_t _dbus_get_is_errno_epipe(int e)
See if errno is EPIPE.
Definition: dbus-sysdeps.c:734
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:689
dbus_bool_t dbus_setenv(const char *varname, const char *value)
Wrapper for setenv().
Definition: dbus-sysdeps.c:124
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.c:190
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_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
Definition: dbus-list.c:271
void _dbus_print_backtrace(void)
On GNU libc systems, print a crude backtrace to stderr.
dbus_bool_t _dbus_get_is_errno_eintr(int e)
See if errno is EINTR.
Definition: dbus-sysdeps.c:724
Object representing an exception.
Definition: dbus-errors.h:48
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
#define DBUS_ERROR_ADDRESS_IN_USE
Can&#39;t bind a socket since its address is in use (i.e.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
Definition: dbus-string.c:264
#define TRUE
Expands to "1".
#define DBUS_ERROR_FAILED
A generic error; "something went wrong" - see the error message for more.
void dbus_move_error(DBusError *src, DBusError *dest)
Moves an error src into dest, freeing src and overwriting dest.
Definition: dbus-errors.c:279
const char * name
public error name field
Definition: dbus-errors.h:50
void _dbus_exit(int code)
Exit the process, returning the given value.
const char * _dbus_strerror_from_errno(void)
Get error message from errno.
Definition: dbus-sysdeps.c:758
const char * _dbus_error_from_system_errno(void)
Converts the current system errno value into a DBusError name.
Definition: dbus-sysdeps.c:691
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...
A node in a linked list.
Definition: dbus-list.h:34
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
#define DBUS_ERROR_ACCESS_DENIED
Security restrictions don&#39;t allow doing what you&#39;re trying to do.
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...
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
void _dbus_logv(DBusSystemLogSeverity severity, const char *msg, va_list args)
Log a message to the system log file (e.g.
DBusList * _dbus_list_get_first_link(DBusList **list)
Gets the first link in the list.
Definition: dbus-list.c:595
#define FALSE
Expands to "0".
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_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:1392
void _dbus_sleep_milliseconds(int milliseconds)
Sleeps the given number of milliseconds.
#define _DBUS_ZERO(object)
Sets all bits in an object to zero.
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
Definition: dbus-sysdeps.c:195
#define DBUS_ERROR_NO_NETWORK
No network access (probably ENETUNREACH on a socket).
void _dbus_set_errno_to_zero(void)
Assign 0 to the global errno variable.
Definition: dbus-sysdeps.c:700
#define DBUS_ERROR_LIMITS_EXCEEDED
Some limited resource is exhausted.
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:2467
dbus_bool_t _dbus_get_is_errno_enomem(int e)
See if errno is ENOMEM.
Definition: dbus-sysdeps.c:714
void _dbus_log(DBusSystemLogSeverity severity, const char *msg,...)
Log a message to the system log file (e.g.
Definition: dbus-sysdeps.c:770