X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fsession.c;h=54ce34ed4b64544c723f1bae50e0bf215a6b3f35;hb=b338e27b3217375d07bfbddd57f3372430919085;hp=8be44e34c12a99ce4b333a243615d5354cbed37c;hpb=740c5b2a20d5110435d0874f8cc6a4c9dfd14777;p=chaz%2Fopenbox diff --git a/openbox/session.c b/openbox/session.c index 8be44e34..54ce34ed 100644 --- a/openbox/session.c +++ b/openbox/session.c @@ -92,17 +92,10 @@ static void save_commands() prop_res.vals[i].length = strlen(sm_argv[i]); } - if (save_file) { - prop_res.vals[i].value = "--sm-save-file"; - prop_res.vals[i++].length = strlen("--sm-save-file"); - prop_res.vals[i].value = save_file; - prop_res.vals[i++].length = strlen(save_file); - } else { - prop_res.vals[i].value = "--sm-client-id"; - prop_res.vals[i++].length = strlen("--sm-client-id"); - prop_res.vals[i].value = sm_id; - prop_res.vals[i++].length = strlen(sm_id); - } + prop_res.vals[i].value = "--sm-save-file"; + prop_res.vals[i++].length = strlen("--sm-save-file"); + prop_res.vals[i].value = save_file; + prop_res.vals[i++].length = strlen(save_file); props[0] = &prop_res; props[1] = &prop_cmd; @@ -163,10 +156,23 @@ void session_startup(gint *argc, gchar ***argv) sm_sessions_path = g_build_filename(parse_xdg_data_home_path(), "openbox", "sessions", NULL); - parse_mkdir_path(sm_sessions_path, 0700); + if (!parse_mkdir_path(sm_sessions_path, 0700)) + g_warning(_("Unable to make directory '%s': %s"), + sm_sessions_path, g_strerror(errno)); if (save_file) session_load(save_file); + else { + gchar *filename; + + /* this algo is from metacity */ + filename = g_strdup_printf("%d-%d-%u.obs", + (gint) time(NULL), + (gint) getpid(), + g_random_int()); + save_file = g_build_filename(sm_sessions_path, filename, NULL); + g_free(filename); + } sm_argc = *argc; sm_argv = *argv; @@ -217,7 +223,7 @@ void session_startup(gint *argc, gchar ***argv) val_hint.value = &hint; val_hint.length = 1; - sprintf(pid, "%ld", (glong)getpid()); + g_snprintf(pid, sizeof(pid), "%ld", (glong) getpid()); val_pid.value = pid; val_pid.length = strlen(pid); @@ -313,24 +319,15 @@ static void sm_shutdown_cancelled(SmcConn conn, SmPointer data) static gboolean session_save() { - gchar *filename; FILE *f; GList *it; gboolean success = TRUE; - /* this algo is from metacity */ - filename = g_strdup_printf("%d-%d-%u.obs", - (gint) time(NULL), - (gint) getpid(), - g_random_int()); - save_file = g_build_filename(sm_sessions_path, filename, NULL); - g_free(filename); - f = fopen(save_file, "w"); if (!f) { success = FALSE; g_warning("unable to save the session to %s: %s", - save_file, strerror(errno)); + save_file, g_strerror(errno)); } else { guint stack_pos = 0; @@ -420,7 +417,7 @@ static gboolean session_save() if (fflush(f)) { success = FALSE; g_warning("error while saving the session to %s: %s", - save_file, strerror(errno)); + save_file, g_strerror(errno)); } fclose(f); }