change log for rtems (2010-09-08)

rtems-vc at rtems.org rtems-vc at rtems.org
Wed Sep 8 08:10:14 UTC 2010


 *sh*:
2010-09-08	Sebastian Huber <sebastian.huber at embedded-brains.de>

	PR 1698/cpukit
	* libcsupport/src/privateenv.c: Check return values of
	rtems_filesystem_evaluate_path().

M 1.2624  cpukit/ChangeLog
M   1.17  cpukit/libcsupport/src/privateenv.c

diff -u rtems/cpukit/ChangeLog:1.2623 rtems/cpukit/ChangeLog:1.2624
--- rtems/cpukit/ChangeLog:1.2623	Wed Sep  1 06:12:37 2010
+++ rtems/cpukit/ChangeLog	Wed Sep  8 02:31:28 2010
@@ -1,3 +1,9 @@
+2010-09-08	Sebastian Huber <sebastian.huber at embedded-brains.de>
+
+	PR 1698/cpukit
+	* libcsupport/src/privateenv.c: Check return values of
+	rtems_filesystem_evaluate_path().
+
 2010-09-01	Ralf Corsépius <ralf.corsepius at rtems.org>
 
 	PR 1696/networking:

diff -u rtems/cpukit/libcsupport/src/privateenv.c:1.16 rtems/cpukit/libcsupport/src/privateenv.c:1.17
--- rtems/cpukit/libcsupport/src/privateenv.c:1.16	Sun Aug 29 14:49:52 2010
+++ rtems/cpukit/libcsupport/src/privateenv.c	Wed Sep  8 02:31:28 2010
@@ -21,16 +21,8 @@
 
 #include <rtems.h>
 #include <rtems/chain.h>
-#include <rtems/libio.h>
 #include <rtems/libio_.h>
 
-#if defined(RTEMS_DEBUG)
-   #define CHECK_STATUS(_x) assert((_x) == )
-   #include <assert.h>
-#else
-   #define CHECK_STATUS(_x) _x
-#endif
-
 /* cleanup a user environment
  * NOTE: this must be called with
  *       thread dispatching disabled!
@@ -53,11 +45,20 @@
 
 rtems_status_code rtems_libio_set_private_env(void)
 {
-  rtems_status_code                 sc;
-  rtems_id                          task_id;
-  rtems_filesystem_location_info_t  loc;
-
-  task_id = rtems_task_self();
+  rtems_status_code sc = RTEMS_SUCCESSFUL;
+  rtems_id task_id = rtems_task_self();
+  rtems_filesystem_location_info_t root_loc;
+  rtems_filesystem_location_info_t current_loc;
+  rtems_user_env_t *new_env = NULL;
+  int rv = 0;
+
+  rv = rtems_filesystem_evaluate_path("/", 1, 0, &root_loc, 0);
+  if (rv != 0)
+    goto error_0;
+
+  rv = rtems_filesystem_evaluate_path("/", 1, 0, &current_loc, 0);
+  if (rv != 0)
+    goto error_1;
 
   /* 
    * Malloc is necessary whenever the current task does not
@@ -72,14 +73,16 @@
    * if( rtems_current_user_env->task_id != task_id ) {
    */
 
-  if (rtems_current_user_env==&rtems_global_user_env || 
-      rtems_current_user_env->task_id != task_id ) {
-    rtems_user_env_t *tmp = malloc(sizeof(rtems_user_env_t));
-    if (!tmp)
-      return RTEMS_NO_MEMORY;
+  if (
+    rtems_current_user_env == &rtems_global_user_env
+      || rtems_current_user_env->task_id != task_id
+  ) {
+    new_env = malloc(sizeof(rtems_user_env_t));
+    if (new_env == NULL)
+      goto error_2;
 
     #ifdef HAVE_USERENV_REFCNT
-      tmp->refcnt = 1;
+      new_env->refcnt = 1;
     #endif
 
     sc = rtems_task_variable_add(
@@ -87,35 +90,39 @@
       (void*)&rtems_current_user_env,
       (void(*)(void *))free_user_env
     );
-    if (sc != RTEMS_SUCCESSFUL) {
-      /* don't use free_user_env because the pathlocs are
-       * not initialized yet
-       */
-       free(tmp);
-       return sc;
-     }
-     rtems_current_user_env = tmp;
+    if (sc != RTEMS_SUCCESSFUL)
+      goto error_3;
+
+    rtems_current_user_env = new_env;
   }
 
-  *rtems_current_user_env = rtems_global_user_env; /* get the global values*/
-  rtems_current_user_env->task_id=task_id;         /* mark the local values*/
+  /* Inherit the global values */
+  *rtems_current_user_env = rtems_global_user_env;
 
-  /*  Clone the pathlocs. In contrast to most other code we must _not_
-   *  free the original locs because what we are trying to do here is forking
-   *  off clones. The reason is a pathloc can be allocated by the file system
-   *  and needs to be freed when deleting the environment.
-   *
-   *  NOTE: Evaluation should always work so only check status when debug
-   *        is enabled.
+  rtems_current_user_env->task_id = task_id;
+
+  /*
+   * Clone the pathlocs. In contrast to most other code we must _not_ free the
+   * original locs because what we are trying to do here is forking off clones.
+   * The reason is a pathloc can be allocated by the file system and needs to
+   * be freed when deleting the environment.
    */
+  rtems_filesystem_root = root_loc;
+  rtems_filesystem_current = current_loc;
+
+  return RTEMS_SUCCESSFUL;
 
-  CHECK_STATUS( rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0) );
-  rtems_filesystem_root    = loc;
+error_3:
+  free(new_env);
 
-  CHECK_STATUS( rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0) );
-  rtems_filesystem_current = loc;
+error_2:
+  rtems_filesystem_freenode(&current_loc);
 
-  return RTEMS_SUCCESSFUL;
+error_1:
+  rtems_filesystem_freenode(&root_loc);
+
+error_0:
+  return RTEMS_NO_MEMORY;
 }
 
 /*



--

Generated by Deluxe Loginfo [http://www.codewiz.org/projects/index.html#loginfo] 2.122 by Bernardo Innocenti <bernie at develer.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/vc/attachments/20100908/56dab004/attachment.html>


More information about the vc mailing list