Linux systemd service Question
Posted: Wed Jan 29, 2025 3:55 pm
Hi
I am trying to create a systemd service but when I try and start the service it fails. The code works if I run it as a regular executable so I am assuming I am doing something wrong with the service style code. Below is the basic code I am using for a Linux daemon. Is there something I have missed? Am I suppose to report something in the various cases after I get the return value from fork_?
I am trying to create a systemd service but when I try and start the service it fails. The code works if I run it as a regular executable so I am assuming I am doing something wrong with the service style code. Below is the basic code I am using for a Linux daemon. Is there something I have missed? Am I suppose to report something in the various cases after I get the return value from fork_?
Code: Select all
; Signals
#SIGHUP = 1
#SIGINT = 2
#SIGQUIT = 3
#SIGILL = 4
#SIGTRAP = 5
#SIGABRT = 6
#SIGIOT = 6
#SIGBUS = 7
#SIGFPE = 8
#SIGKILL = 9
#SIGUSR1 = 10
#SIGSEGV = 11
#SIGUSR2 = 12
#SIGPIPE = 13
#SIGALRM = 14
#SIGTERM = 15
#SIGSTKFLT = 16
#SIGCHLD = 17
#SIGCONT = 18
#SIGSTOP = 19
#SIGTSTP = 20
#SIGTTIN = 21
#SIGTTOU = 22
#SIGURG = 23
#SIGXCPU = 24
#SIGXFSZ = 25
#SIGVTALRM = 26
#SIGPROF = 27
#SIGWINCH = 28
#SIGIO = 29
#SIGPOLL = 29
#SIGPWR = 30
#SIGSYS = 31
#SIGUNUSED = 31
#SIG_BLOCK = 0
#SIG_UNBLOCK = 1
#SIG_SETMASK = 2
#SA_NOCLDSTOP = $00000001
#SA_NOCLDWAIT = $00000002
#SA_SIGINFO = $00000004
#SA_ONSTACK = $08000000
#SA_RESTART = $10000000
#SA_NODEFER = $40000000
#SA_RESETHAND = $80000000
CompilerIf Not Defined(sigset_t, #PB_Structure)
Structure sigset_t Align #PB_Structure_AlignC
__bits.l[32]
EndStructure
CompilerEndIf
CompilerIf Not Defined(sigaction, #PB_Structure)
Structure sigaction Align #PB_Structure_AlignC
StructureUnion
*sa_handler
*sa_sigaction
EndStructureUnion
sa_mask.sigset_t
sa_flags.l
*sa_restorer
EndStructure
CompilerEndIf
ProcedureC SigHandler(Signal.i)
Select Signal
Case #SIGHUP
gnStop = #True
Case #SIGABRT
gnStop = #True
Case #SIGTERM
gnStop = #True
Case #SIGKILL
gnStop = #True
Case #SIGSTOP
gnStop = #True
Case #SIGUSR1
Case #SIGUSR2
EndSelect
EndProcedure
Define sa.sigaction
Global gnStop
sa\sa_handler = @SigHandler()
sa\sa_flags = #SA_RESTART
sigfillset_(@sa\sa_mask)
sigaction_(#SIGSTOP, @sa, #Null)
sigaction_(#SIGABRT, @sa, #Null)
sigaction_(#SIGKILL, @sa, #Null)
sigaction_(#SIGTERM, @sa, #Null)
sigaction_(#SIGUSR1, @sa, #Null)
sigaction_(#SIGUSR2, @sa, #Null)
sigaction_(#SIGHUP, @sa, #Null)
Select fork_()
Case -1
End
Case 0
; Am I suppose to report something here?
Default
End
EndSelect
Procedure Main()
While Not gnStop
Wend
EndProcedure
Main()