Changeset 8f44c6b for functions.c


Ignore:
Timestamp:
Feb 9, 2003, 10:08:38 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:
7e3e00a
Parents:
ddb8252
Message:
Changed version to 2.0.1-pre-1
Moved the (broken) newmsgproc stuff it a function procedure
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    rd309eb3 r8f44c6b  
    88#include <sys/types.h>
    99#include <sys/stat.h>
     10#include <sys/wait.h>
     11#include <errno.h>
    1012#include "owl.h"
    1113
     
    25282530  fclose(file);
    25292531}
     2532
     2533
     2534
     2535void owl_function_do_newmsgproc() {
     2536  if (owl_global_get_newmsgproc(&g) && strcmp(owl_global_get_newmsgproc(&g), "")) {
     2537    /* if there's a process out there, we need to check on it */
     2538    if (owl_global_get_newmsgproc_pid(&g)) {
     2539      owl_function_debugmsg("Checking on newmsgproc pid==%i", owl_global_get_newmsgproc_pid(&g));
     2540      owl_function_debugmsg("Waitpid return is %i", waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG));
     2541      waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG);
     2542      if (waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG)==-1) {
     2543        /* it exited */
     2544        owl_global_set_newmsgproc_pid(&g, 0);
     2545        owl_function_debugmsg("newmsgproc exited");
     2546      } else {
     2547        owl_function_debugmsg("newmsgproc did not exit");
     2548      }
     2549    }
     2550   
     2551    /* if it exited, fork & exec a new one */
     2552    if (owl_global_get_newmsgproc_pid(&g)==0) {
     2553      int i, myargc;
     2554      i=fork();
     2555      if (i) {
     2556        /* parent set the child's pid */
     2557        owl_global_set_newmsgproc_pid(&g, i);
     2558        waitpid(i, NULL, WNOHANG);
     2559        owl_function_debugmsg("I'm the parent and I started a new newmsgproc with pid %i", i);
     2560      } else {
     2561        /* child exec's the program */
     2562        char **parsed;
     2563        parsed=owl_parseline(owl_global_get_newmsgproc(&g), &myargc);
     2564        parsed=realloc(parsed, strlen(owl_global_get_newmsgproc(&g)+300));
     2565        parsed[myargc]=(char *) NULL;
     2566       
     2567        owl_function_debugmsg("About to exec: %s with %i arguments", parsed[0], myargc);
     2568       
     2569        execvp(parsed[0], (char **) parsed);
     2570       
     2571       
     2572        /* was there an error exec'ing? */
     2573        owl_function_debugmsg("Error execing: %s", strerror(errno));
     2574        _exit(127);
     2575      }
     2576    }
     2577  }
     2578}
Note: See TracChangeset for help on using the changeset viewer.