mirror of
				https://github.com/SuperBFG7/ympd
				synced 2025-10-31 22:03:01 +00:00 
			
		
		
		
	Fix: save mympd config on the heap
This commit is contained in:
		
							
								
								
									
										117
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										117
									
								
								src/main.c
									
									
									
									
									
								
							| @@ -174,43 +174,43 @@ int main(int argc, char **argv) { | |||||||
|     srand((unsigned int)time(NULL)); |     srand((unsigned int)time(NULL)); | ||||||
|      |      | ||||||
|     //mympd config defaults |     //mympd config defaults | ||||||
|     t_config config; |     t_config *config = (t_config *)malloc(sizeof(t_config)); | ||||||
|     config.mpdhost = strdup("127.0.0.1"); |     config->mpdhost = strdup("127.0.0.1"); | ||||||
|     config.mpdport = 6600; |     config->mpdport = 6600; | ||||||
|     config.mpdpass = NULL; |     config->mpdpass = NULL; | ||||||
|     config.webport = strdup("80"); |     config->webport = strdup("80"); | ||||||
|     config.ssl = true; |     config->ssl = true; | ||||||
|     config.sslport = strdup("443"); |     config->sslport = strdup("443"); | ||||||
|     config.sslcert = strdup("/etc/mympd/ssl/server.pem"); |     config->sslcert = strdup("/etc/mympd/ssl/server.pem"); | ||||||
|     config.sslkey = strdup("/etc/mympd/ssl/server.key"); |     config->sslkey = strdup("/etc/mympd/ssl/server.key"); | ||||||
|     config.user = strdup("mympd"); |     config->user = strdup("mympd"); | ||||||
|     config.streamport = 8000; |     config->streamport = 8000; | ||||||
|     config.streamurl = strdup(""); |     config->streamurl = strdup(""); | ||||||
|     config.coverimage = true; |     config->coverimage = true; | ||||||
|     config.coverimagename = strdup("folder.jpg"); |     config->coverimagename = strdup("folder.jpg"); | ||||||
|     config.coverimagesize = 240; |     config->coverimagesize = 240; | ||||||
|     config.varlibdir = strdup("/var/lib/mympd"); |     config->varlibdir = strdup("/var/lib/mympd"); | ||||||
|     config.stickers = true; |     config->stickers = true; | ||||||
|     config.mixramp = true; |     config->mixramp = true; | ||||||
|     config.taglist = strdup("Artist,Album,AlbumArtist,Title,Track,Genre,Date,Composer,Performer"); |     config->taglist = strdup("Artist,Album,AlbumArtist,Title,Track,Genre,Date,Composer,Performer"); | ||||||
|     config.searchtaglist = strdup("Artist,Album,AlbumArtist,Title,Genre,Composer,Performer"); |     config->searchtaglist = strdup("Artist,Album,AlbumArtist,Title,Genre,Composer,Performer"); | ||||||
|     config.browsetaglist = strdup("Artist,Album,AlbumArtist,Genre,Composer,Performer"); |     config->browsetaglist = strdup("Artist,Album,AlbumArtist,Genre,Composer,Performer"); | ||||||
|     config.smartpls = true; |     config->smartpls = true; | ||||||
|     config.max_elements_per_page = 100; |     config->max_elements_per_page = 100; | ||||||
|     config.last_played_count = 20; |     config->last_played_count = 20; | ||||||
|     char *etcdir = strdup(argv[1]); |     char *etcdir = strdup(argv[1]); | ||||||
|     config.etcdir = strdup(dirname(etcdir)); |     config->etcdir = strdup(dirname(etcdir)); | ||||||
|     free(etcdir); |     free(etcdir); | ||||||
|     config.syscmds = false; |     config->syscmds = false; | ||||||
|     config.localplayer = true; |     config->localplayer = true; | ||||||
|     config.loglevel = 1; |     config->loglevel = 1; | ||||||
|     config.backgroundcolor = strdup("#888"); |     config->backgroundcolor = strdup("#888"); | ||||||
|      |      | ||||||
|     if (argc == 2) { |     if (argc == 2) { | ||||||
|         printf("Starting myMPD %s\n", MYMPD_VERSION); |         printf("Starting myMPD %s\n", MYMPD_VERSION); | ||||||
|         printf("Libmpdclient %i.%i.%i\n", LIBMPDCLIENT_MAJOR_VERSION, LIBMPDCLIENT_MINOR_VERSION, LIBMPDCLIENT_PATCH_VERSION); |         printf("Libmpdclient %i.%i.%i\n", LIBMPDCLIENT_MAJOR_VERSION, LIBMPDCLIENT_MINOR_VERSION, LIBMPDCLIENT_PATCH_VERSION); | ||||||
|         printf("Parsing config file: %s\n", argv[1]); |         printf("Parsing config file: %s\n", argv[1]); | ||||||
|         if (ini_parse(argv[1], inihandler, &config) < 0) { |         if (ini_parse(argv[1], inihandler, config) < 0) { | ||||||
|             printf("Can't load config file \"%s\"\n", argv[1]); |             printf("Can't load config file \"%s\"\n", argv[1]); | ||||||
|             return EXIT_FAILURE; |             return EXIT_FAILURE; | ||||||
|         } |         } | ||||||
| @@ -229,10 +229,10 @@ int main(int argc, char **argv) { | |||||||
|      |      | ||||||
|     #ifdef DEBUG |     #ifdef DEBUG | ||||||
|     printf("Debug flag enabled, setting loglevel to debug\n"); |     printf("Debug flag enabled, setting loglevel to debug\n"); | ||||||
|     config.loglevel = 3; |     config->loglevel = 3; | ||||||
|     #endif |     #endif | ||||||
|     printf("Setting loglevel to %ld\n", config.loglevel); |     printf("Setting loglevel to %ld\n", config->loglevel); | ||||||
|     loglevel = config.loglevel; |     loglevel = config->loglevel; | ||||||
|  |  | ||||||
|     signal(SIGTERM, signal_handler); |     signal(SIGTERM, signal_handler); | ||||||
|     signal(SIGINT, signal_handler); |     signal(SIGINT, signal_handler); | ||||||
| @@ -241,15 +241,15 @@ int main(int argc, char **argv) { | |||||||
|  |  | ||||||
|     //init webserver |     //init webserver | ||||||
|     struct mg_mgr mgr; |     struct mg_mgr mgr; | ||||||
|     if (!web_server_init(&mgr, &config)) { |     if (!web_server_init(&mgr, config)) { | ||||||
|         return EXIT_FAILURE; |         return EXIT_FAILURE; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     //drop privileges |     //drop privileges | ||||||
|     if (config.user != NULL) { |     if (config->user != NULL) { | ||||||
|         printf("Droping privileges to %s\n", config.user); |         printf("Droping privileges to %s\n", config->user); | ||||||
|         struct passwd *pw; |         struct passwd *pw; | ||||||
|         if ((pw = getpwnam(config.user)) == NULL) { |         if ((pw = getpwnam(config->user)) == NULL) { | ||||||
|             printf("getpwnam() failed, unknown user\n"); |             printf("getpwnam() failed, unknown user\n"); | ||||||
|             web_server_free(&mgr); |             web_server_free(&mgr); | ||||||
|             return EXIT_FAILURE; |             return EXIT_FAILURE; | ||||||
| @@ -281,31 +281,31 @@ int main(int argc, char **argv) { | |||||||
|     snprintf(testdirname, 400, "%s/library", DOC_ROOT); |     snprintf(testdirname, 400, "%s/library", DOC_ROOT); | ||||||
|     if (!testdir("Link to mpd music_directory", testdirname)) { |     if (!testdir("Link to mpd music_directory", testdirname)) { | ||||||
|         printf("Disabling coverimage support\n"); |         printf("Disabling coverimage support\n"); | ||||||
|         config.coverimage = false; |         config->coverimage = false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     snprintf(testdirname, 400, "%s/tmp", config.varlibdir); |     snprintf(testdirname, 400, "%s/tmp", config->varlibdir); | ||||||
|     if (!testdir("Temp dir", testdirname))  |     if (!testdir("Temp dir", testdirname))  | ||||||
|         return EXIT_FAILURE; |         return EXIT_FAILURE; | ||||||
|  |  | ||||||
|     snprintf(testdirname, 400, "%s/smartpls", config.varlibdir); |     snprintf(testdirname, 400, "%s/smartpls", config->varlibdir); | ||||||
|     if (!testdir("Smartpls dir", testdirname))  |     if (!testdir("Smartpls dir", testdirname))  | ||||||
|         return EXIT_FAILURE; |         return EXIT_FAILURE; | ||||||
|  |  | ||||||
|     snprintf(testdirname, 400, "%s/state", config.varlibdir); |     snprintf(testdirname, 400, "%s/state", config->varlibdir); | ||||||
|     if (!testdir("State dir", testdirname))  |     if (!testdir("State dir", testdirname))  | ||||||
|         return EXIT_FAILURE; |         return EXIT_FAILURE; | ||||||
|  |  | ||||||
|     //Create working threads |     //Create working threads | ||||||
|     pthread_t mpd_client_thread, web_server_thread, mympd_api_thread; |     pthread_t mpd_client_thread, web_server_thread, mympd_api_thread; | ||||||
|     //mpd connection |     //mpd connection | ||||||
|     pthread_create(&mpd_client_thread, NULL, mpd_client_loop, &config); |     pthread_create(&mpd_client_thread, NULL, mpd_client_loop, config); | ||||||
|     pthread_setname_np(mpd_client_thread, "mympd_mpdclient"); |     pthread_setname_np(mpd_client_thread, "mympd_mpdclient"); | ||||||
|     //webserver |     //webserver | ||||||
|     pthread_create(&web_server_thread, NULL, web_server_loop, &mgr); |     pthread_create(&web_server_thread, NULL, web_server_loop, &mgr); | ||||||
|     pthread_setname_np(web_server_thread, "mympd_webserver"); |     pthread_setname_np(web_server_thread, "mympd_webserver"); | ||||||
|     //mympd api |     //mympd api | ||||||
|     pthread_create(&mympd_api_thread, NULL, mympd_api_loop, &config); |     pthread_create(&mympd_api_thread, NULL, mympd_api_loop, config); | ||||||
|     pthread_setname_np(mympd_api_thread, "mympd_mympdapi"); |     pthread_setname_np(mympd_api_thread, "mympd_mympdapi"); | ||||||
|  |  | ||||||
|     //Outsourced all work to separate threads, do nothing... |     //Outsourced all work to separate threads, do nothing... | ||||||
| @@ -317,21 +317,22 @@ int main(int argc, char **argv) { | |||||||
|     tiny_queue_free(web_server_queue); |     tiny_queue_free(web_server_queue); | ||||||
|     tiny_queue_free(mpd_client_queue); |     tiny_queue_free(mpd_client_queue); | ||||||
|     tiny_queue_free(mympd_api_queue); |     tiny_queue_free(mympd_api_queue); | ||||||
|     free(config.mpdhost); |     free(config->mpdhost); | ||||||
|     free(config.mpdpass); |     free(config->mpdpass); | ||||||
|     free(config.webport); |     free(config->webport); | ||||||
|     free(config.sslport); |     free(config->sslport); | ||||||
|     free(config.sslcert); |     free(config->sslcert); | ||||||
|     free(config.sslkey); |     free(config->sslkey); | ||||||
|     free(config.user); |     free(config->user); | ||||||
|     free(config.coverimagename); |     free(config->coverimagename); | ||||||
|     free(config.taglist); |     free(config->taglist); | ||||||
|     free(config.searchtaglist); |     free(config->searchtaglist); | ||||||
|     free(config.browsetaglist); |     free(config->browsetaglist); | ||||||
|     free(config.varlibdir); |     free(config->varlibdir); | ||||||
|     free(config.etcdir); |     free(config->etcdir); | ||||||
|     free(config.streamurl); |     free(config->streamurl); | ||||||
|     free(config.backgroundcolor); |     free(config->backgroundcolor); | ||||||
|  |     free(config); | ||||||
|  |  | ||||||
|     return EXIT_SUCCESS; |     return EXIT_SUCCESS; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 jcorporation
					jcorporation