rpms/fcron/devel fcron.spec, 1.18, 1.19 fcron_config_modified.c, 1.1, 1.2
Patrice Dumas
pertusus at fedoraproject.org
Mon Dec 8 13:56:42 UTC 2008
Author: pertusus
Update of /cvs/extras/rpms/fcron/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv24352
Modified Files:
fcron.spec fcron_config_modified.c
Log Message:
* Mon Dec 8 2008 Patrice Dumas <pertusus[AT]free[DOT]fr> 3.0.4-5
- simplify fcron_watch_config.c thanks to watching example in cronie
and also wait for cron.d instead of erroring
- dont provide %{_sysconfdir}/cron.d, since fcron_watch_config may
not be started
Index: fcron.spec
===================================================================
RCS file: /cvs/extras/rpms/fcron/devel/fcron.spec,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- fcron.spec 5 Dec 2008 19:36:58 -0000 1.18
+++ fcron.spec 8 Dec 2008 13:56:11 -0000 1.19
@@ -1,6 +1,6 @@
Name: fcron
Version: 3.0.4
-Release: 4%{?dist}
+Release: 5%{?dist}
Summary: A task scheduler
Summary(fr): Un ordonnanceur de tâches
Summary(it): Uno schedulatore di processi
@@ -148,7 +148,7 @@
%{__install} -m755 fcron_config_modified %{buildroot}%{_bindir}
-mkdir -p %{buildroot}%{_sysconfdir}/cron.d
+#mkdir -p %{buildroot}%{_sysconfdir}/cron.d
# remove a page that is hold in cron
%{__rm} %{buildroot}%{_mandir}/man3/bitstring.3*
@@ -233,9 +233,15 @@
%{_sbindir}/daemon_fcron_watch_config
%dir %attr(770,fcron,fcron) %{_localstatedir}/spool/fcron
%ghost %{_localstatedir}/run/fcron.pid
-%dir %{_sysconfdir}/cron.d
+#%dir %{_sysconfdir}/cron.d
%changelog
+* Mon Dec 8 2008 Patrice Dumas <pertusus[AT]free[DOT]fr> 3.0.4-5
+ - simplify fcron_watch_config.c thanks to watching example in cronie
+ and also wait for cron.d instead of erroring
+ - dont provide %%{_sysconfdir}/cron.d, since fcron_watch_config may
+ not be started
+
* Fri Dec 5 2008 Patrice Dumas <pertusus[AT]free[DOT]fr> 3.0.4-4
- instead of using inotifywait use a specific C program to watch config
- don't try to run anything in the default case and merge the
Index: fcron_config_modified.c
===================================================================
RCS file: /cvs/extras/rpms/fcron/devel/fcron_config_modified.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- fcron_config_modified.c 5 Dec 2008 19:36:58 -0000 1.1
+++ fcron_config_modified.c 8 Dec 2008 13:56:11 -0000 1.2
@@ -25,16 +25,17 @@
# define SYSCONFDIR "/etc"
#endif
+#ifndef CRONDIR
+#define CRONDIR SYSCONFDIR "/cron.d"
+#endif
+
fcron_watched_file watched_config_files [] = {
{ SYSCONFDIR "/crontab", 0 },
{ SYSCONFDIR "/fcrontab", 0 },
+ { CRONDIR, 0 },
{NULL, 0}
};
-#ifndef CRONDIR
-#define CRONDIR SYSCONFDIR "/cron.d"
-#endif
-
/* size of the event structure, not counting name */
#define EVENT_SIZE (sizeof (struct inotify_event))
/* 1024 events with filenames of length 1024 */
@@ -49,79 +50,32 @@
int watch_sysconfdir = 0;
fcron_watched_file *watched_file;
struct stat st;
- DIR *crondir_dir;
- struct dirent *cron_dir_entry;
- char *file_in_crondir_filename;
- int file_in_crondir_size = 1024;
+ int debug = 0;
- if ((file_in_crondir_filename = malloc(sizeof(char) * (file_in_crondir_size+1))) == NULL)
- return EXIT_FAILURE;
-
fd = inotify_init();
if (fd < 0) {
perror("inotify_init()");
return EXIT_FAILURE;
}
- watch_desc = inotify_add_watch(fd, CRONDIR, IN_CREATE | IN_MOVE | IN_DELETE);
- if (watch_desc < 0) {
- perror("inotify_add_watch("CRONDIR")");
- close(fd);
- return EXIT_FAILURE;
- }
-
- /* add watches to files in CRONDIR */
- if ((crondir_dir = opendir(CRONDIR)) == NULL ) {
- perror("opendir("CRONDIR")");
- close(fd);
- return EXIT_FAILURE;
- }
- while ((cron_dir_entry = readdir(crondir_dir))) {
- if (!strncmp(".", cron_dir_entry->d_name, 1) || !strncmp("..", cron_dir_entry->d_name, 2))
- continue;
- /* allocate enough storage for CRONDIR files. This should never been
- * needed, since there are already 1024 char */
- while (file_in_crondir_size < (strlen(cron_dir_entry->d_name) + strlen(CRONDIR"/")+1)) {
- file_in_crondir_size = file_in_crondir_size * 2;
- if ((file_in_crondir_filename = realloc(file_in_crondir_filename, file_in_crondir_size)) == NULL) {
- close(fd);
- return EXIT_FAILURE;
- }
- }
- strcpy(file_in_crondir_filename, CRONDIR"/");
- strcat(file_in_crondir_filename, cron_dir_entry->d_name);
- watch_desc = inotify_add_watch(fd, file_in_crondir_filename, IN_DELETE_SELF | IN_MOVE_SELF | IN_CLOSE_WRITE);
- if (watch_desc < 0) {
- if (lstat(file_in_crondir_filename, &st) == 0)
- {
- fprintf(stderr, "inotify_add_watch(%s): %s\n", file_in_crondir_filename, strerror(errno));
- close(fd);
- return EXIT_FAILURE;
- }
- else { /* the file was removed before the inotify_add_watch */
- return EXIT_SUCCESS;
- }
- }
- }
- closedir(crondir_dir);
-
- /* now turn to crontab and fcrontab.
- * if file exist, add a watch, otherwise set a watch on the up directory
- * to watch file appear */
+ /*
+ * if file or dir exist, add a watch, otherwise set a watch on the up
+ * directory to watch file appear */
for (watched_file = watched_config_files; watched_file->filename != NULL; watched_file++) {
if (lstat(watched_file->filename, &st) == 0) {
- watch_desc = inotify_add_watch(fd, watched_file->filename, IN_DELETE_SELF | IN_MOVE_SELF | IN_CLOSE_WRITE);
+ watch_desc = inotify_add_watch(fd, watched_file->filename, IN_CLOSE_WRITE | IN_ATTRIB | IN_MOVED_TO | IN_MOVED_FROM | IN_MOVE_SELF | IN_DELETE);
if (watch_desc < 0) {
if (lstat(watched_file->filename, &st) == 0) {
fprintf(stderr, "inotify_add_watch(%s): %s\n", watched_file->filename, strerror(errno));
close(fd);
return EXIT_FAILURE;
}
- else { /* file was removed between the first stat and inotify_add_watch */
+ else /* file was removed between the first stat and inotify_add_watch */
return EXIT_SUCCESS;
- }
}
watched_file->already_here = 1;
+ if (debug)
+ fprintf(stderr, "File/dir already there: %s\n", watched_file->filename);
}
else if (! watch_sysconfdir) {
watch_desc_sysconfdir = inotify_add_watch(fd, SYSCONFDIR, IN_CREATE | IN_MOVED_TO);
@@ -130,11 +84,13 @@
close(fd);
return EXIT_FAILURE;
}
+ if (debug)
+ fprintf(stderr, "Watching " SYSCONFDIR " (for %s)\n", watched_file->filename);
watch_sysconfdir = 1;
}
}
- /* the loop is needed in case crontab or fcrontab file is missing
+ /* the loop is needed in case a file or directory is missing
* since in that case we don't exit if another file is added in
* SYSCONFDIR */
while (1)
@@ -168,23 +124,22 @@
{
struct inotify_event *event;
event = (struct inotify_event *) &events_buffer[i];
- /* printf ("wd=%d mask=%u cookie=%u len=%u\n",
- event->wd, event->mask,
- event->cookie, event->len);
-
- if (event->len)
- printf ("name=%s\n", event->name); */
+ if (debug)
+ {
+ printf ("wd=%d mask=%u cookie=%u len=%u\n",
+ event->wd, event->mask, event->cookie, event->len);
+ if (event->len)
+ printf ("name=%s\n", event->name);
+ }
if (watch_sysconfdir && (event->wd == watch_desc_sysconfdir) && event->len) {
for (watched_file = watched_config_files; watched_file->filename != NULL; watched_file++) {
- if ((strcmp(event->name, basename(watched_file->filename)) == 0) && (!watched_file->already_here)) {
+ if ((strcmp(event->name, basename(watched_file->filename)) == 0) && (!watched_file->already_here))
return EXIT_SUCCESS;
- }
}
i += EVENT_SIZE + event->len;
}
- else {
+ else
return EXIT_SUCCESS;
- }
}
}
}
More information about the fedora-extras-commits
mailing list