View Single Post

  #1 (permalink)  
Old 03-07-2008, 12:16 PM
rajnivanza rajnivanza is offline
Junior Member
User
 
Join Date: Mar 2008
My distro: FEDRORA
Posts: 1
Rep Power: 0
rajnivanza is on a distinguished road
Default Xlib: connection to ":0.0" refused by server and Xlib: No protocol specified

hi everybody,

i have problem regarding KDE environment.
i want to open gedit/kwrite application through program from one linux machine to another linux machine.
its work well when login user as "root" but when login user as "normal user" then display error.

I have written given below code:

cCommand = "gedit" / "kwrite"
uname = "/root" / "/home/rajni"

int executeCommand( char *cCommand )
{
char *uname = malloc (sizeof(char) * UNAME_MAX);
if(homeDir(uname) == FAILURE) {
free( uname );
setError( FNAME, "[Error] : homeDir() failed\n" );
return FAILURE;
}

pid_t pid=fork(); //don't know how vfork and environ works together.
if(pid==-1)
{
setError(FNAME,"fork failed. executeCommand()\n");
return FAILURE;
}
else if(pid == 0) //child
{
setenv("HOME",uname,1); //proper solutions pending. see ~/.Xauthority, xauth etc.
setenv("DISPLAY",":0.0",1);
free( uname );
exit(system(cCommand)); //beware of: return(system(cCommand));
}
else //parent
{
sleep(1); //let the child run first
int status;
if (waitpid (pid, &status, WNOHANG) == pid)
{
if (WIFEXITED (statu && WEXITSTATUS (statu == 32512) //system() returns this on
//system(unexistsing_bin);
{
char msg[100];
sprintf(msg,"unable to execute %s. executeComamnd()\n",cCommand);
setError (FNAME,msg); //not working. debug it.
return FAILURE;
}
}
}
return SUCCESS;
}

we get right username path and display error as :
->Xlib: connection to ":0.0" refused by server
->Xlib: No protocol specified

and so,it can't execute the "gedit" / "kwrite" Xcommand successful.

Why is this happening, and how do I fix it?

I would be very grateful if I could receive your favorable reply.

Thanks!!
Reply With Quote