From 523b055c0664d84f6501ac20a2b486c7548e37d7 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 4 Nov 2021 07:37:17 +0800 Subject: [PATCH] Squash: Support RPM. Fix bugs. --- .github/workflows/release.yml | 35 ++++++- README.md | 2 +- trunk/3rdparty/patches/srtp/gcc10-01.patch | 4 + trunk/Dockerfile.pkg | 16 ++++ trunk/auto/depends.sh | 1 + trunk/doc/CHANGELOG.md | 5 + trunk/ide/srs_clion/CMakeLists.txt | 6 +- trunk/packaging/redhat/srs.conf | 50 ++++++++++ trunk/packaging/redhat/srs.init | 76 +++++++++++++++ trunk/packaging/redhat/srs.logrotate | 15 +++ trunk/packaging/redhat/srs.service | 23 +++++ trunk/packaging/redhat/srs.spec | 103 +++++++++++++++++++++ trunk/src/app/srs_app_forward.cpp | 6 ++ trunk/src/app/srs_app_rtc_api.cpp | 12 +-- trunk/src/app/srs_app_st.cpp | 11 ++- trunk/src/core/srs_core.hpp | 2 + trunk/src/core/srs_core_version4.hpp | 2 +- trunk/src/protocol/srs_service_st.cpp | 13 ++- trunk/src/srt/srt_server.cpp | 2 +- trunk/src/utest/srs_utest_reload.hpp | 2 +- trunk/src/utest/srs_utest_service.cpp | 33 +++++++ trunk/usr/lib/systemd/system/srs.service | 1 + 22 files changed, 397 insertions(+), 23 deletions(-) create mode 100644 trunk/3rdparty/patches/srtp/gcc10-01.patch create mode 100644 trunk/Dockerfile.pkg create mode 100644 trunk/packaging/redhat/srs.conf create mode 100644 trunk/packaging/redhat/srs.init create mode 100644 trunk/packaging/redhat/srs.logrotate create mode 100644 trunk/packaging/redhat/srs.service create mode 100644 trunk/packaging/redhat/srs.spec diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f1c423121..bbfbd27d2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,14 +18,17 @@ jobs: uses: actions/checkout@v2 # The github.ref is, for example, refs/tags/v4.0.145 or refs/tags/v4.0-r8 # Generate variables like: - # SRS_TAG=v4.0.145 # SRS_TAG=v4.0-r8 + # SRS_TAG=v4.0.145 + # SRS_VERSION=4.0.145 # SRS_MAJOR=4 # @see https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable - name: Generate varaiables run: | SRS_TAG=$(echo ${{ github.ref }}| awk -F '/' '{print $3}') echo "SRS_TAG=$SRS_TAG" >> $GITHUB_ENV + SRS_VERSION=$(echo ${SRS_TAG}| sed 's/^v//g') + echo "SRS_VERSION=$SRS_VERSION" >> $GITHUB_ENV SRS_MAJOR=$(echo $SRS_TAG| cut -c 2) echo "SRS_MAJOR=$SRS_MAJOR" >> $GITHUB_ENV # Create source tar for release. Note that it's for OpenWRT package srs-server, so the filename MUST be @@ -35,12 +38,24 @@ jobs: # SRS_SOURCE_MD5=83e38700a80a26e30b2df054e69956e5 - name: Create source tar.gz run: | - DEST_DIR=srs-server-$(echo ${SRS_TAG}| sed 's/^v//g') && mkdir -p $DEST_DIR && + DEST_DIR=srs-server-$SRS_VERSION && mkdir -p $DEST_DIR && cp README.md $DEST_DIR && cp LICENSE $DEST_DIR && cp -R trunk $DEST_DIR/trunk && (cd $DEST_DIR/trunk/3rdparty && rm -rf *.zip openssl-*.gz srs-bench) && tar zcf ${DEST_DIR}.tar.gz ${DEST_DIR} && du -sh ${DEST_DIR}* && rm -rf ${DEST_DIR} && echo "SRS_SOURCE_TAR=${DEST_DIR}.tar.gz" >> $GITHUB_ENV && echo "SRS_SOURCE_MD5=$(md5sum ${DEST_DIR}.tar.gz| awk '{print $1}')" >> $GITHUB_ENV + # Create package tar for release + # Generate variables like: + # SRS_PACKAGE_ZIP=SRS-CentOS7-x86_64-4.0.145.zip + # SRS_PACKAGE_MD5=3880a26e30b283edf05700a4e69956e5 + - name: Create package zip + run: | + docker build --tag srs:pkg --build-arg version=$SRS_VERSION -f trunk/Dockerfile.pkg . && + SRS_PACKAGE_ZIP=SRS-CentOS7-x86_64-$SRS_VERSION.zip && + docker run --rm -v $(pwd):/output srs:pkg cp objs/$SRS_PACKAGE_ZIP /output/ && + du -sh $SRS_PACKAGE_ZIP && + echo "SRS_PACKAGE_ZIP=$SRS_PACKAGE_ZIP" >> $GITHUB_ENV && + echo "SRS_PACKAGE_MD5=$(md5sum $SRS_PACKAGE_ZIP| awk '{print $1}')" >> $GITHUB_ENV ################################################################ # Tests @@ -116,15 +131,25 @@ jobs: body: | ${{ github.event.head_commit.message }} ${{ env.SRS_SOURCE_MD5 }} [${{ env.SRS_SOURCE_TAR }}](https://github.com/ossrs/srs/releases/download/${{ env.SRS_TAG }}/${{ env.SRS_SOURCE_TAR }}) + ${{ env.SRS_PACKAGE_MD5 }} [${{ env.SRS_PACKAGE_ZIP }}](https://github.com/ossrs/srs/releases/download/${{ env.SRS_TAG }}/${{ env.SRS_PACKAGE_ZIP }}) draft: false prerelease: true - # Upload release files - - name: Upload Release Assets - id: upload-release-assets + # Upload release source files + - name: Upload Release Assets Source + id: upload-release-assets-source uses: dwenegar/upload-release-assets@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: release_id: ${{ steps.create_release.outputs.id }} assets_path: ${{ env.SRS_SOURCE_TAR }} + # Upload release package files + - name: Upload Release Assets Package + id: upload-release-assets-package + uses: dwenegar/upload-release-assets@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + release_id: ${{ steps.create_release.outputs.id }} + assets_path: ${{ env.SRS_PACKAGE_ZIP }} diff --git a/README.md b/README.md index 4162c34d6..b8852d5c1 100755 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ A big `THANK YOU` also goes to: ## Releases -* 2021-10-28, Release [v4.0.187](https://github.com/ossrs/srs/releases/tag/v4.0.187), 4.0 dev7, v4.0.187, 143831 lines. +* 2021-11-02, Release [v4.0.191](https://github.com/ossrs/srs/releases/tag/v4.0.191), 4.0 dev7, v4.0.191, 143890 lines. * 2021-10-12, Release [v4.0.177](https://github.com/ossrs/srs/releases/tag/v4.0.177), 4.0 dev6, v4.0.177, 143686 lines. * 2021-09-05, Release [v4.0.161](https://github.com/ossrs/srs/releases/tag/v4.0.161), 4.0 dev5, v4.0.161, 145865 lines. * 2021-08-15, Release [v4.0.156](https://github.com/ossrs/srs/releases/tag/v4.0.156), 4.0 dev4, v4.0.156, 145490 lines. diff --git a/trunk/3rdparty/patches/srtp/gcc10-01.patch b/trunk/3rdparty/patches/srtp/gcc10-01.patch new file mode 100644 index 000000000..cd9fa2f3d --- /dev/null +++ b/trunk/3rdparty/patches/srtp/gcc10-01.patch @@ -0,0 +1,4 @@ +82c82 +< char bit_string[MAX_PRINT_STRING_LEN]; +--- +> static char bit_string[MAX_PRINT_STRING_LEN]; diff --git a/trunk/Dockerfile.pkg b/trunk/Dockerfile.pkg new file mode 100644 index 000000000..e6b74172d --- /dev/null +++ b/trunk/Dockerfile.pkg @@ -0,0 +1,16 @@ +FROM ossrs/srs:dev + +# version=4.0.145 +ARG version + +# Install depends tools. +RUN yum install -y zip + +# Setup the packager env. +ENV SRS_AUTO_PACKAGER ossrs + +# Build and install SRS. +ADD srs-server-${version}.tar.gz /srs +WORKDIR /srs/srs-server-${version}/trunk +RUN ./scripts/package.sh --x86-x64 --jobs=2 + diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh index 588658b39..856725075 100755 --- a/trunk/auto/depends.sh +++ b/trunk/auto/depends.sh @@ -617,6 +617,7 @@ if [[ $SRS_RTC == YES ]]; then ( rm -rf ${SRS_OBJS}/srtp2 && cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf libsrtp-2-fit && cp -R ../../3rdparty/libsrtp-2-fit . && cd libsrtp-2-fit && + patch -p0 crypto/math/datatypes.c ../../../3rdparty/patches/srtp/gcc10-01.patch && $SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=`pwd`/_release && make ${SRS_JOBS} && make install && cd .. && rm -rf srtp2 && ln -sf libsrtp-2-fit/_release srtp2 diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 223ecf73c..dea714815 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -30,6 +30,11 @@ The changelog for SRS. ## SRS 4.0 Changelog +* v4.0, 2021-11-04, Merge [#2707](https://github.com/ossrs/srs/pull/2707): Refuse edge request when state is stopping. v4.0.192 +* v4.0, 2021-11-02, Auto create package by github actions. v4.0.191 +* v4.0, 2021-10-30, Merge [#2552](https://github.com/ossrs/srs/pull/2552): Script: Refine CentOS7 service script to restart SRS. v4.0.190 +* v4.0, 2021-10-30, Merge [#2397](https://github.com/ossrs/srs/pull/2397): SRTP: Patch libsrtp2 to fix GCC10 build fail. v4.0.189 +* v4.0, 2021-10-30, Merge [#2284](https://github.com/ossrs/srs/pull/2284): Forward: Fast quit when cycle fail. v4.0.188 * v4.0, 2021-10-28, Merge [#2186](https://github.com/ossrs/srs/pull/2186): Gop: Ignore zero timestamp when shrinking. v4.0.187 * v4.0, 2021-10-27, Merge [#1963](https://github.com/ossrs/srs/pull/1963): Cluster: Origin server shouldn't be it's own coworker. v4.0.186 * v4.0, 2021-10-25, Merge [#2692](https://github.com/ossrs/srs/pull/2692): API: Add server_id into http_hooks. v4.0.185 diff --git a/trunk/ide/srs_clion/CMakeLists.txt b/trunk/ide/srs_clion/CMakeLists.txt index 6c736d598..1108fb66a 100755 --- a/trunk/ide/srs_clion/CMakeLists.txt +++ b/trunk/ide/srs_clion/CMakeLists.txt @@ -25,9 +25,9 @@ set(DEPS_LIBS ${SRS_DIR}/objs/st/libst.a ${SRS_DIR}/objs/openssl/lib/libssl.a ${SRS_DIR}/objs/openssl/lib/libcrypto.a ${SRS_DIR}/objs/srtp2/lib/libsrtp2.a - ${SRS_DIR}/objs/opus/lib/libopus.a - ${SRS_DIR}/objs/ffmpeg/lib/libavutil.a ${SRS_DIR}/objs/ffmpeg/lib/libavcodec.a + ${SRS_DIR}/objs/ffmpeg/lib/libavutil.a + ${SRS_DIR}/objs/opus/lib/libopus.a ${SRS_DIR}/objs/ffmpeg/lib/libswresample.a) foreach(DEPS_LIB ${DEPS_LIBS}) IF (NOT EXISTS ${DEPS_LIB}) @@ -62,7 +62,7 @@ ADD_DEFINITIONS("-g -O0") ADD_EXECUTABLE(srs ${SOURCE_FILES}) TARGET_LINK_LIBRARIES(srs dl) TARGET_LINK_LIBRARIES(srs ${DEPS_LIBS}) -TARGET_LINK_LIBRARIES(srs -ldl) +TARGET_LINK_LIBRARIES(srs -ldl -pthread) MESSAGE(STATUS "@see https://github.com/ossrs/srs/wiki/v4_CN_IDE") diff --git a/trunk/packaging/redhat/srs.conf b/trunk/packaging/redhat/srs.conf new file mode 100644 index 000000000..221c352a4 --- /dev/null +++ b/trunk/packaging/redhat/srs.conf @@ -0,0 +1,50 @@ +# main config for srs. +# @see full.conf for detail config. + +daemon off; +pid /var/lib/srs/srs.pid; +work_dir /var/lib/srs; +listen 1935; +max_connections 1000; +srs_log_tank file; +srs_log_file /var/log/srs/srs.log; + +http_api { + enabled on; + listen 1985; +} + +http_server { + enabled on; + listen 8080; + dir /usr/share/srs/html; +} + +rtc_server { + enabled on; + listen 8000; + # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#config-candidate + candidate $CANDIDATE; +} + +stats { + network 0; + disk sda sdb xvda xvdb; +} + +vhost __defaultVhost__ { + hls { + enabled on; + } + http_remux { + enabled on; + mount [vhost]/[app]/[stream].flv; + } + rtc { + enabled on; + # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc + rtmp_to_rtc off; + # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp + rtc_to_rtmp off; + } +} diff --git a/trunk/packaging/redhat/srs.init b/trunk/packaging/redhat/srs.init new file mode 100644 index 000000000..c0a6ec2f9 --- /dev/null +++ b/trunk/packaging/redhat/srs.init @@ -0,0 +1,76 @@ +#!/bin/sh +# +# srs - a simple, high efficiency and realtime video server +# +# chkconfig: + +### BEGIN INIT INFO +# Provides: srs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: a simple, high efficiency and realtime video server +### END INIT INFO + +# Source function library. +. /etc/rc.d/init.d/functions + +exec="/usr/bin/srs" +prog=${exec##*/} +configfile=/etc/srs/srs.conf + +[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog + +lockfile=/var/lock/subsys/$prog + +start() { + echo -n $"Starting $prog: " + daemon --user nobody $exec -c $configfile + retval=$? + echo + [ $retval -eq 0 ] && touch $lockfile + return $retval +} + +stop() { + echo -n $"Stopping $prog: " + killproc $exec -TERM + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval +} + +reload() { + echo -n $"reloading $prog: " + killproc $exec -HUP + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval +} + +rotate() { + echo -n $"logrotate $prog: " + killproc $exec -USR1 + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval +} + +restart() { + stop + start +} + +case "$1" in + start|stop|restart|reload|rotate) + $1 + ;; + status) + status $prog + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|reload|rotate}" + exit 2 +esac diff --git a/trunk/packaging/redhat/srs.logrotate b/trunk/packaging/redhat/srs.logrotate new file mode 100644 index 000000000..5823687df --- /dev/null +++ b/trunk/packaging/redhat/srs.logrotate @@ -0,0 +1,15 @@ +/var/log/srs/*.log { + daily + missingok + rotate 30 + compress + delaycompress + notifempty + create 640 root nobody + sharedscripts + postrotate + if [ -f /var/lib/srs/srs.pid ]; then + kill -USR1 `cat /var/lib/srs/srs.pid` + fi + endscript +} diff --git a/trunk/packaging/redhat/srs.service b/trunk/packaging/redhat/srs.service new file mode 100644 index 000000000..97b3a9283 --- /dev/null +++ b/trunk/packaging/redhat/srs.service @@ -0,0 +1,23 @@ +[Unit] +Description=srs - a simple, high efficiency and realtime video server +Documentation=https://github.com/ossrs/srs/wiki +After=network-online.target remote-fs.target nss-lookup.target +Wants=network-online.target + +[Service] +Type=simple +User=nobody +Group=nobody +WorkingDirectory=/var/lib/srs +EnvironmentFile=-/etc/sysconfig/srs +PIDFile=/var/lib/srs/srs.pid +ExecStartPre=/usr/bin/srs -c /etc/srs/srs.conf -t +ExecStart=/usr/bin/srs -c /etc/srs/srs.conf +ExecReload=/bin/kill -s HUP $MAINPID +ExecStop=/bin/kill -s TERM $MAINPID +Restart=on-failure +PrivateTmp=true + +[Install] +WantedBy=multi-user.target + diff --git a/trunk/packaging/redhat/srs.spec b/trunk/packaging/redhat/srs.spec new file mode 100644 index 000000000..654854fde --- /dev/null +++ b/trunk/packaging/redhat/srs.spec @@ -0,0 +1,103 @@ +%define use_systemd (0%{?fedora} && 0%{?fedora} >= 18) || (0%{?rhel} && 0%{?rhel} >= 7) || (0%{?suse_version} == 1315) + +Name: srs +Version: 3.0.168 +Release: 1%{?dist} +Summary: a simple, high efficiency and realtime video server + +License: MIT +URL: https://github.com/ossrs/srs +Source0: %{name}-3.0-r8.tar.gz +Source1: srs.conf +Source2: srs.service +Source3: srs.init +Source4: srs.logrotate + +BuildRequires: python +BuildRequires: rsync + +%if %{use_systemd} +BuildRequires: systemd +Requires: systemd +%else +BuildRequires: initscripts +Requires: initscripts +%endif + +%description +SRS is a simple, high efficiency and realtime video server, supports RTMP/WebRTC/HLS/HTTP-FLV/SRT. + +%prep +%setup -q -n srs-3.0-r8 + +%build +cd trunk +./configure --prefix=/usr +make %{?_smp_mflags} + +%install +rm -rf $RPM_BUILD_ROOT + +%{__mkdir_p} $RPM_BUILD_ROOT%{_bindir} +%{__mkdir_p} $RPM_BUILD_ROOT%{_initrddir} +%{__mkdir_p} $RPM_BUILD_ROOT%{_datadir}/%{name} +%{__mkdir_p} $RPM_BUILD_ROOT%{_sharedstatedir}/%{name} +%{__mkdir_p} $RPM_BUILD_ROOT%{_localstatedir}/log/%{name} + +%{__install} -m 755 trunk/objs/srs $RPM_BUILD_ROOT%{_bindir} + +#http_server file +rsync -aqL --delete trunk/objs/nginx/ $RPM_BUILD_ROOT%{_datadir}/%{name}/ + +#%{__mkdir_p} $RPM_BUILD_ROOT%{_sysconfdir}/%{name} +%{__install} -D -m 644 trunk/packaging/redhat/srs.conf $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/srs.conf + +#init files +%if %{use_systemd} +%{__mkdir} -p $RPM_BUILD_ROOT%{_unitdir} +%{__install} -p -m 644 trunk/packaging/redhat/srs.service $RPM_BUILD_ROOT%{_unitdir}/srs.service +%else +%{__mkdir} -p $RPM_BUILD_ROOT%{_initrddir} +%{__install} -p -m 755 trunk/packaging/redhat/srs.init $RPM_BUILD_ROOT%{_initrddir}/srs +sed -i 's/daemon/{s/off/on/g}' %{_sysconfdir}/%{name}/srs.conf +%endif + +#logrotate +%{__install} -D -p -m 644 trunk/packaging/redhat/srs.logrotate $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/srs + + +%pre +# Add the "srs" user +# getent group srs >/dev/null || groupadd -r srs +# getent passwd srs >/dev/null || useradd -r -g srs -s /sbin/nologin -d /var/lib/srs srs + +%post +%if %{use_systemd} +%systemd_post %{name}.service +%endif + +%preun +%if %{use_systemd} +%systemd_preun %{name}.service +%endif + +%files +%defattr(-,root,root,-) +%{_bindir}/* +%config(noreplace) %{_sysconfdir}/srs/srs.conf +%{_sysconfdir}/logrotate.d/srs +%{_datadir}/%{name} +%dir %attr(0755, nobody, nobody) %{_localstatedir}/log/%{name} +%dir %attr(0755, nobody, nobody) %{_sharedstatedir}/%{name} +%doc trunk/conf +%license LICENSE + +%if %{use_systemd} +%{_unitdir}/srs.service +%else +%{_initrddir}/%{name} +%endif + +%changelog +* Mon Nov 1 2021 Purple Grape +- rpm init diff --git a/trunk/src/app/srs_app_forward.cpp b/trunk/src/app/srs_app_forward.cpp index c72fe6506..d9af04e90 100755 --- a/trunk/src/app/srs_app_forward.cpp +++ b/trunk/src/app/srs_app_forward.cpp @@ -175,6 +175,12 @@ srs_error_t SrsForwarder::cycle() srs_freep(err); } + // Never wait if thread error, fast quit. + // @see https://github.com/ossrs/srs/pull/2284 + if ((err = trd->pull()) != srs_success) { + return srs_error_wrap(err, "forwarder"); + } + srs_usleep(SRS_FORWARDER_CIMS); } diff --git a/trunk/src/app/srs_app_rtc_api.cpp b/trunk/src/app/srs_app_rtc_api.cpp index d9b0c97c5..df0ae4b52 100644 --- a/trunk/src/app/srs_app_rtc_api.cpp +++ b/trunk/src/app/srs_app_rtc_api.cpp @@ -237,10 +237,8 @@ srs_error_t SrsGoApiRtcPlay::check_remote_sdp(const SrsSdp& remote_sdp) return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "now only suppor rtcp-mux"); } - for (std::vector::const_iterator iter_media = iter->payload_types_.begin(); iter_media != iter->payload_types_.end(); ++iter_media) { - if (iter->sendonly_) { - return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "play API only support sendrecv/recvonly"); - } + if (iter->sendonly_) { + return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "play API only support sendrecv/recvonly"); } } @@ -489,10 +487,8 @@ srs_error_t SrsGoApiRtcPublish::check_remote_sdp(const SrsSdp& remote_sdp) return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "now only suppor rtcp-mux"); } - for (std::vector::const_iterator iter_media = iter->payload_types_.begin(); iter_media != iter->payload_types_.end(); ++iter_media) { - if (iter->recvonly_) { - return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "publish API only support sendrecv/sendonly"); - } + if (iter->recvonly_) { + return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "publish API only support sendrecv/sendonly"); } } diff --git a/trunk/src/app/srs_app_st.cpp b/trunk/src/app/srs_app_st.cpp index 2e769e020..3d8223c48 100755 --- a/trunk/src/app/srs_app_st.cpp +++ b/trunk/src/app/srs_app_st.cpp @@ -202,7 +202,16 @@ void SrsFastCoroutine::stop() if (trd) { void* res = NULL; int r0 = st_thread_join((st_thread_t)trd, &res); - srs_assert(!r0); + if (r0) { + // By st_thread_join + if (errno == EINVAL) srs_assert(!r0); + if (errno == EDEADLK) srs_assert(!r0); + // By st_cond_timedwait + if (errno == EINTR) srs_assert(!r0); + if (errno == ETIME) srs_assert(!r0); + // Others + srs_assert(!r0); + } srs_error_t err_res = (srs_error_t)res; if (err_res != srs_success) { diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 5e3377299..0613583c2 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -54,7 +54,9 @@ #endif #include +#ifndef srs_assert #define srs_assert(expression) assert(expression) +#endif #include #include diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 6956b133c..eef3bfb57 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 0 -#define VERSION_REVISION 187 +#define VERSION_REVISION 192 #endif diff --git a/trunk/src/protocol/srs_service_st.cpp b/trunk/src/protocol/srs_service_st.cpp index dcc8eeb12..65fa523f4 100644 --- a/trunk/src/protocol/srs_service_st.cpp +++ b/trunk/src/protocol/srs_service_st.cpp @@ -74,8 +74,17 @@ void srs_close_stfd(srs_netfd_t& stfd) { if (stfd) { // we must ensure the close is ok. - int err = st_netfd_close((st_netfd_t)stfd); - srs_assert(err != -1); + int r0 = st_netfd_close((st_netfd_t)stfd); + if (r0) { + // By _st_epoll_fd_close or _st_kq_fd_close + if (errno == EBUSY) srs_assert(!r0); + // By close + if (errno == EBADF) srs_assert(!r0); + if (errno == EINTR) srs_assert(!r0); + if (errno == EIO) srs_assert(!r0); + // Others + srs_assert(!r0); + } stfd = NULL; } } diff --git a/trunk/src/srt/srt_server.cpp b/trunk/src/srt/srt_server.cpp index cb3722f00..03fb16645 100644 --- a/trunk/src/srt/srt_server.cpp +++ b/trunk/src/srt/srt_server.cpp @@ -229,7 +229,7 @@ void srt_server::srt_handle_connection(SRT_SOCKSTATUS status, SRTSOCKET input_fd } else if (srt_conn_ptr->get_mode() == PUSH_SRT_MODE) { conn_event = SRT_EPOLL_IN | SRT_EPOLL_ERR; } else { - srt_log_trace("stream mode error, it shoulde be m=push or m=pull, streamid:%s", + srt_log_trace("stream mode error, it should be m=push or m=pull, streamid:%s", srt_conn_ptr->get_streamid().c_str()); srt_conn_ptr->close(); return; diff --git a/trunk/src/utest/srs_utest_reload.hpp b/trunk/src/utest/srs_utest_reload.hpp index 2af4e64b0..01688b7b5 100644 --- a/trunk/src/utest/srs_utest_reload.hpp +++ b/trunk/src/utest/srs_utest_reload.hpp @@ -10,7 +10,7 @@ /* #include */ -#include +#include #include #include diff --git a/trunk/src/utest/srs_utest_service.cpp b/trunk/src/utest/srs_utest_service.cpp index 20f744bfc..197383555 100644 --- a/trunk/src/utest/srs_utest_service.cpp +++ b/trunk/src/utest/srs_utest_service.cpp @@ -24,6 +24,7 @@ using namespace std; #include #include #include +#include MockSrsConnection::MockSrsConnection() { @@ -1452,3 +1453,35 @@ VOID TEST(TCPServerTest, ContextUtility) } } +class MockStopSelfThread : public ISrsCoroutineHandler +{ +public: + int r0; + int r1; + SrsFastCoroutine trd; + MockStopSelfThread() : trd("mock", this), r0(0), r1(0) { + } + virtual ~MockStopSelfThread() { + } + srs_error_t start() { + return trd.start(); + } + void stop() { + trd.stop(); + } + virtual srs_error_t cycle() { + r0 = st_thread_join((st_thread_t)trd.trd, NULL); + r1 = errno; + return srs_success; + } +}; + +VOID TEST(StopSelfThreadTest, ShouldFailWhenStopSelf) +{ + MockStopSelfThread trd; + trd.start(); + srs_usleep(0); + EXPECT_EQ(-1, trd.r0); + EXPECT_EQ(EDEADLK, trd.r1); +} + diff --git a/trunk/usr/lib/systemd/system/srs.service b/trunk/usr/lib/systemd/system/srs.service index b76bc930a..0a27b9a96 100644 --- a/trunk/usr/lib/systemd/system/srs.service +++ b/trunk/usr/lib/systemd/system/srs.service @@ -4,6 +4,7 @@ After=network.target [Service] Type=forking +Restart=always ExecStart=/etc/init.d/srs start ExecReload=/etc/init.d/srs reload ExecStop=/etc/init.d/srs stop