D-Bus  1.6.4
dbus-sysdeps.h
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-sysdeps.h Wrappers around system/libc features (internal to D-Bus implementation)
3  *
4  * Copyright (C) 2002, 2003 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 #ifndef DBUS_SYSDEPS_H
26 #define DBUS_SYSDEPS_H
27 
28 #include "config.h"
29 
30 #ifdef HAVE_STDINT_H
31 #include <stdint.h>
32 #endif
33 
34 #ifdef HAVE_INTTYPES_H
35 #include <inttypes.h>
36 #endif
37 
38 #include <dbus/dbus-errors.h>
39 #include <dbus/dbus-file.h>
40 #include <dbus/dbus-string.h>
41 
42 /* this is perhaps bogus, but strcmp() etc. are faster if we use the
43  * stuff straight out of string.h, so have this here for now.
44  */
45 #include <string.h>
46 #include <stdarg.h>
47 
48 /* AIX sys/poll.h does #define events reqevents, and other
49  * wonderousness, so must include sys/poll before declaring
50  * DBusPollFD
51  */
52 #ifdef HAVE_POLL
53 #include <sys/poll.h>
54 #endif
55 
56 #ifdef DBUS_WINCE
57 /* Windows CE lacks some system functions (such as errno and clock).
58  We bring them in here. */
59 #include "dbus-sysdeps-wince-glue.h"
60 #endif
61 
63 
64 #ifdef DBUS_WIN
65 #define _DBUS_PATH_SEPARATOR ";"
66 #else
67 #define _DBUS_PATH_SEPARATOR ":"
68 #endif
69 
70 /* Forward declarations */
71 
72 
74 typedef struct DBusList DBusList;
75 
77 typedef struct DBusCredentials DBusCredentials;
78 
80 typedef struct DBusPipe DBusPipe;
81 
88 void _dbus_abort (void) _DBUS_GNUC_NORETURN;
89 
90 const char* _dbus_getenv (const char *varname);
91 dbus_bool_t _dbus_setenv (const char *varname,
92  const char *value);
94 char ** _dbus_get_environment (void);
95 
97 typedef unsigned long dbus_pid_t;
99 typedef unsigned long dbus_uid_t;
101 typedef unsigned long dbus_gid_t;
102 
104 #define DBUS_PID_UNSET ((dbus_pid_t) -1)
105 
106 #define DBUS_UID_UNSET ((dbus_uid_t) -1)
107 
108 #define DBUS_GID_UNSET ((dbus_gid_t) -1)
109 
111 #define DBUS_PID_FORMAT "%lu"
112 
113 #define DBUS_UID_FORMAT "%lu"
114 
115 #define DBUS_GID_FORMAT "%lu"
116 
117 
129  DBusError *error);
130 int _dbus_read_socket (int fd,
131  DBusString *buffer,
132  int count);
133 int _dbus_write_socket (int fd,
134  const DBusString *buffer,
135  int start,
136  int len);
137 int _dbus_write_socket_two (int fd,
138  const DBusString *buffer1,
139  int start1,
140  int len1,
141  const DBusString *buffer2,
142  int start2,
143  int len2);
144 
146  DBusString *buffer,
147  int count,
148  int *fds,
149  int *n_fds);
150 int _dbus_write_socket_with_unix_fds (int fd,
151  const DBusString *buffer,
152  int start,
153  int len,
154  const int *fds,
155  int n_fds);
156 int _dbus_write_socket_with_unix_fds_two (int fd,
157  const DBusString *buffer1,
158  int start1,
159  int len1,
160  const DBusString *buffer2,
161  int start2,
162  int len2,
163  const int *fds,
164  int n_fds);
165 
166 dbus_bool_t _dbus_socket_is_invalid (int fd);
167 
168 int _dbus_connect_tcp_socket (const char *host,
169  const char *port,
170  const char *family,
171  DBusError *error);
172 int _dbus_connect_tcp_socket_with_nonce (const char *host,
173  const char *port,
174  const char *family,
175  const char *noncefile,
176  DBusError *error);
177 int _dbus_listen_tcp_socket (const char *host,
178  const char *port,
179  const char *family,
180  DBusString *retport,
181  int **fds_p,
182  DBusError *error);
183 int _dbus_accept (int listen_fd);
184 
185 
187  DBusCredentials *credentials,
188  DBusError *error);
190  DBusError *error);
191 
193  const DBusString *username);
196 
198  dbus_uid_t *uid_p);
200  dbus_gid_t *gid_p);
202  dbus_gid_t **group_ids,
203  int *n_group_ids);
205  DBusError *error);
207 dbus_bool_t _dbus_windows_user_is_process_owner (const char *windows_sid);
208 
210  DBusCredentials *credentials);
211 
212 dbus_bool_t _dbus_daemon_is_session_bus_address_published (const char *scope);
213 
214 dbus_bool_t _dbus_daemon_publish_session_bus_address (const char* address, const char* shm_name);
215 
216 void _dbus_daemon_unpublish_session_bus_address (void);
217 
219 
223 typedef struct DBusAtomic DBusAtomic;
224 
229 {
230 #ifdef DBUS_WIN
231  volatile long value;
232 #else
233  volatile dbus_int32_t value;
234 #endif
235 };
236 
237 /* The value we get from autofoo is in the form of a cpp expression;
238  * convert that to a conventional defined/undef switch. (We can't get
239  * the conventional defined/undef because of multiarch builds only running
240  * ./configure once, on Darwin.) */
241 #if DBUS_HAVE_ATOMIC_INT_COND
242 # define DBUS_HAVE_ATOMIC_INT 1
243 #else
244 # undef DBUS_HAVE_ATOMIC_INT
245 #endif
246 
247 dbus_int32_t _dbus_atomic_inc (DBusAtomic *atomic);
248 dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic);
249 dbus_int32_t _dbus_atomic_get (DBusAtomic *atomic);
250 
251 
252 /* AIX uses different values for poll */
253 
254 #ifdef _AIX
255 
256 #define _DBUS_POLLIN 0x0001
257 
258 #define _DBUS_POLLPRI 0x0004
259 
260 #define _DBUS_POLLOUT 0x0002
261 
262 #define _DBUS_POLLERR 0x4000
263 
264 #define _DBUS_POLLHUP 0x2000
265 
266 #define _DBUS_POLLNVAL 0x8000
267 #elif defined(__HAIKU__)
268 
269 #define _DBUS_POLLIN 0x0001
270 
271 #define _DBUS_POLLOUT 0x0002
272 
273 #define _DBUS_POLLERR 0x0004
274 
275 #define _DBUS_POLLPRI 0x0020
276 
277 #define _DBUS_POLLHUP 0x0080
278 
279 #define _DBUS_POLLNVAL 0x1000
280 #else
281 
282 #define _DBUS_POLLIN 0x0001
283 
284 #define _DBUS_POLLPRI 0x0002
285 
286 #define _DBUS_POLLOUT 0x0004
287 
288 #define _DBUS_POLLERR 0x0008
289 
290 #define _DBUS_POLLHUP 0x0010
291 
292 #define _DBUS_POLLNVAL 0x0020
293 #endif
294 
298 typedef struct
299 {
300  int fd;
301  short events;
302  short revents;
303 } DBusPollFD;
304 
305 int _dbus_poll (DBusPollFD *fds,
306  int n_fds,
307  int timeout_milliseconds);
308 
309 void _dbus_sleep_milliseconds (int milliseconds);
310 
311 void _dbus_get_monotonic_time (long *tv_sec,
312  long *tv_usec);
313 
314 void _dbus_get_real_time (long *tv_sec,
315  long *tv_usec);
316 
321  DBusError *error);
323  DBusError *error);
324 
326  const DBusString *next_component);
328  DBusString *dirname);
330 
333 
336 
338 typedef struct DBusDirIter DBusDirIter;
339 
341  DBusError *error);
343  DBusString *filename,
344  DBusError *error);
346 
348  DBusError *error);
349 
350 void _dbus_fd_set_close_on_exec (intptr_t fd);
351 
352 const char* _dbus_get_tmpdir (void);
353 
358  int n_bytes);
359 void _dbus_generate_random_bytes_buffer (char *buffer,
360  int n_bytes);
362  int n_bytes);
364  int n_bytes);
365 
366 const char* _dbus_error_from_errno (int error_number);
367 const char* _dbus_error_from_system_errno (void);
368 
369 void _dbus_set_errno_to_zero (void);
375 const char* _dbus_strerror_from_errno (void);
376 
377 void _dbus_disable_sigpipe (void);
378 
379 
380 void _dbus_exit (int code) _DBUS_GNUC_NORETURN;
381 
382 int _dbus_printf_string_upper_bound (const char *format,
383  va_list args);
384 
385 
389 typedef struct
390 {
391  unsigned long mode;
392  unsigned long nlink;
393  dbus_uid_t uid;
394  dbus_gid_t gid;
395  unsigned long size;
396  unsigned long atime;
397  unsigned long mtime;
398  unsigned long ctime;
399 } DBusStat;
400 
401 dbus_bool_t _dbus_stat (const DBusString *filename,
402  DBusStat *statbuf,
403  DBusError *error);
405  int *fd2,
406  dbus_bool_t blocking,
407  DBusError *error);
408 
409 void _dbus_print_backtrace (void);
410 
412  DBusPipe *print_pid_pipe,
413  DBusError *error,
414  dbus_bool_t keep_umask);
415 
416 dbus_bool_t _dbus_verify_daemon_user (const char *user);
417 dbus_bool_t _dbus_change_to_daemon_user (const char *user,
418  DBusError *error);
419 
421  DBusPipe *print_pid_pipe,
422  dbus_pid_t pid_to_write,
423  DBusError *error);
424 
425 dbus_bool_t _dbus_command_for_pid (unsigned long pid,
426  DBusString *str,
427  int max_len,
428  DBusError *error);
429 
431 typedef void (* DBusSignalHandler) (int sig);
432 
433 void _dbus_set_signal_handler (int sig,
434  DBusSignalHandler handler);
435 
436 dbus_bool_t _dbus_user_at_console (const char *username,
437  DBusError *error);
438 
439 void _dbus_init_system_log (void);
440 
441 typedef enum {
442  DBUS_SYSTEM_LOG_INFO,
443  DBUS_SYSTEM_LOG_SECURITY,
444  DBUS_SYSTEM_LOG_FATAL
445 } DBusSystemLogSeverity;
446 
447 void _dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...) _DBUS_GNUC_PRINTF (2, 3);
448 void _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args);
449 
450 /* Define DBUS_VA_COPY() to do the right thing for copying va_list variables.
451  * config.h may have already defined DBUS_VA_COPY as va_copy or __va_copy.
452  */
453 #if !defined (DBUS_VA_COPY)
454 # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
455 # define DBUS_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
456 # elif defined (DBUS_VA_COPY_AS_ARRAY)
457 # define DBUS_VA_COPY(ap1, ap2) memcpy ((ap1), (ap2), sizeof (va_list))
458 # else /* va_list is a pointer */
459 # define DBUS_VA_COPY(ap1, ap2) ((ap1) = (ap2))
460 # endif /* va_list is a pointer */
461 #endif /* !DBUS_VA_COPY */
462 
463 
468 #define _DBUS_BYTE_OF_PRIMITIVE(p, i) \
469  (((const char*)&(p))[(i)])
470 
475 #define _DBUS_DOUBLES_BITWISE_EQUAL(a, b) \
476  (_DBUS_BYTE_OF_PRIMITIVE (a, 0) == _DBUS_BYTE_OF_PRIMITIVE (b, 0) && \
477  _DBUS_BYTE_OF_PRIMITIVE (a, 1) == _DBUS_BYTE_OF_PRIMITIVE (b, 1) && \
478  _DBUS_BYTE_OF_PRIMITIVE (a, 2) == _DBUS_BYTE_OF_PRIMITIVE (b, 2) && \
479  _DBUS_BYTE_OF_PRIMITIVE (a, 3) == _DBUS_BYTE_OF_PRIMITIVE (b, 3) && \
480  _DBUS_BYTE_OF_PRIMITIVE (a, 4) == _DBUS_BYTE_OF_PRIMITIVE (b, 4) && \
481  _DBUS_BYTE_OF_PRIMITIVE (a, 5) == _DBUS_BYTE_OF_PRIMITIVE (b, 5) && \
482  _DBUS_BYTE_OF_PRIMITIVE (a, 6) == _DBUS_BYTE_OF_PRIMITIVE (b, 6) && \
483  _DBUS_BYTE_OF_PRIMITIVE (a, 7) == _DBUS_BYTE_OF_PRIMITIVE (b, 7))
484 
485 dbus_bool_t _dbus_get_autolaunch_address (const char *scope,
486  DBusString *address,
487  DBusError *error);
488 
490  DBusString *address,
491  DBusError *error);
492 
496 typedef union DBusGUID DBusGUID;
497 
499  dbus_bool_t create_if_not_found,
500  DBusError *error);
501 
508 
510  const char *suffix,
511  DBusList **dir_list);
512 
513 unsigned long _dbus_pid_for_log (void);
514 
515 /* FIXME move back to dbus-sysdeps-unix.h probably -
516  * the PID file handling just needs a little more abstraction
517  * in the bus daemon first.
518  */
519 dbus_pid_t _dbus_getpid (void);
520 
521 dbus_bool_t _dbus_change_to_daemon_user (const char *user,
522  DBusError *error);
523 
524 void _dbus_flush_caches (void);
525 
526 void _dbus_request_file_descriptor_limit (unsigned int limit);
527 
528 /*
529  * replaces the term DBUS_PREFIX in configure_time_path by the
530  * current dbus installation directory. On unix this function is a noop
531  *
532  * @param configure_time_path
533  * @return real path
534  */
535 const char *
536 _dbus_replace_install_prefix (const char *configure_time_path);
537 
541 
542 
543 #ifdef DBUS_WIN
544 #include "dbus-sysdeps-win.h"
545 #endif
546 
547 #endif /* DBUS_SYSDEPS_H */