Mercurial > hg > Applications > virsh-wrapper
diff ie-vagrant.c @ 15:f194adc597b6
add source to edit vagrantfile.
author | taiki |
---|---|
date | Tue, 12 Nov 2013 01:50:50 -1000 |
parents | 7003cdf42392 |
children | d8ea207162ca |
line wrap: on
line diff
--- a/ie-vagrant.c Mon Nov 11 20:44:34 2013 -1000 +++ b/ie-vagrant.c Tue Nov 12 01:50:50 2013 -1000 @@ -12,6 +12,8 @@ #include <sys/types.h> #include <regex.h> +#include <time.h> + /******************************************** * Vagrant Wrapper - Secure Yourself * * * @@ -33,6 +35,8 @@ #define NEW(type) ((type*)malloc(sizeof(type))) +#define VAGRANT_FILE "Vagrantfile" + /* Define global variables */ void @@ -41,6 +45,30 @@ printf("Usage: COMMAND [init|up|destroy|ssh]\n"); } +void +exec_init(int uid, int gid) +{ + pid_t pid = fork(); + if (pid < 0) { + perror("fork"); + exit(-1); + } else if (pid == 0) { + if (execl(command, command, init_command, NULL) < 0) { + perror("Execl:"); + } + } else { + sleep(2); + if (chown(VAGRANT_FILE, uid, gid) != 0) { + printf("chown error.\n"); + exit(1); + } + char exec[1024]; + strncpy(exec, "/usr/local/bin/change_vagrantfile.py", 1024); + fprintf(stdout, "executing %s\n", exec); + system(exec); + } +} + /* main(int argc, char **argv) - main process loop */ int main(int argc, char **argv) @@ -70,6 +98,8 @@ exit(1); } */ + + /* Set env valiable */ putenv("VAGRANT_HOME=/root/.vagrant.d/"); putenv("VAGRANT_DEFAULT_PROVIDER=kvm"); @@ -86,9 +116,7 @@ */ if ( strncmp(argv[1], "init", 4) == 0 ) { - if (execl(command, command, init_command, NULL) < 0) { - perror("Execl:"); - } + exec_init(uid, gid); } else if ( strncmp(argv[1], "destroy", 4) == 0 ) { if (execl(command, command, destroy_command, NULL) < 0) { perror("Execl:");