From: Christophe CURIS <[email protected]> The function name could led users to not know where it comes from and why it has to be called. Now the name makes it clear which API it belongs to, and does not expose some internal things that are WUtil's responsibility.
The new function 'wutil_shutdown' should not be called conditionally, it takes care of what is has to automatically (and may in the future be able to perform more cleanup, seamlessly to users). Reverted the prefix "warn:" to "warning:" as per Carlos suggestion and also because this would break current translations. Signed-off-by: Christophe CURIS <[email protected]> --- WINGs/Makefile.am | 1 + WINGs/WINGs/WUtil.h | 9 +++++---- WINGs/error.c | 26 ++++++++------------------ WINGs/error.h | 36 ++++++++++++++++++++++++++++++++++++ WINGs/misc.c | 12 ++++++++++++ src/main.c | 2 ++ src/startup.c | 5 ----- 7 files changed, 64 insertions(+), 27 deletions(-) create mode 100644 WINGs/error.h diff --git a/WINGs/Makefile.am b/WINGs/Makefile.am index d28aff9..3dac104 100644 --- a/WINGs/Makefile.am +++ b/WINGs/Makefile.am @@ -67,6 +67,7 @@ libWUtil_la_SOURCES = \ bagtree.c \ data.c \ error.c \ + error.h \ findfile.c \ handlers.c \ hashtable.c \ diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h index b2e76ab..da74dfc 100644 --- a/WINGs/WINGs/WUtil.h +++ b/WINGs/WINGs/WUtil.h @@ -243,9 +243,6 @@ enum { void __wmessage(const char *func, const char *file, int line, int type, const char *msg, ...) __attribute__((__format__(printf,5,6))); -void syslog_shutdown(void); - - /* ---[ WINGs/findfile.c ]------------------------------------------------ */ /* For the 4 function below, you have to free the returned string when you no longer need it */ @@ -308,10 +305,14 @@ char* wtrimspace(const char *s); */ char *wshellquote(const char *s); -/* ---[ WINGs/wmisc.c ]--------------------------------------------------- */ +/* ---[ WINGs/misc.c ]--------------------------------------------------- */ WMRange wmkrange(int start, int count); +/* An application must call this function before exiting, to let WUtil do some internal cleanup */ +void wutil_shutdown(void); + + /* ---[ WINGs/usleep.c ]-------------------------------------------------- */ void wusleep(unsigned int usec); diff --git a/WINGs/error.c b/WINGs/error.c index 61c3cc0..e94c428 100644 --- a/WINGs/error.c +++ b/WINGs/error.c @@ -32,12 +32,12 @@ #ifdef HAVE_SYSLOG_H #include <syslog.h> + static Bool syslog_initialized = False; -#endif -void syslog_open(char *prog_name) + +static void syslog_open(char *prog_name) { -#ifdef HAVE_SYSLOG int options; if (!prog_name) @@ -46,35 +46,25 @@ void syslog_open(char *prog_name) options = LOG_PID; openlog(prog_name, options, LOG_DAEMON); syslog_initialized = True; -#else - (void) prog_name; -#endif } -void syslog_message(int prio, char *prog_name, char *msg) +static void syslog_message(int prio, char *prog_name, char *msg) { -#ifdef HAVE_SYSLOG if (!syslog_initialized) syslog_open(prog_name); //jump over the program name cause syslog is already displaying it - syslog(prio, "%s", msg+strlen(prog_name)); -#else - (void) prio; - (void) prog_name; - (void) msg; -#endif + syslog(prio, "%s", msg + strlen(prog_name)); } -void syslog_shutdown(void) +void w_syslog_close(void) { -#ifdef HAVE_SYSLOG if (syslog_initialized) { closelog(); syslog_initialized = False; } -#endif } +#endif void __wmessage(const char *func, const char *file, int line, int type, const char *msg, ...) { @@ -128,7 +118,7 @@ void __wmessage(const char *func, const char *file, int line, int type, const ch #endif break; case WMESSAGE_TYPE_WARNING: - strncat(buf, _("warn: "), linemax - 1 - strlen(buf)); + strncat(buf, _("warning: "), linemax - 1 - strlen(buf)); #ifdef HAVE_SYSLOG syslog_priority = LOG_WARNING; syslog_prefix = "WARNING"; diff --git a/WINGs/error.h b/WINGs/error.h new file mode 100644 index 0000000..341c909 --- /dev/null +++ b/WINGs/error.h @@ -0,0 +1,36 @@ +/* WUtil / error.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_ERROR_H +#define WUTIL_ERROR_H + +/* + * This file is not part of WUtil public API + * + * It defines internal things for the error message display functions + */ + + +#ifdef HAVE_SYSLOG_H +/* Function to cleanly close the syslog stuff, called by wutil_shutdown from user side */ +void w_syslog_close(void); +#endif + + +#endif /* WUTIL_ERROR_H */ diff --git a/WINGs/misc.c b/WINGs/misc.c index 48f281d..f5a8c91 100644 --- a/WINGs/misc.c +++ b/WINGs/misc.c @@ -3,6 +3,8 @@ #include "WINGsP.h" +#include "error.h" + WMRange wmkrange(int start, int count) { WMRange range; @@ -12,3 +14,13 @@ WMRange wmkrange(int start, int count) return range; } + +/* + * wutil_shutdown - cleanup in WUtil when user program wants to exit + */ +void wutil_shutdown(void) +{ +#ifdef HAVE_SYSLOG + w_syslog_close(); +#endif +} diff --git a/src/main.c b/src/main.c index 59a21f7..a21290e 100644 --- a/src/main.c +++ b/src/main.c @@ -201,6 +201,8 @@ noreturn void Exit(int status) if (dpy) XCloseDisplay(dpy); + wutil_shutdown(); /* WUtil clean-up */ + exit(status); } diff --git a/src/startup.c b/src/startup.c index 34e3635..6ede6f5 100644 --- a/src/startup.c +++ b/src/startup.c @@ -160,11 +160,6 @@ static RETSIGTYPE handleExitSig(int sig) } sigprocmask(SIG_UNBLOCK, &sigs, NULL); - -#ifdef HAVE_SYSLOG - syslog_shutdown(); -#endif - DispatchEvent(NULL); /* Dispatch events imediately. */ } -- 1.8.5.3 -- To unsubscribe, send mail to [email protected].
