File: openssl-pg-segfault.rb

package info (click to toggle)
ruby-pg 1.5.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,264 kB
  • sloc: ansic: 8,820; ruby: 2,809; makefile: 10
file content (31 lines) | stat: -rw-r--r-- 798 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- ruby -*-

PGHOST   = 'localhost'
PGDB     = 'test'
#SOCKHOST = 'github.com'
SOCKHOST = 'it-trac.laika.com'

# Load pg first, so the libssl.so that libpq is linked against is loaded.
require 'pg'
$stderr.puts "connecting to postgres://#{PGHOST}/#{PGDB}"
conn = PG.connect( PGHOST, :dbname => PGDB )

# Now load OpenSSL, which might be linked against a different libssl.
require 'socket'
require 'openssl'
$stderr.puts "Connecting to #{SOCKHOST}"
sock = TCPSocket.open( SOCKHOST, 443 )
ctx = OpenSSL::SSL::SSLContext.new
sock = OpenSSL::SSL::SSLSocket.new( sock, ctx )
sock.sync_close = true

# The moment of truth...
$stderr.puts "Attempting to connect..."
begin
	sock.connect
rescue Errno
	$stderr.puts "Got an error connecting, but no segfault."
else
	$stderr.puts "Nope, no segfault!"
end