Merge from trunk
[bpt/emacs.git] / src / xsmfns.c
index cb3773f..7b82fd4 100644 (file)
@@ -45,10 +45,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 /* Avoid "differ in sign" warnings */
 #define SSDATA(x)  ((char *) SDATA (x))
 
-/* The user login name.  */
-
-extern Lisp_Object Vuser_login_name;
-
 /* This is the event used when SAVE_SESSION_EVENT occurs.  */
 
 static struct input_event emacs_event;
@@ -91,7 +87,7 @@ Lisp_Object Vx_session_previous_id;
 /* The option to start Emacs without the splash screen when
    restarting Emacs.  */
 
-#define NOSPLASH_OPT "--no-splash"
+static char NOSPLASH_OPT[] = "--no-splash";
 
 /* The option to make Emacs start in the given directory.  */
 
@@ -202,14 +198,14 @@ smc_save_yourself_CB (SmcConn smcConn,
   SmPropValue values[20];
   int val_idx = 0;
   int props_idx = 0;
-
+  int i;
   char *cwd = NULL;
   char *smid_opt, *chdir_opt = NULL;
 
   /* How to start a new instance of Emacs.  */
   props[props_idx] = &prop_ptr[props_idx];
-  props[props_idx]->name = SmCloneCommand;
-  props[props_idx]->type = SmLISTofARRAY8;
+  props[props_idx]->name = xstrdup (SmCloneCommand);
+  props[props_idx]->type = xstrdup (SmLISTofARRAY8);
   props[props_idx]->num_vals = 1;
   props[props_idx]->vals = &values[val_idx++];
   props[props_idx]->vals[0].length = strlen (emacs_program);
@@ -218,8 +214,8 @@ smc_save_yourself_CB (SmcConn smcConn,
 
   /* The name of the program.  */
   props[props_idx] = &prop_ptr[props_idx];
-  props[props_idx]->name = SmProgram;
-  props[props_idx]->type = SmARRAY8;
+  props[props_idx]->name = xstrdup (SmProgram);
+  props[props_idx]->type = xstrdup (SmARRAY8);
   props[props_idx]->num_vals = 1;
   props[props_idx]->vals = &values[val_idx++];
   props[props_idx]->vals[0].length = strlen (SSDATA (Vinvocation_name));
@@ -228,8 +224,8 @@ smc_save_yourself_CB (SmcConn smcConn,
 
   /* How to restart Emacs.  */
   props[props_idx] = &prop_ptr[props_idx];
-  props[props_idx]->name = SmRestartCommand;
-  props[props_idx]->type = SmLISTofARRAY8;
+  props[props_idx]->name = xstrdup (SmRestartCommand);
+  props[props_idx]->type = xstrdup (SmLISTofARRAY8);
   /* /path/to/emacs, --smid=xxx --no-splash --chdir=dir */
   props[props_idx]->num_vals = 4;
   props[props_idx]->vals = &values[val_idx];
@@ -262,8 +258,8 @@ smc_save_yourself_CB (SmcConn smcConn,
 
   /* User id.  */
   props[props_idx] = &prop_ptr[props_idx];
-  props[props_idx]->name = SmUserID;
-  props[props_idx]->type = SmARRAY8;
+  props[props_idx]->name = xstrdup (SmUserID);
+  props[props_idx]->type = xstrdup (SmARRAY8);
   props[props_idx]->num_vals = 1;
   props[props_idx]->vals = &values[val_idx++];
   props[props_idx]->vals[0].length = strlen (SSDATA (Vuser_login_name));
@@ -274,8 +270,8 @@ smc_save_yourself_CB (SmcConn smcConn,
   if (cwd)
     {
       props[props_idx] = &prop_ptr[props_idx];
-      props[props_idx]->name = SmCurrentDirectory;
-      props[props_idx]->type = SmARRAY8;
+      props[props_idx]->name = xstrdup (SmCurrentDirectory);
+      props[props_idx]->type = xstrdup (SmARRAY8);
       props[props_idx]->num_vals = 1;
       props[props_idx]->vals = &values[val_idx++];
       props[props_idx]->vals[0].length = strlen (cwd);
@@ -290,6 +286,11 @@ smc_save_yourself_CB (SmcConn smcConn,
   xfree (chdir_opt);
 
   free (cwd);
+  for (i = 0; i < props_idx; ++i)
+    {
+      xfree (props[i]->type);
+      xfree (props[i]->name);
+    }
 
   /* See if we maybe shall interact with the user.  */
   if (interactStyle != SmInteractStyleAny
@@ -409,8 +410,8 @@ create_client_leader_window (struct x_display_info *dpyinfo, char *client_id)
   XSetClassHint (dpyinfo->display, w, &class_hints);
   XStoreName (dpyinfo->display, w, class_hints.res_name);
 
-  sm_id = XInternAtom (dpyinfo->display, "SM_CLIENT_ID", False);
-  XChangeProperty (dpyinfo->display, w, sm_id, XA_STRING, 8, PropModeReplace,
+  XChangeProperty (dpyinfo->display, w, dpyinfo->Xatom_SM_CLIENT_ID,
+                   XA_STRING, 8, PropModeReplace,
                    (unsigned char *)client_id, strlen (client_id));
 
   dpyinfo->client_leader_window = w;