X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fsession.c;h=23ad02f66b087da8a4be15ad3a50c9510f4ba688;hb=f189b02f857eb5cc80ca925ccb4b0e97c3614bcd;hp=8be44e34c12a99ce4b333a243615d5354cbed37c;hpb=740c5b2a20d5110435d0874f8cc6a4c9dfd14777;p=chaz%2Fopenbox diff --git a/openbox/session.c b/openbox/session.c index 8be44e34..23ad02f6 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; @@ -112,44 +105,32 @@ static void save_commands() g_free(prop_cmd.vals); } -static void remove_args(gint *argc, gchar ***argv, gint index, gint num) -{ - gint i; - - for (i = index; i < index + num; ++i) - (*argv)[i] = (*argv)[i+num]; - *argc -= num; -} - -static void parse_args(gint *argc, gchar ***argv) +static void parse_args(gint argc, gchar **argv) { gint i; - for (i = 1; i < *argc; ++i) { - if (!strcmp((*argv)[i], "--sm-client-id")) { - if (i == *argc - 1) /* no args left */ + for (i = 1; i < argc; ++i) { + if (!strcmp((argv)[i], "--sm-client-id")) { + if (i == argc - 1) /* no args left */ g_printerr(_("--sm-client-id requires an argument\n")); else { - sm_id = g_strdup((*argv)[i+1]); - remove_args(argc, argv, i, 2); + sm_id = g_strdup((argv)[i+1]); ++i; } - } else if (!strcmp((*argv)[i], "--sm-save-file")) { - if (i == *argc - 1) /* no args left */ + } else if (!strcmp((argv)[i], "--sm-save-file")) { + if (i == argc - 1) /* no args left */ g_printerr(_("--sm-save-file requires an argument\n")); else { - save_file = g_strdup((*argv)[i+1]); - remove_args(argc, argv, i, 2); + save_file = g_strdup((argv)[i+1]); ++i; } - } else if (!strcmp((*argv)[i], "--sm-disable")) { + } else if (!strcmp((argv)[i], "--sm-disable")) { sm_disable = TRUE; - remove_args(argc, argv, i, 1); } } } -void session_startup(gint *argc, gchar ***argv) +void session_startup(gint argc, gchar **argv) { #define SM_ERR_LEN 1024 @@ -163,13 +144,26 @@ 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; + sm_argc = argc; + sm_argv = argv; cb.save_yourself.callback = sm_save_yourself; cb.save_yourself.client_data = NULL; @@ -217,7 +211,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 +307,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 +405,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); }