Jump to content




Simple way to do Daemons?


  • You cannot reply to this topic
4 replies to this topic

#1 LDShadowLord

  • Members
  • 115 posts

Posted 06 April 2014 - 01:26 AM

I'm creating a program which is a modified router, while allows me to go all NSA and log everything, but i'd still like access to the shell so does anyone know of a way I could integrate a Daemon? Or link to me a way I could integrate a Daemon? I'd prefer to avoid coroutines as I don't understand them.

#2 1lann

  • Members
  • 516 posts
  • LocationSeattle

Posted 06 April 2014 - 01:34 AM

View PostLDShadowLord, on 06 April 2014 - 01:26 AM, said:

I'm creating a program which is a modified router, while allows me to go all NSA and log everything, but i'd still like access to the shell so does anyone know of a way I could integrate a Daemon? Or link to me a way I could integrate a Daemon? I'd prefer to avoid coroutines as I don't understand them.
A quick example:
local function daemon()
  -- This will run in the background
  -- I would not advise writing anything to the screen :P/>
end
parallel.waitForAny(daemon, function() shell.run("/rom/programs/shell") end)

Edited by 1lann, 06 April 2014 - 01:34 AM.


#3 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 06 April 2014 - 01:40 AM

Essentially the same approach, but a bit different syntactically (it just breaks the shell down into its own function outside of the parallel call):
local function foregroundShell()
  shell.run("shell")
end

local function myMainFunction()
  <your main program loop>
  <this runs in the background>
  <do not write to the screen>
end

parallel.waitForAny(myMainFunction,foregroundShell)

Edited by Dog, 06 April 2014 - 01:51 AM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 06 April 2014 - 01:53 AM

One way is to write a modified version of os.pullEvent, and have it record whatever data you're interested in.

For eg, the default one looks something like this:

function os.pullEvent(eventType)
	myEvent = {os.pullEventRaw(eventType)}
	
	if myEvent[1] == "terminate" then error("Ctrl+T pressed") end
	
	return myEvent
end

You can see that it's basically a wrapper for os.pullEventRaw - it returns whatever that returns, unless it returns a terminate event, in which case it kills your script.

If you declared your own version of that function, which eg looked for key events and saved them into a hidden text file somewhere, then hey presto! Key logger. You literally just take something like the above code block, alter it to taste, run it on startup, then otherwise allow the computer to work "normally".

The code demonstrated here functions under this concept, though it may be a little complex for you to read at this stage.

Edited by Bomb Bloke, 06 April 2014 - 01:54 AM.


#5 LDShadowLord

  • Members
  • 115 posts

Posted 06 April 2014 - 01:53 AM

Excellent, thankyou very much, folks.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users