------------------------------------------------------------
revno: 1470
committer: James Hunt <[email protected]>
branch nick: upstart
timestamp: Thu 2013-03-28 16:55:36 +0000
message:
  * extra/upstart-event-bridge.c: main():
    - Handle daemon pidfile as the upstart-event-bridge does.
    - Write to stdout, not syslog.
modified:
  ChangeLog
  extra/upstart-file-bridge.c


--
lp:upstart
https://code.launchpad.net/~upstart-devel/upstart/trunk

Your team Upstart Reviewers is subscribed to branch lp:upstart.
To unsubscribe from this branch go to 
https://code.launchpad.net/~upstart-devel/upstart/trunk/+edit-subscription
=== modified file 'ChangeLog'
--- ChangeLog	2013-03-28 09:52:16 +0000
+++ ChangeLog	2013-03-28 16:55:36 +0000
@@ -2,6 +2,9 @@
 
 	* scripts/upstart-monitor.py: on_button_press_event():
 	  Handle path_info being None (LP: #1161098).
+	* extra/upstart-event-bridge.c: main():
+	  - Handle daemon pidfile as the upstart-event-bridge does.
+	  - Write to stdout, not syslog.
 
 2013-03-25  James Hunt  <[email protected]>
 

=== modified file 'extra/upstart-file-bridge.c'
--- extra/upstart-file-bridge.c	2013-03-19 20:22:44 +0000
+++ extra/upstart-file-bridge.c	2013-03-28 16:55:36 +0000
@@ -416,11 +416,15 @@
 main (int   argc,
       char *argv[])
 {
-	char          **args;
-	DBusConnection *connection;
-	char          **job_class_paths;
-	int             ret;
-	char           *user_session_addr = NULL;
+	char               **args;
+	char               **job_class_paths;
+	DBusConnection      *connection;
+	char                *pidfile_path = NULL;
+	char                *pidfile = NULL;
+	char                *user_session_addr = NULL;
+	nih_local char     **user_session_path = NULL;
+	char                *path_element = NULL;
+	int                  ret;
 
 	nih_main_init (argv[0]);
 
@@ -537,6 +541,32 @@
 
 	/* Become daemon */
 	if (daemonise) {
+		/* Deal with the pidfile location when becoming a daemon.
+		 * We need to be able to run one bridge per upstart daemon.
+		 * Store the PID file in XDG_RUNTIME_DIR or HOME and include the pid of
+		 * the Upstart instance (last part of the DBus path) in the filename.
+		 */
+
+		/* Extract PID from UPSTART_SESSION */
+		user_session_path = nih_str_split (NULL, user_session_addr, "/", TRUE);
+		for (int i = 0; user_session_path[i] != NULL; i++)
+			path_element = user_session_path[i];
+
+		if (! path_element) {
+			nih_fatal (_("Invalid value for UPSTART_SESSION"));
+			exit (1);
+		}
+
+		pidfile_path = getenv ("XDG_RUNTIME_DIR");
+		if (! pidfile_path)
+			pidfile_path = getenv ("HOME");
+
+		if (pidfile_path) {
+			NIH_MUST (nih_strcat_sprintf (&pidfile, NULL, "%s/upstart-file-bridge.%s.pid",
+					                        pidfile_path, path_element));
+			nih_main_set_pidfile (pidfile);
+		}
+
 		if (nih_main_daemonise () < 0) {
 			NihError *err;
 
@@ -545,12 +575,8 @@
 				   err->message);
 			nih_free (err);
 
-			exit (EXIT_FAILURE);
+			exit (1);
 		}
-
-		/* Send all logging output to syslog */
-		openlog (program_name, LOG_PID, LOG_DAEMON);
-		nih_log_set_logger (nih_logger_syslog);
 	}
 
 	if (user) {
@@ -574,6 +600,10 @@
 
 	ret = nih_main_loop ();
 
+	/* Destroy any PID file we may have created */
+	if (daemonise)
+		nih_main_unlink_pidfile();
+
 	return ret;
 }
 

-- 
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/upstart-devel

Reply via email to