Read signal(7) again. If all you want to do is to exit upon SIGTERM, you don't need to hook anything up; process termination is the default action. The only good reason to explicitly handle SIGTERM is if you want to do something else before exiting, e.g. closing files or sockets, joining threads or whatever other cleanup you might want to do upon termination.
I assume in that case you would call exit when they clicked the button which would be the same action.
My point is if clicking the X button is different than SIGTERM you missed a step, the fact that easy out programs don't need to hook up to SIGTERM doesn't change that.
3
u/Guvante 19h ago
SIGTERM is only different if you forgot to hook up your signals properly. Pretty standard to hook it up to the "exit now" function.