aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-06-04 16:51:41 +0300
committerSergey Poznyakoff <gray@gnu.org>2020-06-04 16:51:41 +0300
commit72750573021b203f832843d272630c6d2cfd60a7 (patch)
treedd19cc70a67d8c2572f9e8dee4937ce90316f80b
parent9aec40f5565dcc277de1c4c4ddd2558ceffdd5bb (diff)
downloadmicron-72750573021b203f832843d272630c6d2cfd60a7.tar.gz
micron-72750573021b203f832843d272630c6d2cfd60a7.tar.bz2
Bugfixes.
* src/micrond.c (micron_environ_init): Initialize detached to 0. * src/crontab.c (command_edit): Create temporary directory in /tmp. * src/watcher.c: Improve diagnostic messages.
-rw-r--r--src/crontab.c42
-rw-r--r--src/micrond.c1
-rw-r--r--src/watcher.c17
3 files changed, 44 insertions, 16 deletions
diff --git a/src/crontab.c b/src/crontab.c
index a2dbdb0..ed1903a 100644
--- a/src/crontab.c
+++ b/src/crontab.c
@@ -478,8 +478,9 @@ command_edit(int argc, char **argv)
char *editor;
char *editor_command;
size_t len;
- char template[] = ".#micronXXXXXX";
- int fd;
+ char *tempdir;
+ char template[] = "micronXXXXXX";
+ int tempfd, fd;
FILE *fp;
struct stat st;
int tempdirfd;
@@ -494,10 +495,21 @@ command_edit(int argc, char **argv)
((editor = getenv("EDITOR")) == NULL || !*editor))
editor = MICRON_EDITOR;
- tempdirfd = create_temp_file(crondirfd, template, 0, 1);
+ tempdir = getenv("TMP");
+ if (!tempdir)
+ tempdir = "/tmp";
+
+ tempfd = open(tempdir, O_RDONLY | O_NONBLOCK | O_DIRECTORY);
+ if (tempfd == -1) {
+ terror("can't open directory %s: %s", tempdir, strerror(errno));
+ return EXIT_FATAL;
+ }
+
+ tempdirfd = create_temp_file(tempfd, template, 0, 1);
if (tempdirfd == -1) {
terror("can't create temporary directory in %s: %s",
crondirname, strerror(errno));
+ close(tempfd);
return EXIT_FATAL;
}
@@ -516,8 +528,8 @@ command_edit(int argc, char **argv)
}
fp = fdopen(fd, "w");
if (!fp) {
- terror("can't fdopen file %s/%s: %s", template, crontabfile,
- strerror(errno));
+ terror("can't fdopen file %s/%s/%s: %s", template, crontabfile,
+ tempdir, strerror(errno));
close(fd);
goto finish;
}
@@ -563,7 +575,7 @@ command_edit(int argc, char **argv)
int i;
if (fchdir(tempdirfd)) {
- terror("failed to change to %s: %s", template,
+ terror("failed to change to %s/%s: %s", tempdir, template,
strerror(errno));
_exit(127);
}
@@ -588,7 +600,20 @@ command_edit(int argc, char **argv)
if (renameat(tempdirfd, crontabfile, crondirfd, crontabfile) == 0)
rc = EXIT_OK;
- else {
+ else if (errno == EXDEV) {
+ FILE *src;
+ fd = openat(tempdirfd, crontabfile, O_RDONLY);
+ if (fd == -1 || (src = fdopen(fd, "r")) == NULL) {
+ terror("can't open file %s/%s/%s: %s", tempdir, template,
+ crontabfile, strerror(errno));
+ close(fd);
+ } else {
+ fp = crontab_open(crontabfile, "w");
+ rc = fcopy(src, fp);
+ fclose(src);
+ fclose(fp);
+ }
+ } else {
terror("failed to rename %s/%s to %s/%s: %s",
template, crontabfile, crondirname, crontabfile,
strerror(errno));
@@ -597,8 +622,9 @@ command_edit(int argc, char **argv)
finish:
cleanupdir(tempdirfd, template);
close(tempdirfd);
- if (unlinkat(crondirfd, template, AT_REMOVEDIR))
+ if (unlinkat(tempfd, template, AT_REMOVEDIR))
terror("failed to remove %s: %s", template, strerror(errno));
+ close(tempfd);
return rc;
}
diff --git a/src/micrond.c b/src/micrond.c
index 0d59b34..1aa350f 100644
--- a/src/micrond.c
+++ b/src/micrond.c
@@ -564,6 +564,7 @@ micron_environ_init(struct micron_environ *ebuf)
{
ebuf->varc = ebuf->varmax = 0;
ebuf->varv = NULL;
+ ebuf->detached = 0;
list_head_init(&ebuf->link);
}
diff --git a/src/watcher.c b/src/watcher.c
index 13fcd16..3a22375 100644
--- a/src/watcher.c
+++ b/src/watcher.c
@@ -100,17 +100,18 @@ event_handler(struct inotify_event *ep)
if (ep->mask & IN_IGNORED)
/* nothing */ ;
else if (ep->mask & IN_Q_OVERFLOW)
- micron_log(LOG_NOTICE, "event queue overflow");
+ micron_log(LOG_NOTICE, "watcher event queue overflow");
else if (ep->mask & IN_UNMOUNT)
/* FIXME? */ ;
else if (!cgrp) {
if (ep->name)
- micron_log(LOG_NOTICE, "unrecognized event %x for %s",
+ micron_log(LOG_NOTICE, "watcher: unrecognized event %x for %s",
ep->mask, ep->name);
else
- micron_log(LOG_NOTICE, "unrecognized event %x", ep->mask);
+ micron_log(LOG_NOTICE, "watcher: unrecognized event %x", ep->mask);
} else if (ep->mask & IN_CREATE) {
- micron_log(LOG_DEBUG, "%s/%s created", cgrp->dirname, ep->name);
+ micron_log(LOG_DEBUG, "watcher: %s/%s created", cgrp->dirname,
+ ep->name);
if (cgrp->type == CGTYPE_GROUPHOST) {
rescan = 1;
usercrongroup_add(cgrp, ep->name);
@@ -122,7 +123,7 @@ event_handler(struct inotify_event *ep)
else
crontab_chattr(cgrp, ep->name);
} else if (ep->mask & (IN_DELETE | IN_MOVED_FROM)) {
- micron_log(LOG_DEBUG, "%s/%s %s", cgrp->dirname, ep->name,
+ micron_log(LOG_DEBUG, "watcher: %s/%s %s", cgrp->dirname, ep->name,
ep->mask & IN_DELETE ? "deleted" : "moved out");
if (cgrp->type == CGTYPE_GROUPHOST) {
watcher_remove(cgrp->wd);
@@ -130,7 +131,7 @@ event_handler(struct inotify_event *ep)
} else
crontab_deleted(cgrp, ep->name);
} else if (ep->mask & (IN_CLOSE_WRITE | IN_MOVED_TO)) {
- micron_log(LOG_DEBUG, "%s/%s %s",
+ micron_log(LOG_DEBUG, "watcher: %s/%s %s",
cgrp->dirname, ep->name,
ep->mask & IN_MOVED_TO ? "moved to" : "written");
rescan = 1;
@@ -140,10 +141,10 @@ event_handler(struct inotify_event *ep)
crontab_updated(cgrp, ep->name);
} else {
if (ep->name)
- micron_log(LOG_NOTICE, "unrecognized event %x for %s",
+ micron_log(LOG_NOTICE, "watcher: unrecognized event %x for %s",
ep->mask, ep->name);
else
- micron_log(LOG_NOTICE, "unrecognized event %x", ep->mask);
+ micron_log(LOG_NOTICE, "watcher: unrecognized event %x", ep->mask);
}
if (rescan) {
LIST_FOREACH(cgrp, &crongroup_head, list)

Return to:

Send suggestions and report system problems to the System administrator.