Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 826142 Details for
Bug 1032123
[RFE] Add process synchronisation routines
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
0001-new-routines-for-socket-based-synchronisation
0001-new-routines-for-socket-based-synchronisation.patch (text/plain), 5.42 KB, created by
Hubert Kario
on 2013-11-19 15:32:03 UTC
(
hide
)
Description:
0001-new-routines-for-socket-based-synchronisation
Filename:
MIME Type:
Creator:
Hubert Kario
Created:
2013-11-19 15:32:03 UTC
Size:
5.42 KB
patch
obsolete
>From a3132fd46601795c0c4512eaaa28e1fdaa315576 Mon Sep 17 00:00:00 2001 >From: Hubert Kario <hkario@redhat.com> >Date: Mon, 18 Nov 2013 20:21:26 +0100 >Subject: [PATCH 1/2] new routines for socket based synchronisation > >Add new function, rlWaitForSocket, that can wait for a network service >to start. To be used instead of `sleep' when testing network-centric >services. > >Signed-off-by: Hubert Kario <hkario@redhat.com> >--- > src/synchronisation.sh | 182 +++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 182 insertions(+) > create mode 100644 src/synchronisation.sh > >diff --git a/src/synchronisation.sh b/src/synchronisation.sh >new file mode 100644 >index 0000000..66078e3 >--- /dev/null >+++ b/src/synchronisation.sh >@@ -0,0 +1,182 @@ >+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >+# >+# Name: synchronisation.sh - part of the BeakerLib project >+# Description: Process synchronisation routines >+# >+# Author: Hubert Kario <hkario@redhat.com> >+# >+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >+# >+# Copyright (c) 2013 Red Hat, Inc. All rights reserved. >+# >+# This copyrighted material is made available to anyone wishing >+# to use, modify, copy, or redistribute it subject to the terms >+# and conditions of the GNU General Public License version 2. >+# >+# This program is distributed in the hope that it will be >+# useful, but WITHOUT ANY WARRANTY; without even the implied >+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR >+# PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public >+# License along with this program; if not, write to the Free >+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, >+# Boston, MA 02110-1301, USA. >+# >+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >+ >+getopt -T || ret=$? >+if [ ${ret:-0} -ne 4 ]; then >+ echo "ERROR: Non enhanced getopt version detected" 1>&2 >+ exit 1 >+fi >+ >+: <<'=cut' >+=pod >+ >+=head1 NAME >+ >+BeakerLib - synchronisation - Process synchronisation routines >+ >+=head1 DESCRIPTION >+ >+This is a library of helpers for process synchronisation >+of applications. >+ >+=head1 FUNCTIONS >+ >+=cut >+ >+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >+# name of routine >+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >+: <<'=cut' >+=pod >+ >+=head2 Process Synchronisation >+ >+=head3 rlWaitForSocket >+ >+Pauses script execution until socket starts listening. >+ >+ rlWaitForSocket {port|path} [-p PID] [-t time] >+ >+=over >+ >+=item port|path >+ >+Network port to wait for opening or a path to UNIX socket. >+Regular expressions are also supported. >+ >+=item -t time >+ >+Timeout in seconds (optional, default=120). If the socket >+isn't opened between the time elapses the command FAILs. >+ >+=item -p PID >+ >+PID of the process to check before running command. If the process >+exits before the socket is opened, the command FAILs. >+ >+=back >+ >+=cut >+ >+rlWaitForSocket(){ >+ >+ local timeout=120 >+ local proc_pid=1 >+ local socket="" >+ local child_pid=0 >+ >+ # that is the GNU extended getopt syntax! >+ TEMP=$(getopt -o t:p: -n 'rlWaitForSocket' -- "$@") >+ if [[ $? != 0 ]] ; then echo "Terminating..." >&2 ; exit 1 ; fi >+ >+ eval set -- "$TEMP" >+ >+ while true ; do >+ case "$1" in >+ -t) timeout="$2"; shift 2 >+ ;; >+ -p) proc_pid="$2"; shift 2 >+ ;; >+ --) shift 1 >+ break >+ ;; >+ *) echo "Internal error!" >&2; exit 1 >+ ;; >+ esac >+ done >+ socket="$1" >+ # the case statement is a portable way to check if variable contains only >+ # digits (regexps are not available in old, RHEL3-era, bash) >+ case "$timeout" in >+ ''|*[!0-9]*) echo "rlWaitForSocket: Invalid timeout provided" 1>&2; exit 1;; >+ esac >+ case "$proc_pid" in >+ ''|*[!0-9]*) echo "rlWaitForSocket: Invalid PID provided" 1>&2; exit 1;; >+ esac >+ case "$socket" in >+ ''|*[!0-9]*) >+ #socket_type="network" >+ grep_opt="\:$socket[[:space:]]" >+ ;; >+ "") echo "rlWaitForSocket: Empty socket specified" 1>&2 >+ exit 1 >+ ;; >+ *) >+ #socket_type="unix" >+ grep_opt="$socket" >+ ;; >+ esac >+ rlLog "Waiting max ${timeout}s for socket \`$socket' to start listening" >+ >+ ( while true ; do >+ netstat -nl | grep -E "$grep_opt" >/dev/null >+ if [[ $? -eq 0 ]]; then >+ exit 0; >+ else >+ if [[ ! -e "/proc/$proc_pid" ]]; then >+ exit 1; >+ fi >+ sleep 1 >+ fi >+ done ) & >+ netstat_pid=$! >+ >+ ( sleep $timeout && kill -HUP $netstat_pid ) 2>/dev/null & >+ watcher=$! >+ >+ wait $netstat_pid >+ ret=$? >+ if [[ $ret -eq 0 ]]; then >+ kill -s SIGKILL $watcher 2>/dev/null >+ rlLog "Socket opened!" >+ else >+ if [[ $ret -eq 1 ]]; then >+ kill -s SIGKILL $watcher 2>/dev/null >+ rlLogWarning "PID terminated!" >+ else >+ rlLogWarning "Timeout elapsed" >+ fi >+ fi >+} >+ >+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >+# AUTHORS >+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >+: <<'=cut' >+=pod >+ >+=head1 AUTHORS >+ >+=over >+ >+=item * >+ >+Hubert Kario <hkario@redhat.com> >+ >+=back >+ >+=cut >-- >1.8.3.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
pmuller
: review-
Actions:
View
|
Diff
Attachments on
bug 1032123
: 826142 |
826144