-/* $OpenBSD: init_main.c,v 1.211 2014/04/18 11:51:17 guenther Exp $ */
+/* $OpenBSD: init_main.c,v 1.212 2014/05/04 05:03:26 guenther Exp $ */
/* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
/*
process0.ps_refcnt = 1;
p->p_p = pr = &process0;
LIST_INSERT_HEAD(&allprocess, pr, ps_list);
+ atomic_setbits_int(&pr->ps_flags, PS_SYSTEM);
/* Set the default routing table/domain. */
process0.ps_rtableid = 0;
-/* $OpenBSD: kern_fork.c,v 1.164 2014/05/03 22:44:36 guenther Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.165 2014/05/04 05:03:26 guenther Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
atomic_setbits_int(&pr->ps_flags, PS_TRACED);
if (flags & FORK_NOZOMBIE)
atomic_setbits_int(&pr->ps_flags, PS_NOZOMBIE);
+ if (flags & FORK_SYSTEM)
+ atomic_setbits_int(&pr->ps_flags, PS_SYSTEM);
/* it's sufficiently inited to be globally visible */
LIST_INSERT_HEAD(&allprocess, pr, ps_list);
/* sanity check some flag combinations */
if (flags & FORK_THREAD) {
- if ((flags & FORK_SIGHAND) == 0)
+ if ((flags & FORK_SIGHAND) == 0 || (flags & FORK_SYSTEM) != 0)
return (EINVAL);
}
if (flags & FORK_SIGHAND && (flags & FORK_SHAREVM) == 0)
process_new(p, curpr, flags);
pr = p->p_p;
}
+ if (pr->ps_flags & PS_SYSTEM)
+ atomic_setbits_int(&p->p_flag, P_SYSTEM);
/*
* Duplicate sub-structures as needed.
-/* $OpenBSD: kern_kthread.c,v 1.34 2014/02/12 05:47:36 guenther Exp $ */
+/* $OpenBSD: kern_kthread.c,v 1.35 2014/05/04 05:03:26 guenther Exp $ */
/* $NetBSD: kern_kthread.c,v 1.3 1998/12/22 21:21:36 kleink Exp $ */
/*-
* parent to wait for.
*/
error = fork1(&proc0, FORK_SHAREVM|FORK_SHAREFILES|FORK_NOZOMBIE|
- FORK_SIGHAND, NULL, 0, func, arg, NULL, &p);
+ FORK_SYSTEM|FORK_SIGHAND, NULL, 0, func, arg, NULL, &p);
if (error)
return (error);
- /*
- * Mark it as a system process.
- */
- atomic_setbits_int(&p->p_flag, P_SYSTEM);
-
/* Name it as specified. */
strlcpy(p->p_comm, name, sizeof p->p_comm);
-/* $OpenBSD: kern_sched.c,v 1.31 2014/02/12 05:47:36 guenther Exp $ */
+/* $OpenBSD: kern_sched.c,v 1.32 2014/05/04 05:03:26 guenther Exp $ */
/*
* Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org>
*
static int num;
if (fork1(&proc0, FORK_SHAREVM|FORK_SHAREFILES|FORK_NOZOMBIE|
- FORK_SIGHAND|FORK_IDLE, NULL, 0, sched_idle, ci, NULL,
+ FORK_SYSTEM|FORK_SIGHAND|FORK_IDLE, NULL, 0, sched_idle, ci, NULL,
&spc->spc_idleproc))
panic("fork idle");
- /*
- * Mark it as a system process.
- */
- atomic_setbits_int(&spc->spc_idleproc->p_flag, P_SYSTEM);
-
/* Name it as specified. */
snprintf(spc->spc_idleproc->p_comm, sizeof(spc->spc_idleproc->p_comm),
"idle%d", num);
-/* $OpenBSD: kern_sig.c,v 1.165 2014/05/04 03:53:37 deraadt Exp $ */
+/* $OpenBSD: kern_sig.c,v 1.166 2014/05/04 05:03:26 guenther Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
int
killpg1(struct proc *cp, int signum, int pgid, int all)
{
- struct proc *p;
struct process *pr;
struct pgrp *pgrp;
int nfound = 0;
* broadcast
*/
LIST_FOREACH(pr, &allprocess, ps_list) {
- p = pr->ps_mainproc;
- if (pr->ps_pid <= 1 || p->p_flag & P_SYSTEM ||
+ if (pr->ps_pid <= 1 || pr->ps_flags & PS_SYSTEM ||
pr == cp->p_p || !cansignal(cp, pr, signum))
continue;
nfound++;
if (signum)
- psignal(p, signum);
+ prsignal(pr, signum);
}
else {
if (pgid == 0)
return (ESRCH);
}
LIST_FOREACH(pr, &pgrp->pg_members, ps_pglist) {
- p = pr->ps_mainproc;
- if (pr->ps_pid <= 1 || p->p_flag & P_SYSTEM ||
+ if (pr->ps_pid <= 1 || pr->ps_flags & PS_SYSTEM ||
!cansignal(cp, pr, signum))
continue;
nfound++;
- if (signum && P_ZOMBIE(p) == 0)
- psignal(p, signum);
+ if (signum)
+ prsignal(pr, signum);
}
}
return (nfound ? 0 : ESRCH);
-/* $OpenBSD: kern_sysctl.c,v 1.247 2014/05/03 23:30:04 guenther Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.248 2014/05/04 05:03:26 guenther Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
* processes
*/
pp = pr->ps_mainproc;
- if ((pp->p_flag & P_SYSTEM) || (pr->ps_flags & PS_EXITING)
+ if ((pr->ps_flags & (PS_SYSTEM | PS_EXITING))
|| pp->p_stat == SIDL || pp->p_stat == SZOMB)
continue;
if (arg > 0 && pp->p_pid != (pid_t)arg) {
* skip system, exiting, embryonic and undead
* processes
*/
- if ((pp->p_flag & P_SYSTEM) || (pr->ps_flags & PS_EXITING)
+ if ((pr->ps_flags & (PS_SYSTEM | PS_EXITING))
|| pp->p_stat == SIDL || pp->p_stat == SZOMB)
continue;
if (arg >= 0 && pp->p_ucred->cr_uid != (uid_t)arg) {
break;
case KERN_PROC_ALL:
- if (p->p_flag & P_SYSTEM)
+ if (pr->ps_flags & PS_SYSTEM)
continue;
break;
return (0);
}
- if (vp->p_flag & P_SYSTEM)
- return (EINVAL);
-
- /* Exiting - don't bother, it will be gone soon anyway */
- if (vp->p_p->ps_flags & PS_EXITING)
+ /* Either system process or exiting/zombie */
+ if (vp->p_p->ps_flags & (PS_SYSTEM | PS_EXITING))
return (EINVAL);
/* Execing - danger. */
return (0);
}
- if (findp->p_flag & P_SYSTEM)
- return (EINVAL);
-
- /* Exiting - don't bother, it will be gone soon anyway */
- if (findp->p_p->ps_flags & PS_EXITING)
+ /* Either system process or exiting/zombie */
+ if (findp->p_p->ps_flags & (PS_SYSTEM | PS_EXITING))
return (EINVAL);
/* Only owner or root can get cwd */
- if (findp->p_ucred->cr_uid != cp->p_ucred->cr_uid &&
+ if (findp->p_p->ps_ucred->cr_uid != cp->p_ucred->cr_uid &&
(error = suser(cp, 0)) != 0)
return (error);
-/* $OpenBSD: sys_process.c,v 1.60 2014/03/30 21:54:48 guenther Exp $ */
+/* $OpenBSD: sys_process.c,v 1.61 2014/05/04 05:03:26 guenther Exp $ */
/* $NetBSD: sys_process.c,v 1.55 1996/05/15 06:17:47 tls Exp $ */
/*-
/*
* (2) it's a system process
*/
- if (ISSET(t->p_flag, P_SYSTEM))
+ if (ISSET(tr->ps_flags, PS_SYSTEM))
return (EPERM);
/*
-/* $OpenBSD: proc.h,v 1.184 2014/04/18 11:51:17 guenther Exp $ */
+/* $OpenBSD: proc.h,v 1.185 2014/05/04 05:03:26 guenther Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
#define PS_SINGLEUNWIND 0x00002000 /* Other threads must unwind. */
#define PS_NOZOMBIE 0x00004000 /* No signal or zombie at exit. */
#define PS_STOPPED 0x00008000 /* Just stopped, need sig to parent. */
+#define PS_SYSTEM 0x00010000 /* No sigs, stats or swapping. */
#define PS_BITS \
("\20\01CONTROLT\02EXEC\03INEXEC\04EXITING\05SUGID" \
"\06SUGIDEXEC\07PPWAIT\010ISPWAIT\011PROFIL\012TRACED" \
"\013WAITED\014COREDUMP\015SINGLEEXIT\016SINGLEUNWIND" \
- "\017NOZOMBIE\020STOPPED")
+ "\017NOZOMBIE\020STOPPED\021SYSTEM")
struct proc {
#define FORK_IDLE 0x00000004
#define FORK_PPWAIT 0x00000008
#define FORK_SHAREFILES 0x00000010
+#define FORK_SYSTEM 0x00000020
#define FORK_NOZOMBIE 0x00000040
#define FORK_SHAREVM 0x00000080
#define FORK_TFORK 0x00000100