- * @daemon specifies whether the calling process is the filesystem daemon or the
- * unmount process.
- */
-static int open_message_queues(struct wimfs_context *ctx, bool daemon)
-{
- int unmount_to_daemon_mq_flags = O_WRONLY | O_CREAT;
- int daemon_to_unmount_mq_flags = O_RDONLY | O_CREAT;
- mode_t mode;
- mode_t orig_umask;
- int ret;
-
- if (daemon) {
- swap(unmount_to_daemon_mq_flags, daemon_to_unmount_mq_flags);
- mode = 0600;
- } else {
- mode = 0666;
- }
-
- orig_umask = umask(0000);
- DEBUG("Opening message queue \"%s\"", ctx->unmount_to_daemon_mq_name);
- ctx->unmount_to_daemon_mq = mq_open(ctx->unmount_to_daemon_mq_name,
- unmount_to_daemon_mq_flags, mode, NULL);
-
- if (ctx->unmount_to_daemon_mq == (mqd_t)-1) {
- ERROR_WITH_ERRNO("mq_open()");
- ret = WIMLIB_ERR_MQUEUE;
- goto out;
- }
-
- DEBUG("Opening message queue \"%s\"", ctx->daemon_to_unmount_mq_name);
- ctx->daemon_to_unmount_mq = mq_open(ctx->daemon_to_unmount_mq_name,
- daemon_to_unmount_mq_flags, mode, NULL);
-
- if (ctx->daemon_to_unmount_mq == (mqd_t)-1) {
- ERROR_WITH_ERRNO("mq_open()");
- mq_close(ctx->unmount_to_daemon_mq);
- mq_unlink(ctx->unmount_to_daemon_mq_name);
- ctx->unmount_to_daemon_mq = (mqd_t)-1;
- ret = WIMLIB_ERR_MQUEUE;
- goto out;
- }
- ret = 0;
-out:
- umask(orig_umask);
- return ret;
-}
-
-/* Try to determine the maximum message size of a message queue. The return
- * value is the maximum message size, or a guess of 8192 bytes if it cannot be
- * determined. */
-static long mq_get_msgsize(mqd_t mq)
-{
- static const char *msgsize_max_file = "/proc/sys/fs/mqueue/msgsize_max";
- FILE *fp;
- struct mq_attr attr;
- long msgsize;
-
- if (mq_getattr(mq, &attr) == 0) {
- msgsize = attr.mq_msgsize;
- } else {
- ERROR_WITH_ERRNO("mq_getattr()");
- ERROR("Attempting to read %s", msgsize_max_file);
- fp = fopen(msgsize_max_file, "rb");
- if (fp) {
- if (fscanf(fp, "%ld", &msgsize) != 1) {
- ERROR("Assuming message size of 8192");
- msgsize = 8192;
- }
- fclose(fp);
- } else {
- ERROR_WITH_ERRNO("Failed to open the file `%s'",
- msgsize_max_file);
- ERROR("Assuming message size of 8192");
- msgsize = 8192;