comparison ie-vagrant.c @ 14:7003cdf42392

can up vagrant machine in user environment (not root)
author taiki
date Mon, 11 Nov 2013 20:44:34 -1000
parents 4e34b48bf7c7
children f194adc597b6
comparison
equal deleted inserted replaced
13:96ae34f2f809 14:7003cdf42392
27 #define command "/usr/bin/vagrant" 27 #define command "/usr/bin/vagrant"
28 #define init_command "init" 28 #define init_command "init"
29 #define up_command "up" 29 #define up_command "up"
30 #define destroy_command "destroy" 30 #define destroy_command "destroy"
31 #define ssh_command "ssh" 31 #define ssh_command "ssh"
32 #define provider_arg "--provider=kvm"
32 33
33 #define NEW(type) ((type*)malloc(sizeof(type))) 34 #define NEW(type) ((type*)malloc(sizeof(type)))
34 35
35 /* Define global variables */ 36 /* Define global variables */
36 37
67 if ( gid != 999 ) { 68 if ( gid != 999 ) {
68 printf("User Not Authorized! Exiting...\n"); 69 printf("User Not Authorized! Exiting...\n");
69 exit(1); 70 exit(1);
70 } 71 }
71 */ 72 */
73 putenv("VAGRANT_HOME=/root/.vagrant.d/");
74 putenv("VAGRANT_DEFAULT_PROVIDER=kvm");
75
72 76
73 /* Set uid, gid, euid and egid to root */ 77 /* Set uid, gid, euid and egid to root */
74 78
75 setegid(0); 79 setegid(0);
76 seteuid(0); 80 seteuid(0);
88 } else if ( strncmp(argv[1], "destroy", 4) == 0 ) { 92 } else if ( strncmp(argv[1], "destroy", 4) == 0 ) {
89 if (execl(command, command, destroy_command, NULL) < 0) { 93 if (execl(command, command, destroy_command, NULL) < 0) {
90 perror("Execl:"); 94 perror("Execl:");
91 } 95 }
92 } else if ( strncmp(argv[1], "up", 2) == 0 ) { 96 } else if ( strncmp(argv[1], "up", 2) == 0 ) {
93 if (execl(command, command, up_command, NULL) < 0) { 97 if (execl(command, command, up_command, provider_arg, NULL) < 0) {
94 perror("Execl:"); 98 perror("Execl:");
95 } 99 }
96 } else if ( strncmp(argv[1], "ssh", 6) == 0 ) { 100 } else if ( strncmp(argv[1], "ssh", 3) == 0 ) {
97 if (execl(command, command, ssh_command, NULL) < 0) { 101 if (execl(command, command, ssh_command, NULL) < 0) {
98 perror("Execl:"); 102 perror("Execl:");
99 } 103 }
100 } else { 104 } else {
101 usage(); 105 usage();