Subject: Patch for FvwmM4/Cpp and "Bugs report"

From: Olivier Chapuis <[email-masked]>
Date: Mon, 27 Sep 1999 13:23:35 +0200

Hello,
I have noted some problems with FvwmM4 (and FvwmCpp).

Assume that you start fvwm in your .xinitrc with fvwm2 -cmd "FvwmM4 .fvwm2rc".
Do : cd somewherebutHOME, startx
Then this does not work, since FvwmM4 try to "m4" the file  
somewherebutHOME/.fvwm2rc
You can imagine other problems, the point is that FvwmM4 does not honor
the "user_home_dir" (=$FVWM_USERHOME if set, or $HOME).

Attached to this message a patch that solved these kind of problems. I
do a very simple thing: I change the workingdir to user_home_dir
before popening m4/cpp.
Also I add the "macro" FVWM_USERHOME and SESSION_MANAGER, these macros
are set to the value of their corresponding environment variable if 
there are not NULL.

Patch description:

Modified files:
        modules         : ChangeLog 
        modules/FvwmM4  : FvwmM4.c, FvwmM4.1
        modules/FvwmCpp : FvwmCpp.c, FvwmCpp.1

NOTE 0: 
I would like to add other definitions for compile-time options
(e.g., HAVE_RPLAY,  ...). There is a macro for that called OPTION
with a list of options (at the present time XPM SHAPE I18N_MB M4/CPP
may be in this "list"). However, it does not seem easy to
use OPTION. I suggest to add other definitions for the main compile
time options: we can reproduce  config.h (e.g., define HAVE_RPLAY
to 1 if it is defined to 1 in config.h, does not define it if it is
not defined in config.h). If you think it is a good idea I can do
a patch.

NOTE 1:
There is a problem with SESSION_MANAGER and in fact with the session
code:
Assume that fvwm run under session on display :0. Then, run fvwm (not
under session and under the same user) on display :1. The problem
is that the second fvwm process think that it runs under session (e.g.,
it executes SessionInitFunc and my patch define SESSION_MANAGER !).

NOTE 2:
It seems that there are small problems if you start fvwm2 as
fvwm2 -cmd "FvwmM4 .fvwm2rc":

A. No more watch during startup :o( ok this is not a problem: user
which use FvwmM4/Cpp can do that with "hands".

B. Assume you run fvwm under session on display :0. If you try to run
fvwm under session on display :1 with the usual command line (just fvwm2), 
then fvwm exit. Find (note that gnome does not exit and 
gnome cannot run two sessions for the same user in a good way ... :o) ). 
However, if you run the second fvwm process under session with the command 
line fvwm2 -cmd "FvwmM4 .fvwm2rc", then in this case fvwm2  does not exit.

C. With gnome, we can see the apps of the "save session" during
startup.

To try to solve B & C I have moved the following lines (of fvwm/fvwm.c)

#ifdef SESSION
  SessionInit(client_id);
#endif

#ifdef GNOME
  GNOME_Init();
#endif

just after the lines:

DBUG("main","Setting up rc file defaults...");
SetRCDefaults();

It seems that this solved B but not C. 
However, I do not really understand all the consequence of the above change ...

Yours, Olivier

Index: modules/ChangeLog
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/ChangeLog,v
retrieving revision 1.304
diff -u -b -B -u -r1.304 ChangeLog
--- modules/ChangeLog	1999/09/26 21:12:04	1.304
+++ modules/ChangeLog	1999/09/27 11:25:54
@@ -1,3 +1,12 @@
+1999-09-27 Olivier Chapuis <[email-masked]>
+	
+	* FvwmM4/FvwmM4.c (m4_defs): 
+	* FvwmM4/FvwmM4.1:
+	* FvwmCpp/FvwmCpp.c (cpp_defs):
+	* FvwmCpp/FvwmCpp.1:
+	Change dir to the "good" directory before popen m4/cpp. 
+	Add FVWM_USERHOME and SESSION_MANAGER.
+
 1999-09-26  Dominik Vogt  <[email-masked]>
 
 	* FvwmTaskBar/ButtonArray.c (find_n): fixed bug that totally screwed up
Index: modules/FvwmCpp/FvwmCpp.1
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmCpp/FvwmCpp.1,v
retrieving revision 1.10
diff -u -b -B -u -r1.10 FvwmCpp.1
--- modules/FvwmCpp/FvwmCpp.1	1999/08/14 22:50:23	1.10
+++ modules/FvwmCpp/FvwmCpp.1	1999/09/27 11:25:55
@@ -73,6 +73,8 @@
 The operating system for CLIENTHOST.
 .IP USER
 The name of the person running fvwm.
