extract setup of the logging subsystem into a function of its own.
Signed-off-by: Michael Adam <obnox@samba.org>
This commit is contained in:
		
							parent
							
								
									d8da7f55f7
								
							
						
					
					
						commit
						ea2eaef173
					
				
							
								
								
									
										37
									
								
								src/log.c
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								src/log.c
									
									
									
									
									
								
							| @ -243,3 +243,40 @@ void send_stored_logs (void) | ||||
|         vector_delete (log_message_storage); | ||||
|         log_message_storage = NULL; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * Initialize the logging subsystem, based on the configuration. | ||||
|  * Returns 0 upon success, -1 upon failure. | ||||
|  * | ||||
|  * This function uses fprintf() instead of log_message(), since | ||||
|  * the logging is not yet set up... | ||||
|  */ | ||||
| int setup_logging (void) | ||||
| { | ||||
|         int ret = -1; | ||||
| 
 | ||||
|         /* Write to a user supplied log file if it's defined.  This will
 | ||||
|          * override using the syslog even if syslog is defined. */ | ||||
|         if (config.logf_name) { | ||||
|                 if (open_log_file (config.logf_name) < 0) { | ||||
|                         fprintf (stderr, | ||||
|                                  "%s: Could not create log file.\n", PACKAGE); | ||||
|                         goto done; | ||||
|                 } | ||||
|                 config.syslog = FALSE;  /* disable syslog */ | ||||
|         } else if (config.syslog) { | ||||
|                 if (config.godaemon == TRUE) | ||||
|                         openlog ("tinyproxy", LOG_PID, LOG_DAEMON); | ||||
|                 else | ||||
|                         openlog ("tinyproxy", LOG_PID, LOG_USER); | ||||
|         } else { | ||||
|                 fprintf (stderr, "%s: Either define a logfile or " | ||||
|                          "enable syslog logging.\n", PACKAGE); | ||||
|                 goto done; | ||||
|         } | ||||
| 
 | ||||
|         ret = 0; | ||||
| 
 | ||||
| done: | ||||
|         return ret; | ||||
| } | ||||
|  | ||||
| @ -117,4 +117,6 @@ extern void log_message (int level, const char *fmt, ...); | ||||
| extern void set_log_level (int level); | ||||
| extern void send_stored_logs (void); | ||||
| 
 | ||||
| extern int setup_logging (void); | ||||
| 
 | ||||
| #endif | ||||
|  | ||||
							
								
								
									
										20
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/main.c
									
									
									
									
									
								
							| @ -305,6 +305,7 @@ int | ||||
| main (int argc, char **argv) | ||||
| { | ||||
|         FILE *config_file; | ||||
|         int ret; | ||||
| 
 | ||||
|         /* Only allow u+rw bits. This may be required for some versions
 | ||||
|          * of glibc so that mkstemp() doesn't make us vulnerable. | ||||
| @ -340,23 +341,8 @@ main (int argc, char **argv) | ||||
| 
 | ||||
|         fclose (config_file); | ||||
| 
 | ||||
|         /* Write to a user supplied log file if it's defined.  This will
 | ||||
|          * override using the syslog even if syslog is defined. */ | ||||
|         if (config.logf_name) { | ||||
|                 if (open_log_file (config.logf_name) < 0) { | ||||
|                         fprintf (stderr, | ||||
|                                  "%s: Could not create log file.\n", argv[0]); | ||||
|                         exit (EX_SOFTWARE); | ||||
|                 } | ||||
|                 config.syslog = FALSE;  /* disable syslog */ | ||||
|         } else if (config.syslog) { | ||||
|                 if (config.godaemon == TRUE) | ||||
|                         openlog ("tinyproxy", LOG_PID, LOG_DAEMON); | ||||
|                 else | ||||
|                         openlog ("tinyproxy", LOG_PID, LOG_USER); | ||||
|         } else { | ||||
|                 fprintf (stderr, "%s: Either define a logfile or " | ||||
|                          "enable syslog logging.\n", argv[0]); | ||||
|         ret = setup_logging (); | ||||
|         if (ret != 0) { | ||||
|                 exit (EX_SOFTWARE); | ||||
|         } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Michael Adam
						Michael Adam