D-Bus  1.4.10
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 #include <dbus/dbus-errors.h>
35 #include <dbus/dbus-file.h>
36 #include <dbus/dbus-string.h>
37 
38 /* this is perhaps bogus, but strcmp() etc. are faster if we use the
39  * stuff straight out of string.h, so have this here for now.
40  */
41 #include <string.h>
42 #include <stdarg.h>
43 
44 /* AIX sys/poll.h does #define events reqevents, and other
45  * wonderousness, so must include sys/poll before declaring
46  * DBusPollFD
47  */
48 #ifdef HAVE_POLL
49 #include <sys/poll.h>
50 #endif
51 
52 #ifdef DBUS_WINCE
53 /* Windows CE lacks some system functions (such as errno and clock).
54  We bring them in here. */
55 #include "dbus-sysdeps-wince-glue.h"
56 #endif
57 
59 
60 #ifdef DBUS_WIN
61 #define _DBUS_PATH_SEPARATOR ";"
62 #else
63 #define _DBUS_PATH_SEPARATOR ":"
64 #endif
65 
66 /* Forward declarations */
67 
68 
70 typedef struct DBusList DBusList;
71 
73 typedef struct DBusCredentials DBusCredentials;
74 
76 typedef struct DBusPipe DBusPipe;
77 
84 void _dbus_abort (void) _DBUS_GNUC_NORETURN;
85 
87 const char* _dbus_getenv (const char *varname);
88 dbus_bool_t _dbus_setenv (const char *varname,
89  const char *value);
91 char ** _dbus_get_environment (void);
92 
94 typedef unsigned long dbus_pid_t;
96 typedef unsigned long dbus_uid_t;
98 typedef unsigned long dbus_gid_t;
99 
101 #define DBUS_PID_UNSET ((dbus_pid_t) -1)
102 
103 #define DBUS_UID_UNSET ((dbus_uid_t) -1)
104 
105 #define DBUS_GID_UNSET ((dbus_gid_t) -1)
106 
108 #define DBUS_PID_FORMAT "%lu"
109 
110 #define DBUS_UID_FORMAT "%lu"
111 
112 #define DBUS_GID_FORMAT "%lu"
113 
114 
126  DBusError *error);
128  DBusError *error);
129 int _dbus_read_socket (int fd,
130  DBusString *buffer,
131  int count);
132 int _dbus_write_socket (int fd,
133  const DBusString *buffer,
134  int start,
135  int len);
136 int _dbus_write_socket_two (int fd,
137  const DBusString *buffer1,
138  int start1,
139  int len1,
140  const DBusString *buffer2,
141  int start2,
142  int len2);
143 
145  DBusString *buffer,
146  int count,
147  int *fds,
148  int *n_fds);
149 int _dbus_write_socket_with_unix_fds (int fd,
150  const DBusString *buffer,
151  int start,
152  int len,
153  const int *fds,
154  int n_fds);
155 int _dbus_write_socket_with_unix_fds_two (int fd,
156  const DBusString *buffer1,
157  int start1,
158  int len1,
159  const DBusString *buffer2,
160  int start2,
161  int len2,
162  const int *fds,
163  int n_fds);
164 
165 dbus_bool_t _dbus_socket_is_invalid (int fd);
166 
167 int _dbus_connect_tcp_socket (const char *host,
168  const char *port,
169  const char *family,
170  DBusError *error);
171 int _dbus_connect_tcp_socket_with_nonce (const char *host,
172  const char *port,
173  const char *family,
174  const char *noncefile,
175  DBusError *error);
176 int _dbus_listen_tcp_socket (const char *host,
177  const char *port,
178  const char *family,
179  DBusString *retport,
180  int **fds_p,
181  DBusError *error);
182 int _dbus_accept (int listen_fd);
183 
184 
186  DBusCredentials *credentials,
187  DBusError *error);
189  DBusError *error);
190 
192  const DBusString *username);
195 
197  dbus_uid_t *uid_p);
199  dbus_gid_t *gid_p);
201  dbus_gid_t **group_ids,
202  int *n_group_ids);
204  DBusError *error);
206 dbus_bool_t _dbus_windows_user_is_process_owner (const char *windows_sid);
207 
209  DBusCredentials *credentials);
210 
211 dbus_bool_t _dbus_daemon_is_session_bus_address_published (const char *scope);
212 
213 dbus_bool_t _dbus_daemon_publish_session_bus_address (const char* address, const char* shm_name);
214 
215 void _dbus_daemon_unpublish_session_bus_address (void);
216 
218 
222 typedef struct DBusAtomic DBusAtomic;
223 
228 {
229 #ifdef DBUS_WIN
230  volatile long value;
231 #else
232  volatile dbus_int32_t value;
233 #endif
234 };
235 
236 /* The value we get from autofoo is in the form of a cpp expression;
237  * convert that to a conventional defined/undef switch. (We can't get
238  * the conventional defined/undef because of multiarch builds only running
239  * ./configure once, on Darwin.) */
240 #if DBUS_HAVE_ATOMIC_INT_COND
241 # define DBUS_HAVE_ATOMIC_INT 1
242 #else
243 # undef DBUS_HAVE_ATOMIC_INT
244 #endif
245 
248 
249 
250 /* AIX uses different values for poll */
251 
252 #ifdef _AIX
253 
254 #define _DBUS_POLLIN 0x0001
255 
256 #define _DBUS_POLLPRI 0x0004
257 
258 #define _DBUS_POLLOUT 0x0002
259 
260 #define _DBUS_POLLERR 0x4000
261 
262 #define _DBUS_POLLHUP 0x2000
263 
264 #define _DBUS_POLLNVAL 0x8000
265 #elif defined(__HAIKU__)
266 
267 #define _DBUS_POLLIN 0x0001
268 
269 #define _DBUS_POLLOUT 0x0002
270 
271 #define _DBUS_POLLERR 0x0004
272 
273 #define _DBUS_POLLPRI 0x0020
274 
275 #define _DBUS_POLLHUP 0x0080
276 
277 #define _DBUS_POLLNVAL 0x1000
278 #else
279 
280 #define _DBUS_POLLIN 0x0001
281 
282 #define _DBUS_POLLPRI 0x0002
283 
284 #define _DBUS_POLLOUT 0x0004
285 
286 #define _DBUS_POLLERR 0x0008
287 
288 #define _DBUS_POLLHUP 0x0010
289 
290 #define _DBUS_POLLNVAL 0x0020
291 #endif
292 
296 typedef struct
297 {
298  int fd;
299  short events;
300  short revents;
301 } DBusPollFD;
302 
303 int _dbus_poll (DBusPollFD *fds,
304  int n_fds,
305  int timeout_milliseconds);
306 
307 void _dbus_sleep_milliseconds (int milliseconds);
308 
309 void _dbus_get_current_time (long *tv_sec,
310  long *tv_usec);
311 
316  DBusError *error);
318  DBusError *error);
319 
321  const DBusString *next_component);
323  DBusString *dirname);
325 
328 
331 
333 typedef struct DBusDirIter DBusDirIter;
334 
336  DBusError *error);
338  DBusString *filename,
339  DBusError *error);
341 
343  DBusError *error);
344 
345 void _dbus_fd_set_close_on_exec (intptr_t fd);
346 
347 const char* _dbus_get_tmpdir (void);
348 
353  int n_bytes);
354 void _dbus_generate_random_bytes_buffer (char *buffer,
355  int n_bytes);
357  int n_bytes);
359  int n_bytes);
360 
361 const char* _dbus_error_from_errno (int error_number);
362 const char* _dbus_error_from_system_errno (void);
363 
364 void _dbus_set_errno_to_zero (void);
370 const char* _dbus_strerror_from_errno (void);
371 
372 void _dbus_disable_sigpipe (void);
373 
374 
375 void _dbus_exit (int code) _DBUS_GNUC_NORETURN;
376 
377 int _dbus_printf_string_upper_bound (const char *format,
378  va_list args);
379 
380 
384 typedef struct
385 {
386  unsigned long mode;
387  unsigned long nlink;
388  dbus_uid_t uid;
389  dbus_gid_t gid;
390  unsigned long size;
391  unsigned long atime;
392  unsigned long mtime;
393  unsigned long ctime;
394 } DBusStat;
395 
396 dbus_bool_t _dbus_stat (const DBusString *filename,
397  DBusStat *statbuf,
398  DBusError *error);
400  int *fd2,
401  dbus_bool_t blocking,
402  DBusError *error);
403 
404 void _dbus_print_backtrace (void);
405 
407  DBusPipe *print_pid_pipe,
408  DBusError *error,
409  dbus_bool_t keep_umask);
410 
411 dbus_bool_t _dbus_verify_daemon_user (const char *user);
412 dbus_bool_t _dbus_change_to_daemon_user (const char *user,
413  DBusError *error);
414 
416  DBusPipe *print_pid_pipe,
417  dbus_pid_t pid_to_write,
418  DBusError *error);
419 
420 dbus_bool_t _dbus_command_for_pid (unsigned long pid,
421  DBusString *str,
422  int max_len,
423  DBusError *error);
424 
426 typedef void (* DBusSignalHandler) (int sig);
427 
428 void _dbus_set_signal_handler (int sig,
429  DBusSignalHandler handler);
430 
431 dbus_bool_t _dbus_user_at_console (const char *username,
432  DBusError *error);
433 
434 void _dbus_init_system_log (void);
435 
436 typedef enum {
437  DBUS_SYSTEM_LOG_INFO,
438  DBUS_SYSTEM_LOG_SECURITY,
439  DBUS_SYSTEM_LOG_FATAL
440 } DBusSystemLogSeverity;
441 
442 void _dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...) _DBUS_GNUC_PRINTF (2, 3);
443 void _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args);
444 
445 /* Define DBUS_VA_COPY() to do the right thing for copying va_list variables.
446  * config.h may have already defined DBUS_VA_COPY as va_copy or __va_copy.
447  */
448 #if !defined (DBUS_VA_COPY)
449 # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
450 # define DBUS_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
451 # elif defined (DBUS_VA_COPY_AS_ARRAY)
452 # define DBUS_VA_COPY(ap1, ap2) memcpy ((ap1), (ap2), sizeof (va_list))
453 # else /* va_list is a pointer */
454 # define DBUS_VA_COPY(ap1, ap2) ((ap1) = (ap2))
455 # endif /* va_list is a pointer */
456 #endif /* !DBUS_VA_COPY */
457 
458 
463 #define _DBUS_BYTE_OF_PRIMITIVE(p, i) \
464  (((const char*)&(p))[(i)])
465 
470 #define _DBUS_DOUBLES_BITWISE_EQUAL(a, b) \
471  (_DBUS_BYTE_OF_PRIMITIVE (a, 0) == _DBUS_BYTE_OF_PRIMITIVE (b, 0) && \
472  _DBUS_BYTE_OF_PRIMITIVE (a, 1) == _DBUS_BYTE_OF_PRIMITIVE (b, 1) && \
473  _DBUS_BYTE_OF_PRIMITIVE (a, 2) == _DBUS_BYTE_OF_PRIMITIVE (b, 2) && \
474  _DBUS_BYTE_OF_PRIMITIVE (a, 3) == _DBUS_BYTE_OF_PRIMITIVE (b, 3) && \
475  _DBUS_BYTE_OF_PRIMITIVE (a, 4) == _DBUS_BYTE_OF_PRIMITIVE (b, 4) && \
476  _DBUS_BYTE_OF_PRIMITIVE (a, 5) == _DBUS_BYTE_OF_PRIMITIVE (b, 5) && \
477  _DBUS_BYTE_OF_PRIMITIVE (a, 6) == _DBUS_BYTE_OF_PRIMITIVE (b, 6) && \
478  _DBUS_BYTE_OF_PRIMITIVE (a, 7) == _DBUS_BYTE_OF_PRIMITIVE (b, 7))
479 
480 dbus_bool_t _dbus_get_autolaunch_address (const char *scope,
481  DBusString *address,
482  DBusError *error);
483 
485  DBusString *address,
486  DBusError *error);
487 
491 typedef union DBusGUID DBusGUID;
492 
494  dbus_bool_t create_if_not_found,
495  DBusError *error);
496 
503 
505  const char *suffix,
506  DBusList **dir_list);
507 
508 unsigned long _dbus_pid_for_log (void);
509 
510 /* FIXME move back to dbus-sysdeps-unix.h probably -
511  * the PID file handling just needs a little more abstraction
512  * in the bus daemon first.
513  */
514 dbus_pid_t _dbus_getpid (void);
515 
516 dbus_bool_t _dbus_change_to_daemon_user (const char *user,
517  DBusError *error);
518 
519 void _dbus_flush_caches (void);
520 
521 void _dbus_request_file_descriptor_limit (unsigned int limit);
522 
523 /*
524  * replaces the term DBUS_PREFIX in configure_time_path by the
525  * current dbus installation directory. On unix this function is a noop
526  *
527  * @param configure_time_path
528  * @return real path
529  */
530 const char *
531 _dbus_replace_install_prefix (const char *configure_time_path);
532 
536 
537 
538 #ifdef DBUS_WIN
539 #include "dbus-sysdeps-win.h"
540 #endif
541 
542 #endif /* DBUS_SYSDEPS_H */