cmdline: handle fatal errors with GError
Don't call g_error(), which will abort the process and dump core.
This commit is contained in:
		@@ -38,6 +38,12 @@
 | 
				
			|||||||
#define USER_CONFIG_FILE_LOCATION1	".mpdconf"
 | 
					#define USER_CONFIG_FILE_LOCATION1	".mpdconf"
 | 
				
			||||||
#define USER_CONFIG_FILE_LOCATION2	".mpd/mpd.conf"
 | 
					#define USER_CONFIG_FILE_LOCATION2	".mpd/mpd.conf"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static GQuark
 | 
				
			||||||
 | 
					cmdline_quark(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return g_quark_from_static_string("cmdline");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_GNUC_NORETURN
 | 
					G_GNUC_NORETURN
 | 
				
			||||||
static void version(void)
 | 
					static void version(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -76,7 +82,9 @@ static const char *summary =
 | 
				
			|||||||
	"Music Player Daemon - a daemon for playing music.";
 | 
						"Music Player Daemon - a daemon for playing music.";
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void parse_cmdline(int argc, char **argv, struct options *options)
 | 
					bool
 | 
				
			||||||
 | 
					parse_cmdline(int argc, char **argv, struct options *options,
 | 
				
			||||||
 | 
						      GError **error_r)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	GError *error = NULL;
 | 
						GError *error = NULL;
 | 
				
			||||||
	GOptionContext *context;
 | 
						GOptionContext *context;
 | 
				
			||||||
@@ -133,6 +141,7 @@ void parse_cmdline(int argc, char **argv, struct options *options)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (option_no_config) {
 | 
						if (option_no_config) {
 | 
				
			||||||
		g_debug("Ignoring config, using daemon defaults\n");
 | 
							g_debug("Ignoring config, using daemon defaults\n");
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
	} else if (argc <= 1) {
 | 
						} else if (argc <= 1) {
 | 
				
			||||||
		/* default configuration file path */
 | 
							/* default configuration file path */
 | 
				
			||||||
		char *path1;
 | 
							char *path1;
 | 
				
			||||||
@@ -151,9 +160,16 @@ void parse_cmdline(int argc, char **argv, struct options *options)
 | 
				
			|||||||
			config_read_file(SYSTEM_CONFIG_FILE_LOCATION);
 | 
								config_read_file(SYSTEM_CONFIG_FILE_LOCATION);
 | 
				
			||||||
		g_free(path1);
 | 
							g_free(path1);
 | 
				
			||||||
		g_free(path2);
 | 
							g_free(path2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
	} else if (argc == 2) {
 | 
						} else if (argc == 2) {
 | 
				
			||||||
		/* specified configuration file */
 | 
							/* specified configuration file */
 | 
				
			||||||
		config_read_file(argv[1]);
 | 
							config_read_file(argv[1]);
 | 
				
			||||||
	} else
 | 
					
 | 
				
			||||||
		g_error("too many arguments");
 | 
							return true;
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							g_set_error(error_r, cmdline_quark(), 0,
 | 
				
			||||||
 | 
								    "too many arguments");
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,6 +22,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <glib.h>
 | 
					#include <glib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdbool.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct options {
 | 
					struct options {
 | 
				
			||||||
	gboolean kill;
 | 
						gboolean kill;
 | 
				
			||||||
	gboolean daemon;
 | 
						gboolean daemon;
 | 
				
			||||||
@@ -29,6 +31,8 @@ struct options {
 | 
				
			|||||||
	gboolean verbose;
 | 
						gboolean verbose;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void parse_cmdline(int argc, char **argv, struct options *options);
 | 
					bool
 | 
				
			||||||
 | 
					parse_cmdline(int argc, char **argv, struct options *options,
 | 
				
			||||||
 | 
						      GError **error_r);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -295,7 +295,12 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
	tag_pool_init();
 | 
						tag_pool_init();
 | 
				
			||||||
	config_global_init();
 | 
						config_global_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	parse_cmdline(argc, argv, &options);
 | 
						success = parse_cmdline(argc, argv, &options, &error);
 | 
				
			||||||
 | 
						if (!success) {
 | 
				
			||||||
 | 
							g_warning("%s", error->message);
 | 
				
			||||||
 | 
							g_error_free(error);
 | 
				
			||||||
 | 
							return EXIT_FAILURE;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	glue_daemonize_init(&options);
 | 
						glue_daemonize_init(&options);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user