1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-medusa-support.c - Covers for access to medusa
from nautilus
Copyright (C) 2001 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Ramiro Estrugo <ramiro@eazel.com>
Rebecca Schulman <rebecka@eazel.com>
*/
#include <config.h>
#include "nautilus-medusa-support.h"
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <eel/eel-glib-extensions.h>
#include <eel/eel-string.h>
#include <dirent.h>
#include <stdio.h>
#include <sys/types.h>
#ifdef HAVE_MEDUSA
#include <libmedusa/medusa-system-state.h>
#endif
static const char * nautilus_medusa_get_configuration_file_path (void);
gboolean
nautilus_medusa_services_are_enabled (void)
{
#ifdef HAVE_MEDUSA
return medusa_system_services_are_enabled ();
#else
return FALSE;
#endif
}
NautilusCronStatus
nautilus_medusa_check_cron_is_enabled (void)
{
DIR *proc_directory;
struct dirent *file;
char *stat_file_name;
FILE *stat_file;
char stat_file_data[128];
const char *stat_file_process_name;
int process_number, bytes_read;
NautilusCronStatus status;
/* We figure out whether cron is running by reading the proc
directory, and checking for a process named or ending with
"crond" */
proc_directory = opendir ("/proc");
if (proc_directory == NULL) {
return NAUTILUS_CRON_STATUS_UNKNOWN;
}
status = NAUTILUS_CRON_STATUS_UNKNOWN;
while ((file = readdir (proc_directory)) != NULL) {
/* Process files have numbers */
if (!eel_str_to_int (file->d_name, &process_number)) {
continue;
}
/* Since we've seen at least one process file, we can change our state
* from "unknown" to "presumed off until proved otherwise".
*/
status = NAUTILUS_CRON_STATUS_OFF;
stat_file_name = g_strdup_printf ("/proc/%d/stat", process_number);
stat_file = fopen (stat_file_name, "r");
g_free (stat_file_name);
if (stat_file == NULL) {
continue;
}
bytes_read = fread (stat_file_data, 1, sizeof (stat_file_data) - 1, stat_file);
fclose (stat_file);
stat_file_data[bytes_read] = '\0';
stat_file_process_name = strchr (stat_file_data, ' ');
if (eel_str_has_prefix (stat_file_process_name, " (crond)") ||
eel_str_has_prefix (stat_file_process_name, " (cron)")) {
status = NAUTILUS_CRON_STATUS_ON;
break;
}
}
closedir (proc_directory);
return status;
}
static const char *
nautilus_medusa_get_configuration_file_path (void)
{
#ifdef HAVE_MEDUSA
return medusa_get_configuration_file_path ();
#else
return NULL;
#endif
}
char *
nautilus_medusa_get_explanation_of_enabling (void)
{
#ifdef HAVE_MEDUSA
return g_strdup_printf (_("If you would like to enable fast searches, you can "
"edit the file %s as root. "
"Setting the enabled flag to \"yes\" will turn medusa "
"services on.\n"
"To start indexing and search services right away, you "
"should also run the following commands as root:\n"
"\n"
"medusa-indexd\n"
"medusa-searchd\n"
"\n"
"Fast searches will not be available until an initial "
"index of your files has been created. This may take "
"a long time."),
nautilus_medusa_get_configuration_file_path ());
#else
return g_strdup_printf (_("Medusa, the application that performs searches, cannot be found on "
"your system. If you have compiled nautilus yourself, "
"you will need to install a copy of medusa and recompile nautilus. "
"(A copy of Medusa may be available at ftp://ftp.gnome.org)\n"
"If you are using a packaged version of Nautilus, fast searching is "
"not available.\n"));
#endif
}
|