summaryrefslogtreecommitdiff
path: root/sys/kern/kern_exit.c
Commit message (Collapse)AuthorAgeFilesLines
* Provide ABI modules hooks for process exec/exit and thread exit.Konstantin Belousov2020-11-231-0/+7
| | | | | | | | | | | | | | | Exec and exit are same as corresponding eventhandler hooks. Thread exit hook is called somewhat earlier, while thread is still owned by the process and enough context is available. Note that the process lock is owned when the hook is called. Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D27309 Notes: svn path=/head/; revision=367959
* Stop using eventhandlers for itimers subsystem exec and exit hooks.Konstantin Belousov2020-11-211-0/+3
| | | | | | | | | | | | | | | | | | While there, do some minor cleanup for kclocks. They are only registered from kern_time.c, make registration function static. Remove event hooks, they are not used by both registered kclocks. Add some consts. Perhaps we can stop registering kclocks at all and statically initialize them. Reviewed by: mjg Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27305 Notes: svn path=/head/; revision=367923
* Split out cwd/root/jail, cmask state from filedesc tableConrad Meyer2020-11-171-0/+1
| | | | | | | | | | | | | | | | No functional change intended. Tracking these structures separately for each proc enables future work to correctly emulate clone(2) in linux(4). __FreeBSD_version is bumped (to 1300130) for consumption by, e.g., lsof. Reviewed by: kib Discussed with: markj, mjg Differential Revision: https://reviews.freebsd.org/D27037 Notes: svn path=/head/; revision=367777
* select: call seltdfini on process and thread exitMateusz Guzik2020-11-161-0/+1
| | | | | | | | | | | Since thread_zone is marked NOFREE the thread_fini callback is never executed, meaning memory allocated by seltdinit is never released. Adding the call to thread_dtor is not sufficient as exiting processes cache the main thread. Notes: svn path=/head/; revision=367714
* Fix a pair of races in SIGIO registrationMark Johnston2020-11-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | First, funsetownlst() list looks at the first element of the list to see whether it's processing a process or a process group list. Then it acquires the global sigio lock and processes the list. However, nothing prevents the first sigio tracker from being freed by a concurrent funsetown() before the sigio lock is acquired. Fix this by acquiring the global sigio lock immediately after checking whether the list is empty. Callers of funsetownlst() ensure that new sigio trackers cannot be added concurrently. Second, fsetown() uses funsetown() to remove an existing sigio structure from a file object. However, funsetown() uses a racy check to avoid the sigio lock, so two threads may call fsetown() on the same file object, both observe that no sigio tracker is present, and enqueue two sigio trackers for the same file object. However, if the file object is destroyed, funsetown() will only remove one sigio tracker, and funsetownlst() may later trigger a use-after-free when it clears the file object reference for each entry in the list. Fix this by introducing funsetown_locked(), which avoids the racy check. Reviewed by: kib Reported by: pho Tested by: pho MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D27157 Notes: svn path=/head/; revision=367588
* proc_realparent: if p_oppid does not match pid of the current parentKonstantin Belousov2020-09-161-1/+1
| | | | | | | | | | | | for non-orphaned process, return reaper instead of init. Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D26416 Notes: svn path=/head/; revision=365812
* Fix several issues with process group orphanage.Konstantin Belousov2020-08-221-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Attempt of adding assertions that pgrp->pg_jobc counters do not underflow in r361967, reverted in r362910, points out bugs in the handling of job control. Peter Holm was able to narrow down the problem to very easy reproduction with timeout(1) which uses reaping. The following list of problems with calculation of pg_jobs which directs SIGHUP/SIGCONT delivery for orphaned process group was identified: - Re-calculation of the orphaned status for children of exiting parent was wrong, but mostly unnoticed when all children were reparented to init(8). When child can be reparented to a different process which could affect the child' job control state, it was not properly accounted for in pg_jobc. - Lockless check for exiting process' parent process group is racy because nothing prevents the parent from changing its group membership. - Exited process is left in the process group, until waited. This affects other calculations of pg_jobc. Split handling of job control status on process changing its process group, and process exiting. Calculate increments and decrements for pg_jobs by exact checking the orphanage instead of assuming process group membership for children and parent. Move the call to killjobc() later under the proctree_lock. Mark exiting process in killjobc() with a new flag P_TREE_GRPEXITED and skip it for all pg_jobc calculations after the flag is set. Add checker that independently recalculates pg_jobc value and compares it with the memoized process group state. This is enabled under INVARIANTS. Reviewed by: jilles Discussed with: kevans Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D26116 Notes: svn path=/head/; revision=364495
* proc: refactor clearing credentials into proc_unset_credMateusz Guzik2020-05-251-2/+1
| | | | Notes: svn path=/head/; revision=361448
* Remove the old NFS lock device driver that uses Giant.Rick Macklem2020-04-091-9/+0
| | | | | | | | | | | | | | | | | This NFS lock device driver was replaced by the kernel NLM around FreeBSD7 and has not normally been used since then. To use it, the kernel had to be built without "options NFSLOCKD" and the nfslockd.ko had to be deleted as well. Since it uses Giant and is no longer used, this patch removes it. With this device driver removed, there is now a lot of unused code in the userland rpc.lockd. That will be removed on a future commit. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D22933 Notes: svn path=/head/; revision=359745
* Retire procfs-based process debugging.John Baldwin2020-04-011-16/+1
| | | | | | | | | | | | | | | | | | Modern debuggers and process tracers use ptrace() rather than procfs for debugging. ptrace() has a supserset of functionality available via procfs and new debugging features are only added to ptrace(). While the two debugging services share some fields in struct proc, they each use dedicated fields and separate code. This results in extra complexity to support a feature that hasn't been enabled in the default install for several years. PR: 244939 (exp-run) Reviewed by: kib, mjg (earlier version) Relnotes: yes Differential Revision: https://reviews.freebsd.org/D23837 Notes: svn path=/head/; revision=359530
* Remove sparc64 kernel supportWarner Losh2020-02-031-0/+1
| | | | | | | | | Remove all sparc64 specific files Remove all sparc64 ifdefs Removee indireeect sparc64 ifdefs Notes: svn path=/head/; revision=357455
* Remove duplicated empty lines from kern/*.cMateusz Guzik2020-01-301-2/+0
| | | | | | | No functional changes. Notes: svn path=/head/; revision=357312
* procdesc: allow to collect status through wait(1) if process is tracedMariusz Zaborski2019-11-251-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | The debugger like truss(1) depends on the wait(2) syscall. This syscall waits for ALL children. When it is waiting for ALL child's the children created by process descriptors are not returned. This behavior was introduced because we want to implement libraries which may pdfork(1). The behavior of process descriptor brakes truss(1) because it will not be able to collect the status of processes with process descriptors. To address this problem the status is returned to parent when the child is traced. While the process is traced the debugger is the new parent. In case the original parent and debugger are the same process it means the debugger explicitly used pdfork() to create the child. In that case the debugger should be using kqueue()/pdwait() instead of wait(). Add test case to verify that. The test case was implemented by markj@. Reviewed by: kib, markj Discussed with: jhb MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D20362 Notes: svn path=/head/; revision=355097
* proc: clear pid bitmap entry after dropping proctree lockMateusz Guzik2019-09-021-1/+2
| | | | | | | | | | | | | | There is no correctness change here, but the procid lock is contended in the fork path and taking it while holding proctree avoidably extends its hold time. Note that there are other ids which can end up getting cleared with the lock. Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=351697
* proc: eliminate the zombproc listMateusz Guzik2019-08-281-7/+1
| | | | | | | | | | | | It is not needed by anything in the kernel and it slightly drives up contention on both proctree and allproc locks. Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D21447 Notes: svn path=/head/; revision=351572
* exit1: fix style nitsMariusz Zaborski2019-08-051-1/+1
| | | | | | | MFC after: 1 month Notes: svn path=/head/; revision=350614
* proc: introduce the proc_add_orphan functionMariusz Zaborski2019-08-051-10/+20
| | | | | | | | | | This API allows adding the process to its parent orphan list. Reviewed by: kib, markj MFC after: 1 month Notes: svn path=/head/; revision=350611
* exit1: postpone clearing P_TRACED flag until the proctree lock is acquiredMariusz Zaborski2019-08-051-1/+3
| | | | | | | | | | | | | | In case of the process being debugged. The P_TRACED is cleared very early, which would make procdesc_close() not calling proc_clear_orphan(). That would result in the debugged process can not be able to collect status of the process with process descriptor. Reviewed by: markj, kib Tested by: pho MFC after: 1 month Notes: svn path=/head/; revision=350610
* proc: make clear_orphan an public APIMariusz Zaborski2019-07-291-6/+6
| | | | | | | | | | This will be useful for other patches with process descriptors. Change its name as well. Reviewed by: markj, kib Notes: svn path=/head/; revision=350429
* Include ktr.h in more compilation unitsConrad Meyer2019-05-211-0/+1
| | | | | | | | | | | | | | | | | | Similar to r348026, exhaustive search for uses of CTRn() and cross reference ktr.h includes. Where it was obvious that an OS compat header of some kind included ktr.h indirectly, .c files were left alone. Some of these files clearly got ktr.h via header pollution in some scenarios, or tinderbox would not be passing prior to this revision, but go ahead and explicitly include it in files using it anyway. Like r348026, these CUs did not show up in tinderbox as missing the include. Reported by: peterj (arm64/mp_machdep.c) X-MFC-With: r347984 Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=348064
* Extract eventfilter declarations to sys/_eventfilter.hConrad Meyer2019-05-201-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | This allows replacing "sys/eventfilter.h" includes with "sys/_eventfilter.h" in other header files (e.g., sys/{bus,conf,cpu}.h) and reduces header pollution substantially. EVENTHANDLER_DECLARE and EVENTHANDLER_LIST_DECLAREs were moved out of .c files into appropriate headers (e.g., sys/proc.h, powernv/opal.h). As a side effect of reduced header pollution, many .c files and headers no longer contain needed definitions. The remainder of the patch addresses adding appropriate includes to fix those files. LOCK_DEBUG and LOCK_FILE_LINE_ARG are moved to sys/_lock.h, as required by sys/mutex.h since r326106 (but silently protected by header pollution prior to this change). No functional change (intended). Of course, any out of tree modules that relied on header pollution for sys/eventhandler.h, sys/lock.h, or sys/mutex.h inclusion need to be fixed. __FreeBSD_version has been bumped. Notes: svn path=/head/; revision=347984
* Set the p_oppid field of orphans when exiting.Mark Johnston2019-04-071-0/+5
| | | | | | | | | | | | | | | | | | Such processes will be reparented to the reaper when the current parent is done with them (i.e., ptrace detached), so p_oppid must be updated accordingly. Add a regression test to exercise this code path. Previously it would not be possible to reap an orphan with a stale oppid. Reviewed by: kib, mjg Tested by: pho MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D19825 Notes: svn path=/head/; revision=346009
* proc: handle sdt exit probe before taking the proc lockMateusz Guzik2018-12-081-9/+11
| | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=341721
* proc: when exiting move to zombproc before taking proctreeMateusz Guzik2018-12-071-1/+2
| | | | | | | | | | | | | | | The kernel was already doing this prior to r329615. It was changed to reduce contention on allproc. However, introduction of pidhash locks and removal of proctree -> allproc ordering from fork thanks to bitmaps fixed things enough to make this change pessimal. waitpid takes proctree on each call and this change (now) causes avoidable stalls if allproc is held. Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=341685
* Manage process-related IDs with bitmapsMateusz Guzik2018-12-071-1/+23
| | | | | | | | | | | | | | | | | | | | | | | Currently unique pid allocation on fork often requires a full walk of process, group, session lists to make sure it is not used by anything. This has a side effect of requiring proctree to be held along with allproc, which adds more contention in poudriere -j 128. The patch below implements trivial bitmaps which gets rid of the problem. Dedicated lock is introduced to manage IDs. While here a bug was discovered: all processes would inherit reap id from the first process spawned by init. This had a side effect of keeping the ID used and when allocation rolls over to the beginning it keeps being skipped. The patch is loosely based on initial work by mjoras@. Reviewed by: kib Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=341684
* proc: create a dedicated lock for zombproc to ligthen the load on allproc_lockMateusz Guzik2018-11-291-2/+4
| | | | | | | | | | | | waitpid always takes proctree to evaluate the list, but only takes allproc if it can reap. With this patch allproc is no longer taken, which helps during poudriere -j 128. Discussed with: kib Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=341176
* Revert "fork: fix use-after-free with vfork"Mateusz Guzik2018-11-231-10/+6
| | | | | | | | | | | | | | | | | | | | | | | This unreliably breaks libc handling of vfork where forking succeded, but execve did not. vfork code in libc performs waitpid with WNOHANG in case of failed exec. With the fix exit codepath was waking up the parent before the child fully transitioned to a zombie. Woken up parent would waitpid, which could find a not-yet-zombie child and fail to reap it due to the WNOHANG flag. While removing the flag fixes the problem, it is not an option due to older releases which would still suffer from the kernel change. Revert the fix until a solution can be worked out. Note that while use-after-free which gets back due to the revert is a real bug, it's side-effects are limited due to the fact that struct proc memory is never released by UMA. Notes: svn path=/head/; revision=340793
* fork: fix use-after-free with vforkMateusz Guzik2018-11-221-6/+10
| | | | | | | | | | | | | | | | | | The pointer to the child is stored without any reference held. Then it is blindly used to wait until P_PPWAIT is cleared. However, if the child is autoreaped it could have exited and get freed before the parent started waiting. Use the existing hold mechanism to mitigate the problem. Most common case of doing exec remains unchanged. The corner case of doing exit performs wake up before waiting for holds to clear. Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D18295 Notes: svn path=/head/; revision=340784
* proc: update list manipulation comment on process exitMateusz Guzik2018-11-211-2/+1
| | | | | | | | | | | | Processes stay in the hash until they get reaped. This code does not unlink the child from the parent, so remove the claim that it does. Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=340748
* proc: implement pid hash locks and an iteratorMateusz Guzik2018-11-211-1/+3
| | | | | | | | | | | | | | | forks, exits and waits are frequently stalled during poudriere -j 128 runs due to killpg and process list exports performed for each package. Both uses take the allproc lock. The latter case can be modified to iterate over the hash with finer grained locking instead. Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D17817 Notes: svn path=/head/; revision=340742
* proc: always store parent pid in p_oppidMateusz Guzik2018-11-161-18/+13
| | | | | | | | | | | | Doing so removes the dependency on proctree lock from sysctl process list export which further reduces contention during poudriere -j 128 runs. Reviewed by: kib (previous version) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D17825 Notes: svn path=/head/; revision=340482
* Add PROC_PDEATHSIG_SET to procctl interface.Konstantin Belousov2018-04-181-0/+13
| | | | | | | | | | | | | Allow processes to request the delivery of a signal upon death of their parent process. Supposed consumer of the feature is PostgreSQL. Submitted by: Thomas Munro Reviewed by: jilles, mjg MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D15106 Notes: svn path=/head/; revision=332740
* Move most of the contents of opt_compat.h to opt_global.h.Brooks Davis2018-04-061-1/+0
| | | | | | | | | | | | | | | | | | | | | opt_compat.h is mentioned in nearly 180 files. In-progress network driver compabibility improvements may add over 100 more so this is closer to "just about everywhere" than "only some files" per the guidance in sys/conf/options. Keep COMPAT_LINUX32 in opt_compat.h as it is confined to a subset of sys/compat/linux/*.c. A fake _COMPAT_LINUX option ensure opt_compat.h is created on all architectures. Move COMPAT_LINUXKPI to opt_dontuse.h as it is only used to control the set of compiled files. Reviewed by: kib, cem, jhb, jtl Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D14941 Notes: svn path=/head/; revision=332122
* Reduce contention on the proctree lock during heavy package build.Mateusz Guzik2018-02-201-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is a proctree -> allproc ordering established. Most of the time it is either xlock -> xlock or slock -> slock. On fork however there is a slock -> xlock pair which results in pathological wait times due to threads keeping proctree held for reading and all waiting on allproc. Switch this to xlock -> xlock. Longer term fix would get rid of proctree in this place to begin with. Right now it is necessary to walk the session/process group lists to determine which id is free. The walk can be avoided e.g. with bitmaps. The exit path used to have one place which dealt with allproc and then with proctree. Move the allproc acquire into the section protected by proctree. This reduces contention against threads waiting on proctree in the fork codepath - the fork proctree holder does not have to wait for allproc as often. Finally, move tidhash manipulation outside of the area protected by either of these locks. The removal from the hash was already unprotected. There is no legitimate reason to look up thread ids for a process still under construction. This results in about 50% wait time reduction during -j 128 package build. Notes: svn path=/head/; revision=329615
* Fix process exit vs reap race introduced in r329449Mateusz Guzik2018-02-191-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The race manifested itself mostly in terms of crashes with "spin lock held too long". Relevant parts of respective code paths: exit: reap: PROC_LOCK(p); PROC_SLOCK(p); p->p_state == PRS_ZOMBIE PROC_UNLOCK(p); PROC_LOCK(p); /* exit work */ if (p->p_state == PRS_ZOMBIE) /* true */ proc_reap() free proc /* more exit work */ PROC_SUNLOCK(p); Thus a still exiting process is reaped. Prior to the change the zombie check was followed by slock/sunlock trip which prevented the problem. Even code prior to this commit has a bug: the proc is still accessed for statistic collection purposes. However, the severity is rather small and the bug may be fixed in a future commit. Reported by: many Tested by: allanjude Notes: svn path=/head/; revision=329542
* exit: get rid of PROC_SLOCK when checking a process to report, take #2Mateusz Guzik2018-02-181-18/+21
| | | | | | | | | | | | The suspension counter needs synchronisation through slock, but we don't need it to check if inspecting the counter is necessary to begin with. In the common case it is not, thus avoid the lock if possible. Reviewed by: kib Tested by: pho Notes: svn path=/head/; revision=329531
* Revert r329448.Mateusz Guzik2018-02-171-0/+7
| | | | | | | | | Turns out is is actually racy, reproducible with stress2/misc/truss.sh Requested by: kib Notes: svn path=/head/; revision=329461
* exit: stop doing PROC_SLOCK just to call proc_reapMateusz Guzik2018-02-171-3/+0
| | | | | | | It immediately does PROC_SUNLOCK anyway and the lock plays no role. Notes: svn path=/head/; revision=329449
* exit: get rid of PROC_SLOCK when checking a process to reportMateusz Guzik2018-02-171-7/+0
| | | | | | | All accessed fields are protected with already held process lock. Notes: svn path=/head/; revision=329448
* On process exit signal the parent after dropping the proctree lock.Mateusz Guzik2018-02-171-7/+16
| | | | Notes: svn path=/head/; revision=329422
* Unref the prison after proctree is dropped.Mateusz Guzik2018-02-171-3/+3
| | | | Notes: svn path=/head/; revision=329421
* Tidy up kern_wait6Mateusz Guzik2018-02-171-10/+10
| | | | | | | | | - don't relock curproc in msleep - don't relock proctree if P_STATCHILD is spotted - reformat the proc_to_reap call in the main loop Notes: svn path=/head/; revision=329419
* Implement 'domainset', a cpuset based NUMA policy mechanism. This allowsJeff Roberson2018-01-121-5/+0
| | | | | | | | | | | | | | | | | | | userspace to control NUMA policy administratively and programmatically. Implement domainset based iterators in the page layer. Remove the now legacy numa_* syscalls. Cleanup some header polution created by having seq.h in proc.h. Reviewed by: markj, kib Discussed with: alc Tested by: pho Sponsored by: Netflix, Dell/EMC Isilon Differential Revision: https://reviews.freebsd.org/D13403 Notes: svn path=/head/; revision=327895
* sys: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326023
* Introduce EVENTHANDLER_LIST and some users.Matt Joras2017-11-091-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This introduces a facility to EVENTHANDLER(9) for explicitly defining a reference to an event handler list. This is useful since previously all invokers of events had to do a locked traversal of the global list of event handler lists in order to find the appropriate event handler list. By keeping a pointer to the appropriate list an invoker can avoid this traversal completely. The pointer is initialized with SYSINIT(9) during the eventhandler stage. Users registering interest in events do not need to know if the event is backed by such a list, since the list is added to the global list of lists. As with lists that are not pre-defined it is safe to register for the events before the list has been created. This converts the process_* and thread_* events to using the new facility, as these are events whose locked traversals end up showing up significantly in ports build workflows (and presumably other workflows with many short lived threads/procs). It may be advantageous to convert other events to using the new facility. The el_flags field is now unused, but leave it be so that this revision can be MFC'd. Reviewed by: bdrewery, markj, mjg Approved by: rstone (mentor) In collaboration with: ian MFC after: 4 weeks Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D12814 Notes: svn path=/head/; revision=325621
* Avoid reusing p_ksi while it is on queue.Konstantin Belousov2017-03-121-1/+22
| | | | | | | | | | | | | | | | | | | | When sending SIGCHLD informing reaper that a zombie was reparented to it, we might race with the situation where the previous parent still not finished delivering SIGCHLD and having its p_ksi structure on the signal queue. While on queue, the ksi should not be used for another send. Fix this by copying p_ksi into newly allocated ksi, which is directly put onto reaper sigqueue. The later ensures that siginfo for reaper SIGCHLD is always present, similar to guarantees for siginfo of child. Reported by: bdrewery Discussed with: jilles Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=315159
* Do not leak mount references for dying threads.Konstantin Belousov2017-02-251-2/+1
| | | | | | | | | | | | | | | | | | | | Thread might create a condition for delayed SU cleanup, which creates a reference to the mount point in td_su, but exit without returning through userret(), e.g. when terminating due to single-threading or process exit. In this case, td_su reference is not dropped and mount point cannot be freed. Handle the situation by clearing td_su also in the thread destructor and in exit1(). softdep_ast_cleanup() has to receive the thread as argument, since e.g. thread destructor is executed in different context. Reported and tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=314253
* When a zombie gets reparented due to the parent exit, send SIGCHLD toKonstantin Belousov2016-12-121-0/+5
| | | | | | | | | | | | | | | | | | | | the reaper. The traditional reaper init(8) is aware of zombies silently reparented to it after the parents exit, it loops around waitpid(2) to collect them. For other reapers, the silent reparenting is surprising and collecting zombies requires a thread blocking in waitpid(2) just for that purpose. It seems that sending second SIGCHLD is a better workaround than forcing all reapers to obey the setup. Reported by: Michael Zuo <muh.muhten@gmail.com>, jilles PR: 213928 Reviewed by: jilles (previous version) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=309886
* Restructure the code to handle reporting of non-exited processes fromKonstantin Belousov2016-12-041-61/+52
| | | | | | | | | | | | | | | | | | | | | | | | | wait(2). - Do not acquire the process spinlock if neither WTRAPPED nor WUNTRACED options were passed [1]. - Extract the code to report alive process into a new helper report_alive_proc() and use it for trapped, stopped and continued childrens. Note that the process spinlock is required around the WTRAPPED and WUNTRACED tests, because P_STOPPED_TRACE and P_STOPPED_SIG flags are set before other threads are stopped at the suspension point, and that threads increment p_suspcount while owning only the process spinlock, the process lock is dropped by them. If the spinlock is not taken for tests, the syscall thread might miss both p_suspcount increment and wakeup in wakeup in thread_suspend_switch(). Based on the submission by: mjg [1] Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=309539
* wait: avoid relocking the child if proc_to_reap returns 1Mateusz Guzik2016-11-241-2/+2
| | | | | | | | | | proc_to_reap would always unlock. However, if it returned 1, kern_wait6 would immediately lock it again. Save the dance. Reviewed by: kib Notes: svn path=/head/; revision=309111