MCPcopy Create free account
hub / github.com/MariaDB/server / start_logging

Function start_logging

plugin/server_audit/server_audit.cc:809–878  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

807#endif /*_WIN32 && !S_ISDIR*/
808
809static int start_logging()
810{
811 last_error_buf[0]= 0;
812 log_write_failures= 0;
813 if (output_type == OUTPUT_FILE)
814 {
815 char alt_path_buffer[FN_REFLEN+1+DEFAULT_FILENAME_LEN];
816 struct stat *f_stat= (struct stat *)alt_path_buffer;
817 const char *alt_fname= file_path;
818
819 while (*alt_fname == ' ')
820 alt_fname++;
821
822 if (*alt_fname == 0)
823 {
824 /* Empty string means the default file name. */
825 alt_fname= default_file_name;
826 }
827 else
828 {
829 /* See if the directory exists with the name of file_path. */
830 /* Log file name should be [file_path]/server_audit.log then. */
831 if (stat(file_path, (struct stat *)alt_path_buffer) == 0 &&
832 S_ISDIR(f_stat->st_mode))
833 {
834 size_t p_len= strlen(file_path);
835 memcpy(alt_path_buffer, file_path, p_len);
836 if (alt_path_buffer[p_len-1] != FN_LIBCHAR)
837 {
838 alt_path_buffer[p_len]= FN_LIBCHAR;
839 p_len++;
840 }
841 memcpy(alt_path_buffer+p_len, default_file_name, DEFAULT_FILENAME_LEN);
842 alt_path_buffer[p_len+DEFAULT_FILENAME_LEN]= 0;
843 alt_fname= alt_path_buffer;
844 }
845 }
846
847 logfile= logger_open(alt_fname, file_rotate_size,
848 rotations, file_buffer_size);
849
850 if (logfile == NULL)
851 {
852 error_header();
853 fprintf(stderr, "Could not create file '%s'.\n",
854 alt_fname);
855 logging= 0;
856 my_snprintf(last_error_buf, sizeof(last_error_buf),
857 "Could not create file '%s'.", alt_fname);
858 is_active= 0;
859 CLIENT_ERROR(1, "SERVER AUDIT plugin can't create file '%s'.",
860 MYF(ME_WARNING), alt_fname);
861 return 1;
862 }
863 error_header();
864 fprintf(stderr, "logging started to the file %s.\n", alt_fname);
865 strncpy(current_log_buf, alt_fname, sizeof(current_log_buf)-1);
866 current_log_buf[sizeof(current_log_buf)-1]= 0;

Callers 5

server_audit_initFunction · 0.85
update_file_pathFunction · 0.85
update_output_typeFunction · 0.85
update_loggingFunction · 0.85
update_syslog_identFunction · 0.85

Calls 4

logger_openFunction · 0.85
error_headerFunction · 0.85
my_snprintfFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected