#define DBFILENAME VARLIBDIR "/config.db"
#define LOCKFILE VARLIBDIR "/.pmxcfs.lockfile"
+#define RESTART_FLAG_FILE RUNDIR "/cfs-restart-flag"
#define CFSDIR "/etc/pve"
gpointer user_data)
{
- cfs_log(log_domain, log_level, NULL, 0, NULL, message);
+ cfs_log(log_domain, log_level, NULL, 0, NULL, "%s", message);
}
static gboolean write_pidfile(pid_t pid)
cfs_plug_t *plug = root_plug->lookup_plug(root_plug, &subpath);
- cfs_debug("find_plug end %s = %p (%s)", path, plug, subpath);
+ cfs_debug("find_plug end %s = %p (%s)", path, (void *) plug, subpath);
if (subpath && subpath[0])
*sub = g_strdup(subpath);
allowed_mode |= (S_IRGRP);
// allow only setting our supported modes (0600 for priv, 0640 for rest)
- if (mode == allowed_mode)
+ // mode has additional bits set, which we ignore; see stat(2)
+ if ((mode & ALLPERMS) == allowed_mode)
ret = 0;
cfs_debug("leave cfs_fuse_chmod %s (%d) mode: %o", path, ret, (int)mode);
{
int ret = -1;
int lockfd = -1;
+ int pipefd[2];
gboolean foreground = FALSE;
gboolean force_local_mode = FALSE;
umask(027);
mkdir(VARLIBDIR, 0755);
+ mkdir(RUNDIR, 0755);
if ((lockfd = open(LOCKFILE, O_RDWR|O_CREAT|O_APPEND, 0600)) == -1) {
cfs_critical("unable to create lock '%s': %s", LOCKFILE, strerror (errno));
for (int i = 10; i >= 0; i--) {
if (flock(lockfd, LOCK_EX|LOCK_NB) != 0) {
if (!i) {
- cfs_critical("unable to aquire pmxcfs lock: %s", strerror (errno));
+ cfs_critical("unable to acquire pmxcfs lock: %s", strerror (errno));
goto err;
}
if (i == 10)
- cfs_message("unable to aquire pmxcfs lock - trying again");
+ cfs_message("unable to acquire pmxcfs lock - trying again");
sleep(1);
}
int len = memdb_read(memdb, "corosync.conf", &conf_data);
if (len >= 0) {
if (force_local_mode) {
- cfs_message("forcing local mode (althought corosync.conf exists)");
+ cfs_message("forcing local mode (although corosync.conf exists)");
cfs_set_quorate(1, TRUE);
} else {
if (!(dcdb = dcdb_new(memdb)))
fuse_set_signal_handlers(fuse_get_session(fuse));
if (!foreground) {
+ if (pipe(pipefd) == -1) {
+ cfs_critical("pipe error: %s", strerror(errno));
+ goto err;
+ }
+
pid_t cpid = fork();
if (cpid == -1) {
cfs_critical("failed to daemonize program - %s", strerror (errno));
goto err;
} else if (cpid) {
+ int readbytes, errno_tmp;
+ char readbuffer;
+ close(pipefd[1]);
+ readbytes = read(pipefd[0], &readbuffer, sizeof(readbuffer));
+ errno_tmp = errno;
+ close(pipefd[0]);
+ if (readbytes == -1) {
+ cfs_critical("read error: %s", strerror(errno_tmp));
+ kill(cpid, SIGKILL);
+ goto err;
+ } else if (readbytes != 1 || readbuffer != '1') {
+ cfs_critical("child failed to send '1'");
+ kill(cpid, SIGKILL);
+ goto err;
+ }
+ /* child finished starting up */
write_pidfile(cpid);
qb_log_fini();
_exit (0);
} else {
int nullfd;
+ close(pipefd[0]);
chroot("/");
server_start(memdb);
+ unlink(RESTART_FLAG_FILE);
+
+ if (!foreground) {
+ /* finished starting up, signaling parent */
+ write(pipefd[1], "1", 1);
+ close(pipefd[1]);
+ }
+
ret = fuse_loop_mt(fuse);
+ open(RESTART_FLAG_FILE, O_CREAT|O_NOCTTY|O_NONBLOCK);
+
cfs_message("teardown filesystem");
server_stop();
if (service_status)
service_dfsm_destroy(service_status);
- sleep(1); /* do not restart too fast */
ret:
if (status_fsm)