Re: [Vala] Vala on OpenIndiana Updated



On Wednesday, August 16, 2017, 4:58:59 PM GMT+1, Jason Martin <agrellum gmail com> wrote:

Maybe a good vala example (someone more qualified than me) of trapping
signals would be handy?

This is an example of handling some signals, but not an example for SIGSEGV. The documentation for 
GLib.Unix.SignalSource states "In GLib versions before 2.36, only `SIGHUP`, `SIGINT`, `SIGTERM` can be 
monitored. In GLib 2.36, `SIGUSR1` and `SIGUSR2` were added. In GLib 2.54, `SIGWINCH` was added."
The example is in Genie, so significant leading whitespace and types are declared after the identifier with a 
colon. Save as unix_signal_example.gs and compile like any other Vala program:

[indent = 4]
init
    var main = new MainLoop()
    var handler = new SignalHandler( main )
    Unix.signal_add( Posix.SIGINT, handler.quit )
    print (@"To end the process use:
kill -2 $((int)Posix.getpid())
or CTRL+C")
    main.run()


class SignalHandler
    _mainloop:MainLoop

    construct( mainloop:MainLoop )
        _mainloop = mainloop

    def quit():bool
        print( @"
Process $((int)Posix.getpid()) has received SIGINT, ending..." )
        _mainloop.quit()
        return Source.REMOVE
For segmentation faults you may find inspiration from vala-stacktrace: 
https://github.com/PerfectCarl/vala-stacktrace
Thanks for keeping us updated,

Al


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]