On Tue, 22 Mar 2011, Enlightenment SVN wrote:

> Log:
> Use pipes for sending commands

can you use ecore_pipe, please ?

Vincent

>
> Author:       nash
> Date:         2011-03-22 02:04:28 -0700 (Tue, 22 Mar 2011)
> New Revision: 57970
> Trac:         http://trac.enlightenment.org/e/changeset/57970
>
> Modified:
>  trunk/ensure/src/ensure.c trunk/ensure/src/ensure.h 
> trunk/ensure/src/libensure.c
>
> Modified: trunk/ensure/src/ensure.c
> ===================================================================
> --- trunk/ensure/src/ensure.c 2011-03-22 09:04:26 UTC (rev 57969)
> +++ trunk/ensure/src/ensure.c 2011-03-22 09:04:28 UTC (rev 57970)
> @@ -35,13 +35,13 @@
>
>
>
> -Evas_Object *window_add(struct ensure *ensure, char **argv);
> +int window_add(struct ensure *ensure, char **argv);
>
> static void on_run(void *data, Evas_Object *button, void *event_info);
> static void on_check(void *data, Evas_Object *button, void *event_info);
>
>
> -static void dochild(char **args, int fd);
> +static void dochild(char **args, int fd, int commandfd);
>
> static int signal_init(void);
> static Eina_Bool signalfd_child(void *data, Ecore_Fd_Handler *fd_handler);
> @@ -113,7 +113,7 @@
>       }
>       ensure->args = argv + 1;
>
> -        mainwindow = window_add(ensure, argv);
> +        window_add(ensure, argv);
>
>       signal_init();
>
> @@ -128,7 +128,7 @@
>
>
>
> -Evas_Object *
> +int
> window_add(struct ensure *ensure, char **args){
>         Evas_Object *win,*bg,*bx,*ctrls,*run,*check,*gl;
>       Evas_Object *viewbx, *view, *lbl;
> @@ -199,18 +199,6 @@
>         evas_object_size_hint_weight_set(ctrls, EVAS_HINT_EXPAND, 0);
>         evas_object_size_hint_align_set(ctrls, EVAS_HINT_FILL, 
> EVAS_HINT_FILL);
>
> -
> -     /* Buttons: Main event is the 'clicked' event */
> -     /*
> -     config = elm_button_add(ctrls);
> -     elm_button_label_set(config, "Config");
> -     elm_button_autorepeat_set(config, false);
> -     elm_box_pack_start(ctrls, config);
> -     evas_object_show(config);
> -     evas_object_smart_callback_add(config, "clicked", on_switch_config,
> -                     NULL);
> -     */
> -
>       run = elm_button_add(ctrls);
>       elm_button_label_set(run, "Run");
>       elm_button_autorepeat_set(run, false);
> @@ -234,8 +222,7 @@
>       evas_object_resize(win, 320, 480);
>       evas_object_show(win);
>
> -        /* Urh.. the list widget for now */
> -        return gl;
> +        return 0;
>
> }
>
> @@ -522,11 +509,9 @@
>       ensure->results = eina_list_prepend(ensure->results, res);
>       ensure->cur = res;
>
> -     printf("Sending kill to %d\n",childid);
> -     if (kill(childid, SIGUSR2))
> -             perror("kill(child, SIGUSR2))");
> +     printf("Sending check to %d\n",childid);
> +     write(ensure->commandfd,"Check\n",6);
>       printf("Done\n");
> -
> }
>
>
> @@ -539,6 +524,7 @@
> on_run(void *ensurev, Evas_Object *button ensure_unused, void *event_info 
> ensure_unused){
>       pid_t pid;
>       int pipefd[2];
> +     int sendpipefd[2];
>       struct ensure *ensure = ensurev;
>
>       elm_object_disabled_set(runbutton, true);
> @@ -550,6 +536,11 @@
>               fprintf(stderr,"Unable to create pipe\n");
>               return;
>       }
> +     if (pipe(sendpipefd)){
> +             fprintf(stderr,"Unable to create send pipe\n");
> +             return;
> +     }
> +     ensure->commandfd = sendpipefd[1];
>
>       /* Watch the fd */
>       ecore_main_fd_handler_add(pipefd[0], ECORE_FD_READ, child_data,
> @@ -564,11 +555,13 @@
>               break;
>       case 0:
>               close(pipefd[0]);
> -             dochild(ensure->args,pipefd[1]);
> +             close(sendpipefd[1]);
> +             dochild(ensure->args,pipefd[1],sendpipefd[0]);
>               exit(7);
>       default:
>               /* Parent */
>               close(pipefd[1]);
> +             close(sendpipefd[0]);
>               childid = pid;
>               break;
>       }
> @@ -580,12 +573,12 @@
>  * Run the child process
>  */
> static void
> -dochild(char **args, int fd){
> -     char buf[4];
> +dochild(char **args, int fd, int commandfd){
> +     char buf[30];
>
> //    setlinebuf(fd);
>       setenv("LD_PRELOAD", LIBENSURE_DIR "/libensure.so",1);
> -     snprintf(buf, sizeof(buf), "%d",fd);
> +     snprintf(buf, sizeof(buf), "%d:%d",fd, commandfd);
>       setenv("ENSURE_FD", buf, 1);
>       execvp(args[0],args);
>       perror("execvp");
>
> Modified: trunk/ensure/src/ensure.h
> ===================================================================
> --- trunk/ensure/src/ensure.h 2011-03-22 09:04:26 UTC (rev 57969)
> +++ trunk/ensure/src/ensure.h 2011-03-22 09:04:28 UTC (rev 57970)
> @@ -52,6 +52,8 @@
>
>       struct result *cur;
>       Eina_List *results;
> +
> +     int commandfd;
> };
>
>
>
> Modified: trunk/ensure/src/libensure.c
> ===================================================================
> --- trunk/ensure/src/libensure.c      2011-03-22 09:04:26 UTC (rev 57969)
> +++ trunk/ensure/src/libensure.c      2011-03-22 09:04:28 UTC (rev 57970)
> @@ -1,8 +1,6 @@
> #include <limits.h>
> #include <stdio.h>
> -#include <signal.h>
> #include <stdbool.h>
> -#include <sys/signalfd.h>
> #include <unistd.h>
>
>
> @@ -16,8 +14,7 @@
> #define ensure_unused __attribute__((unused))
>
> static Eina_Bool libensure_dump(void);
> -static Eina_Bool ecore_signal(void *data, int tyoe, void *event);
> -static Eina_Bool ecore_fd_signal(void *data ensure_unused, Ecore_Fd_Handler 
> *fdh);
> +static Eina_Bool libensure_command_recv(void *data ensure_unused, 
> Ecore_Fd_Handler *fdh);
>
> static void libensure_objdump(Evas_Object *o, Evas_Object *parent);
>
> @@ -27,38 +24,30 @@
>
> __attribute__((constructor)) void
> libensure_init(void){
> -     int fd;
> -     int sendfd;
> +     int sendfd, commandfd;
>       const char *p;
> -     sigset_t sigusr2;
>
>       if (verbose == -1)
>               verbose = !!getenv("LIBENSURE_DEBUG");
>
>       ecore_init();
>
> -     sigemptyset(&sigusr2);
> -     sigaddset(&sigusr2, SIGUSR2);
> -
> -     fd = signalfd(-1, &sigusr2, SFD_CLOEXEC | SFD_NONBLOCK);
> -     if (fd == -1){
> -             perror("signalfd");
> -             exit(1);
> -     }
> -     if (verbose) fprintf(stderr,"Signal fd is %d\n",fd);
> -     ecore_main_fd_handler_add(fd,ECORE_FD_READ|ECORE_FD_ERROR,
> -                     ecore_fd_signal, NULL,
> -                     NULL, NULL);
> -
> -     ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER, ecore_signal, NULL);
> -
>       p = getenv("ENSURE_FD");
>       if (p){
> -             sendfd = strtol(p, NULL, 0);
> -             if (verbose) fprintf(stderr,"LibEnsure: Using fd %d!\n",sendfd);
> +             if (verbose) fprintf(stderr,"ENSURE_FD=%s",p);
> +             sscanf(p, "%d:%d", &sendfd, &commandfd);
> +             if (verbose) fprintf(stderr,"LibEnsure: Send: %d Command %d!\n",
> +                             sendfd, commandfd);
>               outfile = fdopen(sendfd, "w");
> +     } else {
> +             fprintf(stderr,"Warning: No send/command fd\n");
> +             exit(0);
>       }
>
> +     ecore_main_fd_handler_add(commandfd,ECORE_FD_READ|ECORE_FD_ERROR,
> +                     libensure_command_recv, NULL,
> +                     NULL, NULL);
> +
>       if (!outfile) {
>               if(verbose) fprintf(stderr,"LibEnsure: Warning using stdout\n");
>               outfile = stdout;
> @@ -70,25 +59,24 @@
> }
>
> static Eina_Bool
> -ecore_signal(void *data, int tyoe, void *event){
> -     Ecore_Event_Signal_User *user = event;
> -     if (!event || user->number != 2) return 1;
> -
> -     libensure_dump();
> -
> -     return 0;
> -}
> -
> -static Eina_Bool
> -ecore_fd_signal(void *data ensure_unused, Ecore_Fd_Handler *fdh){
> -     struct signalfd_siginfo siginfo;
> +libensure_command_recv(void *data ensure_unused, Ecore_Fd_Handler *fdh){
> +     char buf[100];
> +     char *save;
>       int fd;
>
>       fd = ecore_main_fd_handler_fd_get(fdh);
>
> -     read(fd, &siginfo, sizeof(struct signalfd_siginfo));
> +     read(fd, buf, sizeof(buf));
> +     strtok_r(buf, "\n\r", &save);
>
> -     libensure_dump();
> +     if (strncmp(buf, "Check", 5) == 0){
> +             libensure_dump();
> +     } else if (strncmp(buf, "Highlight:", 10) == 0){
> +             printf("Got highlight: Unimplemented\n");
> +     } else {
> +             printf("Unknown command: %s\n",buf);
> +     }
> +
>       return 0;
> }
>
>
>
> ------------------------------------------------------------------------------
> Enable your software for Intel(R) Active Management Technology to meet the
> growing manageability and security demands of your customers. Businesses
> are taking advantage of Intel(R) vPro (TM) technology - will your software
> be a part of the solution? Download the Intel(R) Manageability Checker
> today! http://p.sf.net/sfu/intel-dev2devmar
> _______________________________________________
> enlightenment-svn mailing list
> enlightenment-...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/enlightenment-svn
>
>

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to