Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#38665 - [arch-install-scripts] killing pacstrap still lets the underlying pacman subprocess alive

Attached to Project: Arch Linux
Opened by Francis Moreau (fmoreau) - Sunday, 26 January 2014, 11:27 GMT
Last edited by Dave Reisner (falconindy) - Friday, 07 February 2014, 14:50 GMT
Task Type Bug Report
Category Arch Projects
Status Closed
Assigned To Dave Reisner (falconindy)
Architecture All
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description: after starting pacstrap to initialize a new chroot, I tried to kill it for some reasons. But although the pacstrap process is gone, the pacman subprocess (started by pacstrap) is still running.

Additional info:
* package version(s)
arch-install-scripts 12-1
pacman 4.1.2-5


Steps to reproduce:
$ pacstrap /mnt base
...
$ pkill pacstrap
$ ps aux | grep pacman
root 1241 5.5 0.0 153416 15112 pts/2 S 12:21 0:01 pacman -r /mnt -Sy base --cachedir=/mnt/var/cache/pacman/pkg --noconfirm
$ pkill pacman
$ ps aux | grep pacman
$
This task depends upon

Closed by  Dave Reisner (falconindy)
Friday, 07 February 2014, 14:50 GMT
Reason for closing:  Won't implement
Additional comments about closing:  This doesn't make sense to include as part of pacstrap since it's an interactive script and already properly handles SIGINT, as interactive scripts do. it makes no sense to treat pacstrap as a daemon and handle such signals as SIGTERM.
Comment by Dave Reisner (falconindy) - Monday, 27 January 2014, 13:32 GMT
Need more info. At what exact point did you kill pacstrap? Pacman will intentionally block some signals while it touches the filesystem.
Comment by Francis Moreau (fmoreau) - Monday, 27 January 2014, 13:39 GMT
Well, I tried a couple times at different moments: while collecting, downloading packages orinstalling packages, the result is always the same, pacman is still running in the background.

Probably SIGHUP signal is blocked by pacman, but I don't think it's a good idea to let pacman still running if its parent is killed.
Comment by Dave Reisner (falconindy) - Monday, 27 January 2014, 13:50 GMT
Your origin bug report claims you used pkill to send the default signal, SIGTERM. Now you mention SIGINT. Which did you use?

SIGINT is blocked during install and caught during downloads. I don't recall anything in pacstrap that would prevent the usual propagation of signals to child processes....
Comment by Francis Moreau (fmoreau) - Monday, 27 January 2014, 13:56 GMT
No one is mentionning SIGINT.

I was just thinking that pacman is indeed blocking a signal (was thinking about SIGHUP) which prevents it to exit if its parent died.

Just try it, try to send SIGTERM to pacman and see what's happening and tell me if you think it's a correct behaviour.

If you think so, please explain.

Thanks.
Comment by Dave Reisner (falconindy) - Monday, 27 January 2014, 14:54 GMT
> No one is mentionning SIGINT.
Right, I just pointing out the disparity between your initial report and followup (which I guess I slightly misread while on the train).

I don't even understand what would cause you to perform this sequence of actions, but it's the default behavior of bash. You can do something as simple as:

#!/bin/bash
sleep 100

Name this script whatever, run it, kill the script, and the sleep process will remain. The point is that you're sending TERM to a specific process, not the process group. The *only* case where bash will clean up after itself is if you send a signal to the jobspec of a backgrounded job from the same shell (e.g. ./foo & kill %1).

I really have to wonder if this isn't something that you, the user, need to fix. pkill has a -g flag which probably does what you want.
Comment by Francis Moreau (fmoreau) - Thursday, 06 February 2014, 08:43 GMT
Hi, sorry for the delay.

I'm not sure to understand why you took bash as an example. It surely handles signals in its own way but my question was about pacstrap.

> Right, I just pointing out the disparity between your initial report and followup (which I guess I slightly misread while on the train).

which disparity ?

I'm sorry if my question was unclear, so let try one more time: as a user point of view, I find odd that when killing pacstrap (pkill pacstrap), there's still a background process (pacman) that's still initializing a directory and thus preventing any operations on that directory such as unmounting it, cleaning it etc...

Maybe it's more a pacman behaviour: if its parent process exits before it finishes, isn't this a hint that it should stop its job ?

Thanks
Comment by Dave Reisner (falconindy) - Thursday, 06 February 2014, 13:56 GMT
> I'm not sure to understand why you took bash as an example. It surely handles signals in its own way but my question was about pacstrap.
It's not an example, it's what's relevant here because pacstrap IS a bash script. Your bug report has everything to do with the default signal handling behavior of bash, which I previously explained.


> I find odd that when killing pacstrap (pkill pacstrap),
And again, this is what I find confusing. What situation are you finding yourself in that you're sending pkill to pacstrap and not just interrupting the process with ^C?


> Maybe it's more a pacman behaviour: if its parent process exits before it finishes, isn't this a hint that it should stop its job ?
This doesn't even make sense -- pacman has nothing to do with this. Replace the "pacman" command in pacstrap with "sleep 100" and you'll see the exact same behavior.
Comment by Francis Moreau (fmoreau) - Thursday, 06 February 2014, 14:00 GMT
pacstrap can be started not only from an interactive shell but from a program too, no ? so what's wrong sending it a SIGTERM ?

You keep using the "sleep 100" example. But leaving a background sleep is not really the same that a background process doing heavy IOs.
Comment by Dave Reisner (falconindy) - Thursday, 06 February 2014, 14:12 GMT
I have no idea what it is you're doing, and you're being extremely lean on details. I can't help you if you don't explain wtf it is you're doing.

Really, what is your use case?
Comment by Francis Moreau (fmoreau) - Friday, 07 February 2014, 08:12 GMT
I'm simply trying to write a (python) script that installs archlinux on a disk. Obviously it calls pacstrap to do that, and I'd like to make it smart enought to let the system clean (no ghost processes) if it's terminated for *any* reasons.
Comment by Dave Reisner (falconindy) - Friday, 07 February 2014, 14:49 GMT
> I'd like to make it smart enought to let the system clean (no ghost processes) if it's terminated for *any* reasons.
Install your own signal handler to kill the process group if you really think that you need this.

def on_sigterm(signum, unused_frame):
signal.signal(signum, signal.SIG_DFL)
os.kill(-os.getpid(), signum)

signal.signal(signal.SIGTERM, on_sigterm)

Loading...