[Spice-devel] [PATCH spice-streaming-agent 5/9] Introduce a short class to have RAII on the syslog

Jonathon Jongsma jjongsma at redhat.com
Fri Jun 29 19:32:49 UTC 2018


On Wed, 2018-06-13 at 14:06 +0200, Lukáš Hrázký wrote:
> Signed-off-by: Lukáš Hrázký <lhrazky at redhat.com>
> ---
>  src/spice-streaming-agent.cpp | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-
> agent.cpp
> index d5ed034..392936a 100644
> --- a/src/spice-streaming-agent.cpp
> +++ b/src/spice-streaming-agent.cpp
> @@ -386,6 +386,22 @@ do_capture(StreamPort &stream_port, FrameLog
> &frame_log)
>      }
>  }
>  
> +class SyslogRAII

I don't personally like this name very much. I'm not sure that I have
any good suggestions, though.  

Brainstorming: SyslogInitializer, SyslogLifetime, SyslogInstance, ...?

> +{
> +public:
> +    SyslogRAII()
> +    {
> +        openlog("spice-streaming-agent",
> +                isatty(fileno(stderr)) ? (LOG_PERROR|LOG_PID) :
> LOG_PID, LOG_USER);
> +    }
> +
> +    ~SyslogRAII()
> +    {
> +        closelog();
> +    }
> +};
> +
> +
>  int main(int argc, char* argv[])
>  {
>      const char *stream_port_name = "/dev/virtio-ports/org.spice-
> space.stream.0";
> @@ -410,8 +426,7 @@ int main(int argc, char* argv[])
>      };
>      std::vector<std::string> old_args(argv, argv+argc);
>  
> -    openlog("spice-streaming-agent",
> -            isatty(fileno(stderr)) ? (LOG_PERROR|LOG_PID) : LOG_PID,
> LOG_USER);
> +    SyslogRAII syslog_raii;
>  
>      setlogmask(logmask);
>  
> @@ -503,6 +518,5 @@ int main(int argc, char* argv[])
>          ret = EXIT_FAILURE;
>      }
>  
> -    closelog();
>      return ret;
>  }


More information about the Spice-devel mailing list