Changeset 8b293ea


Ignore:
Timestamp:
Jun 24, 2011, 11:55:45 AM (6 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
413c910, 43744ce, 1c01cdf7
Parents:
b343c2c
git-author:
David Benjamin <davidben@mit.edu> (06/03/11 22:58:53)
git-committer:
David Benjamin <davidben@mit.edu> (06/24/11 11:55:45)
Message:
Use glib spawn functions when launching a newmsgproc

The glib version is smaller and has the advantage of not leaking all our
file descriptors to the process. More importantly, it does not call
malloc between fork and exec which is not safe in the presence of
threads.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    rb343c2c r8b293ea  
    31563156    }
    31573157   
    3158     /* if it exited, fork & exec a new one */
     3158    /* if it exited, spawn a new one */
    31593159    if (owl_global_get_newmsgproc_pid(&g)==0) {
    3160       pid_t i;
    31613160      int myargc;
    3162       i=fork();
    3163       if (i) {
    3164         /* parent set the child's pid */
    3165         owl_global_set_newmsgproc_pid(&g, i);
    3166         owl_function_debugmsg("I'm the parent and I started a new newmsgproc with pid %i", i);
    3167       } else {
    3168         /* child exec's the program */
    3169         char **parsed;
    3170         parsed=owl_parseline(owl_global_get_newmsgproc(&g), &myargc);
    3171         if (myargc < 0) {
    3172           owl_function_debugmsg("Could not parse newmsgproc '%s': unbalanced quotes?", owl_global_get_newmsgproc(&g));
    3173         }
    3174         if (myargc <= 0) {
    3175           _exit(127);
    3176         }
    3177         owl_function_debugmsg("About to exec \"%s\" with %d arguments", parsed[0], myargc);
    3178        
    3179         execvp(parsed[0], parsed);
    3180        
    3181        
    3182         /* was there an error exec'ing? */
    3183         owl_function_debugmsg("Cannot run newmsgproc '%s': cannot exec '%s': %s",
    3184                               owl_global_get_newmsgproc(&g), parsed[0], strerror(errno));
    3185         _exit(127);
     3161      char **argv = owl_parseline(owl_global_get_newmsgproc(&g), &myargc);
     3162      if (myargc < 0) {
     3163        owl_function_debugmsg("Could not parse newmsgproc '%s': unbalanced quotes?",
     3164                              owl_global_get_newmsgproc(&g));
     3165      } else if (myargc > 0) {
     3166        /* Spawn the child. */
     3167        pid_t pid;
     3168        GError *error = NULL;
     3169        owl_function_debugmsg("About to exec \"%s\" with %d arguments", argv[0], myargc);
     3170        if (g_spawn_async(NULL, argv, NULL,
     3171                          G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
     3172                          NULL, NULL, &pid, &error)) {
     3173          owl_global_set_newmsgproc_pid(&g, pid);
     3174          owl_function_debugmsg("I'm the parent and I started a new newmsgproc with pid %i", pid);
     3175        } else {
     3176          owl_function_debugmsg("Cannot run newmsgproc '%s': %s",
     3177                                owl_global_get_newmsgproc(&g), error->message);
     3178          g_error_free(error);
     3179        }
    31863180      }
     3181      g_strfreev(argv);
    31873182    }
    31883183  }
Note: See TracChangeset for help on using the changeset viewer.