------------------------------------------------------------
revno: 1408
committer: James Hunt <[email protected]>
branch nick: upstart-setenv+getenv
timestamp: Wed 2012-12-19 16:26:16 +0000
message:
  * dbus/com.ubuntu.Upstart.xml: Added ListEnv method.
  * init/control.c:
    - Fixed comments.
    - control_list_end(): New function.
  * init/control.h:
    - Added missing prototypes for control_set_env() and
      control_get_env().
    - Added control_list_env().
  * init/job_class.c:
    - job_class_environment_get(): New function.
  * init/job_class.h: Added job_class_environment_get().
modified:
  dbus/com.ubuntu.Upstart.xml
  init/control.c
  init/control.h
  init/job_class.c
  init/job_class.h


--
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 'dbus/com.ubuntu.Upstart.xml'
--- dbus/com.ubuntu.Upstart.xml	2012-12-19 09:08:57 +0000
+++ dbus/com.ubuntu.Upstart.xml	2012-12-19 16:26:16 +0000
@@ -52,6 +52,10 @@
       <arg name="replace" type="b" direction="in" />
     </method>
 
+    <method name="ListEnv">
+      <arg name="env" type="as" direction="out" />
+    </method>
+
     <!-- Signals for changes to the job list -->
     <signal name="JobAdded">
       <arg name="job" type="o" />

=== modified file 'init/control.c'
--- init/control.c	2012-12-19 09:08:57 +0000
+++ init/control.c	2012-12-19 16:26:16 +0000
@@ -1180,11 +1180,10 @@
  * @name: name of environment variable to retrieve,
  * @value: value of @name.
  *
- * Implements the SetEnv method of the com.ubuntu.Upstart
+ * Implements the GetEnv method of the com.ubuntu.Upstart
  * interface.
  *
- * Called to request Upstart store a particular name/value pair that
- * will be exported to all jobs' environments.
+ * Called to obtain the value of a specified job environment variable.
  *
  * Returns: zero on success, negative value on raised error.
  **/
@@ -1215,14 +1214,14 @@
 		return 0;
 	}
 
-	/* Disallow users from changing Upstarts environment, unless they happen to
+	/* Disallow users from querying Upstarts environment, unless they happen to
 	 * own this process (which they may do in the test scenario and
 	 * when running Upstart as a non-privileged user).
 	 */
 	if (session && session->user != uid) {
 		nih_dbus_error_raise_printf (
 			DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
-			_("You do not have permission to modify the init environment"));
+			_("You do not have permission to query the init environment"));
 		return -1;
 	}
 
@@ -1244,3 +1243,54 @@
 			_("No such variable"), name);
 	return -1;
 }
+
+/**
+ * control_list_env:
+ *
+ * @data: not used,
+ * @message: D-Bus connection and message received,
+ * @env: pointer to array of all job environment variables.
+ *
+ * Implements the ListEnv method of the com.ubuntu.Upstart
+ * interface.
+ *
+ * Called to obtain an array of all environment variables that will be
+ * set in a jobs environment.
+ *
+ * Returns: zero on success, negative value on raised error.
+ **/
+int
+control_list_env (void            *data,
+		 NihDBusMessage   *message,
+		 char           ***env)
+{
+	Session     *session;
+	uid_t        uid;
+
+	nih_assert (message != NULL);
+	nih_assert (env);
+
+	/* Get the relevant session */
+	session = session_from_dbus (NULL, message);
+
+	uid = getuid ();
+
+	/* Disallow users from querying Upstarts environment, unless they happen to
+	 * own this process (which they may do in the test scenario and
+	 * when running Upstart as a non-privileged user).
+	 */
+	if (session && session->user != uid) {
+		nih_dbus_error_raise_printf (
+			DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
+			_("You do not have permission to query the init environment"));
+		return -1;
+	}
+
+	job_class_environment_init ();
+
+	*env = job_class_environment_get (message);
+	if (! *env)
+		nih_return_no_memory_error (-1);
+
+	return 0;
+}

=== modified file 'init/control.h'
--- init/control.h	2012-12-14 23:43:15 +0000
+++ init/control.h	2012-12-19 16:26:16 +0000
@@ -118,6 +118,24 @@
 void control_notify_event_emitted (Event *event);
 void control_notify_restarted (void);
 
+int control_set_env (void           *data,
+		 NihDBusMessage *message,
+		 const char     *var,
+		 int             replace)
+	__attribute__ ((warn_unused_result));
+
+int control_get_env (void             *data,
+		 NihDBusMessage   *message,
+		 char             *name,
+		 char            **value)
+	__attribute__ ((warn_unused_result));
+
+int
+control_list_env (void             *data,
+		 NihDBusMessage   *message,
+		 char           ***env)
+	__attribute__ ((warn_unused_result));
+
 NIH_END_EXTERN
 
 #endif /* INIT_CONTROL_H */

=== modified file 'init/job_class.c'
--- init/job_class.c	2012-12-19 09:08:57 +0000
+++ init/job_class.c	2012-12-19 16:26:16 +0000
@@ -119,9 +119,29 @@
 		job_environ = NIH_MUST (nih_str_array_new (NULL));
 		NIH_MUST (environ_append (&job_environ, NULL, 0, TRUE, default_environ));
 	}
-
-}
-
+}
+
+/**
+ * job_class_environment_get:
+ *
+ * Obtain a copy of the environment a job will be provided with.
+ *
+ * Returns: Newly-allocated copy of the job environment array, or NULL
+ * on error.
+ **/
+char **
+job_class_environment_get (const void *parent)
+{
+	char   **env = NULL;
+
+	job_class_environment_init ();
+
+	env = nih_str_array_copy (parent, NULL, job_environ);
+	if (! env)
+		return NULL;
+
+	return env;
+}
 
 /**
  * job_class_new:

=== modified file 'init/job_class.h'
--- init/job_class.h	2012-12-19 09:08:57 +0000
+++ init/job_class.h	2012-12-19 16:26:16 +0000
@@ -347,6 +347,9 @@
 
 void job_class_prepare_reexec (void);
 
+char ** job_class_environment_get (const void *parent)
+	__attribute__ ((warn_unused_result, malloc));
+
 NIH_END_EXTERN
 
 #endif /* INIT_JOB_CLASS_H */

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

Reply via email to