X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fsession.c;h=54ce34ed4b64544c723f1bae50e0bf215a6b3f35;hb=b338e27b3217375d07bfbddd57f3372430919085;hp=57a463e192b21dbd5efeb91955de27ae2ce83cdd;hpb=eaa3b3aaa72c5828902639dfa215f6c3b6c2a282;p=chaz%2Fopenbox diff --git a/openbox/session.c b/openbox/session.c index 57a463e1..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; @@ -169,6 +162,17 @@ void session_startup(gint *argc, gchar ***argv) 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; @@ -219,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); @@ -315,27 +319,15 @@ static void sm_shutdown_cancelled(SmcConn conn, SmPointer data) static gboolean session_save() { - gchar *filename; FILE *f; GList *it; gboolean success = TRUE; - if (save_file) - unlink(save_file); - - /* 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; @@ -425,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); }