BOOL reopen_logs( void ) { pstring fname; mode_t oldumask; XFILE *new_dbf = NULL; XFILE *old_dbf = NULL; BOOL ret = True; if (stdout_logging) return True; oldumask = umask( 022 ); pstrcpy(fname, debugf ); if (lp_loaded()) { char *logfname; logfname = lp_logfile(); if (*logfname) pstrcpy(fname, logfname); } pstrcpy( debugf, fname ); new_dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644); if (!new_dbf) { log_overflow = True; DEBUG(0, ("Unable to open new log file %s: %s\n", debugf, strerror(errno))); log_overflow = False; if (dbf) x_fflush(dbf); ret = False; } else { x_setbuf(new_dbf, NULL); old_dbf = dbf; dbf = new_dbf; if (old_dbf) (void) x_fclose(old_dbf); } /* Fix from [email protected] * to fix problem where smbd's that generate less * than 100 messages keep growing the log. */ force_check_log_size(); (void)umask(oldumask); /* Take over stderr to catch ouput into logs */ if (dbf && sys_dup2(x_fileno(dbf), 2) == -1) { close_low_fds(True); /* Close stderr too, if dup2 can't point it at the logfile */ } return ret; }
static char *smb_readline_replacement(const char *prompt, void (*callback)(void), char **(completion_fn)(const char *text, int start, int end)) { char *line = NULL; int fd = x_fileno(x_stdin); char *ret; /* Prompt might be NULL in non-interactive mode. */ if (prompt) { x_fprintf(x_stdout, "%s", prompt); x_fflush(x_stdout); } line = (char *)malloc(BUFSIZ); if (!line) { return NULL; } while (!smb_rl_done) { struct pollfd pfd; ZERO_STRUCT(pfd); pfd.fd = fd; pfd.events = POLLIN|POLLHUP; if (sys_poll_intr(&pfd, 1, 5000) == 1) { ret = x_fgets(line, BUFSIZ, x_stdin); if (ret == 0) { SAFE_FREE(line); } return ret; } if (callback) { callback(); } } SAFE_FREE(line); return NULL; }
/* ************************************************************************** ** * Flush debug output, including the format buffer content. * * Input: none * Output: none * * ************************************************************************** ** */ void dbgflush( void ) { bufr_print(); if(dbf) (void)x_fflush( dbf ); } /* dbgflush */
/* ************************************************************************** ** * Write an debug message on the debugfile. * This is called by dbghdr() and format_debug_text(). * ************************************************************************** ** */ int Debug1( const char *format_str, ... ) { va_list ap; int old_errno = errno; debug_count++; if( stdout_logging ) { va_start( ap, format_str ); if(dbf) (void)x_vfprintf( dbf, format_str, ap ); va_end( ap ); errno = old_errno; return( 0 ); } #ifdef WITH_SYSLOG if( !lp_syslog_only() ) #endif { if( !dbf ) { mode_t oldumask = umask( 022 ); dbf = x_fopen( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644 ); (void)umask( oldumask ); if( dbf ) { x_setbuf( dbf, NULL ); } else { errno = old_errno; return(0); } } } #ifdef WITH_SYSLOG if( syslog_level < lp_syslog() ) { /* map debug levels to syslog() priorities * note that not all DEBUG(0, ...) calls are * necessarily errors */ static int priority_map[] = { LOG_ERR, /* 0 */ LOG_WARNING, /* 1 */ LOG_NOTICE, /* 2 */ LOG_INFO, /* 3 */ }; int priority; pstring msgbuf; if( syslog_level >= ( sizeof(priority_map) / sizeof(priority_map[0]) ) || syslog_level < 0) priority = LOG_DEBUG; else priority = priority_map[syslog_level]; va_start( ap, format_str ); vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); va_end( ap ); msgbuf[255] = '\0'; syslog( priority, "%s", msgbuf ); } #endif check_log_size(); #ifdef WITH_SYSLOG if( !lp_syslog_only() ) #endif { va_start( ap, format_str ); if(dbf) (void)x_vfprintf( dbf, format_str, ap ); va_end( ap ); if(dbf) (void)x_fflush( dbf ); } errno = old_errno; return( 0 ); } /* Debug1 */