Changeset 700c712 for owl.c


Ignore:
Timestamp:
Sep 25, 2002, 3:59:56 PM (22 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
55faab7
Parents:
601a9e0
Message:
Started adding code for newmsgproc.  It doesn't fully work yet!
  Don't use it!
File:
1 edited

Legend:

Unmodified
Added
Removed
  • owl.c

    r601a9e0 r700c712  
    2121#include <time.h>
    2222#include <sys/param.h>
     23#include <sys/types.h>
     24#include <sys/wait.h>
     25#include <errno.h>
    2326#include "owl.h"
    2427
     
    325328    if (newzephyrs && followlast) {
    326329      owl_function_lastmsg_noredisplay();
     330    }
     331
     332    /* check if newmsgproc is active, if not but the option is on,
     333       make it active */
     334    if (newzephyrs) {
     335      if (owl_global_get_newmsgproc(&g) && strcmp(owl_global_get_newmsgproc(&g), "")) {
     336        /* if there's a process out there, we need to check on it */
     337        if (owl_global_get_newmsgproc_pid(&g)) {
     338          owl_function_debugmsg("Checking on newmsgproc pid==%i", owl_global_get_newmsgproc_pid(&g));
     339          owl_function_debugmsg("Waitpid return is %i", waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG));
     340          waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG);
     341          if (waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG)==-1) {
     342            /* it exited */
     343            owl_global_set_newmsgproc_pid(&g, 0);
     344            owl_function_debugmsg("newmsgproc exited");
     345          } else {
     346            owl_function_debugmsg("newmsgproc did not exit");
     347          }
     348        }
     349       
     350        /* if it exited, fork & exec a new one */
     351        if (owl_global_get_newmsgproc_pid(&g)==0) {
     352          int i, argc;
     353          i=fork();
     354          if (i) {
     355            /* parent set the child's pid */
     356            owl_global_set_newmsgproc_pid(&g, i);
     357            waitpid(i, NULL, WNOHANG);
     358            owl_function_debugmsg("I'm the parent and I started a new newmsgproc with pid %i", i);
     359          } else {
     360            /* child exec's the program */
     361            char **parsed;
     362           
     363            parsed=owl_parseline(owl_global_get_newmsgproc(&g), &argc);
     364            parsed=realloc(parsed, strlen(owl_global_get_newmsgproc(&g)+300));
     365            parsed[argc]='\0';
     366
     367            owl_function_debugmsg("About to exec: -%s- with %i arguments", parsed[0], argc);
     368
     369            execvp(*parsed, parsed);
     370           
     371
     372            /* was there an error exec'ing? */
     373            owl_function_debugmsg("Error execing: %s", strerror(errno));
     374            _exit(127);
     375          }
     376        }
     377      }
    327378    }
    328379   
Note: See TracChangeset for help on using the changeset viewer.