int cleanupDirectories() { ServiceManager sm(getRootDir()); int ret = sm.cleanupDirectories(); return (ret); }
int stopService(char* programName, int argc, char** argv) { ServiceManager sm(getRootDir()); int ret = sm.stop(programName, argc, argv); return (ret); }
void MainWindow::on_openAction_triggered(bool checked) { Q_UNUSED(checked) QString path = fileText->text(), filename; filename = QFileDialog::getOpenFileName(this, tr("Select a file"), getRootDir(path)); if(!filename.isEmpty()) fileText->setText(filename); }
void Storage::freeSpace() { //there might be a situation where only the current directory is left and //occupies the whole space. We cannot delete anything. Don't waste time scanning. if (failedFreeSpace) return; //printf("freeSpace()\n"); time_t min=time(0); char minDir[PATH_MAX]; char fullPath[PATH_MAX]; DIR *top=opendir(getRootDir()); if (top) { int haveDir=0; struct dirent *chandir, path; struct stat chandirstat; while ( (!readdir_r(top, &path, &chandir) && chandir != NULL) ) { if (strcmp(chandir->d_name, "..")==0 || strcmp(chandir->d_name, ".")==0) continue; snprintf(fullPath, PATH_MAX, "%s/%s", getRootDir(), chandir->d_name); if (stat(fullPath, &chandirstat)==0) { if (S_ISDIR(chandirstat.st_mode)) { if (chandirstat.st_ctime < min && strcmp(fullPath, currentDir)) { min=chandirstat.st_ctime; strcpy(minDir, fullPath); haveDir++; } } } } closedir(top); //if haveDir, only current directory present, which must not be deleted if (haveDir>=2) byteCount-=cleanSubDir(minDir); else failedFreeSpace=true; } }
int listServices(char* programName) { const char *root = getRootDir(); int ret = 0; if (root != NULL) { ServiceManager sm(root); ret = sm.list(programName); } else { return -1; } return (ret); }
int main(int argc, char** argv){ int i; FILEENTRY fe; // open image and read bootsector FILE * f = fopen(argv[1],"r"); BOOTSECTOR bs = readBootsector (f); // change to / fseek(f,getRootDir(&bs),SEEK_SET); // change to requested directory char* path = argv[2]; char buffer [9]; // buffer to read until next / int j = 0; for ( i = 1; path[i-1] != 0; ++i ){ if ( path[i] == '/' || path[i] == 0 ){ if ( j == 0 ) break; while ( j < 8 ) buffer[j++] = ' '; if ( !changeWorkDir(f,&bs,buffer) ) return 1; j = 0; } else { buffer[j] = path[i]; j++; } } // list files while ( 1 ){ // read file entry fe = readFileEntry(f); // print file entries if ( fe.name [0] == 0 ) break; if ( fe.name [0] != FILE_ENTRY_ERASED && fe.flags != FILE_ENTRY_IGNORABLE ){ printFileEntry(&fe); } } return 0; }
void Storage::getFilename(char *buffer, int bufLength, PageID page) { snprintf(buffer, bufLength, "%s/%s/%03x_%02x.vtx", getRootDir(), *page.channel.ToString(), page.page, page.subPage); }
void PackedStorage::getFilename(char *buffer, int bufLength, PageID page) { //This is a different scheme: page 576_07 will have the name 570s.vtx, the same as e.g. 571_01 or 575_00 //Think of "the five hundred seventies" snprintf(buffer, bufLength, "%s/%s/%03xs.vtx", getRootDir(), *page.channel.ToString(), (page.page & 0xFF0)); }
char* createServiceDirectory() { const char *rootPath = getRootDir(); char hostname[DEFAULT_STRING_LENGTH]; int serviceDirLength; if (rootPath == NULL) { // // exit! // logUser("Error: Cannot get the root directory."); return NULL; } if (gethostname(hostname, DEFAULT_STRING_LENGTH) == -1) { // // we cannot get hostname, we return - maybe we should just // set it localhost? // logUser("Error: Cannot retrieve the hostname."); return NULL; } #define MD5_LENGTH 16 char md5[(MD5_LENGTH * 2) + 1]; memset(md5, '\0', (MD5_LENGTH * 2) + 1); if (serviceId == NULL) { srandom(time(0) * getpid()); long int a = random(); char *astr = new char[sizeof(a) + 1]; strncpy(astr,(char *)&a, sizeof(a)); md5_state_t *md5_state = new md5_state_t(); unsigned char *md5_digest = new unsigned char[MD5_LENGTH]; md5_init(md5_state); md5_append(md5_state, (const unsigned char *)astr, sizeof(astr)); md5_finish(md5_state, md5_digest); int di = 0; for (di = 0; di < MD5_LENGTH; ++di) { sprintf(md5 + (di * 2), "%02X", md5_digest[di]); } *(md5 + (di * 2)) = '\0'; delete [] md5_state; delete [] md5_digest; delete [] astr; } else { strncpy(md5, serviceId, MD5_LENGTH * 2); } logUser("Info: Service directory MD5 %s.", md5); serviceDirLength = strlen(rootPath) + strlen("/D-") + strlen(hostname) + strlen("-") + strlen(md5) + 1; // // In no case the service directory path can // be longer than DEFAULT_STRING_LENGTH chars. // if (serviceDirLength > DEFAULT_STRING_LENGTH) { logUser("PANIC: Service directory name would exceed length of %d characters.", DEFAULT_STRING_LENGTH); return NULL; } // // If the service directory path is longer than // MAX_SERVICE_DIR_LENGTH, we opened only the TCP // socket connection to avoid the creation of a // UNIX socket file. Read the comments in // ServiceDisplay::start() about the -nolisten // option for more details. // if (serviceDirLength > MAX_SERVICE_DIR_LENGTH) { logUser("Warning: Service directory path too long. Listening on AF_INET socket."); nolisten = AF_UNIX; } char *path = new char[strlen(rootPath) + strlen("/D-") + strlen(hostname) + strlen("-") + strlen(md5) + 1]; // // Transform name in a fully qualified name. // strcpy(path, rootPath); strcat(path, "/D-"); strcat(path, hostname); strcat(path, "-"); strcat(path, md5); if (mkdir(path, S_IRUSR|S_IWUSR|S_IXUSR)) { // // we cannot create the directory // int errorNumber = errno; logUser("Error: Cannot create directory '%s'",path); logUser("Error: because of '%s'", strerror(errorNumber)); if (errorNumber == EEXIST) { logUser("Error: Directory exists already, we can use it!"); } else { delete [] path; path = NULL; } } return path; }