Web Server forum
Back To The Forum Home!Search!Private Messaging System
Visit your User Control Panel!Register your FREE username now!Visit Our Calendar!View the Member List!Faqs!Search our Forums!


Web Server Talk Web Server Talk > Unix and Linux reviews > OpenBSD > OpenBSD Technical topics > ported Solaris' psig to OpenBSD




Go to first unread post first unread  Last Thread   Next Thread
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    ported Solaris' psig to OpenBSD  
Steffen Wendzel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-01-06 07:13 PM

Hi,

I just ported Solaris' psig-tool to OpenBSD. I modified the pkill
code to do that (patch included). psig shows the signal settings
of a process.

examples:
------------------------snip---------------------------
cdp_xe@eygo:~/Mail$ psig cdpnntpd
command: cdpnntpd, pid: 7775
signal mask:
ignore mask: HUP(0) URG(15) TSTP(17) TTIN(20) TTOU(21) IO(22)
WINCH(27) INFO(28)
catch mask:  INT(1) TERM(14) CHLD(19)
cdp_xe@eygo:~/Mail$ psig Xorg
command: Xorg, pid: 14254
signal mask:
ignore mask: URG(15) CHLD(19) IO(22) WINCH(27) INFO(28)
catch mask:
command: Xorg, pid: 21348
signal mask:
ignore mask: PIPE(12) URG(15) CHLD(19) TTIN(20) TTOU(21)
WINCH(27) INFO(28) USR1(29)
catch mask:  HUP(0) INT(1) ILL(3) EMT(6) FPE(7) BUS(9) SEGV(10)
SYS(11) ALRM(13) TERM(14) IO(22) XCPU(23) XFSZ(24) USR2(30)
cdp_xe@eygo:~/Mail$ psig pland
command: pland, pid: 9833
signal mask:
ignore mask: PIPE(12) URG(15) CHLD(19) IO(22) WINCH(27) INFO(28)
catch mask:  HUP(0) INT(1) QUIT(2) ILL(3) BUS(9) SEGV(10)
ALRM(13) TERM(14)
cdp_xe@eygo:~/Mail$ psig xconsole
command: xconsole, pid: 11506
signal mask:
ignore mask: URG(15) CHLD(19) IO(22) WINCH(27) INFO(28)
catch mask:
------------------------snap---------------------------

Here is the output of

# cvs diff Makefile pkill.1 pkill.c

------------------------snip---------------------------
Index: Makefile
 ========================================
===========================
RCS file: /cvs/src/usr.bin/pkill/Makefile,v
retrieving revision 1.1
diff -r1.1 Makefile
11a12
> LINKS+= ${BINDIR}/pkill ${BINDIR}/psig
12a14
> MLINKS+=pkill.1 psig.1
Index: pkill.1
 ========================================
===========================
RCS file: /cvs/src/usr.bin/pkill/pkill.1,v
retrieving revision 1.7
diff -r1.7 pkill.1
42,43c42,43
< .Nm pgrep , pkill
< .Nd find or signal processes by name
---
> .Nm pgrep , pkill , psig
> .Nd find, signal or show signal settings (of) processes by name
66a67,76
> .Nm psig
> .Op Fl fnvx
> .Op Fl G Ar gid
> .Op Fl g Ar pgrp
> .Op Fl P Ar ppid
> .Op Fl s Ar sid
> .Op Fl t Ar tty
> .Op Fl U Ar uid
> .Op Fl u Ar euid
> .Op Ar pattern ..
78a89,94
> The
> .Nm psig
> command searches the process table on the running system and shows the
> signal settings of all processes that match the criteria given on the
> command line.
> .Pp
198a215,221
> .Pp
> .Nm psig
> first appeared in
> .Ox 4.0 .
> It is modelled after a utility of the same name that is shipped with in Su
n
> Solaris 8, but is not exactly the same.
>
201c224,227
< .Aq ad@NetBSD.org .
---
> .Aq ad@NetBSD.org ,
> .Pp
> .An Steffen Wendzel
> .Aq cdp@doomed-reality.org .
Index: pkill.c
 ========================================
