dbus/dbus dbus-sysdeps.h,1.43,1.44 dbus-sysdeps.c,1.81,1.82

Colin Walters walters at freedesktop.org
Fri Oct 29 12:59:17 PDT 2004


Update of /cvs/dbus/dbus/dbus
In directory gabe:/tmp/cvs-serv27378/dbus

Modified Files:
	dbus-sysdeps.h dbus-sysdeps.c 
Log Message:
2004-10-29  Colin Walters  <walters at redhat.com>

	* dbus/dbus-sysdeps.h (_dbus_become_daemon): Also take
	parameter for fd to write pid to.	

	* dbus/dbus-sysdeps.c (_dbus_become_daemon): Implement it.
	
	* bus/bus.c (bus_context_new): Pass print_pid_fd
	to _dbus_become_daemon (bug #1720)


Index: dbus-sysdeps.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps.h,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- dbus-sysdeps.h	9 Sep 2004 10:20:17 -0000	1.43
+++ dbus-sysdeps.h	29 Oct 2004 19:59:14 -0000	1.44
@@ -298,6 +298,7 @@
 void        _dbus_print_backtrace  (void);
 
 dbus_bool_t _dbus_become_daemon   (const DBusString *pidfile,
+				   int               print_pid_fd,
                                    DBusError        *error);
 dbus_bool_t _dbus_write_pid_file  (const DBusString *filename,
                                    unsigned long     pid,

Index: dbus-sysdeps.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- dbus-sysdeps.c	25 Oct 2004 18:48:58 -0000	1.81
+++ dbus-sysdeps.c	29 Oct 2004 19:59:14 -0000	1.82
@@ -3131,11 +3131,13 @@
  * Does the chdir, fork, setsid, etc. to become a daemon process.
  *
  * @param pidfile #NULL, or pidfile to create
+ * @param print_pid_fd file descriptor to print pid to, or -1 for none
  * @param error return location for errors
  * @returns #FALSE on failure
  */
 dbus_bool_t
 _dbus_become_daemon (const DBusString *pidfile,
+		     int               print_pid_fd,
                      DBusError        *error)
 {
   const char *s;
@@ -3201,6 +3203,42 @@
               return FALSE;
             }
         }
+
+      /* Write PID if requested */
+      if (print_pid_fd >= 0)
+	{
+	  DBusString pid;
+	  int bytes;
+	  
+	  if (!_dbus_string_init (&pid))
+	    {
+	      _DBUS_SET_OOM (error);
+              kill (child_pid, SIGTERM);
+	      return FALSE;
+	    }
+	  
+	  if (!_dbus_string_append_int (&pid, _dbus_getpid ()) ||
+	      !_dbus_string_append (&pid, "\n"))
+	    {
+	      _dbus_string_free (&pid);
+	      _DBUS_SET_OOM (error);
+              kill (child_pid, SIGTERM);
+	      return FALSE;
+	    }
+	  
+	  bytes = _dbus_string_get_length (&pid);
+	  if (_dbus_write (print_pid_fd, &pid, 0, bytes) != bytes)
+	    {
+	      dbus_set_error (error, DBUS_ERROR_FAILED,
+			      "Printing message bus PID: %s\n",
+			      _dbus_strerror (errno));
+	      _dbus_string_free (&pid);
+              kill (child_pid, SIGTERM);
+	      return FALSE;
+	    }
+	  
+	  _dbus_string_free (&pid);
+	}
       _dbus_verbose ("parent exiting\n");
       _exit (0);
       break;



More information about the dbus-commit mailing list