2
* Author: Sunil Soman sunils@cs.ucsb.edu
5
#include <edu_ucsb_eucalyptus_storage_LVM2Manager.h>
14
#define EUCALYPTUS_ENV_VAR_NAME "EUCALYPTUS"
16
static const char* blockSize = "1M";
18
int run_command_and_get_pid(char *cmd, char **args) {
20
int fds_to_close[1024];
23
if ((pid = fork()) == -1) {
24
perror("Could not run command");
31
struct dirent *fd_dir;
34
int my_pid = getpid();
40
char* home = getenv (EUCALYPTUS_ENV_VAR_NAME);
42
home = strdup (""); /* root by default */
46
fprintf(stderr, "command: %s\n", cmd);
50
snprintf(fd_path, 128, "/proc/%d/fd", my_pid);
52
if ((proc_fd_dir = opendir(fd_path)) != NULL) {
54
while ((fd_dir = readdir(proc_fd_dir)) != NULL) {
55
if (isdigit(fd_dir->d_name[0])) {
56
fds_to_close[curr_fd++] = atoi(fd_dir->d_name);
60
for(i=0 ; i < curr_fd; ++i) {
61
close(fds_to_close[i]);
65
for(i=0 ; i < 1024; ++i) {
70
freopen( "/dev/null", "r", stdin);
71
freopen( "/dev/null", "w", stdout);
72
freopen( "/dev/null", "w", stderr);
73
exit(execvp(cmd, args));
78
void sigchld(int signal)
80
while (0 < waitpid(-1, NULL, WNOHANG));
83
JNIEXPORT void JNICALL Java_edu_ucsb_eucalyptus_storage_LVM2Manager_registerSignals
84
(JNIEnv *env, jobject obj) {
85
signal(SIGCHLD, sigchld);