示例#1
0
        public HardwareManager()
        {
            manager                = new Hal.Manager();
            manager.DeviceAdded   += OnHalDeviceAdded;
            manager.DeviceRemoved += OnHalDeviceRemoved;

            Volume.HardwareManager = this;
        }
示例#2
0
        protected Volume(BlockDevice parent, Hal.Manager manager, Hal.Device device) : base(manager, device)
        {
            this.parent = parent ?? BlockDevice.Resolve <IBlockDevice> (manager, device.Parent);

            method_names = HalDevice.PropertyExists(method_names_property)
                ? device.GetPropertyStringList(method_names_property)
                : new string[0];
        }
示例#3
0
        public static DiskDevice Resolve(Hal.Manager manager, Hal.Device device)
        {
            if (device["storage.drive_type"] == "disk")
            {
                return(new DiskDevice(manager, device));
            }

            return(null);
        }
示例#4
0
        public static CdromDevice Resolve(Hal.Manager manager, Hal.Device device)
        {
            if (device["storage.drive_type"] == "cdrom")
            {
                return(new CdromDevice(manager, device));
            }

            return(null);
        }
示例#5
0
        public static UsbDevice Resolve(Hal.Manager manager, Hal.Device device)
        {
            if (device["info.subsystem"] == "usb_device" &&
                device.PropertyExists("usb_device.product_id") &&
                device.PropertyExists("usb_device.vendor_id"))
            {
                return(new UsbDevice(manager, device));
            }

            return(null);
        }
示例#6
0
        public CdDriveCombo()
        {
            hal = new Hal.Manager ();
            store = new ListStore (typeof (string), typeof (string), typeof (string));

            Model = store;

            CellRendererText renderer = new CellRendererText ();
            PackStart (renderer, true);
            AddAttribute (renderer, "text", 0);

            Hal.Device[] list = hal.FindDeviceByCapabilityAsDevice ("storage.cdrom");
            if (list != null) {
                foreach (Hal.Device dev in list) {
                    AddDevice (dev);
                }
            }
        }
示例#7
0
        public static BlockDevice Resolve <T> (Hal.Manager manager, Hal.Device device) where T : IBlockDevice
        {
            if (device.QueryCapability("block") && device.PropertyExists("block.device"))
            {
                if (typeof(T) == typeof(ICdromDevice))
                {
                    return(CdromDevice.Resolve(manager, device));
                }
                else if (typeof(T) == typeof(IDiskDevice))
                {
                    return(DiskDevice.Resolve(manager, device));
                }

                return((BlockDevice)CdromDevice.Resolve(manager, device)
                       ?? (BlockDevice)DiskDevice.Resolve(manager, device));
            }

            return(null);
        }
示例#8
0
        public static Volume Resolve(BlockDevice parent, Hal.Manager manager, Hal.Device device)
        {
            if (!device.IsVolume)
            {
                return(null);
            }

            try {
                Volume volume = (parent is ICdromDevice || (parent == null && device.QueryCapability("volume.disc")))
                    ? DiscVolume.Resolve(parent, manager, device)
                    : new Volume(parent, manager, device);

                return(CheckVolumeMounted(volume) ? volume : null);
            } catch (Exception e) {
                Hyena.Log.Exception(e);
            }

            return(null);
        }
示例#9
0
 protected BlockDevice(Hal.Manager manager, Hal.Device device) : base(manager, device)
 {
 }
