signals

Linux signal handling. How to get address of interrupted instruction? [duplicate]

冷暖自知 提交于 2021-02-07 14:19:21
问题 This question already has answers here : Getting fault address that generated a UNIX signal (2 answers) Closed 3 years ago . Is there any way to figure out address of machine instruction, that was interrupted by some signal? Assuming that we are at handler established by sigaction() and have all access to passed siginfo_t and ucontext_t . As far as I see man pages says nothing about it. 回答1: Not portable. But this is for x86_64: The structure ucontext_t contains the value of the register REG

Signals don't re-enable properly across execv()

坚强是说给别人听的谎言 提交于 2021-02-07 08:02:20
问题 I am writing a system-critical program for a Linux distribution that I am developing. It needs to restart itself on receiving certain signals, to try to avoid crashing. The problem is, after the restart, I cannot re-enable that signal. That is, the signal cannot be received twice. After execv()'ing itself, when the new process calls signal() to set up the signal, SIG_DFL is returned. Every time. Even if I call it twice in a row -- indicating that it was never set in the first place. Is some

Signals don't re-enable properly across execv()

我的未来我决定 提交于 2021-02-07 07:58:24
问题 I am writing a system-critical program for a Linux distribution that I am developing. It needs to restart itself on receiving certain signals, to try to avoid crashing. The problem is, after the restart, I cannot re-enable that signal. That is, the signal cannot be received twice. After execv()'ing itself, when the new process calls signal() to set up the signal, SIG_DFL is returned. Every time. Even if I call it twice in a row -- indicating that it was never set in the first place. Is some

SIGINT signal gets dropped during write to a pipe

可紊 提交于 2021-02-07 06:45:06
问题 I have a program that dumps pcap data gathered using the libpcap to stdout using pcap_dump function, with stdout as the FILE *. There is a little bit of cleanup necessary on SIGINT, so I handle that with sigaction(). This works nicely when executed from a shell. However, this program is intended to be called by another program, which doesn't seem to work. This "caller" program calls a pipe(), then a fork(), then the child's stdout file descriptor is closed, and replaced with the write end of

Scanf is not waiting for input

。_饼干妹妹 提交于 2021-02-05 11:51:07
问题 I know scanf waits for input. But in this program I have written it is printing hello in an infinite loop. Its not waiting for me to enter. #include <signal.h> #include <stdio.h> #include <string.h> #include <sys/time.h> #include<unistd.h> void timer_handler (int signum) { static int count = 0; printf ("timer expired %d times\n", ++count); } int main () { struct sigaction sa; struct itimerval timer; memset (&sa, 0, sizeof (sa)); sa.sa_handler = &timer_handler; sigaction (SIGALRM, &sa, NULL);

Scanf is not waiting for input

倖福魔咒の 提交于 2021-02-05 11:50:24
问题 I know scanf waits for input. But in this program I have written it is printing hello in an infinite loop. Its not waiting for me to enter. #include <signal.h> #include <stdio.h> #include <string.h> #include <sys/time.h> #include<unistd.h> void timer_handler (int signum) { static int count = 0; printf ("timer expired %d times\n", ++count); } int main () { struct sigaction sa; struct itimerval timer; memset (&sa, 0, sizeof (sa)); sa.sa_handler = &timer_handler; sigaction (SIGALRM, &sa, NULL);

Simple synchronization with C signals

这一生的挚爱 提交于 2021-02-05 06:40:31
问题 I'm trying to solve an exercise which requires that : "the starting process must fork two times. The father and the children must synchronize to write, one after another, in the first position of a temporary file reading the characters written on three different files (one for each process). The program must use signals to implement the synchronization mechanism." So far i've tried to solve this by doing so : P1 (the father) starts reading/writing first. Before stopping himself (through a

Django create profile for user signal

早过忘川 提交于 2021-02-04 21:32:23
问题 im trying to create profile for user account using signals but after writing the codes is not creating at all Django 3.0.5 users/models.py from django.db import models from django.contrib.auth.models import User from PIL import Image class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) profile_image = models.ImageField(default='default.jpg', upload_to='profile_pics') def __str__(self): return f'{self.user.username} Profile' def save(self): super().save()

django signals, how to use “instance”

末鹿安然 提交于 2021-02-04 13:09:12
问题 I am trying to create a system which enables user to upload a zipfile, and then extract it using post_save signal. class Project: .... file_zip=FileField(upload_to='projects/%Y/%m/%d') @receiver(post_save, sender=Project) def unzip_and_process(sender, **kwargs): #project_zip = FieldFile.open(file_zip, mode='rb') file_path = sender.instance.file_zip.path with zipfile.ZipFile(file_path, 'r') as project_zip: project_zip.extractall(re.search('[^\s]+(?=\.zip)', file_path).group(0)) project_zip

django signals, how to use “instance”

ε祈祈猫儿з 提交于 2021-02-04 13:08:06
问题 I am trying to create a system which enables user to upload a zipfile, and then extract it using post_save signal. class Project: .... file_zip=FileField(upload_to='projects/%Y/%m/%d') @receiver(post_save, sender=Project) def unzip_and_process(sender, **kwargs): #project_zip = FieldFile.open(file_zip, mode='rb') file_path = sender.instance.file_zip.path with zipfile.ZipFile(file_path, 'r') as project_zip: project_zip.extractall(re.search('[^\s]+(?=\.zip)', file_path).group(0)) project_zip