int fuse_set_signal_handlers(struct fuse_session *se) { if (set_one_signal_handler(SIGHUP, exit_handler) == -1 || set_one_signal_handler(SIGINT, exit_handler) == -1 || set_one_signal_handler(SIGTERM, exit_handler) == -1 || set_one_signal_handler(SIGPIPE, SIG_IGN) == -1) return -1; fuse_instance = se; return 0; }
void fuse_remove_signal_handlers(struct fuse_session *se) { if (fuse_instance != se) fprintf(stderr, "fuse: fuse_remove_signal_handlers: unknown session\n"); else fuse_instance = NULL; set_one_signal_handler(SIGHUP, SIG_DFL); set_one_signal_handler(SIGINT, SIG_DFL); set_one_signal_handler(SIGTERM, SIG_DFL); set_one_signal_handler(SIGPIPE, SIG_DFL); }
int fusefs_setup(char *mountpoint, const struct fuse_operations *op, char *opts) { char fuse_new_opts[1024]; char fuse_mount_opts[1024]; char nopts[1024]; char *cur; char *ptr; fuse_new_opts[0] = '\0'; fuse_mount_opts[0] = '\0'; for (cur=opts;cur;cur = ptr) { ptr = strchr(cur,','); if (ptr) *(ptr++) = '\0'; if (fuse_is_lib_option(cur)) { if (fuse_new_opts[0]) { strcpy(nopts,fuse_new_opts); snprintf(fuse_new_opts,1024,"%s,%s",nopts,cur); } else { snprintf(fuse_new_opts,1024,"%s",cur); } } else { if (fuse_mount_opts[0]) { strcpy(nopts,fuse_mount_opts); snprintf(fuse_mount_opts,1024,"%s,%s",nopts,cur); } else { snprintf(fuse_mount_opts,1024,"%s",cur); } } } fusefd = -1; if (fuse_instance != NULL) { return 0; } if (mounted_at != NULL) { return 0; } /* First, mount us */ fusefd = fuse_mount(mountpoint, fuse_mount_opts[0] ? fuse_mount_opts : NULL); if (fusefd == -1) return 0; fuse_instance = fuse_new(fusefd, fuse_new_opts[0] ? fuse_new_opts : NULL, op, sizeof(*op)); if (fuse_instance == NULL) goto err_unmount; /* Set signal handlers */ if (set_one_signal_handler(SIGHUP, fusefs_ehandler) == -1 || set_one_signal_handler(SIGINT, fusefs_ehandler) == -1 || set_one_signal_handler(SIGTERM, fusefs_ehandler) == -1 || set_one_signal_handler(SIGPIPE, SIG_IGN) == -1) return 0; atexit(fusefs_ehandler); /* We've initialized it! */ mounted_at = strdup(mountpoint); return 1; err_destroy: fuse_destroy(fuse_instance); err_unmount: fuse_unmount(mountpoint); return 0; }
int main (int argc, char **argv) { guint owner_id; GBytes *introspection_bytes; g_autoptr(GError) error = NULL; g_autofree char *path = NULL; GDBusConnection *session_bus; GOptionContext *context; setlocale (LC_ALL, ""); /* Avoid even loading gvfs to avoid accidental confusion */ g_setenv ("GIO_USE_VFS", "local", TRUE); context = g_option_context_new ("- document portal"); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("option parsing failed: %s\n", error->message); return 1; } if (opt_daemon) { pid_t pid; ssize_t read_res; daemon_event_fd = eventfd (0, EFD_CLOEXEC); pid = fork (); if (pid != 0) { guint64 counter; read_res = read (daemon_event_fd, &counter, sizeof (counter)); if (read_res != 8) exit (1); exit (counter - 1); } } if (opt_verbose) g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, message_handler, NULL); g_set_prgname (argv[0]); loop = g_main_loop_new (NULL, FALSE); path = g_build_filename (g_get_user_data_dir (), "xdg-app/db", TABLE_NAME, NULL); db = xdg_app_db_new (path, FALSE, &error); if (db == NULL) { g_printerr ("Failed to load db: %s\n", error->message); do_exit (2); } session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (session_bus == NULL) { g_printerr ("No session bus: %s\n", error->message); do_exit (3); } permission_store = xdg_app_permission_store_proxy_new_sync (session_bus,G_DBUS_PROXY_FLAGS_NONE, "org.freedesktop.XdgApp", "/org/freedesktop/XdgApp/PermissionStore", NULL, &error); if (permission_store == NULL) { g_print ("No permission store: %s\n", error->message); do_exit (4); } /* We want do do our custom post-mainloop exit */ g_dbus_connection_set_exit_on_close (session_bus, FALSE); g_signal_connect (session_bus, "closed", G_CALLBACK (session_bus_closed), NULL); if (set_one_signal_handler(SIGHUP, exit_handler, 0) == -1 || set_one_signal_handler(SIGINT, exit_handler, 0) == -1 || set_one_signal_handler(SIGTERM, exit_handler, 0) == -1 || set_one_signal_handler(SIGPIPE, SIG_IGN, 0) == -1) { do_exit (5); } introspection_bytes = g_resources_lookup_data ("/org/freedesktop/portal/Documents/org.freedesktop.portal.Documents.xml", 0, NULL); g_assert (introspection_bytes != NULL); introspection_data = g_dbus_node_info_new_for_xml (g_bytes_get_data (introspection_bytes, NULL), NULL); owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, "org.freedesktop.portal.Documents", G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | (opt_replace ? G_BUS_NAME_OWNER_FLAGS_REPLACE : 0), on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL); g_main_loop_run (loop); xdp_fuse_exit (); g_bus_unown_name (owner_id); g_dbus_node_info_unref (introspection_data); do_exit (final_exit_status); return 0; }