示例#10
0
		static void DoMain (string [] args)
		{
			SystemInformation.SetProcessName ("beagle-build-index");

			if (args.Length < 2)
				PrintUsage ();

			ArrayList allowed_patterns = new ArrayList ();
			ArrayList denied_patterns = new ArrayList ();

			int i = 0;
			while (i < args.Length) {
			
				string arg = args [i];
				++i;
				string next_arg = i < args.Length ? args [i] : null;
			
				switch (arg) {
				case "-h":
				case "--help":
					PrintUsage ();
					break;
					
				case "--tag":
					if (next_arg != null)
						arg_tag = next_arg;
					++i;
					break;
					
				case "-r":
				case "--recursive":
					arg_recursive = true;
					break;

				case "--enable-deletion":
					arg_delete = true;
					break;

				case "--disable-directories":
					arg_disable_directories = true;
					break;
					
				case "--enable-text-cache":
					arg_cache_text = true;
					break;

				case "--target":
					if (next_arg != null)
						arg_output = Path.IsPathRooted (next_arg) ? next_arg : Path.GetFullPath (next_arg);
					++i;
					break;

				case "--disable-filtering":
					arg_disable_filtering = true;
					break;

				case "--disable-on-battery":
					arg_disable_on_battery = true;
					break;

				case "--allow-pattern":
					if (next_arg == null)
						break;

					if (next_arg.IndexOf (',') != -1) {
						foreach (string pattern in next_arg.Split (','))
							allowed_patterns.Add (pattern);
						
					} else {
						allowed_patterns.Add (next_arg);
					}
					
					++i;
					break;

				case "--deny-pattern":
					if (next_arg == null)
						break;

					if (next_arg.IndexOf (',') != -1) {
						foreach (string pattern in next_arg.Split (','))
							denied_patterns.Add (pattern);

					} else {
						denied_patterns.Add (next_arg);
					}

					++i;
					break;

				case "--disable-restart":
					arg_disable_restart = true;
					break;

				case "--source":
					if (next_arg == null)
						break;

					arg_source = next_arg;
					++i;
					break;

				case "--removable":
					arg_removable = true;
					break;

				default:
					if (arg.StartsWith ("-") || arg.StartsWith ("--"))
						PrintUsage ();

					string path = Path.IsPathRooted (arg) ? arg : Path.GetFullPath (arg);
					if (path != "/" && path.EndsWith ("/"))
						path = path.TrimEnd ('/');
					
					if (Directory.Exists (path))
						pending_directories.Enqueue (new DirectoryInfo (path));
					else if (File.Exists (path))
						pending_files.Enqueue (new FileInfo (path));
					break;
				}
			}
			
			/////////////////////////////////////////////////////////
				
			if (arg_output == null) {
				Logger.Log.Error ("--target must be specified");
				Environment.Exit (1);
			}

			// Set the storage dir, this should be used to store log messages
			// and filterver.dat
			PathFinder.StorageDir = arg_output;

			foreach (FileSystemInfo info in pending_directories) {
				if (Path.GetFullPath (arg_output) == info.FullName) {
					Logger.Log.Error ("Target directory cannot be one of the source paths.");
					Environment.Exit (1);
				}
			}

			foreach (FileSystemInfo info in pending_files) {
				if (Path.GetFullPath (arg_output) == info.FullName) {
					Logger.Log.Error ("Target directory cannot be one of the source paths.");
					Environment.Exit (1);
				}
			}
			
			if (!Directory.Exists (Path.GetDirectoryName (arg_output))) {
				Logger.Log.Error ("Index directory not available for construction: {0}", arg_output);
				Environment.Exit (1);
			}

			// Be *EXTRA PARANOID* about the contents of the target
			// directory, because creating an indexing driver will
			// nuke it.
			if (Directory.Exists (arg_output)) {

				foreach (FileInfo info in DirectoryWalker.GetFileInfos (arg_output)) {
					if (Array.IndexOf (allowed_files, info.Name) == -1) {
						Logger.Log.Error ("{0} doesn't look safe to delete: non-Beagle file {1} was found", arg_output, info.FullName);
						Environment.Exit (1);
					}
				}

				foreach (DirectoryInfo info in DirectoryWalker.GetDirectoryInfos (arg_output)) {
					if (Array.IndexOf (allowed_dirs, info.Name) == -1) {
						Logger.Log.Error ("{0} doesn't look safe to delete: non-Beagle directory {1} was found", arg_output, info.FullName);
						Environment.Exit (1);
					}
				}
			}

			string config_file_path = Path.Combine (arg_output, "StaticIndex.xml");
			string prev_source = null;
			if (File.Exists (config_file_path)) {
				Config static_index_config = Conf.LoadFrom (config_file_path);
				if (static_index_config == null) {
					Log.Error ("Invalid configuation file {0}", config_file_path);
					Environment.Exit (1);
				}

				prev_source = static_index_config.GetOption ("Source", null);
				if (arg_source != null && prev_source != arg_source) {
					Log.Error ("Source already set to {0} for existing static index. Cannot set source to {1}.", prev_source, arg_source);
					Environment.Exit (1);
				}

				bool prev_removable = static_index_config.GetOption ("Removable", false);
				if (arg_removable != prev_removable) {
					Log.Error ("Index previously created for {0}-removable path",
						   (prev_removable ? "" : "non"));
					Environment.Exit (1);
				} else {
					volume_label = static_index_config.GetOption ("VolumeLabel", null);
				}

				// If arg_source is not given, and prev_source is present, use prev_source
				// as the arg_source. This is useful for re-running build-index without
				// giving --arg_source for already existing static index
				arg_source = prev_source;
			}

			// Removable media related options
			if (arg_removable) {
				if (pending_files.Count > 0) {
					Log.Error ("Indexing individual files is not allowed for removable media.");
					Environment.Exit (1);
				} else if (pending_directories.Count > 1) {
					Log.Error ("Indexing multiple root directories is not allowed for removable media.");
					Environment.Exit (1);
				}

				mnt_dir = ((DirectoryInfo) pending_directories.Peek ()).FullName;
				if (mnt_dir.Length != 1)
					mnt_dir = mnt_dir.TrimEnd ('/');

				// compute volume label
				// (1) directory name if block.is_volume is false
				// (2) hal volume.label if set
				// (3) hal volume.uuid if set
				Hal.Manager manager = new Hal.Manager (new Hal.Context ());
				Hal.Device mnt_device = null;

				foreach (Hal.Device device in manager.FindDeviceStringMatch ("volume.mount_point", mnt_dir))
					mnt_device = device;

				string new_volume_label = null;
				if (mnt_device != null) {
					new_volume_label = mnt_device.GetPropertyString ("volume.label");


					if (String.IsNullOrEmpty (new_volume_label))
						new_volume_label = mnt_device.GetPropertyString ("volume.uuid");
				}

				if (new_volume_label == null)
					new_volume_label = ((DirectoryInfo) pending_directories.Peek ()).Name;

				// Sanity check
				// Volume label is part of the URI, so cannot be changed once set
				if (volume_label == null) {
					volume_label = new_volume_label;
				} else if (volume_label != new_volume_label) {
					Log.Error ("Volume label (earlier '{0}') changed (to '{1}')! You need to create a new index.", volume_label, new_volume_label);
					Environment.Exit (1);
				}
			}

			if (arg_source == null) {
				DirectoryInfo dir = new DirectoryInfo (StringFu.SanitizePath (arg_output));
				arg_source = dir.Name;
			}

			if (! BatteryMonitor.UsingAC && arg_disable_on_battery) {
				Log.Always ("Indexer is disabled when on battery power (--disable-on-battery)");
				Environment.Exit (0);
			}

			string global_files_config = Path.Combine (PathFinder.ConfigDataDir, "config-files");
			global_files_config = Path.Combine (global_files_config, Conf.Names.FilesQueryableConfig + ".xml");
			if (! File.Exists (global_files_config)) {
				Log.Error ("Global configuration file not found {0}", global_files_config);
				Environment.Exit (0);
			}

			// Setup regexes for allowed/denied patterns
			if (allowed_patterns.Count > 0) {
				allowed_regex = StringFu.GetPatternRegex (allowed_patterns);
			} else {
				// Read the exclude values from config
				// For system-wide indexes, only the global config value will be used
				Config config = Conf.Get (Conf.Names.FilesQueryableConfig);
				List<string[]> values = config.GetListOptionValues (Conf.Names.ExcludePattern);
				if (values != null)
					foreach (string[] exclude in values)
						denied_patterns.Add (exclude [0]);

				if (denied_patterns.Count > 0)
					denied_regex = StringFu.GetPatternRegex (denied_patterns);
			}

			Log.Always ("Starting beagle-build-index (pid {0}) at {1}", Process.GetCurrentProcess ().Id, DateTime.Now);

			// Set system priorities so we don't slow down the system
			SystemPriorities.ReduceIoPriority ();
			SystemPriorities.SetSchedulerPolicyBatch ();
			SystemPriorities.Renice (19);
			
			driver = new LuceneIndexingDriver (arg_output, MINOR_VERSION, false);
			driver.TextCache = (arg_cache_text) ? new TextCache (arg_output) : null;
			if (driver.TextCache != null)
				driver.TextCache.WorldReadable = true;

			backing_fa_store = new FileAttributesStore_Sqlite (driver.TopDirectory, driver.Fingerprint);
			fa_store = new FileAttributesStore (backing_fa_store);
			
			// Set up signal handlers
#if MONO_1_9
			Shutdown.SetupSignalHandlers (delegate (int signal)
							{
								if (signal == (int) Mono.Unix.Native.Signum.SIGINT ||
								    signal == (int) Mono.Unix.Native.Signum.SIGTERM)
									Shutdown.BeginShutdown ();
							});
#else
			SetupSignalHandlers ();
#endif

			Thread monitor_thread = null;

			Stopwatch watch = new Stopwatch ();
			watch.Start ();

			if (!arg_disable_restart) {
				// Start the thread that monitors memory usage.
				monitor_thread = ExceptionHandlingThread.Start (new ThreadStart (MemoryMonitorWorker));
			}

			// Start indexworker to do the crawling and indexing
			IndexWorker ();

			// Join any threads so that we know that we're the only thread still running
			if (monitor_thread != null)
				monitor_thread.Join ();

			watch.Stop ();
			Logger.Log.Debug ("Elapsed time {0}.", watch);

			// Write this after indexing is done. This is because, if creating a new index,
			// LuceneIndexingDriver.Create() is called which purges the entire directory.

			if (prev_source == null) {
				Config static_index_config = Conf.LoadNew ("StaticIndex.xml");

				// Write StaticIndex.xml containing:
				// The name of the source
				static_index_config.SetOption ("Source", arg_source);
				static_index_config ["Source"].Description = "Source of the static index";

				if (arg_removable) {
					static_index_config.SetOption ("VolumeLabel", volume_label);
					static_index_config ["VolumeLabel"].Description = "Volume label of the removable source";

					static_index_config.SetOption ("Removable", true);
					static_index_config ["Removable"].Description = "Removable source";
				}

				Conf.SaveTo (static_index_config, config_file_path);
			}

			if (restart) {
				Logger.Log.Debug ("Restarting beagle-build-index");
				Process p = new Process ();
				p.StartInfo.UseShellExecute = false;
				// FIXME: Maybe this isn't the right way to do things?  It should be ok,
				// the PATH is inherited from the shell script which runs mono itself.
				p.StartInfo.FileName = "mono";
				p.StartInfo.Arguments = String.Join (" ", Environment.GetCommandLineArgs ());
				p.Start ();
			}

			Log.Always ("Exiting beagle-build-index (pid {0}) at {1}", Process.GetCurrentProcess ().Id, DateTime.Now);
		}
