mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-18 20:10:29 +01:00
WINGs: Fix crash on exit while trying to save user config changes
Recent patches has introduced the ability to exit cleanly from the WINGs library, but this introduced some side effects because a function is registered with 'atexit' to save user config on exit, which may not work anymore because WMReleaseApplication frees some stuff needed for that task. This patch handles this so that both method works, in case user of the lib would forget to call the clean exit function. Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
1b2e8a6491
commit
a2328d9842
@@ -81,6 +81,7 @@ libWUtil_la_SOURCES = \
|
|||||||
string.c \
|
string.c \
|
||||||
tree.c \
|
tree.c \
|
||||||
userdefaults.c \
|
userdefaults.c \
|
||||||
|
userdefaults.h \
|
||||||
usleep.c \
|
usleep.c \
|
||||||
wapplication.c \
|
wapplication.c \
|
||||||
wconfig.h \
|
wconfig.h \
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
#include "wconfig.h"
|
#include "wconfig.h"
|
||||||
|
|
||||||
#include "WINGs.h"
|
#include "WINGs.h"
|
||||||
|
#include "WINGsP.h"
|
||||||
|
#include "userdefaults.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct W_UserDefaults {
|
typedef struct W_UserDefaults {
|
||||||
WMPropList *defaults;
|
WMPropList *defaults;
|
||||||
@@ -114,9 +117,19 @@ char *wglobaldefaultspathfordomain(const char *domain)
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void w_save_defaults_changes(void)
|
||||||
saveDefaultsChanges(void)
|
|
||||||
{
|
{
|
||||||
|
if (WMApplication.applicationName == NULL) {
|
||||||
|
/*
|
||||||
|
* This means that the user has properly exited by calling the
|
||||||
|
* function 'WMReleaseApplication' (which has already called us)
|
||||||
|
* but we're being called again by the fallback 'atexit' method
|
||||||
|
* (the legacy way of saving changes on exit which is kept for
|
||||||
|
* application that would forget to call 'WMReleaseApplication')
|
||||||
|
*/
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* save the user defaults databases */
|
/* save the user defaults databases */
|
||||||
synchronizeUserDefaults(NULL);
|
synchronizeUserDefaults(NULL);
|
||||||
}
|
}
|
||||||
@@ -127,7 +140,7 @@ static void registerSaveOnExit(void)
|
|||||||
static Bool registeredSaveOnExit = False;
|
static Bool registeredSaveOnExit = False;
|
||||||
|
|
||||||
if (!registeredSaveOnExit) {
|
if (!registeredSaveOnExit) {
|
||||||
atexit(saveDefaultsChanges);
|
atexit(w_save_defaults_changes);
|
||||||
registeredSaveOnExit = True;
|
registeredSaveOnExit = True;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
WINGs/userdefaults.h
Normal file
34
WINGs/userdefaults.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/* WUtil / userdefaults.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Window Maker Team
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WUTIL_USERDEFAULTS_H
|
||||||
|
#define WUTIL_USERDEFAULTS_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is not part of WUtil public API
|
||||||
|
*
|
||||||
|
* It defines internal things for the user configuration handling functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* Save user configuration, to be used when application exits only */
|
||||||
|
void w_save_defaults_changes(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* WUTIL_USERDEFAULTS_H */
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "WINGsP.h"
|
#include "WINGsP.h"
|
||||||
#include "wconfig.h"
|
#include "wconfig.h"
|
||||||
|
#include "userdefaults.h"
|
||||||
|
|
||||||
|
|
||||||
struct W_Application WMApplication;
|
struct W_Application WMApplication;
|
||||||
@@ -51,6 +52,14 @@ void WMInitializeApplication(const char *applicationName, int *argc, char **argv
|
|||||||
void WMReleaseApplication(void) {
|
void WMReleaseApplication(void) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We save the configuration on exit, this used to be handled
|
||||||
|
* through an 'atexit' registered function but if application
|
||||||
|
* properly calls WMReleaseApplication then the info to that
|
||||||
|
* will have been freed by us.
|
||||||
|
*/
|
||||||
|
w_save_defaults_changes();
|
||||||
|
|
||||||
W_ReleaseNotificationCenter();
|
W_ReleaseNotificationCenter();
|
||||||
|
|
||||||
if (WMApplication.applicationName)
|
if (WMApplication.applicationName)
|
||||||
|
|||||||
Reference in New Issue
Block a user