MCPcopy Create free account
hub / github.com/F-Stack/f-stack / serverLogFromHandler

Function serverLogFromHandler

app/redis-6.2.6/src/server.c:1191–1211  ·  view source on GitHub ↗

Log a fixed message without printf-alike capabilities, in a way that is * safe to call from a signal handler. * * We actually use this only for signals that are not fatal from the point * of view of Redis. Signals that are going to kill the server anyway and * where we need printf-alike features are served by serverLog(). */

Source from the content-addressed store, hash-verified

1189 * of view of Redis. Signals that are going to kill the server anyway and
1190 * where we need printf-alike features are served by serverLog(). */
1191void serverLogFromHandler(int level, const char *msg) {
1192 int fd;
1193 int log_to_stdout = server.logfile[0] == '\0';
1194 char buf[64];
1195
1196 if ((level&0xff) < server.verbosity || (log_to_stdout && server.daemonize))
1197 return;
1198 fd = log_to_stdout ? STDOUT_FILENO :
1199 open(server.logfile, O_APPEND|O_CREAT|O_WRONLY, 0644);
1200 if (fd == -1) return;
1201 ll2string(buf,sizeof(buf),getpid());
1202 if (write(fd,buf,strlen(buf)) == -1) goto err;
1203 if (write(fd,":signal-handler (",17) == -1) goto err;
1204 ll2string(buf,sizeof(buf),time(NULL));
1205 if (write(fd,buf,strlen(buf)) == -1) goto err;
1206 if (write(fd,") ",2) == -1) goto err;
1207 if (write(fd,msg,strlen(msg)) == -1) goto err;
1208 if (write(fd,"\n",1) == -1) goto err;
1209err:
1210 if (!log_to_stdout) close(fd);
1211}
1212
1213/* Return the UNIX time in microseconds */
1214long long ustime(void) {

Callers 3

sigShutdownHandlerFunction · 0.85
sigKillChildHandlerFunction · 0.85
watchdogSignalHandlerFunction · 0.85

Calls 3

ll2stringFunction · 0.85
writeFunction · 0.70
closeFunction · 0.70

Tested by

no test coverage detected