示例#11
0
 private DiskDevice(Hal.Manager manager, Hal.Device device) : base(manager, device)
 {
 }
示例#12
0
        static void DoMain(string [] args)
        {
            SystemInformation.SetProcessName("beagle-build-index");

            if (args.Length < 2)
            {
                PrintUsage();
            }

            ArrayList allowed_patterns = new ArrayList();
            ArrayList denied_patterns  = new ArrayList();

            int i = 0;

            while (i < args.Length)
            {
                string arg = args [i];
                ++i;
                string next_arg = i < args.Length ? args [i] : null;

                switch (arg)
                {
                case "-h":
                case "--help":
                    PrintUsage();
                    break;

                case "--tag":
                    if (next_arg != null)
                    {
                        arg_tag = next_arg;
                    }
                    ++i;
                    break;

                case "-r":
                case "--recursive":
                    arg_recursive = true;
                    break;

                case "--enable-deletion":
                    arg_delete = true;
                    break;

                case "--disable-directories":
                    arg_disable_directories = true;
                    break;

                case "--enable-text-cache":
                    arg_cache_text = true;
                    break;

                case "--target":
                    if (next_arg != null)
                    {
                        arg_output = Path.IsPathRooted(next_arg) ? next_arg : Path.GetFullPath(next_arg);
                    }
                    ++i;
                    break;

                case "--disable-filtering":
                    arg_disable_filtering = true;
                    break;

                case "--disable-on-battery":
                    arg_disable_on_battery = true;
                    break;

                case "--allow-pattern":
                    if (next_arg == null)
                    {
                        break;
                    }

                    if (next_arg.IndexOf(',') != -1)
                    {
                        foreach (string pattern in next_arg.Split(','))
                        {
                            allowed_patterns.Add(pattern);
                        }
                    }
                    else
                    {
                        allowed_patterns.Add(next_arg);
                    }

                    ++i;
                    break;

                case "--deny-pattern":
                    if (next_arg == null)
                    {
                        break;
                    }

                    if (next_arg.IndexOf(',') != -1)
                    {
                        foreach (string pattern in next_arg.Split(','))
                        {
                            denied_patterns.Add(pattern);
                        }
                    }
                    else
                    {
                        denied_patterns.Add(next_arg);
                    }

                    ++i;
                    break;

                case "--disable-restart":
                    arg_disable_restart = true;
                    break;

                case "--source":
                    if (next_arg == null)
                    {
                        break;
                    }

                    arg_source = next_arg;
                    ++i;
                    break;

                case "--removable":
                    arg_removable = true;
                    break;

                default:
                    if (arg.StartsWith("-") || arg.StartsWith("--"))
                    {
                        PrintUsage();
                    }

                    string path = Path.IsPathRooted(arg) ? arg : Path.GetFullPath(arg);
                    if (path != "/" && path.EndsWith("/"))
                    {
                        path = path.TrimEnd('/');
                    }

                    if (Directory.Exists(path))
                    {
                        pending_directories.Enqueue(new DirectoryInfo(path));
                    }
                    else if (File.Exists(path))
                    {
                        pending_files.Enqueue(new FileInfo(path));
                    }
                    break;
                }
            }

            /////////////////////////////////////////////////////////

            if (arg_output == null)
            {
                Logger.Log.Error("--target must be specified");
                Environment.Exit(1);
            }

            // Set the storage dir, this should be used to store log messages
            // and filterver.dat
            PathFinder.StorageDir = arg_output;

            foreach (FileSystemInfo info in pending_directories)
            {
                if (Path.GetFullPath(arg_output) == info.FullName)
                {
                    Logger.Log.Error("Target directory cannot be one of the source paths.");
                    Environment.Exit(1);
                }
            }

            foreach (FileSystemInfo info in pending_files)
            {
                if (Path.GetFullPath(arg_output) == info.FullName)
                {
                    Logger.Log.Error("Target directory cannot be one of the source paths.");
                    Environment.Exit(1);
                }
            }

            if (!Directory.Exists(Path.GetDirectoryName(arg_output)))
            {
                Logger.Log.Error("Index directory not available for construction: {0}", arg_output);
                Environment.Exit(1);
            }

            // Be *EXTRA PARANOID* about the contents of the target
            // directory, because creating an indexing driver will
            // nuke it.
            if (Directory.Exists(arg_output))
            {
                foreach (FileInfo info in DirectoryWalker.GetFileInfos(arg_output))
                {
                    if (Array.IndexOf(allowed_files, info.Name) == -1)
                    {
                        Logger.Log.Error("{0} doesn't look safe to delete: non-Beagle file {1} was found", arg_output, info.FullName);
                        Environment.Exit(1);
                    }
                }

                foreach (DirectoryInfo info in DirectoryWalker.GetDirectoryInfos(arg_output))
                {
                    if (Array.IndexOf(allowed_dirs, info.Name) == -1)
                    {
                        Logger.Log.Error("{0} doesn't look safe to delete: non-Beagle directory {1} was found", arg_output, info.FullName);
                        Environment.Exit(1);
                    }
                }
            }

            string config_file_path = Path.Combine(arg_output, "StaticIndex.xml");
            string prev_source      = null;

            if (File.Exists(config_file_path))
            {
                Config static_index_config = Conf.LoadFrom(config_file_path);
                if (static_index_config == null)
                {
                    Log.Error("Invalid configuation file {0}", config_file_path);
                    Environment.Exit(1);
                }

                prev_source = static_index_config.GetOption("Source", null);
                if (arg_source != null && prev_source != arg_source)
                {
                    Log.Error("Source already set to {0} for existing static index. Cannot set source to {1}.", prev_source, arg_source);
                    Environment.Exit(1);
                }

                bool prev_removable = static_index_config.GetOption("Removable", false);
                if (arg_removable != prev_removable)
                {
                    Log.Error("Index previously created for {0}-removable path",
                              (prev_removable ? "" : "non"));
                    Environment.Exit(1);
                }
                else
                {
                    volume_label = static_index_config.GetOption("VolumeLabel", null);
                }

                // If arg_source is not given, and prev_source is present, use prev_source
                // as the arg_source. This is useful for re-running build-index without
                // giving --arg_source for already existing static index
                arg_source = prev_source;
            }

            // Removable media related options
            if (arg_removable)
            {
                if (pending_files.Count > 0)
                {
                    Log.Error("Indexing individual files is not allowed for removable media.");
                    Environment.Exit(1);
                }
                else if (pending_directories.Count > 1)
                {
                    Log.Error("Indexing multiple root directories is not allowed for removable media.");
                    Environment.Exit(1);
                }

                mnt_dir = ((DirectoryInfo)pending_directories.Peek()).FullName;
                if (mnt_dir.Length != 1)
                {
                    mnt_dir = mnt_dir.TrimEnd('/');
                }

                // compute volume label
                // (1) directory name if block.is_volume is false
                // (2) hal volume.label if set
                // (3) hal volume.uuid if set
                Hal.Manager manager    = new Hal.Manager(new Hal.Context());
                Hal.Device  mnt_device = null;

                foreach (Hal.Device device in manager.FindDeviceStringMatch("volume.mount_point", mnt_dir))
                {
                    mnt_device = device;
                }

                string new_volume_label = null;
                if (mnt_device != null)
                {
                    new_volume_label = mnt_device.GetPropertyString("volume.label");


                    if (String.IsNullOrEmpty(new_volume_label))
                    {
                        new_volume_label = mnt_device.GetPropertyString("volume.uuid");
                    }
                }

                if (new_volume_label == null)
                {
                    new_volume_label = ((DirectoryInfo)pending_directories.Peek()).Name;
                }

                // Sanity check
                // Volume label is part of the URI, so cannot be changed once set
                if (volume_label == null)
                {
                    volume_label = new_volume_label;
                }
                else if (volume_label != new_volume_label)
                {
                    Log.Error("Volume label (earlier '{0}') changed (to '{1}')! You need to create a new index.", volume_label, new_volume_label);
                    Environment.Exit(1);
                }
            }

            if (arg_source == null)
            {
                DirectoryInfo dir = new DirectoryInfo(StringFu.SanitizePath(arg_output));
                arg_source = dir.Name;
            }

            if (!BatteryMonitor.UsingAC && arg_disable_on_battery)
            {
                Log.Always("Indexer is disabled when on battery power (--disable-on-battery)");
                Environment.Exit(0);
            }

            string global_files_config = Path.Combine(PathFinder.ConfigDataDir, "config-files");

            global_files_config = Path.Combine(global_files_config, Conf.Names.FilesQueryableConfig + ".xml");
            if (!File.Exists(global_files_config))
            {
                Log.Error("Global configuration file not found {0}", global_files_config);
                Environment.Exit(0);
            }

            // Setup regexes for allowed/denied patterns
            if (allowed_patterns.Count > 0)
            {
                allowed_regex = StringFu.GetPatternRegex(allowed_patterns);
            }
            else
            {
                // Read the exclude values from config
                // For system-wide indexes, only the global config value will be used
                Config          config = Conf.Get(Conf.Names.FilesQueryableConfig);
                List <string[]> values = config.GetListOptionValues(Conf.Names.ExcludePattern);
                if (values != null)
                {
                    foreach (string[] exclude in values)
                    {
                        denied_patterns.Add(exclude [0]);
                    }
                }

                if (denied_patterns.Count > 0)
                {
                    denied_regex = StringFu.GetPatternRegex(denied_patterns);
                }
            }

            Log.Always("Starting beagle-build-index (pid {0}) at {1}", Process.GetCurrentProcess().Id, DateTime.Now);

            // Set system priorities so we don't slow down the system
            SystemPriorities.ReduceIoPriority();
            SystemPriorities.SetSchedulerPolicyBatch();
            SystemPriorities.Renice(19);

            driver           = new LuceneIndexingDriver(arg_output, MINOR_VERSION, false);
            driver.TextCache = (arg_cache_text) ? new TextCache(arg_output) : null;
            if (driver.TextCache != null)
            {
                driver.TextCache.WorldReadable = true;
            }

            backing_fa_store = new FileAttributesStore_Sqlite(driver.TopDirectory, driver.Fingerprint);
            fa_store         = new FileAttributesStore(backing_fa_store);

            // Set up signal handlers
#if MONO_1_9
            Shutdown.SetupSignalHandlers(delegate(int signal)
            {
                if (signal == (int)Mono.Unix.Native.Signum.SIGINT ||
                    signal == (int)Mono.Unix.Native.Signum.SIGTERM)
                {
                    Shutdown.BeginShutdown();
                }
            });
#else
            SetupSignalHandlers();
#endif

            Thread monitor_thread = null;

            Stopwatch watch = new Stopwatch();
            watch.Start();

            if (!arg_disable_restart)
            {
                // Start the thread that monitors memory usage.
                monitor_thread = ExceptionHandlingThread.Start(new ThreadStart(MemoryMonitorWorker));
            }

            // Start indexworker to do the crawling and indexing
            IndexWorker();

            // Join any threads so that we know that we're the only thread still running
            if (monitor_thread != null)
            {
                monitor_thread.Join();
            }

            watch.Stop();
            Logger.Log.Debug("Elapsed time {0}.", watch);

            // Write this after indexing is done. This is because, if creating a new index,
            // LuceneIndexingDriver.Create() is called which purges the entire directory.

            if (prev_source == null)
            {
                Config static_index_config = Conf.LoadNew("StaticIndex.xml");

                // Write StaticIndex.xml containing:
                // The name of the source
                static_index_config.SetOption("Source", arg_source);
                static_index_config ["Source"].Description = "Source of the static index";

                if (arg_removable)
                {
                    static_index_config.SetOption("VolumeLabel", volume_label);
                    static_index_config ["VolumeLabel"].Description = "Volume label of the removable source";

                    static_index_config.SetOption("Removable", true);
                    static_index_config ["Removable"].Description = "Removable source";
                }

                Conf.SaveTo(static_index_config, config_file_path);
            }

            if (restart)
            {
                Logger.Log.Debug("Restarting beagle-build-index");
                Process p = new Process();
                p.StartInfo.UseShellExecute = false;
                // FIXME: Maybe this isn't the right way to do things?  It should be ok,
                // the PATH is inherited from the shell script which runs mono itself.
                p.StartInfo.FileName  = "mono";
                p.StartInfo.Arguments = String.Join(" ", Environment.GetCommandLineArgs());
                p.Start();
            }

            Log.Always("Exiting beagle-build-index (pid {0}) at {1}", Process.GetCurrentProcess().Id, DateTime.Now);
        }
示例#13
0
 private DiscVolume(BlockDevice parent, Hal.Manager manager, Hal.Device device) : base(parent, manager, device)
 {
 }
示例#14
0
 public Device(Hal.Manager manager, Hal.Device device)
 {
     this.manager = manager;
     this.device  = device;
 }
示例#15
0
 public Device (Hal.Manager manager, Hal.Device device)
 {
     this.manager = manager;
     this.device = device;
 }
示例#16
0
        public static List<string> FindCdDrives()
        {
            Hal.Manager hal = new Hal.Manager ();

            List<string> devices = new List<string> ();
            Hal.Device[] list = hal.FindDeviceByCapabilityAsDevice ("storage.cdrom");
            if (list == null) {
                return devices;
            }

            foreach (Hal.Device dev in list) {
                devices.Add (dev.GetPropertyString ("block.device"));
            }

            return devices;
        }
示例#17
0
 private CdromDevice(Hal.Manager manager, Hal.Device device) : base(manager, device)
 {
 }
示例#18
0
 public new static DiscVolume Resolve(BlockDevice parent, Hal.Manager manager, Hal.Device device)
 {
     return(device.QueryCapability("volume.disc") ? new DiscVolume(parent, manager, device) : null);
 }