Note that there are some explanatory texts on larger screens.

plurals
  1. POexecl doesn't work in a while(1) loop, server side; C script
    text
    copied!<p>I have a problem with a little C script which should run as a server and launch a popup for every message arriving. The <a href="http://linux.about.com/library/cmd/blcmdl3_execl.htm" rel="nofollow noreferrer">execl</a> syntax is correct because if I try a little script with </p> <pre><code>main() { execl(...); } </code></pre> <p>it works.</p> <p>When I put it in a while(1) loop it doesn't work. Everything else is working, like <code>printf</code> or string operation, but not the <code>execl</code>. Even if I fork it doesn't work. How can I make it work?</p> <p>And I've tried with the <code>fork()</code>, but it doesn't work either.</p> <p>Here's the complete server C code.</p> <pre><code>#include &lt;arpa/inet.h&gt; #include &lt;netinet/in.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/socket.h&gt; #include &lt;unistd.h&gt; #include &lt;string.h&gt; #define BUFLEN 512 #define PORT 9930 void diep(char *s) { perror(s); exit(1); } int main() { struct sockaddr_in si_me, si_other; int s, i, slen=sizeof(si_other), broadcastPermission; char buf[100], zeni[BUFLEN]; if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1) diep("socket"); broadcastPermission = 1; if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, (void *) &amp;broadcastPermission, sizeof(broadcastPermission)) &lt; 0) diep("setsockopt() failed"); memset((char *) &amp;si_me, 0, sizeof(si_me)); si_me.sin_family = AF_INET; si_me.sin_port = htons(PORT); si_me.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(s, &amp;si_me, sizeof(si_me))==-1) diep("bind"); while (1) { if (recvfrom(s, buf, BUFLEN, 0, &amp;si_other, &amp;slen)==-1) diep("recvfrom()"); //printf("Received packet from %s:%d\nData: %s\n", inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port), buf); strcpy(zeni, ""); strcat(zeni, "zenity --warning --title Hack!! --text "); strcat(zeni, buf); printf("cmd: %s\n", zeni); //system (zeni); execl("/usr/bin/zenity", "/usr/bin/zenity", "--warning", "--title", "Warn!", "--text", buf, (char *) NULL); } close(s); return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload