ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is there a common signal issued to all programs on a log out / reboot / shutdown. I'm currently using SIGHUP but this signal may or may not be issued depending on the Linux configuration (Ubuntu issues SIGHUPs by default, Fedora does not.) Is there a signal I've missed?
Hmmm. I need to know both logout and shutdown so my application can delete it's temp files and flush it's logs before it closes. I'm not seeing a SIGTERM at logout or shutdown. I only get a SIGTERM when it is specifically sent to my application (via System Monitor for example.) I'll give SIGKILL a try.
1. Logout the linux user (closes all applications and brings up the user selection for logging in.)
2. I want to make sure you understand that this code works fine in Ubuntu but not in Fedora. Here are the significant parts where the signals are set up in the derive of the wxApp.
Code:
WhyCantIConnectApp::WhyCantIConnectApp() : wxApp(), m_frame(NULL)
{
#ifdef __UNIX__
SetupLinuxSignals();
#endif
}
// The m_frame pointer is set from the creation of the main window.
#ifdef __UNIX__
void WhyCantIConnectApp::OnCleanupSignal()
{
if(m_frame)
m_frame->SystemQuickDestroyMainFrame();
}
void WhyCantIConnectApp::SetupLinuxSignals()
{
struct sigaction sigHup;
sigHup.sa_handler = CleanupSignal;
sigemptyset(&sigHup.sa_mask);
sigHup.sa_flags = 0;
sigHup.sa_flags |= SA_RESTART;
sigaction(SIGHUP, &sigHup, 0);
struct sigaction sigTerm;
sigTerm.sa_handler = CleanupSignal;
sigemptyset(&sigTerm.sa_mask);
sigTerm.sa_flags = 0;
sigTerm.sa_flags |= SA_RESTART;
sigaction(SIGTERM, &sigTerm, 0);
}
void CleanupSignal(int sig)
{
wxGetApp().OnCleanupSignal();
}
#endif
1. Oh, I see what's the misunderstanding: unix is a multiasking-multiuser system, countless users can be logged on in the same time, their logging in and out hardly matters.
2. Doesn't look proper C-code to me. Try something much simpler.
It appears that SIGKILL is issued immediately after SIGTERM which does not allow enough time for my application to react.
The bug report supplies a simple application to test with (pretty much the same as yours NevemTeve.)
Code:
#include <time.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
void myFuncTerm();
int main(void)
{
if (signal(SIGTERM, myFuncTerm) == SIG_ERR) {
printf("SIGTERM error.\n");
}
printf("READY\n");
while (1) {
sleep(2);
}
}
void myFuncTerm()
{
FILE *f;
int retVal;
time_t current_time;
char* c_time_string;
current_time = time(NULL);
c_time_string = ctime(¤t_time);
f = fopen("testing.txt", "a");
if (f == NULL) {
printf("File open error!\n");
return;
}
retVal = fprintf(f, "SIGTERM! - %s\n", c_time_string);
if (retVal < 0) {
printf("File write error!\n");
return;
}
fflush(f);
fclose(f);
}
During my testing with this app, the majority of the time the file was never created. The few times the file was created, it was never written to.
systemd allows you to configure if SIGHUP signals should be sent. The SIGHUP is issued well before the shutdown so I'll use these until I see a resolution to this problem.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.