static void logfile_param_changed(cvar_t *self) { if (logfile_enable->integer) { logfile_close(); logfile_open(); } }
static void logfile_enable_changed(cvar_t *self) { logfile_close(); if (self->integer) { logfile_open(); } }
/* ==================== server_free() ==================== */ void server_free(server_t *server) { /* FIXME */ exit_server_work_queue(server); int i; for ( i = 0 ; i < VNODES ; i++ ){ vnode_t *vnode = server->vnodes[i]; if ( vnode != NULL ){ vnode_free(vnode); server->vnodes[i] = NULL; } } for ( i = 0 ; i < LOGFILES ; i++ ) { logfile_t *logfile = server->logfiles[i]; if ( logfile != NULL ) { logfile_close(logfile); logfile_free(logfile); server->logfiles[i] = NULL; } } connection_destroy(&server->connection); pthread_mutex_destroy(&server->send_pending_lock); pthread_cond_destroy(&server->send_pending_cond); zfree(server); }
/* This function forks a child which calls child_main(). First, * however, it has to establish communication paths to and from the * newborn child. It creates two socket pairs -- one for writing to * the child (from the parent) and one for reading from the child * (writing to the parent). Since that's four socket ends, each * process has to close the two ends it doesn't need. The remaining * two socket ends are retained for reading and writing. In the * child, the STDIN and STDOUT file descriptors refer to these * sockets. In the parent, the function arguments f_in and f_out are * set to refer to these sockets. */ pid_t local_child(int argc, char **argv, int *f_in, int *f_out, int (*child_main)(int, char*[])) { pid_t pid; int to_child_pipe[2]; int from_child_pipe[2]; /* The parent process is always the sender for a local rsync. */ assert(am_sender); if (fd_pair(to_child_pipe) < 0 || fd_pair(from_child_pipe) < 0) { rsyserr(FERROR, errno, "pipe"); exit_cleanup(RERR_IPC); } pid = do_fork(); if (pid == -1) { rsyserr(FERROR, errno, "fork"); exit_cleanup(RERR_IPC); } if (pid == 0) { am_sender = 0; am_server = 1; filesfrom_fd = -1; chmod_modes = NULL; /* Let the sending side handle this. */ if (dup2(to_child_pipe[0], STDIN_FILENO) < 0 || close(to_child_pipe[1]) < 0 || close(from_child_pipe[0]) < 0 || dup2(from_child_pipe[1], STDOUT_FILENO) < 0) { rsyserr(FERROR, errno, "Failed to dup/close"); exit_cleanup(RERR_IPC); } if (to_child_pipe[0] != STDIN_FILENO) close(to_child_pipe[0]); if (from_child_pipe[1] != STDOUT_FILENO) close(from_child_pipe[1]); child_main(argc, argv); } /* Let the client side handle this. */ if (logfile_name) { logfile_name = NULL; logfile_close(); } if (close(from_child_pipe[1]) < 0 || close(to_child_pipe[0]) < 0) { rsyserr(FERROR, errno, "Failed to close"); exit_cleanup(RERR_IPC); } *f_in = from_child_pipe[0]; *f_out = to_child_pipe[1]; return pid; }
main() { logfile_type lf; logfile_init(&lf,"logfile.log"); logfile_print(&lf,"Testando %d",123); printf("Espere um tempo e entre com um numero: "); getchar(); logfile_print(&lf,"Testando %d",456); logfile_print(&lf,"Testando %d",457); logfile_print(&lf,"Testando %d",458); logfile_print(&lf,"Testando %d",459); logfile_close(&lf); }
/* ============= Com_Quit Both client and server can use this, and it will do the apropriate things. This function never returns. ============= */ void Com_Quit(const char *reason, error_type_t type) { char buffer[MAX_STRING_CHARS]; char *what = type == ERR_RECONNECT ? "restarted" : "quit"; if (reason && *reason) { Q_snprintf(buffer, sizeof(buffer), "Server %s: %s\n", what, reason); } else { Q_snprintf(buffer, sizeof(buffer), "Server %s\n", what); } SV_Shutdown(buffer, type); CL_Shutdown(); NET_Shutdown(); logfile_close(); FS_Shutdown(); Sys_Quit(); // doesn't get there }
/* This function forks a child which calls child_main(). First, * however, it has to establish communication paths to and from the * newborn child. It creates two socket pairs -- one for writing to * the child (from the parent) and one for reading from the child * (writing to the parent). Since that's four socket ends, each * process has to close the two ends it doesn't need. The remaining * two socket ends are retained for reading and writing. In the * child, the STDIN and STDOUT file descriptors refer to these * sockets. In the parent, the function arguments f_in and f_out are * set to refer to these sockets. */ pid_t local_child(int argc, char **argv, int *f_in, int *f_out, int (*child_main)(int, char*[])) { pid_t pid; int to_child_pipe[2]; int from_child_pipe[2]; /* The parent process is always the sender for a local rsync. */ assert(am_sender); if (fd_pair(to_child_pipe) < 0 || fd_pair(from_child_pipe) < 0) { rsyserr(FERROR, errno, "pipe"); exit_cleanup(RERR_IPC); } pid = do_fork(); if (pid == -1) { rsyserr(FERROR, errno, "fork"); exit_cleanup(RERR_IPC); } if (pid == 0) { am_sender = 0; am_server = 1; filesfrom_fd = -1; munge_symlinks = 0; /* Each side needs its own option. */ chmod_modes = NULL; /* Let the sending side handle this. */ /* Let the client side handle this. */ if (logfile_name) { logfile_name = NULL; logfile_close(); } if (remote_option_cnt) { int rc = remote_option_cnt + 1; const char **rv = remote_options; if (!parse_arguments(&rc, &rv)) { option_error(); exit_cleanup(RERR_SYNTAX); } } if (dup2(to_child_pipe[0], STDIN_FILENO) < 0 || close(to_child_pipe[1]) < 0 || close(from_child_pipe[0]) < 0 || dup2(from_child_pipe[1], STDOUT_FILENO) < 0) { rsyserr(FERROR, errno, "Failed to dup/close"); exit_cleanup(RERR_IPC); } if (to_child_pipe[0] != STDIN_FILENO) close(to_child_pipe[0]); if (from_child_pipe[1] != STDOUT_FILENO) close(from_child_pipe[1]); #ifdef ICONV_CONST setup_iconv(); #endif child_main(argc, argv); } if (close(from_child_pipe[1]) < 0 || close(to_child_pipe[0]) < 0) { rsyserr(FERROR, errno, "Failed to close"); exit_cleanup(RERR_IPC); } *f_in = from_child_pipe[0]; *f_out = to_child_pipe[1]; return pid; }
/* ============= Com_Error Both client and server can use this, and it will do the apropriate things. ============= */ void Com_Error(error_type_t code, const char *fmt, ...) { char msg[MAXERRORMSG]; va_list argptr; size_t len; // may not be entered recursively if (com_errorEntered) { #ifdef _DEBUG if (com_debug_break && com_debug_break->integer) { Sys_DebugBreak(); } #endif Sys_Error("recursive error after: %s", com_errorMsg); } com_errorEntered = qtrue; va_start(argptr, fmt); len = Q_vscnprintf(msg, sizeof(msg), fmt, argptr); va_end(argptr); // save error msg // can't print into it directly since it may // overlap with one of the arguments! memcpy(com_errorMsg, msg, len + 1); // fix up drity message buffers MSG_Init(); // abort any console redirects Com_AbortRedirect(); // reset Com_Printf recursion level com_printEntered = 0; X86_POP_FPCW; if (code == ERR_DISCONNECT || code == ERR_RECONNECT) { Com_WPrintf("%s\n", com_errorMsg); SV_Shutdown(va("Server was killed: %s\n", com_errorMsg), code); CL_Disconnect(code); goto abort; } #ifdef _DEBUG if (com_debug_break && com_debug_break->integer) { Sys_DebugBreak(); } #endif // make otherwise non-fatal errors fatal if (com_fatal_error && com_fatal_error->integer) { code = ERR_FATAL; } if (code == ERR_DROP) { Com_EPrintf("********************\n" "ERROR: %s\n" "********************\n", com_errorMsg); SV_Shutdown(va("Server crashed: %s\n", com_errorMsg), ERR_DROP); CL_Disconnect(ERR_DROP); goto abort; } if (com_logFile) { FS_FPrintf(com_logFile, "FATAL: %s\n", com_errorMsg); } SV_Shutdown(va("Server fatal crashed: %s\n", com_errorMsg), ERR_FATAL); CL_Shutdown(); NET_Shutdown(); logfile_close(); FS_Shutdown(); Sys_Error("%s", com_errorMsg); // doesn't get there abort: if (com_logFile) { FS_Flush(com_logFile); } com_errorEntered = qfalse; longjmp(abortframe, -1); }
// close down the multi logfile void multi_log_close() { multi_log_write_trailer(); logfile_close(LOGFILE_MULTI_LOG); }