+.IP HOME
+The home directory of the person running fvwm.
 .IP VERSION
 The X11 version.
 .IP REVISION
@@ -109,6 +111,10 @@
 .IP FVWM_MODULEDIR
 The directory where fvwm looks for .fvwmrc and modules by default, as
 determined at compile time.
+.IP FVWM_USERHOME
+The value of $FVWM_USERHOME. Undefined if this variable is not set.
+.IP SESSION_MANAGER
+The value of $SESSION_MANAGER. Undefined if this variable is not set.
 
 .SH EXAMPLE PROLOG
 
@@ -135,7 +141,8 @@
 #define FVWM_VERSION 2.0 pl 1
 #define OPTIONS SHAPE XPM Cpp
 #define FVWM_MODULEDIR /local/homes/dsp/nation/modules
-
+#define FVWM_USERHOME /local/homes/dsp/nation/.fvwm2rc.d
+#define SESSION_MANAGER local/grumpy:/tmp/.ICE-unix/440,tcp/spx20:1025
 .EE
 
 .SH BUGS
Index: modules/FvwmCpp/FvwmCpp.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmCpp/FvwmCpp.c,v
retrieving revision 1.21
diff -u -b -B -u -r1.21 FvwmCpp.c
--- modules/FvwmCpp/FvwmCpp.c	1999/09/24 15:05:17	1.21
+++ modules/FvwmCpp/FvwmCpp.c	1999/09/27 11:25:57
@@ -200,7 +200,25 @@
   int fd;
   int ScreenWidth, ScreenHeight;
   int Mscreen;
+  char *user_home_dir;
 
+  /* Figure out the wroking directory and go to it */
+  user_home_dir = getenv("FVWM_USERHOME");
+  if ( user_home_dir == NULL )
+    user_home_dir = getenv("HOME");
+#ifdef HAVE_GETPWUID
+  if ( user_home_dir == NULL ) {
+    struct passwd* pw = getpwuid(getuid());
+    if ( pw != NULL )
+      user_home_dir = strdup( pw->pw_dir );
+  }
+#endif
+  if ( user_home_dir != NULL ) {
+    if ( chdir(user_home_dir) < 0 ) 
+      fprintf(stderr, "%s: <<Warning>> chdir to %s failed in m4_defs",
+	      MyName, user_home_dir);
+  }
+
   /* Generate a temporary filename.  Honor the TMPDIR environment variable,
      if set. Hope nobody deletes this file! */
 
@@ -381,6 +400,13 @@
 
   fputs(MkDef("FVWM_MODULEDIR", FVWM_MODULEDIR), tmpf);
   fputs(MkDef("FVWM_CONFIGDIR", FVWM_CONFIGDIR), tmpf);
+  
+  if (vc=getenv("FVWM_USERHOME"))
+     fputs(MkDef("FVWM_USERHOME", vc), tmpf);
+#ifdef SESSION
+  if (vc=getenv("SESSION_MANAGER"))
+    fputs(MkDef("SESSION_MANAGER", vc), tmpf);
+#endif
 
   /*
    * At this point, we've sent the definitions to cpp.  Just include
Index: modules/FvwmM4/FvwmM4.1
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmM4/FvwmM4.1,v
retrieving revision 1.6
diff -u -b -B -u -r1.6 FvwmM4.1
--- modules/FvwmM4/FvwmM4.1	1999/06/23 12:41:31	1.6
+++ modules/FvwmM4/FvwmM4.1	1999/09/27 11:25:57
@@ -91,6 +91,8 @@
 The operating system for CLIENTHOST.
 .IP USER
 The name of the person running fvwm.
+.IP HOME
+The home directory of the person running fvwm.
 .IP VERSION
 The X11 version.
 .IP REVISION
@@ -127,6 +129,10 @@
 .IP FVWM_MODULEDIR
 The directory where fvwm looks for .fvwmrc and modules by default, as
 determined at compile time.
+.IP FVWM_USERHOME
+The value of $FVWM_USERHOME. Undefined if this variable is not set.
+.IP SESSION_MANAGER
+The value of $SESSION_MANAGER. Undefined if this variable is not set.
 
 .SH EXAMPLE PROLOG
 
@@ -153,6 +159,8 @@
 define(FVWM_VERSION,``1.24l'')dnl
 define(OPTIONS,``SHAPE XPM M4 '')dnl
 define(FVWM_MODULEDIR,``/local/homes/dsp/nation/modules'')dnl
+define(FVWM_USERHOME,``/local/homes/dsp/nation/.fvwm2rc.d'')dnl
+define(SESSION_MANAGER,``local/grumpy:/tmp/.ICE-unix/440,tcp/spx20:1025'')dnl
 .EE
 
 .SH AUTHOR
Index: modules/FvwmM4/FvwmM4.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmM4/FvwmM4.c,v
retrieving revision 1.19
diff -u -b -B -u -r1.19 FvwmM4.c
--- modules/FvwmM4/FvwmM4.c	1999/09/24 15:05:18	1.19
+++ modules/FvwmM4/FvwmM4.c	1999/09/27 11:25:57
@@ -215,7 +215,25 @@
   int fd;
   int ScreenWidth, ScreenHeight;
   int Mscreen;
+  char *user_home_dir;
 
+  /* Figure out the working directory and go to it */
+  user_home_dir = getenv("FVWM_USERHOME");
+  if ( user_home_dir == NULL )
+    user_home_dir = getenv("HOME");
+#ifdef HAVE_GETPWUID
+  if ( user_home_dir == NULL ) {
+    struct passwd* pw = getpwuid(getuid());
+    if ( pw != NULL )
+      user_home_dir = strdup( pw->pw_dir );
+  }
+#endif
+  if ( user_home_dir != NULL ) {
+    if ( chdir(user_home_dir) < 0 ) 
+      fprintf(stderr, "%s: <<Warning>> chdir to %s failed in m4_defs",
+	      MyName, user_home_dir);
+  }
+  
   /* Generate a temporary filename.  Honor the TMPDIR environment variable,
      if set. Hope nobody deletes this file! */
 
