void check_first(char **argv, char **envp, pid_t pid, t_shell *shell) { int i; i = 0; if (shell->buffer[0] == 'l' && shell->buffer[1] == 's' && shell->buffer[3] == ' ' && shell->buffer[4] == '\0') { execve(path_dir("/bin/", "ls"), argv, NULL); exit(1); } if (my_strncmp(shell->buffer, "cd", 2) == 0) { i = chdir(shell->reader[1]); exit(1); } else if (my_strcmp(shell->buffer, "exit") == 0) { kill(pid, 1); exit(1); } else if (my_strcmp(shell->buffer, "env") == 0) show_env(envp); else if (my_strcmp(shell->buffer, "clear") == 0) clear_window(); }
module_t *module_new(const char *Name) { module_t *Module = GC_MALLOC(sizeof(module_t) + sizeof(module_provider_t)); Module->Type = ModuleT; Module->Name = Name; Module->Path = path_dir(Name); Module->Lock[0] = RecursiveMutex; Module->TimeStamp = INT_MAX; Module->Providers = new(module_provider_t); Module->Providers->Module = Module; Module->Providers->HasImports = 0; return Module; };
void exec_read_succeed(char **argv, char **envp, pid_t pid, t_shell *shell) { struct sigaction stop; int i; int j; j = 0; i = 0; stop.sa_handler = SIG_DFL; sigaction(SIGINT, &stop, NULL); check_first(argv, envp, pid, shell); while (shell->tab[i] != NULL) { if (access(path_dir(shell->tab[i], shell->reader[j]), X_OK) != -1) { execve(path_dir(shell->tab[i], shell->reader[j]), shell->reader, envp); exit(1); } i++; } shell->reader[j] = NULL; exec_read_failed(); }
int full_info_dir(int argc, char **argv, DIR *rep, char *path) { struct dirent *readfile; struct stat statut; struct group getgr; struct passwd user; while ((readfile = readdir(rep)) != NULL) { lstat(path_dir(path, readfile->d_name), &statut); type_file(&statut, readfile); right_file(readfile, &statut); info_file(&statut, &user, &getgr); timels(&statut); my_putstr(readfile->d_name); my_putchar('\n'); } return (1); }
static module_t *module_load_internal(const char *Path, const char *File, const char *Alias) { //pthread_t Thread = pthread_self(); //printf("<thread @ %x> Entering module_load_internal:%d(%s, %s)\n", Thread, __LINE__, Path, File); const char *Name = path_join(Path, File); pthread_mutex_lock(LibRivaMutex); module_t *Module = stringtable_get(Modules, Name); if (Module) { pthread_mutex_unlock(LibRivaMutex); module_reload(Module); //printf("<thread @ %x> Leaving module_load_internal:%d(%s, %s)\n", Thread, __LINE__, Path, File); return Module; }; module_provider_t *Providers = module_find_loaders(Name, ModuleLoaders, -1); if (!Providers) { pthread_mutex_unlock(LibRivaMutex); //printf("<thread @ %x> Leaving module_load_internal:%d(%s, %s)\n", Thread, __LINE__, Path, File); return 0; }; Module = stringtable_get(Modules, Name); if (Module) { pthread_mutex_unlock(LibRivaMutex); module_reload(Module); //printf("<thread @ %x> Leaving module_load_internal:%d(%s, %s)\n", pthread_self(), __LINE__, Path, File); return Module; }; Module = new(module_t); Module->Type = ModuleT; Module->Name = Name; Module->Path = path_dir(Name); Module->TimeStamp = ModuleTimeStamp; Module->Lock[0] = RecursiveMutex; stringtable_put(Modules, Name, Module); if (Alias) stringtable_put(Modules, Alias, Module); pthread_mutex_lock(Module->Lock); pthread_mutex_unlock(LibRivaMutex); module_call_loaders(Name, Module, Providers); pthread_mutex_unlock(Module->Lock); //printf("<thread @ %x> Leaving module_load_internal:%d(%s, %s)\n", Thread, __LINE__, Path, File); return Module; };
void LibraryWatcher::ScanSubdirectory(const QString& path, const Subdirectory& subdir, ScanTransaction* t, bool force_noincremental) { QFileInfo path_info(path); QDir path_dir(path); // Do not scan symlinked dirs that are already in collection if (path_info.isSymLink()) { QString real_path = path_info.symLinkTarget(); for (const Directory& dir : watched_dirs_) { if (real_path.startsWith(dir.path)) { t->AddToProgress(1); return; } } } // Do not scan directories containing a .nomedia or .nomusic file if (path_dir.exists(kNoMediaFile) || path_dir.exists(kNoMusicFile)) { t->AddToProgress(1); return; } if (!t->ignores_mtime() && !force_noincremental && t->is_incremental() && subdir.mtime == path_info.lastModified().toTime_t()) { // The directory hasn't changed since last time t->AddToProgress(1); return; } QMap<QString, QStringList> album_art; QStringList files_on_disk; SubdirectoryList my_new_subdirs; // If a directory is moved then only its parent gets a changed notification, // so we need to look and see if any of our children don't exist any more. // If one has been removed, "rescan" it to get the deleted songs SubdirectoryList previous_subdirs = t->GetImmediateSubdirs(path); for (const Subdirectory& subdir : previous_subdirs) { if (!QFile::exists(subdir.path) && subdir.path != path) { t->AddToProgressMax(1); ScanSubdirectory(subdir.path, subdir, t, true); } } // First we "quickly" get a list of the files in the directory that we // think might be music. While we're here, we also look for new // subdirectories // and possible album artwork. QDirIterator it( path, QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot); while (it.hasNext()) { if (stop_requested_) return; QString child(it.next()); QFileInfo child_info(child); if (child_info.isDir()) { if (!child_info.isHidden() && !t->HasSeenSubdir(child)) { // We haven't seen this subdirectory before - add it to a list and // later we'll tell the backend about it and scan it. Subdirectory new_subdir; new_subdir.directory_id = -1; new_subdir.path = child; new_subdir.mtime = child_info.lastModified().toTime_t(); my_new_subdirs << new_subdir; } } else { QString ext_part(ExtensionPart(child)); QString dir_part(DirectoryPart(child)); if (sValidImages.contains(ext_part)) album_art[dir_part] << child; else if (!child_info.isHidden()) files_on_disk << child; } } if (stop_requested_) return; // Ask the database for a list of files in this directory SongList songs_in_db = t->FindSongsInSubdirectory(path); QSet<QString> cues_processed; // Now compare the list from the database with the list of files on disk for (const QString& file : files_on_disk) { if (stop_requested_) return; // associated cue QString matching_cue = NoExtensionPart(file) + ".cue"; Song matching_song; if (FindSongByPath(songs_in_db, file, &matching_song)) { uint matching_cue_mtime = GetMtimeForCue(matching_cue); // The song is in the database and still on disk. // Check the mtime to see if it's been changed since it was added. QFileInfo file_info(file); if (!file_info.exists()) { // Partially fixes race condition - if file was removed between being // added to the list and now. files_on_disk.removeAll(file); continue; } // cue sheet's path from library (if any) QString song_cue = matching_song.cue_path(); uint song_cue_mtime = GetMtimeForCue(song_cue); bool cue_deleted = song_cue_mtime == 0 && matching_song.has_cue(); bool cue_added = matching_cue_mtime != 0 && !matching_song.has_cue(); // watch out for cue songs which have their mtime equal to // qMax(media_file_mtime, cue_sheet_mtime) bool changed = (matching_song.mtime() != qMax(file_info.lastModified().toTime_t(), song_cue_mtime)) || cue_deleted || cue_added; // Also want to look to see whether the album art has changed QString image = ImageForSong(file, album_art); if ((matching_song.art_automatic().isEmpty() && !image.isEmpty()) || (!matching_song.art_automatic().isEmpty() && !matching_song.has_embedded_cover() && !QFile::exists(matching_song.art_automatic()))) { changed = true; } // the song's changed - reread the metadata from file if (t->ignores_mtime() || changed) { qLog(Debug) << file << "changed"; // if cue associated... if (!cue_deleted && (matching_song.has_cue() || cue_added)) { UpdateCueAssociatedSongs(file, path, matching_cue, image, t); // if no cue or it's about to lose it... } else { UpdateNonCueAssociatedSong(file, matching_song, image, cue_deleted, t); } } // nothing has changed - mark the song available without re-scanning if (matching_song.is_unavailable()) t->readded_songs << matching_song; } else { // The song is on disk but not in the DB SongList song_list = ScanNewFile(file, path, matching_cue, &cues_processed); if (song_list.isEmpty()) { continue; } qLog(Debug) << file << "created"; // choose an image for the song(s) QString image = ImageForSong(file, album_art); for (Song song : song_list) { song.set_directory_id(t->dir()); if (song.art_automatic().isEmpty()) song.set_art_automatic(image); t->new_songs << song; } } } // Look for deleted songs for (const Song& song : songs_in_db) { if (!song.is_unavailable() && !files_on_disk.contains(song.url().toLocalFile())) { qLog(Debug) << "Song deleted from disk:" << song.url().toLocalFile(); t->deleted_songs << song; } } // Add this subdir to the new or touched list Subdirectory updated_subdir; updated_subdir.directory_id = t->dir(); updated_subdir.mtime = path_info.exists() ? path_info.lastModified().toTime_t() : 0; updated_subdir.path = path; if (subdir.directory_id == -1) t->new_subdirs << updated_subdir; else t->touched_subdirs << updated_subdir; t->AddToProgress(1); // Recurse into the new subdirs that we found t->AddToProgressMax(my_new_subdirs.count()); for (const Subdirectory& my_new_subdir : my_new_subdirs) { if (stop_requested_) return; ScanSubdirectory(my_new_subdir.path, my_new_subdir, t, true); } }
bool bmp_save(bmpfile_t *bmp, const char *filename) { FILE *fp; int row; unsigned char *buf; /* Create the file */ check_dir(); if ((fp = fopen(path_dir("./rt_images", filename), "wb")) == NULL) { printf("\nfile not created\n"); return FALSE; } /* Write the file */ bmp_write_header(bmp, fp); bmp_write_dib(bmp, fp); bmp_write_palette(bmp, fp); if (bmp->dib.depth == 16) { uint32_t data_bytes = bmp->dib.width * 2; uint32_t padding_bytes = 4 - data_bytes % 4; for (row = bmp->dib.height - 1; row >= 0; --row) { int i; unsigned char zero_byte = 0; uint32_t write_number = 0; for (i = 0; write_number < data_bytes; ++i, write_number += 2) { uint16_t red = (uint16_t)(bmp->pixels[i][row].red / 8); uint16_t green = (uint16_t)(bmp->pixels[i][row].green / 4); uint16_t blue = (uint16_t)(bmp->pixels[i][row].blue / 8); uint16_t value = (red << 11) + (green << 5) + blue; if (_is_big_endian()) value = UINT16_SWAP_LE_BE_CONSTANT(value); fwrite(&value, sizeof(uint16_t), 1, fp); } for (write_number = 0; write_number < padding_bytes; ++write_number) fwrite(&zero_byte, 1, 1, fp); } } else { double bytes_per_pixel; int bytes_per_line; bytes_per_pixel = (bmp->dib.depth * 1.0) / 8.0; bytes_per_line = (int)ceil(bytes_per_pixel * bmp->dib.width); if (bytes_per_line % 4 != 0) bytes_per_line += 4 - bytes_per_line % 4; buf = malloc(bytes_per_line); for (row = bmp->dib.height - 1; row >= 0; --row) { memset(buf, 0, bytes_per_line); switch (bmp->dib.depth) { case 1: bmp_get_row_data_for_1(bmp, buf, bytes_per_line, row); break; case 4: bmp_get_row_data_for_4(bmp, buf, bytes_per_line, row); break; case 8: bmp_get_row_data_for_8(bmp, buf, bytes_per_line, row); break; case 24: bmp_get_row_data_for_24(bmp, buf, bytes_per_line, row); break; case 32: bmp_get_row_data_for_32(bmp, buf, bytes_per_line, row); break; } fwrite(buf, bytes_per_line, 1, fp); } free(buf); } fclose(fp); return TRUE; }