static void ensure_dir_exists(char *dir) { struct stat stat_buf; char *parent; char *q; if (dir[0] == 0) { return; } parent = strdup(dir); q = strrchr(parent, '/'); if (q) { *q = 0; ensure_dir_exists(parent); } if (stat(dir, &stat_buf) < 0) { int res; #ifdef WINDOWS res = mkdir(dir); #endif #ifdef SOLARIS res = mkdir(dir, 0755); #endif if (res != 0) { fprintf(stderr, "Can't create directory: %s. Consider use the -jam -appsdir <other-dir> option.\n", dir); exit(1); } } browser_free(parent); }
gint main(gint argc, gchar *argv[]) { /* setup the functions filetransfer will use in place of the shadow library */ b.shadowlib = &bmain_functionTable; /* Let's download some files */ browser_start(&b, argc, argv); /* now we need to watch all the epoll descriptors in our main loop */ gint epolld = epoll_create(1); if(epolld == -1) { bmain_log(SHADOW_LOG_LEVEL_WARNING, __FUNCTION__, "Error in server epoll_create"); close(epolld); return -1; } struct epoll_event ev; ev.events = EPOLLIN|EPOLLOUT; /* watch the inner epoll descriptor */ if(b.epolld) { ev.data.fd = b.epolld; epoll_ctl(epolld, EPOLL_CTL_ADD, ev.data.fd, &ev); } /* main loop on our epoll descriptors that watch the filetransfer epollds */ struct epoll_event events[10]; int nReadyFDs; while(TRUE) { /* wait for some events */ nReadyFDs = epoll_wait(epolld, events, 10, 0); if(nReadyFDs == -1) { bmain_log(SHADOW_LOG_LEVEL_WARNING, __FUNCTION__, "error in client epoll_wait"); return -1; } /* activate for every socket thats ready */ for(int i = 0; i < nReadyFDs; i++) { browser_activate(&b, events[i].data.fd); } /* break out if the client is done */ if(b.state == SB_SUCCESS) { break; } } /* cleanup and close */ if(b.epolld) { ev.data.fd = b.epolld; epoll_ctl(epolld, EPOLL_CTL_DEL, ev.data.fd, &ev); } close(epolld); browser_free(&b); return 0; }
static void browserplugin_free() { browser_free(&b); }