Nmap Development mailing list archives

[NSE] need to get waiting threads to resume after a thread having mutex dies


From: jah <jah () zadkiel plus com>
Date: Thu, 07 Aug 2008 23:30:04 +0100

Hello,

If a thread that has a mutex finishes due to an error, threads waiting
for that mutex remain waiting for ever. Attached is an example which
needs to be run against two targets to illustrate the problem.
I've tried working this out for myself, but without success.  I feel
like someone who's picked-up a golf club for the first time, I'm just
hacking around.  Over to the pros I think.  I'll just watch.

Regards,

jah
id="bar"
author=""
runlevel="1"
description = ""

hostrule = function( host )
  return true
end

nmap.registry.foo = {}

action = function( host )

  print( ( "Thread for %s RUNNING.\n" ):format( host.ip ) )
  table.insert( nmap.registry.foo, host.ip )

  local mutex = nmap.mutex( id )


  print( ( "Thread for %s wants mutex.\n" ):format( host.ip ) )
  mutex "lock"
  print( ( "Thread for %s has mutex.\n" ):format( host.ip ) )

    if nmap.registry.foo[1] == host.ip then

      local sock = nmap.new_socket()
      sock:set_timeout( 0 )

      print( ( "Thread for %s yields briefly.\n" ):format( host.ip ) )
      status, error = sock:connect(host.ip, 80)
      sock:close()

      print( ( "Thread for %s has resumed and will now DIE horribly!" ):format( host.ip ) )

      -- this causes the thread to exit before it unlocks the mutex
      nmap.registry[nil] = 1

    end

  mutex "done"



  return table.concat( nmap.registry.foo, ", " )

end

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org

Current thread: