LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-19-2010, 03:51 AM   #1
vikhyat@linux
LQ Newbie
 
Registered: Sep 2009
Posts: 2

Rep: Reputation: 0
Unhappy How to run GUI application from userdefined boot time daemon server


Dear All,
I am writing one simple server daemon and running with /etc/init.d/server
its running properly but when i want to run one simple QT GUI with system() function , its not able to run it and returning 256 as return code .

if same daemon i m running from terminal then its working properly and also system() function is getting success with return value 0 and GUI is getting popped up.

What is the problem i m not getting ....
plzzzz can any one help me..........

i m using ubuntu-9.10
below is the code ....

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <syslog.h>

int main()
{
//local variables
int sockfd,clifd,ret;
int client_flag = 0;
int server_flag = 1;
struct sockaddr_in server_addr,client_addr;
socklen_t client_len ;
int server_len;

daemon(0, 0);


/* open log file */
setlogmask(LOG_UPTO(LOG_INFO));
openlog("server:", LOG_CONS | LOG_PID, LOG_LOCAL2);


//creating the socket
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd < 0){
perror("Error socket creation:");
return sockfd;
}

//filling the socket address detail

server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(8181);
server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
server_len = sizeof(server_addr);

//binding the socket
ret = bind(sockfd, (struct sockaddr *)&server_addr,server_len);
if(ret < 0){
perror("Error in bind");
return ret;
}

//creating the listening queue
ret = listen(sockfd, 10);
if(ret < 0){
perror("Error in listen");
return ret;
}

while(1){
//accepting the connection from client

client_len = sizeof(client_addr);
clifd = accept(sockfd, (struct sockaddr *)&client_addr, &client_len);
if(clifd < 0){
perror("Error in accept in server_init ");
return clifd;
}

client_flag = 0;

//reading the client_flag
ret = read(clifd, &client_flag,sizeof(client_flag));
if(ret < 0){
perror("Error in read");
return ret;
}

// if flag is true i want to run the GUI "console"
//console is Qt4 application
if(client_flag) {
syslog(LOG_NOTICE," *************** \n");

/* Here its returning 256 is if it is running from boot time and if after boot i will restrat it from terminal like "/etc/init.d/server restart" then it will return 0 success and GUI will popped up properly.*/

ret = system("/usr/sbin/test/console 1") ;

syslog(LOG_NOTICE," *************** %d\n",ret);


}
//writing the server_flag
ret = write(clifd, &server_flag,sizeof(server_flag));
if(ret < 0){
perror("Error in write");
return ret;
}


close(clifd);
}

closelog();
close(sockfd);
return 0;

}

Last edited by vikhyat@linux; 01-19-2010 at 10:26 PM. Reason: code
 
Old 01-19-2010, 09:17 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,553

Rep: Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946
Quote:
Originally Posted by vikhyat@linux View Post
Dear All,
I am writing one simple server daemon and running with /etc/init.d/server
its running properly but when i want to run one simple QT GUI with system() function , its not able to run it and returning 256 as return code .

if same daemon i m running from terminal then its working properly and also system() function is getting success with return value 0 and GUI is getting popped up.

What is the problem i m not getting ....
plzzzz can any one help me..........

Thanksssss.......
Spell out your words.

And perhaps if you actually provided some useful information, we could help. Things like version/distro of Linux? What the code is? What kidn of hardware?

All we know now is, you've written something, and it's returning 256. Short answer is: fix and debug your code. Longer answer: post some relevant parts of your code, actual details/errors, and maybe we can help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run GUI application from userdefined boot time daemon server vikhyat@linux Linux - Newbie 1 01-19-2010 09:15 AM
Configure an application to run as a daemon in Fedora 12 Ness_Wiggin Linux - Server 2 11-29-2009 11:50 PM
How can I automatically start a daemon at boot time. iamjayanth Linux - Software 5 12-18-2008 12:55 AM
hot to auto start oracle application server on Redhat AS3 at the boot time procfs Linux - Software 2 05-22-2007 11:42 PM
How to run app as daemon on boot? kalahari875 Mandriva 1 06-03-2004 10:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration