1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-sysdeps-util-unix.c Would be in dbus-sysdeps-unix.c, but not used in libdbus
4 * Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc.
5 * Copyright (C) 2003 CodeFactory AB
7 * Licensed under the Academic Free License version 2.1
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.
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.
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
26 #include "dbus-sysdeps.h"
27 #include "dbus-sysdeps-unix.h"
28 #include "dbus-internals.h"
29 #include "dbus-pipe.h"
30 #include "dbus-protocol.h"
31 #include "dbus-string.h"
32 #define DBUS_USERDB_INCLUDES_PRIVATE 1
33 #include "dbus-userdb.h"
34 #include "dbus-test.h"
36 #include <sys/types.h>
45 #ifdef HAVE_SYS_RESOURCE_H
46 #include <sys/resource.h>
49 #include <sys/socket.h>
54 #ifdef HAVE_SYS_SYSLIMITS_H
55 #include <sys/syslimits.h>
63 * @addtogroup DBusInternalsUtils
69 * Does the chdir, fork, setsid, etc. to become a daemon process.
71 * @param pidfile #NULL, or pidfile to create
72 * @param print_pid_pipe pipe to print daemon's pid to, or -1 for none
73 * @param error return location for errors
74 * @param keep_umask #TRUE to keep the original umask
75 * @returns #FALSE on failure
78 _dbus_become_daemon (const DBusString *pidfile,
79 DBusPipe *print_pid_pipe,
81 dbus_bool_t keep_umask)
87 _dbus_verbose ("Becoming a daemon...\n");
89 _dbus_verbose ("chdir to /\n");
92 dbus_set_error (error, DBUS_ERROR_FAILED,
93 "Could not chdir() to root directory");
97 _dbus_verbose ("forking...\n");
98 switch ((child_pid = fork ()))
101 _dbus_verbose ("fork failed\n");
102 dbus_set_error (error, _dbus_error_from_errno (errno),
103 "Failed to fork daemon: %s", _dbus_strerror (errno));
108 _dbus_verbose ("in child, closing std file descriptors\n");
110 /* silently ignore failures here, if someone
111 * doesn't have /dev/null we may as well try
115 dev_null_fd = open ("/dev/null", O_RDWR);
116 if (dev_null_fd >= 0)
118 dup2 (dev_null_fd, 0);
119 dup2 (dev_null_fd, 1);
121 s = _dbus_getenv ("DBUS_DEBUG_OUTPUT");
122 if (s == NULL || *s == '\0')
123 dup2 (dev_null_fd, 2);
125 _dbus_verbose ("keeping stderr open due to DBUS_DEBUG_OUTPUT\n");
131 /* Get a predictable umask */
132 _dbus_verbose ("setting umask\n");
136 _dbus_verbose ("calling setsid()\n");
138 _dbus_assert_not_reached ("setsid() failed");
143 if (!_dbus_write_pid_to_file_and_pipe (pidfile, print_pid_pipe,
146 _dbus_verbose ("pid file or pipe write failed: %s\n",
148 kill (child_pid, SIGTERM);
152 _dbus_verbose ("parent exiting\n");
162 * Creates a file containing the process ID.
164 * @param filename the filename to write to
165 * @param pid our process ID
166 * @param error return location for errors
167 * @returns #FALSE on failure
170 _dbus_write_pid_file (const DBusString *filename,
174 const char *cfilename;
178 cfilename = _dbus_string_get_const_data (filename);
180 fd = open (cfilename, O_WRONLY|O_CREAT|O_EXCL|O_BINARY, 0644);
184 dbus_set_error (error, _dbus_error_from_errno (errno),
185 "Failed to open \"%s\": %s", cfilename,
186 _dbus_strerror (errno));
190 if ((f = fdopen (fd, "w")) == NULL)
192 dbus_set_error (error, _dbus_error_from_errno (errno),
193 "Failed to fdopen fd %d: %s", fd, _dbus_strerror (errno));
194 _dbus_close (fd, NULL);
198 if (fprintf (f, "%lu\n", pid) < 0)
200 dbus_set_error (error, _dbus_error_from_errno (errno),
201 "Failed to write to \"%s\": %s", cfilename,
202 _dbus_strerror (errno));
208 if (fclose (f) == EOF)
210 dbus_set_error (error, _dbus_error_from_errno (errno),
211 "Failed to close \"%s\": %s", cfilename,
212 _dbus_strerror (errno));
220 * Writes the given pid_to_write to a pidfile (if non-NULL) and/or to a
221 * pipe (if non-NULL). Does nothing if pidfile and print_pid_pipe are both
224 * @param pidfile the file to write to or #NULL
225 * @param print_pid_pipe the pipe to write to or #NULL
226 * @param pid_to_write the pid to write out
227 * @param error error on failure
228 * @returns FALSE if error is set
231 _dbus_write_pid_to_file_and_pipe (const DBusString *pidfile,
232 DBusPipe *print_pid_pipe,
233 dbus_pid_t pid_to_write,
238 _dbus_verbose ("writing pid file %s\n", _dbus_string_get_const_data (pidfile));
239 if (!_dbus_write_pid_file (pidfile,
243 _dbus_verbose ("pid file write failed\n");
244 _DBUS_ASSERT_ERROR_IS_SET(error);
250 _dbus_verbose ("No pid file requested\n");
253 if (print_pid_pipe != NULL && _dbus_pipe_is_valid (print_pid_pipe))
258 _dbus_verbose ("writing our pid to pipe %d\n",
261 if (!_dbus_string_init (&pid))
263 _DBUS_SET_OOM (error);
267 if (!_dbus_string_append_int (&pid, pid_to_write) ||
268 !_dbus_string_append (&pid, "\n"))
270 _dbus_string_free (&pid);
271 _DBUS_SET_OOM (error);
275 bytes = _dbus_string_get_length (&pid);
276 if (_dbus_pipe_write (print_pid_pipe, &pid, 0, bytes, error) != bytes)
278 /* _dbus_pipe_write sets error only on failure, not short write */
279 if (error != NULL && !dbus_error_is_set(error))
281 dbus_set_error (error, DBUS_ERROR_FAILED,
282 "Printing message bus PID: did not write enough bytes\n");
284 _dbus_string_free (&pid);
288 _dbus_string_free (&pid);
292 _dbus_verbose ("No pid pipe to write to\n");
299 * Verify that after the fork we can successfully change to this user.
301 * @param user the username given in the daemon configuration
302 * @returns #TRUE if username is valid
305 _dbus_verify_daemon_user (const char *user)
309 _dbus_string_init_const (&u, user);
311 return _dbus_get_user_id_and_primary_group (&u, NULL, NULL);
315 /* The HAVE_LIBAUDIT case lives in selinux.c */
316 #ifndef HAVE_LIBAUDIT
318 * Changes the user and group the bus is running as.
320 * @param user the user to become
321 * @param error return location for errors
322 * @returns #FALSE on failure
325 _dbus_change_to_daemon_user (const char *user,
332 _dbus_string_init_const (&u, user);
334 if (!_dbus_get_user_id_and_primary_group (&u, &uid, &gid))
336 dbus_set_error (error, DBUS_ERROR_FAILED,
337 "User '%s' does not appear to exist?",
342 /* setgroups() only works if we are a privileged process,
343 * so we don't return error on failure; the only possible
344 * failure is that we don't have perms to do it.
346 * not sure this is right, maybe if setuid()
347 * is going to work then setgroups() should also work.
349 if (setgroups (0, NULL) < 0)
350 _dbus_warn ("Failed to drop supplementary groups: %s\n",
351 _dbus_strerror (errno));
353 /* Set GID first, or the setuid may remove our permission
356 if (setgid (gid) < 0)
358 dbus_set_error (error, _dbus_error_from_errno (errno),
359 "Failed to set GID to %lu: %s", gid,
360 _dbus_strerror (errno));
364 if (setuid (uid) < 0)
366 dbus_set_error (error, _dbus_error_from_errno (errno),
367 "Failed to set UID to %lu: %s", uid,
368 _dbus_strerror (errno));
374 #endif /* !HAVE_LIBAUDIT */
378 * Attempt to ensure that the current process can open
379 * at least @limit file descriptors.
381 * If @limit is lower than the current, it will not be
382 * lowered. No error is returned if the request can
385 * @limit Number of file descriptors
388 _dbus_request_file_descriptor_limit (unsigned int limit)
390 #ifdef HAVE_SETRLIMIT
392 struct rlimit target_lim;
394 /* No point to doing this practically speaking
395 * if we're not uid 0. We expect the system
396 * bus to use this before we change UID, and
397 * the session bus takes the Linux default
398 * of 1024 for both cur and max.
403 if (getrlimit (RLIMIT_NOFILE, &lim) < 0)
406 if (lim.rlim_cur >= limit)
409 /* Ignore "maximum limit", assume we have the "superuser"
410 * privileges. On Linux this is CAP_SYS_RESOURCE.
412 target_lim.rlim_cur = target_lim.rlim_max = limit;
413 /* Also ignore errors; if we fail, we will at least work
414 * up to whatever limit we had, which seems better than
415 * just outright aborting.
417 * However, in the future we should probably log this so OS builders
418 * have a chance to notice any misconfiguration like dbus-daemon
419 * being started without CAP_SYS_RESOURCE.
421 setrlimit (RLIMIT_NOFILE, &target_lim);
426 _dbus_init_system_log (void)
428 #if HAVE_DECL_LOG_PERROR
429 openlog ("dbus", LOG_PID | LOG_PERROR, LOG_DAEMON);
431 openlog ("dbus", LOG_PID, LOG_DAEMON);
436 * Log a message to the system log file (e.g. syslog on Unix).
438 * @param severity a severity value
439 * @param msg a printf-style format string
440 * @param args arguments for the format string
444 _dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...)
448 va_start (args, msg);
450 _dbus_system_logv (severity, msg, args);
456 * Log a message to the system log file (e.g. syslog on Unix).
458 * @param severity a severity value
459 * @param msg a printf-style format string
460 * @param args arguments for the format string
462 * If the FATAL severity is given, this function will terminate the program
463 * with an error code.
466 _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args)
471 case DBUS_SYSTEM_LOG_INFO:
472 flags = LOG_DAEMON | LOG_NOTICE;
474 case DBUS_SYSTEM_LOG_SECURITY:
475 flags = LOG_AUTH | LOG_NOTICE;
477 case DBUS_SYSTEM_LOG_FATAL:
478 flags = LOG_DAEMON|LOG_CRIT;
484 #ifndef HAVE_DECL_LOG_PERROR
486 /* vsyslog() won't write to stderr, so we'd better do it */
489 DBUS_VA_COPY (tmp, args);
490 fprintf (stderr, "dbus[" DBUS_PID_FORMAT "]: ", _dbus_getpid ());
491 vfprintf (stderr, msg, tmp);
492 fputc ('\n', stderr);
497 vsyslog (flags, msg, args);
499 if (severity == DBUS_SYSTEM_LOG_FATAL)
503 /** Installs a UNIX signal handler
505 * @param sig the signal to handle
506 * @param handler the handler
509 _dbus_set_signal_handler (int sig,
510 DBusSignalHandler handler)
512 struct sigaction act;
515 sigemptyset (&empty_mask);
516 act.sa_handler = handler;
517 act.sa_mask = empty_mask;
519 sigaction (sig, &act, NULL);
522 /** Checks if a file exists
524 * @param file full path to the file
525 * @returns #TRUE if file exists
528 _dbus_file_exists (const char *file)
530 return (access (file, F_OK) == 0);
533 /** Checks if user is at the console
535 * @param username user to check
536 * @param error return location for errors
537 * @returns #TRUE is the user is at the consolei and there are no errors
540 _dbus_user_at_console (const char *username,
548 if (!_dbus_string_init (&f))
550 _DBUS_SET_OOM (error);
554 if (!_dbus_string_append (&f, DBUS_CONSOLE_AUTH_DIR))
556 _DBUS_SET_OOM (error);
560 _dbus_string_init_const (&u, username);
562 if (!_dbus_concat_dir_and_file (&f, &u))
564 _DBUS_SET_OOM (error);
568 result = _dbus_file_exists (_dbus_string_get_const_data (&f));
571 _dbus_string_free (&f);
578 * Checks whether the filename is an absolute path
580 * @param filename the filename
581 * @returns #TRUE if an absolute path
584 _dbus_path_is_absolute (const DBusString *filename)
586 if (_dbus_string_get_length (filename) > 0)
587 return _dbus_string_get_byte (filename, 0) == '/';
595 * @param filename the filename to stat
596 * @param statbuf the stat info to fill in
597 * @param error return location for error
598 * @returns #FALSE if error was set
601 _dbus_stat (const DBusString *filename,
605 const char *filename_c;
608 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
610 filename_c = _dbus_string_get_const_data (filename);
612 if (stat (filename_c, &sb) < 0)
614 dbus_set_error (error, _dbus_error_from_errno (errno),
615 "%s", _dbus_strerror (errno));
619 statbuf->mode = sb.st_mode;
620 statbuf->nlink = sb.st_nlink;
621 statbuf->uid = sb.st_uid;
622 statbuf->gid = sb.st_gid;
623 statbuf->size = sb.st_size;
624 statbuf->atime = sb.st_atime;
625 statbuf->mtime = sb.st_mtime;
626 statbuf->ctime = sb.st_ctime;
633 * Internals of directory iterator
637 DIR *d; /**< The DIR* from opendir() */
642 * Open a directory to iterate over.
644 * @param filename the directory name
645 * @param error exception return object or #NULL
646 * @returns new iterator, or #NULL on error
649 _dbus_directory_open (const DBusString *filename,
654 const char *filename_c;
656 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
658 filename_c = _dbus_string_get_const_data (filename);
660 d = opendir (filename_c);
663 dbus_set_error (error, _dbus_error_from_errno (errno),
664 "Failed to read directory \"%s\": %s",
666 _dbus_strerror (errno));
669 iter = dbus_new0 (DBusDirIter, 1);
673 dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
674 "Could not allocate memory for directory iterator");
684 * Get next file in the directory. Will not return "." or ".." on
685 * UNIX. If an error occurs, the contents of "filename" are
686 * undefined. The error is never set if the function succeeds.
688 * This function is not re-entrant, and not necessarily thread-safe.
689 * Only use it for test code or single-threaded utilities.
691 * @param iter the iterator
692 * @param filename string to be set to the next file in the dir
693 * @param error return location for error
694 * @returns #TRUE if filename was filled in with a new filename
697 _dbus_directory_get_next_file (DBusDirIter *iter,
698 DBusString *filename,
704 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
708 ent = readdir (iter->d);
715 dbus_set_error (error,
716 _dbus_error_from_errno (err),
717 "%s", _dbus_strerror (err));
721 else if (ent->d_name[0] == '.' &&
722 (ent->d_name[1] == '\0' ||
723 (ent->d_name[1] == '.' && ent->d_name[2] == '\0')))
727 _dbus_string_set_length (filename, 0);
728 if (!_dbus_string_append (filename, ent->d_name))
730 dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
731 "No memory to read directory entry");
742 * Closes a directory iteration.
745 _dbus_directory_close (DBusDirIter *iter)
752 fill_user_info_from_group (struct group *g,
756 _dbus_assert (g->gr_name != NULL);
758 info->gid = g->gr_gid;
759 info->groupname = _dbus_strdup (g->gr_name);
761 /* info->members = dbus_strdupv (g->gr_mem) */
763 if (info->groupname == NULL)
765 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
773 fill_group_info (DBusGroupInfo *info,
775 const DBusString *groupname,
778 const char *group_c_str;
780 _dbus_assert (groupname != NULL || gid != DBUS_GID_UNSET);
781 _dbus_assert (groupname == NULL || gid == DBUS_GID_UNSET);
784 group_c_str = _dbus_string_get_const_data (groupname);
788 /* For now assuming that the getgrnam() and getgrgid() flavors
789 * always correspond to the pwnam flavors, if not we have
790 * to add more configure checks.
793 #if defined (HAVE_POSIX_GETPWNAM_R) || defined (HAVE_NONPOSIX_GETPWNAM_R)
802 /* retrieve maximum needed size for buf */
803 buflen = sysconf (_SC_GETGR_R_SIZE_MAX);
805 /* sysconf actually returns a long, but everything else expects size_t,
806 * so just recast here.
807 * https://bugs.freedesktop.org/show_bug.cgi?id=17061
809 if ((long) buflen <= 0)
815 buf = dbus_malloc (buflen);
818 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
823 #ifdef HAVE_POSIX_GETPWNAM_R
825 result = getgrnam_r (group_c_str, &g_str, buf, buflen,
828 result = getgrgid_r (gid, &g_str, buf, buflen,
831 g = getgrnam_r (group_c_str, &g_str, buf, buflen);
833 #endif /* !HAVE_POSIX_GETPWNAM_R */
834 /* Try a bigger buffer if ERANGE was returned:
835 https://bugs.freedesktop.org/show_bug.cgi?id=16727
837 if (result == ERANGE && buflen < 512 * 1024)
848 if (result == 0 && g == &g_str)
850 b = fill_user_info_from_group (g, info, error);
856 dbus_set_error (error, _dbus_error_from_errno (errno),
857 "Group %s unknown or failed to look it up\n",
858 group_c_str ? group_c_str : "???");
863 #else /* ! HAVE_GETPWNAM_R */
865 /* I guess we're screwed on thread safety here */
868 g = getgrnam (group_c_str);
872 return fill_user_info_from_group (g, info, error);
876 dbus_set_error (error, _dbus_error_from_errno (errno),
877 "Group %s unknown or failed to look it up\n",
878 group_c_str ? group_c_str : "???");
882 #endif /* ! HAVE_GETPWNAM_R */
886 * Initializes the given DBusGroupInfo struct
887 * with information about the given group name.
889 * @param info the group info struct
890 * @param groupname name of group
891 * @param error the error return
892 * @returns #FALSE if error is set
895 _dbus_group_info_fill (DBusGroupInfo *info,
896 const DBusString *groupname,
899 return fill_group_info (info, DBUS_GID_UNSET,
905 * Initializes the given DBusGroupInfo struct
906 * with information about the given group ID.
908 * @param info the group info struct
909 * @param gid group ID
910 * @param error the error return
911 * @returns #FALSE if error is set
914 _dbus_group_info_fill_gid (DBusGroupInfo *info,
918 return fill_group_info (info, gid, NULL, error);
922 * Parse a UNIX user from the bus config file. On Windows, this should
923 * simply always fail (just return #FALSE).
925 * @param username the username text
926 * @param uid_p place to return the uid
927 * @returns #TRUE on success
930 _dbus_parse_unix_user_from_config (const DBusString *username,
933 return _dbus_get_user_id (username, uid_p);
938 * Parse a UNIX group from the bus config file. On Windows, this should
939 * simply always fail (just return #FALSE).
941 * @param groupname the groupname text
942 * @param gid_p place to return the gid
943 * @returns #TRUE on success
946 _dbus_parse_unix_group_from_config (const DBusString *groupname,
949 return _dbus_get_group_id (groupname, gid_p);
953 * Gets all groups corresponding to the given UNIX user ID. On UNIX,
954 * just calls _dbus_groups_from_uid(). On Windows, should always
955 * fail since we don't know any UNIX groups.
958 * @param group_ids return location for array of group IDs
959 * @param n_group_ids return location for length of returned array
960 * @returns #TRUE if the UID existed and we got some credentials
963 _dbus_unix_groups_from_uid (dbus_uid_t uid,
964 dbus_gid_t **group_ids,
967 return _dbus_groups_from_uid (uid, group_ids, n_group_ids);
971 * Checks to see if the UNIX user ID is at the console.
972 * Should always fail on Windows (set the error to
973 * #DBUS_ERROR_NOT_SUPPORTED).
975 * @param uid UID of person to check
976 * @param error return location for errors
977 * @returns #TRUE if the UID is the same as the console user and there are no errors
980 _dbus_unix_user_is_at_console (dbus_uid_t uid,
983 return _dbus_is_console_user (uid, error);
988 * Checks to see if the UNIX user ID matches the UID of
989 * the process. Should always return #FALSE on Windows.
991 * @param uid the UNIX user ID
992 * @returns #TRUE if this uid owns the process.
995 _dbus_unix_user_is_process_owner (dbus_uid_t uid)
997 return uid == _dbus_geteuid ();
1001 * Checks to see if the Windows user SID matches the owner of
1002 * the process. Should always return #FALSE on UNIX.
1004 * @param windows_sid the Windows user SID
1005 * @returns #TRUE if this user owns the process.
1008 _dbus_windows_user_is_process_owner (const char *windows_sid)
1013 /** @} */ /* End of DBusInternalsUtils functions */
1016 * @addtogroup DBusString
1021 * Get the directory name from a complete filename
1022 * @param filename the filename
1023 * @param dirname string to append directory name to
1024 * @returns #FALSE if no memory
1027 _dbus_string_get_dirname (const DBusString *filename,
1028 DBusString *dirname)
1032 _dbus_assert (filename != dirname);
1033 _dbus_assert (filename != NULL);
1034 _dbus_assert (dirname != NULL);
1036 /* Ignore any separators on the end */
1037 sep = _dbus_string_get_length (filename);
1039 return _dbus_string_append (dirname, "."); /* empty string passed in */
1041 while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
1044 _dbus_assert (sep >= 0);
1047 return _dbus_string_append (dirname, "/");
1049 /* Now find the previous separator */
1050 _dbus_string_find_byte_backward (filename, sep, '/', &sep);
1052 return _dbus_string_append (dirname, ".");
1054 /* skip multiple separators */
1055 while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
1058 _dbus_assert (sep >= 0);
1061 _dbus_string_get_byte (filename, 0) == '/')
1062 return _dbus_string_append (dirname, "/");
1064 return _dbus_string_copy_len (filename, 0, sep - 0,
1065 dirname, _dbus_string_get_length (dirname));
1067 /** @} */ /* DBusString stuff */
1070 string_squash_nonprintable (DBusString *str)
1075 buf = _dbus_string_get_data (str);
1076 len = _dbus_string_get_length (str);
1078 for (i = 0; i < len; i++)
1080 unsigned char c = (unsigned char) buf[i];
1083 else if (c < 0x20 || c > 127)
1089 * Get a printable string describing the command used to execute
1090 * the process with pid. This string should only be used for
1091 * informative purposes such as logging; it may not be trusted.
1093 * The command is guaranteed to be printable ASCII and no longer
1096 * @param pid Process id
1097 * @param str Append command to this string
1098 * @param max_len Maximum length of returned command
1099 * @param error return location for errors
1100 * @returns #FALSE on error
1103 _dbus_command_for_pid (unsigned long pid,
1108 /* This is all Linux-specific for now */
1113 if (!_dbus_string_init (&path))
1115 _DBUS_SET_OOM (error);
1119 if (!_dbus_string_init (&cmdline))
1121 _DBUS_SET_OOM (error);
1122 _dbus_string_free (&path);
1126 if (!_dbus_string_append_printf (&path, "/proc/%ld/cmdline", pid))
1129 fd = open (_dbus_string_get_const_data (&path), O_RDONLY);
1132 dbus_set_error (error,
1133 _dbus_error_from_errno (errno),
1134 "Failed to open \"%s\": %s",
1135 _dbus_string_get_const_data (&path),
1136 _dbus_strerror (errno));
1140 if (!_dbus_read (fd, &cmdline, max_len))
1142 dbus_set_error (error,
1143 _dbus_error_from_errno (errno),
1144 "Failed to read from \"%s\": %s",
1145 _dbus_string_get_const_data (&path),
1146 _dbus_strerror (errno));
1150 if (!_dbus_close (fd, error))
1153 string_squash_nonprintable (&cmdline);
1155 if (!_dbus_string_copy (&cmdline, 0, str, _dbus_string_get_length (str)))
1158 _dbus_string_free (&cmdline);
1159 _dbus_string_free (&path);
1162 _DBUS_SET_OOM (error);
1164 _dbus_string_free (&cmdline);
1165 _dbus_string_free (&path);