cathcing `mozilla -remote ping()` within c++

Here is my problem. An extension and alternative to my initial post $BROWSER variable

This is what I have done so far to counter it.

In my application, I have used

/usr/bin/mozilla -remote "openURL(URL)"

The -remote makes sure that I go and open the URL in an existing instance of mozilla.

This is what is happening inside. I start the server. Login with a user. Sync the data on the client. After that the server restarts itself and gives a login page to the user who just did the sync.

If I am user U1 and have the server running in the context of U1, then the above will work.

But if I am user U2 on the same machine, using the server running on U1, then while doing an execv on the above shows me the following at the prompt of U1.

No running window found.

This message is shown when mozilla doesnt find a running instance of the /usr/bin/mozilla.

Now, there is another option,

/usr/bin/mozilla -remote "ping()"

which will tell me if there is an instance of mozilla running or not. My problem is how can I capture the result of the above ping command inside my application.(if it possible).

Possible work-arounds that you may come up is:

  1. Give a
/usr/bin/mozilla "openURL(URL)"

. I know that and do not want to use that.
2. Use /usr/bin/mozilla -remote "ping()" in a shell script. I need to run the whole thing within the context of the application. No using external scripts.

uname -a is
Linux xxxxxxx 2.4.21-27.ELsmp #1 SMP Wed Dec 1 21:59:02 EST 2004 i686 i686 i386 GNU/Linux

I will try to give you as much details(if needed), but I cant give out the code. Company policy.

Thanks,
vino

Looks like no one has faced this problem before.

Anyway here is a solution. I am exploiting the following fact.

@mozilla is not running for user1.
[user1]$ mozilla -remote ping()
No running window found.
[user1]$ echo $?
2
[user1]$
@mozilla is running for current user1
[user1]$ mozilla -remote ping()
[user1]$ echo $?
0
[user1]$ 

Which means if there is no instance of mozilla running, then it throws up No running window found. i.e. output will come via stderr

To confirm the above case, here is a snippet of the relevant lines from the strace output.

write(2, "No running window found.\n", 25No running window found.
) = 25

If there is an instance of mozilla running, then no such line will be found.

Here is the relevant code.

#include <stdio.h>
#include <string.h>
main()
{
        FILE* pipe;
        char str[25] = { 0 };
        pipe=popen("/usr/bin/mozilla -remote \"ping()\" 2>&1","r");

        // No running window found. 
        // or 
        // Error: No running window found.        
        // is what we are trying to capture. 
        // Anything else, is same as nada.

        // Caution.
        // Might have to increase the size from 25 to 32
        fgets(str,25,pipe);
        printf("%s",str);

        pclose(pipe);
}

Based on the contents of str, we can move ahead.

Vino