===========================
RCS file: /cvs/src/usr.bin/pkill/pkill.c,v
retrieving revision 1.14
diff -r1.14 pkill.c
90a91
> int   psig;
111a113
> int   sigact(struct kinfo_proc2 *, int);
132a135,137
>       } else if (strcmp(__progname, "psig") == 0) {
>               action = sigact;
>               psig = 1;
462a468,591
>       return (0);
> }
>
> void
> print_signals(u_int32_t mask)
> {
>       u_int32_t       testmask;
>       unsigned short  n;
>
>       for (testmask = 1, n = 0; n < 32; n++) {
>               if (mask & (testmask << n)) {
>                       switch(n + 1) {
>                       case SIGHUP:
>                               printf("HUP(");
>                               break;
>                       case SIGINT:
>                               printf("INT(");
>                               break;
>                       case SIGQUIT:
>                               printf("QUIT(");
>                               break;
>                       case SIGILL:
>                               printf("ILL(");
>                               break;
>                       case SIGTRAP:
>                               printf("TRAP(");
>                               break;
>                       case SIGABRT:
>                               printf("ABRT(");
>                               break;
>                       case SIGEMT:
>                               printf("EMT(");
>                               break;
>                       case SIGFPE:
>                               printf("FPE(");
>                               break;
>                       case SIGBUS:
>                               printf("BUS(");
>                               break;
>                       case SIGSEGV:
>                               printf("SEGV(");
>                               break;
>                       case SIGSYS:
>                               printf("SYS(");
>                               break;
>                       case SIGPIPE:
>                               printf("PIPE(");
>                               break;
>                       case SIGALRM:
>                               printf("ALRM(");
>                               break;
>                       case SIGTERM:
>                               printf("TERM(");
>                               break;
>                       case SIGURG:
>                               printf("URG(");
>                               break;
>                       case SIGSTOP:
>                               printf("STOP(");
>                               break;
>                       case SIGTSTP:
>                               printf("TSTP(");
>                               break;
>                       case SIGCONT:
>                               printf("CONT(");
>                               break;
>                       case SIGCHLD:
>                               printf("CHLD(");
>                               break;
>                       case SIGTTIN:
>                               printf("TTIN(");
>                               break;
>                       case SIGTTOU:
>                               printf("TTOU(");
>                               break;
>                       case SIGIO:
>                               printf("IO(");
>                               break;
>                       case SIGXCPU:
>                               printf("XCPU(");
>                               break;
>                       case SIGXFSZ:
>                               printf("XFSZ(");
>                               break;
>                       case SIGVTALRM:
>                               printf("VTALRM(");
>                               break;
>                       case SIGPROF:
>                               printf("PROF(");
>                               break;
>                       case SIGWINCH:
>                               printf("WINCH(");
>                               break;
>                       case SIGINFO:
>                               printf("INFO(");
>                               break;
>                       case SIGUSR1:
>                               printf("USR1(");
>                               break;
>                       case SIGUSR2:
>                               printf("USR2(");
>                               break;
>                       default:
>                               printf("UNKNOWN(");
>                               break;
>                       }
>                       printf("%i) ", n);
>               }
>       }
> }
>
> int
> sigact(struct kinfo_proc2 *kp, int dummy)
> {
>
>       printf("command: %s, pid: %i\n", kp->p_comm, (int)kp->p_pid);
>       printf("\tsignal mask: ");
>       print_signals(kp->p_sigmask);
>       printf("\n\tignore mask: ");
>       print_signals(kp->p_sigignore);
>       printf("\n\tcatch mask:  ");
>       print_signals(kp->p_sigcatch);
>       printf("\n");
>
------------------------snap---------------------------

It would be damn cool if this would be applied in the official source and
available in the next release.

-- steffen






[ Post a follow-up to this message ]



    Re: ported Solaris' psig to OpenBSD  
Steffen Wendzel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-02-06 12:13 AM

here is the cvs diff -up output.
-- steffen

Index: Makefile
 ========================================
===========================
RCS file: /cvs/src/usr.bin/pkill/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- Makefile    6 Jan 2004 20:07:49 -0000       1.1
+++ Makefile    1 May 2006 20:22:26 -0000
@@ -9,6 +9,8 @@ LDADD+= -lkvm
DPADD+=        ${LIBKVM}

LINKS+=        ${BINDIR}/pkill ${BINDIR}/pgrep
+LINKS+= ${BINDIR}/pkill ${BINDIR}/psig
MLINKS+=pkill.1 pgrep.1
+MLINKS+=pkill.1 psig.1

.include <bsd.prog.mk>
Index: pkill.1
 ========================================
===========================
RCS file: /cvs/src/usr.bin/pkill/pkill.1,v
retrieving revision 1.7
diff -u -p -r1.7 pkill.1
--- pkill.1     16 Jul 2005 11:58:10 -0000      1.7
+++ pkill.1     1 May 2006 20:22:26 -0000
@@ -39,8 +39,8 @@
.Dt PKILL 1
.Os
.Sh NAME
-.Nm pgrep , pkill
-.Nd find or signal processes by name
+.Nm pgrep , pkill , psig
+.Nd find, signal or show signal settings (of) processes by name
.Sh SYNOPSIS
.Nm pgrep
.Op Fl flnvx
@@ -64,6 +64,16 @@
.Op Fl U Ar uid
.Op Fl u Ar euid
.Op Ar pattern ...
+.Nm psig
+.Op Fl fnvx
+.Op Fl G Ar gid
+.Op Fl g Ar pgrp
+.Op Fl P Ar ppid
+.Op Fl s Ar sid
+.Op Fl t Ar tty
+.Op Fl U Ar uid
+.Op Fl u Ar euid
+.Op Ar pattern ..
.Sh DESCRIPTION
The
.Nm pgrep
@@ -76,6 +86,12 @@ The
command searches the process table on the running system and signals all
processes that match the criteria given on the command line.
.Pp
+The
+.Nm psig
+command searches the process table on the running system and shows the
+signal settings of all processes that match the criteria given on the
+command line.
+.Pp
The following options are available:
.Bl -tag -width Ds
.It Fl d Ar delim
@@ -196,6 +212,16 @@ first appeared in
.Ox 3.5 .
They are modelled after utilities of the same name that appeared in Sun
Solaris 7.
+.Pp
+.Nm psig
+first appeared in
+.Ox 4.0 .
+It is modelled after a utility of the same name that is shipped with in Sun
+Solaris 8, but is not exactly the same.
+
.Sh AUTHORS
.An Andrew Doran
-.Aq ad@NetBSD.org .
+.Aq ad@NetBSD.org ,
+.Pp
+.An Steffen Wendzel
+.Aq cdp@doomed-reality.org .
Index: pkill.c
 ========================================
===========================
RCS file: /cvs/src/usr.bin/pkill/pkill.c,v
retrieving revision 1.14
diff -u -p -r1.14 pkill.c
--- pkill.c     16 Jul 2005 11:48:46 -0000      1.14
+++ pkill.c     1 May 2006 20:22:28 -0000
@@ -88,6 +88,7 @@ char  *selected;
char   *delim = "\n";
int    nproc;
int    pgrep;
+int    psig;
int    signum = SIGTERM;
int    newest;
int    inverse;
@@ -109,6 +110,7 @@ int main(int, char **);
void   usage(void);
int    killact(struct kinfo_proc2 *, int);
int    grepact(struct kinfo_proc2 *, int);
+int    sigact(struct kinfo_proc2 *, int);
void   makelist(struct listhead *, enum listtype, char *);

extern char *__progname;
@@ -130,6 +132,9 @@ main(int argc, char **argv)
if (strcmp(__progname, "pgrep") == 0) {
action = grepact;
pgrep = 1;
+       } else if (strcmp(__progname, "psig") == 0) {
+               action = sigact;
+               psig = 1;
} else {
action = killact;
p = argv[1];
@@ -460,6 +465,130 @@ grepact(struct kinfo_proc2 *kp, int prin
else
printf("%d", (int)kp->p_pid);

+       return (0);
+}
+
+void
+print_signals(u_int32_t mask)
+{
+       u_int32_t       testmask;
+       unsigned short  n;
+
+       for (testmask = 1, n = 0; n < 32; n++) {
+               if (mask & (testmask << n)) {
+                       switch(n+1) {
+                       case SIGHUP:
+                               printf("HUP(");
+                               break;
+                       case SIGINT:
+                               printf("INT(");
+                               break;
+                       case SIGQUIT:
+                               printf("QUIT(");
+                               break;
+                       case SIGILL:
+                               printf("ILL(");
+                               break;
+                       case SIGTRAP:
+                               printf("TRAP(");
+                               break;
+                       case SIGABRT:
+                               printf("ABRT(");
+                               break;
+                       case SIGEMT:
+                               printf("EMT(");
+                               break;
+                       case SIGFPE:
+                               printf("FPE(");
+                               break;
+                       case SIGBUS:
+                               printf("BUS(");
+                               break;
+                       case SIGSEGV:
+                               printf("SEGV(");
+                               break;
+                       case SIGSYS:
+                               printf("SYS(");
+                               break;
+                       case SIGPIPE:
+                               printf("PIPE(");
+                               break;
+                       case SIGALRM:
+                               printf("ALRM(");
+                               break;
+                       case SIGTERM:
+                               printf("TERM(");
+                               break;
+                       case SIGURG:
+                               printf("URG(");
+                               break;
+                       case SIGSTOP:
+                               printf("STOP(");
+                               break;
+                       case SIGTSTP:
+                               printf("TSTP(");
+                               break;
+                       case SIGCONT:
+                               printf("CONT(");
+                               break;
+                       case SIGCHLD:
+                               printf("CHLD(");
+                               break;
+                       case SIGTTIN:
+                               printf("TTIN(");
+                               break;
+                       case SIGTTOU:
+                               printf("TTOU(");
+                               break;
+                       case SIGIO:
+                               printf("IO(");
+                               break;
+                       case SIGXCPU:
+                               printf("XCPU(");
+                               break;
+                       case SIGXFSZ:
+                               printf("XFSZ(");
+                               break;
+                       case SIGVTALRM:
+                               printf("VTALRM(");
+                               break;
+                       case SIGPROF:
+                               printf("PROF(");
+                               break;
+                       case SIGWINCH:
+                               printf("WINCH(");
+                               break;
+                       case SIGINFO:
+                               printf("INFO(");
+                               break;
+                       case SIGUSR1:
+                               printf("USR1(");
+                               break;
+                       case SIGUSR2:
+                               printf("USR2(");
+                               break;
+                       default:
+                               printf("UNKNOWN(");
+                               break;
+                       }
+                       printf("%i) ", n);
+               }
+       }
+}
+
+int
+sigact(struct kinfo_proc2 *kp, int dummy)
+{
+
+       printf("command: %s, pid: %i\n", kp->p_comm, (int)kp->p_pid);
+       printf("\tsignal mask: ");
+       print_signals(kp->p_sigmask);
+       printf("\n\tignore mask: ");
+       print_signals(kp->p_sigignore);
+       printf("\n\tcatch mask:  ");
+       print_signals(kp->p_sigcatch);
+       printf("\n");
+
return (0);
}






[ Post a follow-up to this message ]



    Re: ported Solaris' psig to OpenBSD  
Steffen Wendzel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-02-06 06:14 PM

so... what do you think about psig? do you want to apply this patch?

-- steffen






[ Post a follow-up to this message ]



    Re: ported Solaris' psig to OpenBSD  
Ted Unangst


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-02-06 06:14 PM

On 5/2/06, Steffen Wendzel <cdp_xe@gmx.net> wrote:
> so... what do you think about psig? do you want to apply this patch?

don't get antsy.  patches only get better with time. 






[ Post a follow-up to this message ]



    Re: ported Solaris' psig to OpenBSD  
Sam Chill


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-03-06 06:13 AM

> On 5/2/06, Steffen Wendzel <cdp_xe@gmx.net> wrote:
> so... what do you think about psig? do you want to apply this patch?

For what it's worth it compiles and works nicely on my system (-current).






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:48 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register