J'écris un démon de serveur simple et fonctionne avec /etc/init.d/server son fonctionnement correctement, mais quand je veux exécuter une interface graphique QT simple avec system() fonction, il n'est pas capable de l'exécuter et retourne 256 comme code de retour.Comment exécuter l'application GUI à partir du serveur de démon de démarrage défini par l'utilisateur
si le même démon s'exécute à partir du terminal, alors il fonctionne correctement et la fonction system() obtient le succès avec la valeur de retour 0 et l'interface graphique est surgie.
Quel est le problème im ne pas obtenir .... plzzzz quelqu'un peut me aider ..........
im en utilisant ubuntu-9.10 ci-dessous est le 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;
}
ce qui est le démon sans tête je n'ai pas? – user258190
C'est un démon qui n'utilise pas d'affichage. –
alors comment démarrer GUI à partir du démon parce que ma solution est comme ça quand je vais envoyer une demande alors que la fonction system() démarre le gui? ... plz si un concept me dire .... et quoi que vous soyez disant que cela fonctionne parfaitement, c'est une autre partie de ma solution .... – user258190