The Open Source Swiss Army Knife

/code/c/ISO_c_basics/
/code/c/ISO_c_basics/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /code   /c   /ISO_c_basics 
Permalink: snprintf.c
Title: add
article options : please login   |  raw source view  

// postgresql-7.4.1/src/backend/postmaster/postmaster.c
/*
 * Try to report backend fork() failure to client before we close the
 * connection.	Since we do not care to risk blocking the postmaster on
 * this connection, we set the connection to non-blocking and try only once.
 *
 * This is grungy special-purpose code; we cannot use backend libpq since
 * it's not up and running.
 */
static void
report_fork_failure_to_client(Port *port, int errnum)
{
	char		buffer[1000];

	/* Format the error message packet (always V2 protocol) */
	snprintf(buffer, sizeof(buffer), "E%s%s\n",
			 gettext("could not fork new process for connection: "),
			 strerror(errnum));

	/* Set port to non-blocking.  Don't do send() if this fails */
	if (FCNTL_NONBLOCK(port->sock) < 0)
		return;

	send(port->sock, buffer, strlen(buffer) + 1, 0);
}

/* mod_pgsqllog.c 1.3   on log handler  */
void sql_log() {
  char statement[MAX_STATEMENT_LEN];
/*  <snip> ... </snip>  */
    /* create the SQL statement string */
    length = snprintf (statement, sizeof (statement),
                       "INSERT INTO %s VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%i', '%s', '%s', '%s', '%s', '%s', '%s', '%i', '%i', '%s')",
                       env->table, (trusted_hostname),
                       (r->protocol ? r->protocol : ""),
                       (r->content_type ? r->content_type : ""),
                       (r->content_encoding ? r->content_encoding : ""),
                       (trusted_uri), (trusted_filename),
                       (r->server->server_hostname ? r->server->
                        server_hostname : ""),
                       (r->server->port ? r->server->port : -1),
                       (trusted_referer),
                       (trusted_useragent),
                       (r->connection->remote_ip ? r->connection->
                        remote_ip : ""),
                       (trusted_remotehost),
                       (trusted_user),
                       (r->
                        request_time ? epoch_timestamp (r->
                                                        request_time) :
                        "NULL"), (r->bytes_sent ? r->bytes_sent : 0),
                       (r->status ? r->status : -1), (trusted_method));

    /* SQL statement trucated due to length - send to error log */
    if (length == -1)
    {
      fprintf (stderr,
               "%s WARNING: Dropping PostgreSQL logging of request from client %s (bytes-sent: %i)\n",
               MODULE_NAME, r->hostname, r->bytes_sent);
      lock_unlock (handle);
      return (-1);
    }

}


Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top