Patch: Non-unique msgid for abandon in back- (ITS#1793) ================ Written by Hallvard B. Furuseth and placed into the public domain. This software is not subject to any license of the University of Oslo. ================ It has just occurred to me - duh - that the process ID of a back-shell command is a perfectly good unique ID for it, and more useful than any connection id/message id thingy. Doesn't need extra arguments to the shell commands either, except a pid: line to abandon. And msgid: can still be removed in a future version. Here is a patch. Hallvard B. Furuseth , May 2002. diff -u2 -r doc/man/man5/slapd-shell.5~ doc/man/man5/slapd-shell.5 --- doc/man/man5/slapd-shell.5~ Fri May 10 08:20:33 2002 +++ doc/man/man5/slapd-shell.5 Fri May 10 15:35:40 2002 @@ -16,8 +16,6 @@ .SH WARNING .B "This backend's calling conventions have changed since OpenLDAP 2.0." -The operations receive a new "opid:" (operation ID) line, to be used -instead of "msgid:". -The "msgid:" line will be removed in a future version. -Also, abandon now gets a new "abandonid:" line. +The abandon operation now gets a new "pid:" line. +The "msgid:" lines will be removed in a future version. .SH CONFIGURATION These @@ -37,8 +35,7 @@ .nf ABANDON -opid: msgid: }> -abandonid: +pid: .fi .TP @@ -46,6 +43,5 @@ .nf ADD -opid: -msgid: +msgid: }> @@ -55,6 +51,5 @@ .nf BIND -opid: -msgid: +msgid: }> dn: @@ -67,6 +62,5 @@ .nf COMPARE -opid: -msgid: +msgid: }> dn: @@ -77,6 +71,5 @@ .nf DELETE -opid: -msgid: +msgid: }> dn: @@ -86,6 +79,5 @@ .nf MODIFY -opid: -msgid: +msgid: }> dn: @@ -100,6 +92,5 @@ .nf MODRDN -opid: -msgid: +msgid: }> dn: @@ -112,6 +103,5 @@ .nf SEARCH -opid: -msgid: +msgid: }> base: @@ -128,13 +118,8 @@ .nf UNBIND -opid: -msgid: +msgid: }> dn: .fi -.LP -An -.I operation ID -is a "connection ID/message ID" string identifying an operation. .LP Note that you need only supply configuration lines for those commands you diff -u2 -r servers/slapd/back-shell/abandon.c~ servers/slapd/back-shell/abandon.c --- servers/slapd/back-shell/abandon.c~ Fri May 10 08:20:34 2002 +++ servers/slapd/back-shell/abandon.c Fri May 10 15:35:54 2002 @@ -29,9 +29,14 @@ Operation *o; - /* no abandon command defined - just kill the process handling it */ - if ( si->si_abandon == NULL ) { - ldap_pvt_thread_mutex_lock( &conn->c_mutex ); - pid = -1; - LDAP_STAILQ_FOREACH( o, &conn->c_ops, o_next ) { + ldap_pvt_thread_mutex_lock( &conn->c_mutex ); + pid = -1; + LDAP_STAILQ_FOREACH( o, &conn->c_ops, o_next ) { + if ( o->o_msgid == msgid ) { + pid = (pid_t) o->o_private; + break; + } + } + if( pid == -1 ) { + LDAP_STAILQ_FOREACH( o, &conn->c_pending_ops, o_next ) { if ( o->o_msgid == msgid ) { pid = (pid_t) o->o_private; @@ -39,22 +44,17 @@ } } - if( pid == -1 ) { - LDAP_STAILQ_FOREACH( o, &conn->c_pending_ops, o_next ) { - if ( o->o_msgid == msgid ) { - pid = (pid_t) o->o_private; - break; - } - } - } - ldap_pvt_thread_mutex_unlock( &conn->c_mutex ); + } + ldap_pvt_thread_mutex_unlock( &conn->c_mutex ); - if ( pid != -1 ) { - Debug( LDAP_DEBUG_ARGS, "shell killing pid %d\n", + if ( pid == -1 ) { + Debug( LDAP_DEBUG_ARGS, "shell could not find op %d\n", msgid, 0, 0 ); + return 0; + } + + /* no abandon command defined - just kill the process handling it */ + if ( si->si_abandon == NULL ) { + Debug( LDAP_DEBUG_ARGS, "shell killing pid %d\n", (int) pid, 0, 0 ); - kill( pid, SIGTERM ); - } else { - Debug( LDAP_DEBUG_ARGS, "shell could not find op %d\n", - msgid, 0, 0 ); - } + kill( pid, SIGTERM ); return 0; } @@ -66,8 +66,7 @@ /* write out the request to the abandon process */ fprintf( wfp, "ABANDON\n" ); - fprintf( wfp, "opid: %ld/%ld\n", op->o_connid, (long) op->o_msgid ); fprintf( wfp, "msgid: %d\n", msgid ); print_suffixes( wfp, be ); - fprintf( wfp, "abandonid: %ld/%d\n", op->o_connid, msgid ); + fprintf( wfp, "pid: %ld\n", (long) pid ); fclose( wfp ); diff -u2 -r servers/slapd/back-shell/add.c~ servers/slapd/back-shell/add.c --- servers/slapd/back-shell/add.c~ Fri May 10 08:20:35 2002 +++ servers/slapd/back-shell/add.c Fri May 10 15:23:18 2002 @@ -42,5 +42,4 @@ /* write out the request to the add process */ fprintf( wfp, "ADD\n" ); - fprintf( wfp, "opid: %ld/%ld\n", op->o_connid, (long) op->o_msgid ); fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid ); print_suffixes( wfp, be ); diff -u2 -r servers/slapd/back-shell/bind.c~ servers/slapd/back-shell/bind.c --- servers/slapd/back-shell/bind.c~ Fri May 10 08:20:35 2002 +++ servers/slapd/back-shell/bind.c Fri May 10 15:23:18 2002 @@ -47,5 +47,4 @@ /* write out the request to the bind process */ fprintf( wfp, "BIND\n" ); - fprintf( wfp, "opid: %ld/%ld\n", op->o_connid, (long) op->o_msgid ); fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid ); print_suffixes( wfp, be ); diff -u2 -r servers/slapd/back-shell/compare.c~ servers/slapd/back-shell/compare.c --- servers/slapd/back-shell/compare.c~ Fri May 10 08:20:35 2002 +++ servers/slapd/back-shell/compare.c Fri May 10 15:23:18 2002 @@ -49,5 +49,4 @@ /* write out the request to the compare process */ fprintf( wfp, "COMPARE\n" ); - fprintf( wfp, "opid: %ld/%ld\n", op->o_connid, (long) op->o_msgid ); fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid ); print_suffixes( wfp, be ); diff -u2 -r servers/slapd/back-shell/delete.c~ servers/slapd/back-shell/delete.c --- servers/slapd/back-shell/delete.c~ Fri May 10 08:20:35 2002 +++ servers/slapd/back-shell/delete.c Fri May 10 15:23:18 2002 @@ -43,5 +43,4 @@ /* write out the request to the delete process */ fprintf( wfp, "DELETE\n" ); - fprintf( wfp, "opid: %ld/%ld\n", op->o_connid, (long) op->o_msgid ); fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid ); print_suffixes( wfp, be ); diff -u2 -r servers/slapd/back-shell/modify.c~ servers/slapd/back-shell/modify.c --- servers/slapd/back-shell/modify.c~ Fri May 10 08:20:35 2002 +++ servers/slapd/back-shell/modify.c Fri May 10 15:23:18 2002 @@ -46,5 +46,4 @@ /* write out the request to the modify process */ fprintf( wfp, "MODIFY\n" ); - fprintf( wfp, "opid: %ld/%ld\n", op->o_connid, (long) op->o_msgid ); fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid ); print_suffixes( wfp, be ); diff -u2 -r servers/slapd/back-shell/modrdn.c~ servers/slapd/back-shell/modrdn.c --- servers/slapd/back-shell/modrdn.c~ Fri May 10 08:20:35 2002 +++ servers/slapd/back-shell/modrdn.c Fri May 10 15:23:18 2002 @@ -61,5 +61,4 @@ /* write out the request to the modrdn process */ fprintf( wfp, "MODRDN\n" ); - fprintf( wfp, "opid: %ld/%ld\n", op->o_connid, (long) op->o_msgid ); fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid ); print_suffixes( wfp, be ); diff -u2 -r servers/slapd/back-shell/search.c~ servers/slapd/back-shell/search.c --- servers/slapd/back-shell/search.c~ Fri May 10 08:20:35 2002 +++ servers/slapd/back-shell/search.c Fri May 10 15:23:18 2002 @@ -53,5 +53,4 @@ /* write out the request to the search process */ fprintf( wfp, "SEARCH\n" ); - fprintf( wfp, "opid: %ld/%ld\n", op->o_connid, (long) op->o_msgid ); fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid ); print_suffixes( wfp, be ); diff -u2 -r servers/slapd/back-shell/unbind.c~ servers/slapd/back-shell/unbind.c --- servers/slapd/back-shell/unbind.c~ Fri May 10 08:20:35 2002 +++ servers/slapd/back-shell/unbind.c Fri May 10 15:23:18 2002 @@ -37,5 +37,4 @@ /* write out the request to the unbind process */ fprintf( wfp, "UNBIND\n" ); - fprintf( wfp, "opid: %ld/%ld\n", op->o_connid, (long) op->o_msgid ); fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid ); print_suffixes( wfp, be );