void caps_init(void) { log_info("Loading capabilities cache"); cache_loc = files_get_data_path(FILE_CAPSCACHE); if (g_file_test(cache_loc, G_FILE_TEST_EXISTS)) { g_chmod(cache_loc, S_IRUSR | S_IWUSR); } cache = g_key_file_new(); g_key_file_load_from_file(cache, cache_loc, G_KEY_FILE_KEEP_COMMENTS, NULL); jid_to_ver = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); jid_to_caps = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)caps_destroy); prof_features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL); g_hash_table_add(prof_features, strdup(STANZA_NS_CAPS)); g_hash_table_add(prof_features, strdup(XMPP_NS_DISCO_INFO)); g_hash_table_add(prof_features, strdup(XMPP_NS_DISCO_ITEMS)); g_hash_table_add(prof_features, strdup(STANZA_NS_MUC)); g_hash_table_add(prof_features, strdup(STANZA_NS_CONFERENCE)); g_hash_table_add(prof_features, strdup(STANZA_NS_VERSION)); g_hash_table_add(prof_features, strdup(STANZA_NS_CHATSTATES)); g_hash_table_add(prof_features, strdup(STANZA_NS_PING)); if (prefs_get_boolean(PREF_RECEIPTS_SEND)) { g_hash_table_add(prof_features, strdup(STANZA_NS_RECEIPTS)); } if (prefs_get_boolean(PREF_LASTACTIVITY)) { g_hash_table_add(prof_features, strdup(STANZA_NS_LASTACTIVITY)); } my_sha1 = NULL; }
/** * a_preferences_save_to_file: * * Returns: TRUE on success */ gboolean a_preferences_save_to_file() { gchar *fn = g_build_filename(a_get_viking_dir(), VIKING_PREFS_FILE, NULL); FILE *f = g_fopen(fn, "w"); // Since preferences file may contain sensitive information, // it'll be better to store it so it can only be read by the user if ( g_chmod(fn, 0600) != 0 ) g_warning ( "%s: Failed to set permissions on %s", __FUNCTION__, fn ); g_free ( fn ); if ( f ) { VikLayerParam *param; VikLayerTypedParamData *val; int i; for ( i = 0; i < params->len; i++ ) { param = (VikLayerParam *) g_ptr_array_index(params,i); val = (VikLayerTypedParamData *) g_hash_table_lookup ( values, param->name ); if ( val ) if ( val->type != VIK_LAYER_PARAM_PTR ) file_write_layer_param ( f, param->name, val->type, val->data ); } fclose(f); f = NULL; return TRUE; } return FALSE; }
void tlscerts_init(void) { log_info("Loading TLS certificates"); tlscerts_loc = files_get_data_path(FILE_TLSCERTS); if (g_file_test(tlscerts_loc, G_FILE_TEST_EXISTS)) { g_chmod(tlscerts_loc, S_IRUSR | S_IWUSR); } tlscerts = g_key_file_new(); g_key_file_load_from_file(tlscerts, tlscerts_loc, G_KEY_FILE_KEEP_COMMENTS, NULL); certs_ac = autocomplete_new(); gsize len = 0; gchar **groups = g_key_file_get_groups(tlscerts, &len); int i = 0; for (i = 0; i < g_strv_length(groups); i++) { autocomplete_add(certs_ac, groups[i]); } g_strfreev(groups); current_fp = NULL; }
static void change_dir_modes (const gchar *path) { GDir *dir; GError *err = NULL; const gchar *file = NULL; dir = g_dir_open (path, 0, &err); if (err) { g_warning ("Error opening directory %s: %s \n", path, err->message); g_clear_error (&err); return; } while ((file = g_dir_read_name (dir))) { gchar *full_path = g_build_filename (path, file, NULL); if (g_file_test (full_path, G_FILE_TEST_IS_DIR)) change_dir_modes (full_path); g_free (full_path); } if (g_chmod (path, 0700) == -1) g_warning ("%s: Failed to chmod of '%s': %s", G_STRFUNC, path, g_strerror (errno)); g_dir_close (dir); }
void accounts_load(void) { log_info("Loading accounts"); all_ac = autocomplete_new(); enabled_ac = autocomplete_new(); accounts_loc = _get_accounts_file(); if (g_file_test(accounts_loc, G_FILE_TEST_EXISTS)) { g_chmod(accounts_loc, S_IRUSR | S_IWUSR); } accounts = g_key_file_new(); g_key_file_load_from_file(accounts, accounts_loc, G_KEY_FILE_KEEP_COMMENTS, NULL); // create the logins searchable list for autocompletion gsize naccounts; gchar **account_names = g_key_file_get_groups(accounts, &naccounts); gsize i; for (i = 0; i < naccounts; i++) { autocomplete_add(all_ac, account_names[i]); if (g_key_file_get_boolean(accounts, account_names[i], "enabled", NULL)) { autocomplete_add(enabled_ac, account_names[i]); } } g_strfreev(account_names); }
/** * a_preferences_save_to_file: * * Returns: TRUE on success */ gboolean a_preferences_save_to_file() { gchar *fn = g_build_filename(a_get_viking_dir(), VIKING_PREFS_FILE, NULL); // TODO: error checking FILE *f = g_fopen(fn, "w"); /* Since preferences files saves OSM login credentials, * it'll be better to store it in secret. */ g_chmod(fn, 0600); g_free ( fn ); if ( f ) { VikLayerParam *param; VikLayerTypedParamData *val; int i; for ( i = 0; i < params->len; i++ ) { param = (VikLayerParam *) g_ptr_array_index(params,i); val = (VikLayerTypedParamData *) g_hash_table_lookup ( values, param->name ); if ( val ) if ( val->type != VIK_LAYER_PARAM_PTR ) file_write_layer_param ( f, param->name, val->type, val->data ); } fclose(f); f = NULL; return TRUE; } return FALSE; }
static void pdf_load_job_cache_set_attributes (PdfLoadJob *job) { GFileInfo *info; GFile *file; if (job->download_file != NULL) { gchar *path; path = g_file_get_path (job->download_file); /* In case the downloaded file is not the final PDF, then we * need to convert it. */ if (g_strcmp0 (path, job->pdf_path) != 0) { /* make the file private */ g_chmod (path, 0600); job->uri = g_file_get_uri (job->download_file); pdf_load_job_from_openoffice (job); g_free (path); return; } g_clear_object (&job->download_file); g_free (path); } /* make the file private */ g_chmod (job->pdf_path, 0600); file = g_file_new_for_path (job->pdf_path); info = g_file_info_new (); g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED, job->original_file_mtime); g_file_set_attributes_async (file, info, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, job->cancellable, cache_set_attributes_ready_cb, job); g_object_unref (info); g_object_unref (file); }
void prefs_load(void) { GError *err; prefs_loc = _get_preferences_file(); if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) { g_chmod(prefs_loc, S_IRUSR | S_IWUSR); } prefs = g_key_file_new(); g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS, NULL); err = NULL; log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err); if (err) { log_maxsize = 0; g_error_free(err); } // move pre 0.4.7 otr.warn to enc.warn err = NULL; gboolean otr_warn = g_key_file_get_boolean(prefs, PREF_GROUP_UI, "otr.warn", &err); if (err == NULL) { g_key_file_set_boolean(prefs, PREF_GROUP_UI, _get_key(PREF_ENC_WARN), otr_warn); g_key_file_remove_key(prefs, PREF_GROUP_UI, "otr.warn", NULL); } else { g_error_free(err); } // migrate pre 0.4.7 time settings format if (g_key_file_has_key(prefs, PREF_GROUP_UI, "time", NULL)) { char *time = g_key_file_get_string(prefs, PREF_GROUP_UI, "time", NULL); if (g_strcmp0(time, "minutes") == 0) { g_key_file_set_string(prefs, PREF_GROUP_UI, "time", "%H:%M"); } else if (g_strcmp0(time, "seconds") == 0) { g_key_file_set_string(prefs, PREF_GROUP_UI, "time", "%H:%M:%S"); } else if (g_strcmp0(time, "off") == 0) { g_key_file_set_string(prefs, PREF_GROUP_UI, "time", ""); } } if (g_key_file_has_key(prefs, PREF_GROUP_UI, "time.statusbar", NULL)) { char *time = g_key_file_get_string(prefs, PREF_GROUP_UI, "time.statusbar", NULL); if (g_strcmp0(time, "minutes") == 0) { g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", "%H:%M"); } else if (g_strcmp0(time, "seconds") == 0) { g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", "%H:%M:%S"); } else if (g_strcmp0(time, "off") == 0) { g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", ""); } } _save_prefs(); boolean_choice_ac = autocomplete_new(); autocomplete_add(boolean_choice_ac, "on"); autocomplete_add(boolean_choice_ac, "off"); }
/** @brief Modifies permission of file - like chmod() * * @param file filename or fullpath of file * @param mode the permission mode like chmod() * @returns TRUE on success, FALSE otherwise * */ osync_bool osync_testing_file_chmod(const char *file, int mode) { /* GLib 2.16.3 Note: "[...] Software that needs to manage file permissions on Windows exactly should use the Win32 API." TODO: Do we have to care about this on Windows?! */ return g_chmod(file, mode); }
static void _save_cache(void) { gsize g_data_size; gchar *g_cache_data = g_key_file_to_data(cache, &g_data_size, NULL); g_file_set_contents(cache_loc, g_cache_data, g_data_size, NULL); g_chmod(cache_loc, S_IRUSR | S_IWUSR); g_free(g_cache_data); }
static void _save_pubkeys(void) { gsize g_data_size; gchar *g_pubkeys_data = g_key_file_to_data(pubkeyfile, &g_data_size, NULL); g_file_set_contents(pubsloc, g_pubkeys_data, g_data_size, NULL); g_chmod(pubsloc, S_IRUSR | S_IWUSR); g_free(g_pubkeys_data); }
static void _save_tlscerts(void) { gsize g_data_size; gchar *g_tlscerts_data = g_key_file_to_data(tlscerts, &g_data_size, NULL); g_file_set_contents(tlscerts_loc, g_tlscerts_data, g_data_size, NULL); g_chmod(tlscerts_loc, S_IRUSR | S_IWUSR); g_free(g_tlscerts_data); }
static int chmod_wrapper (const char *filename, mode_t mode) { #ifdef HAVE_G_CHMOD return g_chmod (filename, mode); #else return chmod (filename, mode); #endif }
static BinaryRegistryCache * gst_registry_binary_cache_init (GstRegistry * registry, const char *location) { BinaryRegistryCache *cache = g_slice_new0 (BinaryRegistryCache); cache->location = location; cache->tmp_location = g_strconcat (location, ".tmpXXXXXX", NULL); cache->cache_fd = g_mkstemp (cache->tmp_location); if (cache->cache_fd == -1) { int ret; GStatBuf statbuf; gchar *dir; /* oops, I bet the directory doesn't exist */ dir = g_path_get_dirname (location); g_mkdir_with_parents (dir, 0777); ret = g_stat (dir, &statbuf); if (ret != -1 && (statbuf.st_mode & 0700) != 0700) { g_chmod (dir, 0700); } g_free (dir); /* the previous g_mkstemp call overwrote the XXXXXX placeholder ... */ g_free (cache->tmp_location); cache->tmp_location = g_strconcat (location, ".tmpXXXXXX", NULL); cache->cache_fd = g_mkstemp (cache->tmp_location); if (cache->cache_fd == -1) { GST_DEBUG ("g_mkstemp() failed: %s", g_strerror (errno)); g_free (cache->tmp_location); g_slice_free (BinaryRegistryCache, cache); return NULL; } ret = g_stat (cache->tmp_location, &statbuf); if (ret != -1 && (statbuf.st_mode & 0600) != 0600) { g_chmod (cache->tmp_location, 0600); } } return cache; }
void plugin_settings_init(void) { char *settings_file = files_get_data_path(FILE_PLUGIN_SETTINGS); if (g_file_test(settings_file, G_FILE_TEST_EXISTS)) { g_chmod(settings_file, S_IRUSR | S_IWUSR); } settings = g_key_file_new(); g_key_file_load_from_file(settings, settings_file, G_KEY_FILE_KEEP_COMMENTS, NULL); gsize g_data_size; gchar *g_data = g_key_file_to_data(settings, &g_data_size, NULL); g_file_set_contents(settings_file, g_data, g_data_size, NULL); g_chmod(settings_file, S_IRUSR | S_IWUSR); g_free(g_data); free(settings_file); }
void plugin_themes_init(void) { char *themes_file = files_get_data_path(FILE_PLUGIN_THEMES); if (g_file_test(themes_file, G_FILE_TEST_EXISTS)) { g_chmod(themes_file, S_IRUSR | S_IWUSR); } themes = g_key_file_new(); g_key_file_load_from_file(themes, themes_file, G_KEY_FILE_KEEP_COMMENTS, NULL); gsize g_data_size; gchar *g_data = g_key_file_to_data(themes, &g_data_size, NULL); g_file_set_contents(themes_file, g_data, g_data_size, NULL); g_chmod(themes_file, S_IRUSR | S_IWUSR); g_free(g_data); free(themes_file); }
void log_init(log_level_t filter) { level_filter = filter; tz = g_time_zone_new_local(); gchar *log_file = _get_main_log_file(); logp = fopen(log_file, "a"); g_chmod(log_file, S_IRUSR | S_IWUSR); mainlogfile = g_string_new(log_file); free(log_file); }
void chat_log_chat(const gchar * const login, gchar *other, const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp) { struct dated_chat_log *dated_log = g_hash_table_lookup(logs, other); // no log for user if (dated_log == NULL) { dated_log = _create_log(other, login); g_hash_table_insert(logs, strdup(other), dated_log); // log exists but needs rolling } else if (_log_roll_needed(dated_log)) { dated_log = _create_log(other, login); g_hash_table_replace(logs, strdup(other), dated_log); } gchar *date_fmt = NULL; GDateTime *dt = NULL; if (tv_stamp == NULL) { dt = g_date_time_new_now_local(); } else { dt = g_date_time_new_from_timeval_utc(tv_stamp); } date_fmt = g_date_time_format(dt, "%H:%M:%S"); FILE *logp = fopen(dated_log->filename, "a"); g_chmod(dated_log->filename, S_IRUSR | S_IWUSR); if (logp != NULL) { if (direction == PROF_IN_LOG) { if (strncmp(msg, "/me ", 4) == 0) { fprintf(logp, "%s - *%s %s\n", date_fmt, other, msg + 4); } else { fprintf(logp, "%s - %s: %s\n", date_fmt, other, msg); } } else { if (strncmp(msg, "/me ", 4) == 0) { fprintf(logp, "%s - *me %s\n", date_fmt, msg + 4); } else { fprintf(logp, "%s - me: %s\n", date_fmt, msg); } } fflush(logp); int result = fclose(logp); if (result == EOF) { log_error("Error closing file %s, errno = %d", dated_log->filename, errno); } } g_free(date_fmt); g_date_time_unref(dt); }
static void setup (TestCase *tc, gconstpointer data) { GPtrArray *ptr = g_ptr_array_new (); const TestFixture *fix = data; const gchar *old_val = g_getenv ("XDG_CONFIG_DIRS"); gint i; struct group *gr = NULL; g_setenv ("XDG_CONFIG_DIRS", config_dir, TRUE); tc->cert_dir = g_build_filename (config_dir, "cockpit", "ws-certs.d", NULL); /* make sure we start clean */ delete_all(tc); if (fix->readonly_dir) { g_assert (g_mkdir_with_parents (tc->cert_dir, 0755) == 0); g_assert (g_chmod (tc->cert_dir, 0555) == 0); } g_ptr_array_add (ptr, "certificate"); if (fix->ensure) { cockpit_expect_info ("Generating temporary certificate*"); cockpit_expect_info ("Error generating temporary dummy cert using sscg, falling back to openssl*"); g_ptr_array_add (ptr, "--ensure"); } g_ptr_array_add (ptr, "--user"); g_ptr_array_add (ptr, (gchar *) g_get_user_name ()); gr = getgrnam (g_get_user_name ()); if (gr != NULL) { g_ptr_array_add (ptr, "--group"); g_ptr_array_add (ptr, (gchar *) g_get_user_name ()); } for (i = 0; fix->files[i] != NULL; i++) g_ptr_array_add (ptr, (gchar *) fix->files[i]); if (fix->expected_message) cockpit_expect_message (fix->expected_message); tc->ret = cockpit_remotectl_certificate (ptr->len, (gchar **) ptr->pdata); g_ptr_array_free (ptr, TRUE); if (old_val) g_setenv ("XDG_CONFIG_DIRS", old_val, TRUE); else g_unsetenv ("XDG_CONFIG_DIRS"); }
void plugin_settings_init(void) { gchar *xdg_data = xdg_get_data_home(); GString *fileloc = g_string_new(xdg_data); g_string_append(fileloc, "/profanity/plugin_settings"); g_free(xdg_data); if (g_file_test(fileloc->str, G_FILE_TEST_EXISTS)) { g_chmod(fileloc->str, S_IRUSR | S_IWUSR); } settings = g_key_file_new(); g_key_file_load_from_file(settings, fileloc->str, G_KEY_FILE_KEEP_COMMENTS, NULL); gsize g_data_size; gchar *g_data = g_key_file_to_data(settings, &g_data_size, NULL); g_file_set_contents(fileloc->str, g_data, g_data_size, NULL); g_chmod(fileloc->str, S_IRUSR | S_IWUSR); g_free(g_data); g_string_free(fileloc, TRUE); }
static void _save_prefs(void) { gsize g_data_size; gchar *g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL); gchar *base = g_path_get_basename(prefs_loc); gchar *true_loc = get_file_or_linked(prefs_loc, base); g_file_set_contents(true_loc, g_prefs_data, g_data_size, NULL); g_chmod(prefs_loc, S_IRUSR | S_IWUSR); g_free(base); free(true_loc); g_free(g_prefs_data); }
void change_permissions_of_a_directory(void) { /* Change the permissions of a file or directory. */ const gchar *file_name = "Test.txt"; if (!g_file_test(file_name, G_FILE_TEST_EXISTS)) { g_print ("File %s doesn't exists. \n", file_name); } else { g_print ("Changing %s permissions. \n", file_name); g_chmod(file_name, 0700); } }
static void _save_accounts(void) { gsize g_data_size; gchar *g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL); gchar *xdg_data = xdg_get_data_home(); GString *base_str = g_string_new(xdg_data); g_string_append(base_str, "/profanity/"); gchar *true_loc = get_file_or_linked(accounts_loc, base_str->str); g_file_set_contents(true_loc, g_accounts_data, g_data_size, NULL); g_chmod(accounts_loc, S_IRUSR | S_IWUSR); g_free(xdg_data); free(true_loc); g_free(g_accounts_data); g_string_free(base_str, TRUE); }
static void _save_settings(void) { gsize g_data_size; gchar *g_data = g_key_file_to_data(settings, &g_data_size, NULL); char *fileloc = files_get_data_path(FILE_PLUGIN_SETTINGS); gchar *base = g_path_get_basename(fileloc); gchar *true_loc = get_file_or_linked(fileloc, base); g_free(base); g_file_set_contents(true_loc, g_data, g_data_size, NULL); free(true_loc); g_free(g_data); g_chmod(fileloc, S_IRUSR | S_IWUSR); free(fileloc); }
static gboolean save_event(struct namespace_data_s *ns_data, gridcluster_event_t *e, GError **error) { time_t old_timestamp = 0L; gchar *path, *ueid; gboolean rc; GByteArray *encoded = NULL; encoded = gridcluster_encode_event(e, error); if (!encoded) { GSETERROR(error, "Serialisation error"); return FALSE; } if (0 != g_mkdir_with_parents(ns_data->queues.dir_incoming, event_directory_mode)) { GSETERROR(error, "mkdir(%s) error", ns_data->queues.dir_incoming); g_byte_array_free(encoded, TRUE); return FALSE; } path = path_get_from_event_aggrname(e, ns_data->queues.dir_incoming); ueid = ueid_get_from_event(e); /* get the previous timestamp and unlink the previous file */ old_timestamp = event_get_timestamp(path, NULL); if (0 == unlink(path)) DEBUG("Unlinked a previous event at [%s]", path); if (!(rc = g_file_set_contents(path, (gchar*)encoded->data, encoded->len, error))) GSETERROR(error,"Failed to write the serialized event UEID[%s] at [%s]", ueid, path); else { gboolean xattr_rc; xattr_rc = event_set_timestamp(path, old_timestamp ? old_timestamp : time(0)); g_chmod(path, event_file_mode); INFO("Incoming event UEID[%s] saved at [%s] (%s : %s)", ueid, path, (xattr_rc ? "xattr timestamp set" : "xattr timestamp not set"), strerror(errno)); } g_byte_array_free(encoded, TRUE); g_free(path); g_free(ueid); return rc; }
void teardown (void) { if (actual_address) g_free(actual_address); if (expected_error) g_error_free(expected_error); if (actual_error) g_error_free(actual_error); if (tmp_dir) { g_chmod(tmp_dir, 0755); cut_remove_path(tmp_dir, NULL); g_free(tmp_dir); } }
static void set_face_from_filename (const char *filename) { GtkWidget *image; GdkPixbuf *pixbuf; GdkPixbuf *scaled; image = glade_xml_get_widget (xml, "face_image"); pixbuf = gdk_pixbuf_new_from_file (filename, NULL); scaled = scale_pixbuf (pixbuf); g_object_unref (pixbuf); pixbuf = scaled; if (! pixbuf) return; if (gdk_pixbuf_save (pixbuf, photofile, "png", NULL, NULL) != TRUE) { GtkWidget *d; char *tmp = g_filename_to_utf8 (photofile, -1, NULL, NULL, NULL); char *msg; msg = g_strdup_printf (_("File %s cannot be opened for " "writing."), tmp); d = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot open file"), msg); gtk_dialog_run (GTK_DIALOG (d)); gtk_widget_destroy (d); g_free (tmp); g_free (msg); } else { /* Change to g_chmod after glib 2.8 release */ g_chmod (photofile, 0644); } gtk_image_set_from_file (GTK_IMAGE (image), photofile); }
static void authentication_message_got_headers_cb (SoupMessage* msg, KatzeHttpAuthSave* save) { /* Anything but 401 and 5xx means the password was accepted */ if (msg->status_code != 401 && msg->status_code < 500) { gchar* opaque_info; FILE* file; opaque_info = katze_http_auth_soup_auth_get_hash (save->auth); if (!g_hash_table_lookup (save->http_auth->logins, opaque_info)) { KatzeHttpAuthLogin* login = g_slice_new (KatzeHttpAuthLogin); login->username = save->username; login->password = save->password; g_hash_table_insert (save->http_auth->logins, opaque_info, login); if ((file = g_fopen (save->http_auth->filename, "a"))) { fprintf (file, "%s\t%s\t%s\n", opaque_info, login->username, login->password); fclose (file); g_chmod (save->http_auth->filename, 0600); } } else { /* FIXME g_free (save->username); g_free (save->password); */ } } else { /* FIXME g_free (save->username); g_free (save->password); */ } /* FIXME g_object_unref (save->auth); */ /* FIXME g_slice_free (KatzeHttpAuthSave, save); */ g_signal_handlers_disconnect_by_func (msg, authentication_message_got_headers_cb, save); }
gboolean _gumd_dbus_server_p2p_start ( GumdDbusServer *self) { g_return_val_if_fail (GUMD_IS_DBUS_SERVER_P2P (self), FALSE); DBG("Start P2P DBus Server"); GumdDbusServerP2P *server = GUMD_DBUS_SERVER_P2P (self); if (!server->priv->bus_server) { GError *err = NULL; gchar *guid = g_dbus_generate_guid (); server->priv->bus_server = g_dbus_server_new_sync ( server->priv->address, G_DBUS_SERVER_FLAGS_NONE, guid, NULL, NULL, &err); g_free (guid); if (!server->priv->bus_server) { WARN ("Failed to start server at address '%s':%s", server->priv->address, err ? err->message : "NULL"); g_error_free (err); return FALSE; } g_signal_connect (server->priv->bus_server, "new-connection", G_CALLBACK(_on_client_request), server); } if (!g_dbus_server_is_active (server->priv->bus_server)) { const gchar *path = NULL; g_dbus_server_start (server->priv->bus_server); path = g_strstr_len(server->priv->address, -1, "unix:path=") + 10; if (path) { if (g_chmod (path, S_IRUSR | S_IWUSR) < 0) { WARN("Setting server socket permission failed with error '%s'", strerror(errno)); } } } DBG("Dbus server started at : %s", server->priv->address); return TRUE; }
/* TRUE on success */ static gboolean layer_defaults_save_to_file() { gboolean answer = TRUE; GError *error = NULL; gchar *fn = g_build_filename ( a_get_viking_dir(), VIKING_LAYER_DEFAULTS_INI_FILE, NULL ); gsize size; gchar *keyfilestr = g_key_file_to_data ( keyfile, &size, &error ); if ( error ) { g_warning ( error->message ); g_error_free ( error ); answer = FALSE; goto tidy; } // optionally could do: // g_file_set_contents ( fn, keyfilestr, size, &error ); // if ( error ) { // g_warning ( "%s: %s", error->message, fn ); // g_error_free ( error ); // answer = FALSE; // goto tidy; // } FILE *ff; if ( !(ff = g_fopen ( fn, "w")) ) { g_warning ( _("Could not open file: %s"), fn ); answer = FALSE; goto tidy; } // Layer defaults not that secret, but just incase... g_chmod ( fn, 0600 ); fputs ( keyfilestr, ff ); fclose ( ff ); tidy: g_free ( keyfilestr ); g_free ( fn ); return answer; }