@@ -411,6 +429,13 @@
 
   fputs(MkDef("FVWM_MODULEDIR", FVWM_MODULEDIR), tmpf);
   fputs(MkDef("FVWM_CONFIGDIR", FVWM_CONFIGDIR), tmpf);
+
+  if (vc=getenv("FVWM_USERHOME"))
+     fputs(MkDef("FVWM_USERHOME", vc), tmpf);
+#ifdef SESSION
+  if (vc=getenv("SESSION_MANAGER"))
+    fputs(MkDef("SESSION_MANAGER", vc), tmpf);
+#endif
 
   /*
    * At this point, we've sent the definitions to m4.  Just include

---

From: Dominik Vogt <[email-masked]>
Date: Tue, 28 Sep 1999 00:44:14 +0200

On Mon, Sep 27, 1999 at 01:23:35PM +0200, Olivier Chapuis wrote:
>...
>... patches 

Can you please disassemble the patches into different files?
This patch is too complicated for me :-)

Bye

Dominik ^_^

--
Dominik Vogt, [email-masked]
Reply-To: [email-masked]
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Olivier Chapuis <[email-masked]>
Date: Tue, 28 Sep 1999 07:19:39 +0200

> This patch is too complicated for me :-)

What is the problem?
olivier

---

From: Dominik Vogt <[email-masked]>
Date: Tue, 28 Sep 1999 12:22:53 +0200

> > This patch is too complicated for me :-)

Several patches that seem to be a bit dangerous in a single patch.

Bye

Dominik ^_^

-- 
Dominik Vogt, Hewlett-Packard GmbH, Dept. BVS
Herrenberger Str.130, 71034 Boeblingen, Germany
phone: 07031/14-4596, fax: 07031/14-3883, [email-masked]
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Olivier Chapuis <[email-masked]>
Date: Tue, 28 Sep 1999 15:04:05 +0200

> Several patches that seem to be a bit dangerous in a single patch.

Ok,
Forget all my "NOTE*" in my first message :o), my patch
does not concern these notes.
I have attached 3 patches one for M4, one for Cpp and one
for the ChangeLog.
I think that these patches are not dangerous
(I use intensively FvwmM4 with this patch and it works well).
I have added two new values FVWM_USERHOME and SESSION_MANAGER,
and with these patches M4/Cpp will chdir to the "user_home_dir"
so that m4/cpp make this directory as their working directories.
Since the value "HOME" has been omitted in the man page I add it.
There are quite symmetric since Cpp / M4 are (it was the reason I do
it in one patch). Maybe you can just apply the M4 patch and probably
a bit mutation will produce automatically the corresponding change
to Cpp :o). Maybe these patches are not good ideas, but ...

Olivier

 .SH EXAMPLE PROLOG
 
@@ -135,7 +141,8 @@
 
 .SH BUGS

@@ -381,6 +400,13 @@

   /*

Index: modules/ChangeLog

 
 .SH EXAMPLE PROLOG
 
@@ -153,6 +159,8 @@
 
 .SH AUTHOR

@@ -411,6 +429,13 @@

   /*

---

From: Dominik Vogt <[email-masked]>
Date: Tue, 28 Sep 1999 15:35:56 +0200

> to Cpp :o). Maybe these patches are not good ideas, but ...

Okay, I have applied the patches.  Now, if you could again explain
in a few simple words (so that idiots like me are able to understand)
what the other patch you sent was supposed to do?  Your original mail
was so long that I became utterly confused :-)

Bye

Dominik ^_^

---

From: Olivier Chapuis <[email-masked]>
Date: Wed, 29 Sep 1999 12:13:24 +0200

> was so long that I became utterly confused :-)

Hello,
First of all, I am sorry for my english !
In my first message there are only the patch that you applied. I have 
made the error to add comments which was not directly concerned by the 
patch that I have send. This one contains no patch and it is in two
parts (+ a "bye").

#----------------------------------------------------------------------------

PART 1: Starting fvwm with FvwmM4/Cpp

Assume that you start fvwm in your .xsession/.xinitrc script with the
command line:
	fvwm -cmd "FvwmM4 .fvwm2rc"
Then:
	1. fvwm do its "init"
	2. fvwm executes the command line: executeModule FvwmM4
	3. fvwm go to its "main loop"
	4. So now fvwm run :o)

the point is that fvwm read the file preprocessed by FvwmM4
at step 4. This implies some *litle* problems
    a. No more watch cursor during startup.
    b. If you use gnome, the applications of the saved
       session flash or are clearly visible during "startup".
    c. SessionInit("client-id") may some time work in an unexpected way

Last night I have modified FvwmM4 so that if you start fvwm
with the command line

fvwm2 -cmd "ModuleSynchronous FvwmM4 -noread -outfile .fvwm2rc
Main.fvwm" -cmd "Read .fvwm2rc"

(noread is a new option which 
	i. implies  m4-debug;
	ii. report the "I have finished my startup and now I am running" 
	    message of M4 to fvwm *after* that FvwmM4 has closed its 
	    pipe to m4;
	iii. Does not say to fvwm to read the preprocessed file.)

Then:   1. fvwm do its "init"
       	2. fvwm executes "ModuleSynchronous FvwmM4 ...." and  * write
.fvwm2rc *
	3. fvwm executes "Read .fvwm2rc"
	4. fvwm has finish to run its options and then create the resize
	   window, SessionInit, ..., Go to its events loop, ...

That is: we can start fvwm in the same way that with the command line
	fvwm2 -cmd "Read .fvwm2rc"
This solved problem b. and c. but not a. because I think that FvwmM4
kill the watch cursor ( but we may add a -cursor option to M4 :o).
Moreover, I think that it is a more "generic" way to start fvwm with
a preprocessor and this can avoid future problems (but as usual
with fvwm the user can choose and use M4/Cpp as before ! ).

So the QUESTION is : Do you want such a patch ??
(I have tested it with --enable-debug-msgs)

Do not read this: Maybe a we can implement a new executeModule function:
executeModuleAndFunc: it will executeModule, then wait for a "message"
from  the  module (as executeModuleSync), then execute "command" at once
if
the module ask it in is "message", then fvwm will come back to the "main
loop".

#--------------------------------------------------------------------

PART 2: Add More value to FvwmM4/Cpp ?

I would like to add other values to FvwmM4/Cpp for compile-time options
(e.g., HAVE_RPLAY,  ...). There is a value for that called OPTION
with a list of options (at the present time XPM SHAPE I18N_MB M4/CPP
may be in this "list"). However, it does not seem easy to
use OPTION. I suggest to add other definitions for the main compile
time options: we can reproduce  main config.h values (e.g., define 
CTO_HAVE_RPLAY to 1 in Cpp/M4 if it is defined to 1 in config.h, does 
not define it in Cpp/M4 if it is not defined in config.h). 
If you think it is a good idea I can do a patch (or add this to
the previous one).

#--------------------------------------------------------------------
BYE:

Yes, I am sorry, this message is very long. I hope it is clear but my
english does not allow me to be as clear as I would like. 
But, print it and go to take a coffee with it.
Moreover, I have to show you that I begin to understand the fvwm code, 
so that you can trust me :o). 

Yours, Olivier

---

From: Olivier Chapuis <[email-masked]>
Date: Thu, 30 Sep 1999 09:12:14 +0200

> patch that I have send. This one contains no patch and it is in two

Ok, ModuleSynchronous can do that ! So the patch is now with
a -start option which forces to send the message "ok I am runing"
after that FvwmM4 closed is pipe with m4.
However, I still do not understand why the watch cursor disapear ...
Olivier
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]