projects/xwrited

changeset 19:f0accfc74f7b

Port to GLib version 2.48 or later

Use GApplication instead of the custom XWritedUnique object for uniqueness.
Use GNotification from GIO instead of libnotify.
Remove help and debug options from documentation.
Replace intltool with GNU gettext (version 0.19 or later required).
author Guido Berhoerster <guido+xwrited@berhoerster.name>
date Sat Jul 28 22:02:24 2018 +0200 (22 months ago)
parents 4a5330979433
children 683ebd334b21
files Makefile README data/docbook-update-source-data.xsl data/xwrited.1.xml data/xwrited.desktop.in docbook-update-source-data.xsl main.c org.guido-berhoerster.code.xwrited.desktop.in po/LINGUAS po/POTFILES.in po/de.po po/id.po xwd-application.c xwd-application.h xwd-utmp-utempter.c xwd-utmp-utmpx.c xwd-utmp.h xwrited-debug.c xwrited-debug.h xwrited-unique.c xwrited-unique.h xwrited-utmp-utempter.c xwrited-utmp-utmpx.c xwrited-utmp.h xwrited.1.xml xwrited.c
line diff
     1.1 --- a/Makefile	Wed Sep 14 09:46:59 2016 +0200
     1.2 +++ b/Makefile	Sat Jul 28 22:02:24 2018 +0200
     1.3 @@ -1,5 +1,5 @@
     1.4  #
     1.5 -# Copyright (C) 2016 Guido Berhoerster <guido+xwrited@berhoerster.name>
     1.6 +# Copyright (C) 2018 Guido Berhoerster <guido+xwrited@berhoerster.name>
     1.7  #
     1.8  # Permission is hereby granted, free of charge, to any person obtaining
     1.9  # a copy of this software and associated documentation files (the
    1.10 @@ -22,9 +22,10 @@
    1.11  #
    1.12  
    1.13  PACKAGE =	xwrited
    1.14 -APP_NAME =	org.guido-berhoerster.code.xwrited
    1.15 +APPLICATION_ID = org.guido-berhoerster.code.xwrited
    1.16  VERSION =	2
    1.17  DISTNAME :=	$(PACKAGE)-$(VERSION)
    1.18 +BUG_ADDRESS =	guido+xwrited@berhoerster.name
    1.19  
    1.20  # gcc, clang, icc, Sun/Solaris Studio
    1.21  CC :=		$(CC) -std=c99
    1.22 @@ -35,18 +36,35 @@
    1.23  #MAKEDEPEND.c =	$(CC) -xM1 $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS)
    1.24  # X makedepend
    1.25  #MAKEDEPEND.c =	makedepend -f- -Y -- $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) --
    1.26 +LINK.c =	$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH)
    1.27 +LINK.o =	$(CC) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH)
    1.28 +CP :=		cp
    1.29  INSTALL :=	install
    1.30  INSTALL.exec :=	$(INSTALL) -D -m 0755
    1.31  INSTALL.data :=	$(INSTALL) -D -m 0644
    1.32 +INSTALL.link :=	$(CP) -f -P
    1.33  PAX :=		pax
    1.34  GZIP :=		gzip
    1.35  SED :=		sed
    1.36 -PASTE :=	paste
    1.37 -MSGFMT :=	msgfmt
    1.38 -INTLTOOL_UPDATE := intltool-update
    1.39 -INTLTOOL_MERGE := intltool-merge
    1.40  XSLTPROC :=	xsltproc
    1.41  DOCBOOK5_MANPAGES_STYLESHEET =	http://docbook.sourceforge.net/release/xsl-ns/current/manpages/docbook.xsl
    1.42 +DOCBOOK5_MANPAGES_FLAGS = --stringparam man.authors.section.enabled 0 \
    1.43 +		--stringparam man.copyright.section.enabled 0
    1.44 +MSGFMT =	msgfmt
    1.45 +MSGMERGE =	msgmerge
    1.46 +XGETTEXT =	xgettext
    1.47 +XGETTEXT_OPTIONS = --copyright-holder "$(AUTHOR)" \
    1.48 +		--package-name '$(PACKAGE)' \
    1.49 +		--package-version '$(VERSION)' \
    1.50 +		--msgid-bugs-address '$(BUG_ADDRESS)' \
    1.51 +		--default-domain '$(PACKAGE)' \
    1.52 +		--from-code UTF-8 \
    1.53 +		--keyword=_ \
    1.54 +		--keyword=N_ \
    1.55 +		--keyword=C_:1c,2 \
    1.56 +		--keyword=NC_:1c,2 \
    1.57 +		--keyword=g_dngettext:2,3 \
    1.58 +		--add-comments
    1.59  
    1.60  define generate-manpage-rule =
    1.61  %.$(1): %.$(1).xml
    1.62 @@ -54,7 +72,7 @@
    1.63  	    --xinclude \
    1.64  	    --stringparam package $$(PACKAGE) \
    1.65  	    --stringparam version $$(VERSION)\
    1.66 -	    data/docbook-update-source-data.xsl $$< | \
    1.67 +	    docbook-update-source-data.xsl $$< | \
    1.68  	    $$(XSLTPROC) \
    1.69  	    --xinclude \
    1.70  	    $$(DOCBOOK5_MANPAGES_FLAGS) \
    1.71 @@ -75,95 +93,94 @@
    1.72  OS_NAME :=	$(shell uname -s)
    1.73  OS_RELEASE :=	$(shell uname -r)
    1.74  
    1.75 -ifeq ($(shell pkg-config --exists 'glib-2.0 >= 2.25.5' && printf "true"),true)
    1.76 -  HAVE_GLIB_GDBUS = 1
    1.77 +OBJS =		xwrited.o \
    1.78 +		xwd-application.o
    1.79 +ifneq ($(findstring $(OS_NAME),Linux FreeBSD),)
    1.80 +  OBJS +=	xwd-utmp-utempter.o
    1.81  else
    1.82 -  HAVE_GLIB_GDBUS = 0
    1.83 +  OBJS +=	xwd-utmp-utmpx.o
    1.84  endif
    1.85  
    1.86 -PKGCONFIG_LIBS := dbus-1 glib-2.0 libnotify
    1.87 -ifeq ($(HAVE_GLIB_GDBUS),1)
    1.88 -  PKGCONFIG_LIBS +=	dbus-glib-1
    1.89 -endif
    1.90 -OBJS =		main.o xwrited-debug.o xwrited-unique.o
    1.91 -ifneq ($(findstring $(OS_NAME),Linux FreeBSD),)
    1.92 -  OBJS +=	xwrited-utmp-utempter.o
    1.93 -else
    1.94 -  OBJS +=	xwrited-utmp-utmpx.o
    1.95 -endif
    1.96 -MANPAGES =	data/$(PACKAGE).1
    1.97 -AUTOSTART_FILE = data/$(PACKAGE).desktop
    1.98 -MOFILES :=	$(patsubst %.po,%.mo,$(wildcard po/*.po))
    1.99 +MANPAGES =	$(PACKAGE).1
   1.100 +
   1.101 +AUTOSTART_FILE = $(APPLICATION_ID).desktop
   1.102 +
   1.103 +LINGUAS :=	$(shell sed 's/\#.*//' po/LINGUAS)
   1.104 +MOFILES :=	$(patsubst %,po/%.mo,$(LINGUAS))
   1.105 +POTFILES_IN :=	$(shell sed 's/\#.*//' po/POTFILES.in)
   1.106  POTFILE =	po/$(PACKAGE).pot
   1.107 -POSRCS :=	$(shell $(SED) -e 's/\#.*//' -e '/^[ \t]*$$/d' \
   1.108 -		-e 's/^\[[^]]*\]//' po/POTFILES.in | $(PASTE) -s -d ' ')
   1.109 -DOCBOOK5_MANPAGES_FLAGS = --stringparam man.authors.section.enabled 0 \
   1.110 -			  --stringparam man.copyright.section.enabled 0
   1.111  
   1.112  .DEFAULT_TARGET = all
   1.113  
   1.114 -.PHONY: all clean clobber dist install
   1.115 +.PHONY: all pot update-po clean clobber dist install
   1.116  
   1.117 -all: $(PACKAGE) $(MANPAGES) $(MOFILES) $(AUTOSTART_FILE)
   1.118 +all: $(PACKAGE) $(AUTOSTART_FILE) $(MOFILES) $(MANPAGES)
   1.119  
   1.120 -$(PACKAGE): CPPFLAGS :=	$(shell pkg-config --cflags $(PKGCONFIG_LIBS)) \
   1.121 -			-D_XOPEN_SOURCE=600 \
   1.122 -			-DPACKAGE="\"$(PACKAGE)\"" \
   1.123 -			-DAPP_NAME=\"$(APP_NAME)\" \
   1.124 +$(PACKAGE): XCFLAGS =	$(shell pkg-config --cflags gobject-2.0 gio-2.0 \
   1.125 +			glib-2.0) \
   1.126 +			-DPACKAGE=\"$(PACKAGE)\" \
   1.127 +			-DAPPLICATION_ID=\"$(APPLICATION_ID)\" \
   1.128  			-DVERSION=\"$(VERSION)\" \
   1.129 -			-DLOCALEDIR="\"$(localedir)\"" \
   1.130 -			-DG_LOG_DOMAIN=\"$(PACKAGE)\"
   1.131 -$(PACKAGE): LDLIBS :=	$(shell pkg-config --libs $(PKGCONFIG_LIBS))
   1.132 -ifeq ($(HAVE_GLIB_GDBUS),1)
   1.133 -  $(PACKAGE): XCPPFLAGS += -DHAVE_GLIB_GDBUS
   1.134 -endif
   1.135 +			-DG_LOG_DOMAIN=\"$(PACKAGE)\" \
   1.136 +			-DPACKAGE_LOCALE_DIR="\"$(localedir)\"" \
   1.137 +			-DGETTEXT_PACKAGE=\"$(PACKAGE)\"
   1.138 +$(PACKAGE): LDLIBS =	$(shell pkg-config --libs gobject-2.0 gio-2.0 \
   1.139 +			glib-2.0)
   1.140 +
   1.141  ifeq ($(OS_NAME),Linux)
   1.142 +  $(PACKAGE): XCPPFLAGS += -D_XOPEN_SOURCE=600
   1.143    $(PACKAGE): LDLIBS +=	-lutempter
   1.144  else ifeq ($(OS_NAME),FreeBSD)
   1.145    $(PACKAGE): LDLIBS +=	-lulog
   1.146  else ifeq ($(OS_NAME),SunOS)
   1.147 -  $(PACKAGE): XCPPFLAGS += -I/usr/xpg4/include
   1.148 +  $(PACKAGE): XCPPFLAGS += -D_XOPEN_SOURCE=600 -I/usr/xpg4/include
   1.149    $(PACKAGE): XLDFLAGS += -L/usr/xpg4/lib -R/usr/xpg4/lib
   1.150  endif
   1.151 +
   1.152  $(PACKAGE): $(OBJS)
   1.153  	$(LINK.o) $^ $(LDLIBS) -o $@
   1.154  
   1.155 -$(POTFILE): po/POTFILES.in $(POSRCS)
   1.156 -	cd po/ && $(INTLTOOL_UPDATE) --pot --gettext-package="$(PACKAGE)"
   1.157 +$(POTFILE): po/POTFILES.in $(POTFILES_IN)
   1.158 +	$(XGETTEXT) $(XGETTEXT_OPTIONS) --files-from $< --output $@
   1.159  
   1.160  pot: $(POTFILE)
   1.161  
   1.162  update-po: $(POTFILE)
   1.163 -	cd po/ && for lang in $(patsubst po/%.mo,%,$(MOFILES)); do \
   1.164 -	    $(INTLTOOL_UPDATE) --dist --gettext-package="$(PACKAGE)" \
   1.165 -	    $${lang}; \
   1.166 +	for pofile in $(patsubst %.mo,%.po,$(MOFILES)); do \
   1.167 +	    $(MSGMERGE) --update --backup off $$pofile $<; \
   1.168  	done
   1.169  
   1.170 +%.mo: %.po
   1.171 +	$(MSGFMT) --output $@ $<
   1.172 +
   1.173 +%.desktop: %.desktop.in
   1.174 +	$(MSGFMT) --desktop --template $< -d po --output $@
   1.175 +
   1.176 +$(foreach section,1 2 3 4 5 6 7 8 9,$(eval $(call generate-manpage-rule,$(section))))
   1.177 +
   1.178 +%.mo: %.po
   1.179 +	$(MSGFMT) -o $@ $<
   1.180 +
   1.181  %.o: %.c
   1.182  	$(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
   1.183  	$(COMPILE.c) -o $@ $<
   1.184  
   1.185 -$(foreach section,1 2 3 4 5 6 7 8 9,$(eval $(call generate-manpage-rule,$(section))))
   1.186 -
   1.187 -%.desktop: %.desktop.in $(MOFILES)
   1.188 -	$(INTLTOOL_MERGE) --desktop-style --utf8 po $< $@
   1.189 -
   1.190 -%.mo: %.po
   1.191 -	$(MSGFMT) -o $@ $<
   1.192 -
   1.193 -install:
   1.194 +install: all
   1.195  	$(INSTALL.exec) $(PACKAGE) "$(DESTDIR)$(bindir)/$(PACKAGE)"
   1.196 -	for lang in $(patsubst po/%.mo,%,$(MOFILES)); do \
   1.197 -	    $(INSTALL.data) po/$${lang}.mo \
   1.198 -	        "$(DESTDIR)$(localedir)/$${lang}/LC_MESSAGES/$(PACKAGE).mo"; \
   1.199 +	$(INSTALL.data) $(AUTOSTART_FILE) \
   1.200 +	    $(DESTDIR)$(xdgautostartdir)/$(AUTOSTART_FILE)
   1.201 +	for lang in $(LINGUAS); do \
   1.202 +	   $(INSTALL.data) po/$${lang}.mo \
   1.203 +	        $(DESTDIR)$(localedir)/$${lang}/LC_MESSAGES/$(PACKAGE).mo; \
   1.204  	done
   1.205 -	$(INSTALL.data) $(AUTOSTART_FILE) \
   1.206 -	        "$(DESTDIR)$(xdgautostartdir)/$(notdir $(AUTOSTART_FILE))"
   1.207 -	$(INSTALL.data) data/$(PACKAGE).1 \
   1.208 -	        "$(DESTDIR)$(mandir)/man1/$(PACKAGE).1"
   1.209 +	for manpage in $(MANPAGES); do \
   1.210 +	    $(INSTALL.data) $${manpage} \
   1.211 +	        "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
   1.212 +	done
   1.213  
   1.214  clean:
   1.215 -	rm -f $(PACKAGE) $(OBJS) $(POTFILE) $(MOFILES) $(MANPAGES) $(AUTOSTART_FILE)
   1.216 +	rm -f $(PACKAGE) $(OBJS) $(AUTOSTART_FILE) $(POTFILE) $(MOFILES) \
   1.217 +	    $(MANPAGES)
   1.218  
   1.219  clobber: clean
   1.220  	rm -f $(patsubst %.o,%.d,$(OBJS))
   1.221 @@ -173,4 +190,6 @@
   1.222  	    -s ',^\.$$,,' -s ',\./,$(DISTNAME)/,' . | \
   1.223  	    $(GZIP) > $(DISTNAME).tar.gz
   1.224  
   1.225 +-include local.mk
   1.226 +
   1.227  -include $(patsubst %.o,%.d,$(OBJS))
     2.1 --- a/README	Wed Sep 14 09:46:59 2016 +0200
     2.2 +++ b/README	Sat Jul 28 22:02:24 2018 +0200
     2.3 @@ -14,13 +14,12 @@
     2.4  Illumos-derived distributions.  The following tools and shared libraries are
     2.5  required to build xwrited:
     2.6  
     2.7 -- GNU make >= 3.81
     2.8 +- GNU make version 3.81 or later
     2.9  - GNU or BSD install
    2.10 -- GLib version 2.26 or later
    2.11 -- the D-Bus GLib bindings for GLib < 2.25.5
    2.12 +- GNU gettext 0.19 or later
    2.13 +- GLib version 2.48 or later
    2.14  - libutempter on Linux
    2.15 -
    2.16 -Rebuilding the man pages additionally requires the xsltproc tool from libxml2.
    2.17 +- the xsltproc tool from libxml2
    2.18  
    2.19  Before building xwrited check the commented macros in the Makefile for any
    2.20  macros you may need to override depending on the used toolchain and operating
    2.21 @@ -78,10 +77,10 @@
    2.22  License
    2.23  -------
    2.24  
    2.25 -Except otherwise noted, all files are Copyright (C) 2014 Guido Berhoerster and
    2.26 +Except otherwise noted, all files are Copyright (C) 2018 Guido Berhoerster and
    2.27  distributed under the following license terms:
    2.28  
    2.29 -Copyright (C) 2014 Guido Berhoerster <guido+xwrited@berhoerster.name>
    2.30 +Copyright (C) 2018 Guido Berhoerster <guido+xwrited@berhoerster.name>
    2.31  
    2.32  Permission is hereby granted, free of charge, to any person obtaining
    2.33  a copy of this software and associated documentation files (the
     3.1 --- a/data/docbook-update-source-data.xsl	Wed Sep 14 09:46:59 2016 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,29 +0,0 @@
     3.4 -<?xml version="1.0"?>
     3.5 -<xsl:stylesheet
     3.6 -  version="1.0"
     3.7 -  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     3.8 -  xmlns:db="http://docbook.org/ns/docbook"
     3.9 -  xmlns="http://docbook.org/ns/docbook"
    3.10 -  exclude-result-prefixes="xsl db">
    3.11 -
    3.12 -  <xsl:param name="package" select="''" />
    3.13 -  <xsl:param name="version" select="''" />
    3.14 -
    3.15 -  <xsl:template match="db:refmeta/db:refmiscinfo[@class = 'source' or
    3.16 -    @class = 'version']"/>
    3.17 -
    3.18 -  <xsl:template match="db:refmeta">
    3.19 -    <xsl:copy>
    3.20 -      <xsl:apply-templates/>
    3.21 -      <refmiscinfo class="source"><xsl:value-of select="$package"/></refmiscinfo>
    3.22 -      <refmiscinfo class="version"><xsl:value-of select="$version"/></refmiscinfo>
    3.23 -    </xsl:copy>
    3.24 -  </xsl:template>
    3.25 -
    3.26 -  <xsl:template match="@*|node()">
    3.27 -    <xsl:copy>
    3.28 -      <xsl:apply-templates select="@*|node()"/>
    3.29 -    </xsl:copy>
    3.30 -  </xsl:template>
    3.31 -
    3.32 -</xsl:stylesheet>
     4.1 --- a/data/xwrited.1.xml	Wed Sep 14 09:46:59 2016 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,159 +0,0 @@
     4.4 -<?xml version="1.0"?>
     4.5 -<!--
     4.6 -
     4.7 -Copyright (C) 2014 Guido Berhoerster <guido+xwrited@berhoerster.name>
     4.8 -
     4.9 -Permission is hereby granted, free of charge, to any person obtaining
    4.10 -a copy of this software and associated documentation files (the
    4.11 -"Software"), to deal in the Software without restriction, including
    4.12 -without limitation the rights to use, copy, modify, merge, publish,
    4.13 -distribute, sublicense, and/or sell copies of the Software, and to
    4.14 -permit persons to whom the Software is furnished to do so, subject to
    4.15 -the following conditions:
    4.16 -
    4.17 -The above copyright notice and this permission notice shall be included
    4.18 -in all copies or substantial portions of the Software.
    4.19 -
    4.20 -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    4.21 -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    4.22 -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    4.23 -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    4.24 -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    4.25 -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    4.26 -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    4.27 -
    4.28 --->
    4.29 -<refentry xmlns="http://docbook.org/ns/docbook" xml:lang="en">
    4.30 -  <info>
    4.31 -    <author>
    4.32 -      <personname>
    4.33 -        <firstname>Guido</firstname>
    4.34 -        <surname>Berhoerster</surname>
    4.35 -      </personname>
    4.36 -      <email>guido+xwrited@berhoerster.name</email>
    4.37 -      <personblurb/>
    4.38 -    </author>
    4.39 -    <date>27 April, 2014</date>
    4.40 -  </info>
    4.41 -  <refmeta>
    4.42 -    <refentrytitle>xwrited</refentrytitle>
    4.43 -    <manvolnum>1</manvolnum>
    4.44 -    <refmiscinfo class="source"/>
    4.45 -    <refmiscinfo class="version"/>
    4.46 -    <refmiscinfo class="manual">User Commands</refmiscinfo>
    4.47 -  </refmeta>
    4.48 -  <refnamediv>
    4.49 -    <refname>xwrited</refname>
    4.50 -    <refpurpose>display write and wall messages as desktop
    4.51 -    notifications</refpurpose>
    4.52 -  </refnamediv>
    4.53 -  <refsynopsisdiv>
    4.54 -    <cmdsynopsis>
    4.55 -      <command>xwrited</command>
    4.56 -      <arg choice="opt">
    4.57 -        <option>-d</option>
    4.58 -      </arg>
    4.59 -      <arg choice="opt">
    4.60 -        <option>-h</option>
    4.61 -      </arg>
    4.62 -      <arg choice="opt">
    4.63 -        <option>-V</option>
    4.64 -      </arg>
    4.65 -      <arg choice="opt">
    4.66 -        <option>-?</option>
    4.67 -      </arg>
    4.68 -      <arg choice="opt">
    4.69 -        <option>--debug</option>
    4.70 -      </arg>
    4.71 -      <arg choice="opt">
    4.72 -        <option>--help</option>
    4.73 -      </arg>
    4.74 -      <arg choice="opt">
    4.75 -        <option>--version</option>
    4.76 -      </arg>
    4.77 -    </cmdsynopsis>
    4.78 -  </refsynopsisdiv>
    4.79 -  <refsect1>
    4.80 -    <title>Description</title>
    4.81 -    <para>The <command>xwrited</command> utility displays
    4.82 -    <citerefentry><refentrytitle>write</refentrytitle><manvolnum>1</manvolnum>
    4.83 -    </citerefentry> and
    4.84 -    <citerefentry><refentrytitle>wall</refentrytitle><manvolnum>1</manvolnum>
    4.85 -    </citerefentry> messages as desktop notifications. A notification daemon
    4.86 -    compliant to the freedesktop.org Desktop Notification Specification draft
    4.87 -    needs to be running in order to display the notifications.</para>
    4.88 -  </refsect1>
    4.89 -  <refsect1>
    4.90 -    <title>Options</title>
    4.91 -    <para>The following options are supported:</para>
    4.92 -    <variablelist>
    4.93 -      <varlistentry>
    4.94 -        <term>
    4.95 -          <option>-h</option>
    4.96 -        </term>
    4.97 -        <term>
    4.98 -          <option>-?</option>
    4.99 -        </term>
   4.100 -        <term>
   4.101 -          <option>--help</option>
   4.102 -        </term>
   4.103 -        <listitem>
   4.104 -          <para>Print a summary of all command line options and exit.</para>
   4.105 -        </listitem>
   4.106 -      </varlistentry>
   4.107 -      <varlistentry>
   4.108 -        <term>
   4.109 -          <option>-d</option>
   4.110 -        </term>
   4.111 -        <term>
   4.112 -          <option>--debug</option>
   4.113 -        </term>
   4.114 -        <listitem>
   4.115 -          <para>Enable debugging output.</para>
   4.116 -        </listitem>
   4.117 -      </varlistentry>
   4.118 -      <varlistentry>
   4.119 -        <term>
   4.120 -          <option>-V</option>
   4.121 -        </term>
   4.122 -        <term>
   4.123 -          <option>--version</option>
   4.124 -        </term>
   4.125 -        <listitem>
   4.126 -          <para>Print the version number and exit.</para>
   4.127 -        </listitem>
   4.128 -      </varlistentry>
   4.129 -    </variablelist>
   4.130 -  </refsect1>
   4.131 -  <refsect1>
   4.132 -    <title>Exit Status</title>
   4.133 -    <para>The following exit values are returned:</para>
   4.134 -    <variablelist>
   4.135 -      <varlistentry>
   4.136 -        <term>0</term>
   4.137 -        <listitem>
   4.138 -          <para>Command successfully executed.</para>
   4.139 -        </listitem>
   4.140 -      </varlistentry>
   4.141 -      <varlistentry>
   4.142 -        <term>&gt; 0</term>
   4.143 -        <listitem>
   4.144 -          <para>An error has occured.</para>
   4.145 -        </listitem>
   4.146 -      </varlistentry>
   4.147 -    </variablelist>
   4.148 -  </refsect1>
   4.149 -  <refsect1>
   4.150 -    <title>See Also</title>
   4.151 -    <para><citerefentry><refentrytitle>write</refentrytitle>
   4.152 -    <manvolnum>1</manvolnum></citerefentry>,
   4.153 -    <citerefentry> <refentrytitle>wall</refentrytitle><manvolnum>1</manvolnum>
   4.154 -    </citerefentry></para>
   4.155 -  </refsect1>
   4.156 -  <refsect1>
   4.157 -    <title>Notes</title>
   4.158 -    <para>xwrited assumes that messages are encoded in UTF-8 because there is
   4.159 -    no way for it to determine the character set encoding of the received
   4.160 -    data.</para>
   4.161 -  </refsect1>
   4.162 -</refentry>
     5.1 --- a/data/xwrited.desktop.in	Wed Sep 14 09:46:59 2016 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,8 +0,0 @@
     5.4 -[Desktop Entry]
     5.5 -Encoding=UTF-8
     5.6 -_Name=xwrited
     5.7 -_Comment=Display write and wall messages as desktop notifications
     5.8 -Exec=xwrited
     5.9 -Terminal=false
    5.10 -Type=Application
    5.11 -Categories=System;Monitor;
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/docbook-update-source-data.xsl	Sat Jul 28 22:02:24 2018 +0200
     6.3 @@ -0,0 +1,29 @@
     6.4 +<?xml version="1.0"?>
     6.5 +<xsl:stylesheet
     6.6 +  version="1.0"
     6.7 +  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     6.8 +  xmlns:db="http://docbook.org/ns/docbook"
     6.9 +  xmlns="http://docbook.org/ns/docbook"
    6.10 +  exclude-result-prefixes="xsl db">
    6.11 +
    6.12 +  <xsl:param name="package" select="''" />
    6.13 +  <xsl:param name="version" select="''" />
    6.14 +
    6.15 +  <xsl:template match="db:refmeta/db:refmiscinfo[@class = 'source' or
    6.16 +    @class = 'version']"/>
    6.17 +
    6.18 +  <xsl:template match="db:refmeta">
    6.19 +    <xsl:copy>
    6.20 +      <xsl:apply-templates/>
    6.21 +      <refmiscinfo class="source"><xsl:value-of select="$package"/></refmiscinfo>
    6.22 +      <refmiscinfo class="version"><xsl:value-of select="$version"/></refmiscinfo>
    6.23 +    </xsl:copy>
    6.24 +  </xsl:template>
    6.25 +
    6.26 +  <xsl:template match="@*|node()">
    6.27 +    <xsl:copy>
    6.28 +      <xsl:apply-templates select="@*|node()"/>
    6.29 +    </xsl:copy>
    6.30 +  </xsl:template>
    6.31 +
    6.32 +</xsl:stylesheet>
     7.1 --- a/main.c	Wed Sep 14 09:46:59 2016 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,507 +0,0 @@
     7.4 -/*
     7.5 - * Copyright (C) 2015 Guido Berhoerster <guido+xwrited@berhoerster.name>
     7.6 - *
     7.7 - * Permission is hereby granted, free of charge, to any person obtaining
     7.8 - * a copy of this software and associated documentation files (the
     7.9 - * "Software"), to deal in the Software without restriction, including
    7.10 - * without limitation the rights to use, copy, modify, merge, publish,
    7.11 - * distribute, sublicense, and/or sell copies of the Software, and to
    7.12 - * permit persons to whom the Software is furnished to do so, subject to
    7.13 - * the following conditions:
    7.14 - *
    7.15 - * The above copyright notice and this permission notice shall be included
    7.16 - * in all copies or substantial portions of the Software.
    7.17 - *
    7.18 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    7.19 - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    7.20 - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    7.21 - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    7.22 - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    7.23 - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    7.24 - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    7.25 - */
    7.26 -
    7.27 -#include <stdio.h>
    7.28 -#include <stdlib.h>
    7.29 -#include <string.h>
    7.30 -#include <unistd.h>
    7.31 -#include <fcntl.h>
    7.32 -#include <sys/stat.h>
    7.33 -#include <signal.h>
    7.34 -#include <errno.h>
    7.35 -#include <locale.h>
    7.36 -#include <libintl.h>
    7.37 -#include <glib.h>
    7.38 -#include <glib/gi18n.h>
    7.39 -#include <libnotify/notify.h>
    7.40 -#include "xwrited-debug.h"
    7.41 -#include "xwrited-unique.h"
    7.42 -#include "xwrited-utmp.h"
    7.43 -
    7.44 -#define BUFFER_TIMEOUT (250)
    7.45 -
    7.46 -enum {
    7.47 -	PIPE_R_FD = 0,
    7.48 -	PIPE_W_FD
    7.49 -};
    7.50 -
    7.51 -static int		signal_pipe_fd[2] = { -1, -1 };
    7.52 -static guint		notify_timeout_id;
    7.53 -static GMainLoop	*loop;
    7.54 -static GString		*buffer;
    7.55 -
    7.56 -static void
    7.57 -on_signal(int signo)
    7.58 -{
    7.59 -	int		old_errno = errno;
    7.60 -	ssize_t		n;
    7.61 -	sigset_t	sigset;
    7.62 -
    7.63 -	/* try to read unread signals from the pipe and add the new one to it */
    7.64 -	n = read(signal_pipe_fd[PIPE_R_FD], &sigset, sizeof (sigset));
    7.65 -	if ((n == -1) || ((size_t)n < sizeof (sigset))) {
    7.66 -		sigemptyset(&sigset);
    7.67 -	}
    7.68 -	sigaddset(&sigset, signo);
    7.69 -	write(signal_pipe_fd[PIPE_W_FD], &sigset, sizeof (sigset));
    7.70 -
    7.71 -	errno = old_errno;
    7.72 -}
    7.73 -
    7.74 -static gboolean
    7.75 -signal_read_cb(GIOChannel *source, GIOCondition cond, gpointer user_data)
    7.76 -{
    7.77 -	sigset_t	sigset;
    7.78 -	sigset_t	old_sigset;
    7.79 -	GIOStatus	status;
    7.80 -	gsize		n;
    7.81 -	GError		*error = NULL;
    7.82 -
    7.83 -	/*
    7.84 -	 * deal with pending signals previously received in the signal handler,
    7.85 -	 * try to read a sigset from the pipe, avoid partial reads by blocking
    7.86 -	 * all signals during the read operation
    7.87 -	 */
    7.88 -	sigfillset(&sigset);
    7.89 -	sigprocmask(SIG_BLOCK, &sigset, &old_sigset);
    7.90 -	status = g_io_channel_read_chars(source, (gchar *)&sigset,
    7.91 -	    sizeof (sigset), &n, &error);
    7.92 -	sigprocmask(SIG_SETMASK, &old_sigset, NULL);
    7.93 -	if (status != G_IO_STATUS_NORMAL) {
    7.94 -		if (status != G_IO_STATUS_AGAIN) {
    7.95 -			if (error != NULL) {
    7.96 -				g_critical("failed to read from signal pipe: "
    7.97 -				    "%s", error->message);
    7.98 -				g_error_free(error);
    7.99 -				g_main_loop_quit(loop);
   7.100 -			} else {
   7.101 -				g_critical("failed to read from signal pipe");
   7.102 -				g_main_loop_quit(loop);
   7.103 -			}
   7.104 -		}
   7.105 -	} else if (n != sizeof (sigset)) {
   7.106 -		g_critical("short read from signal pipe");
   7.107 -		g_main_loop_quit(loop);
   7.108 -	} else {
   7.109 -		if ((sigismember(&sigset, SIGINT) == 1) ||
   7.110 -		    (sigismember(&sigset, SIGTERM) == 1) ||
   7.111 -		    (sigismember(&sigset, SIGQUIT) == 1) ||
   7.112 -		    (sigismember(&sigset, SIGHUP) == 1)) {
   7.113 -			g_debug("received signal, exiting");
   7.114 -			g_main_loop_quit(loop);
   7.115 -		}
   7.116 -	}
   7.117 -
   7.118 -	return (TRUE);
   7.119 -}
   7.120 -
   7.121 -static gboolean
   7.122 -send_notification(void)
   7.123 -{
   7.124 -	gboolean	retval = FALSE;
   7.125 -	GString		*utf8_str = NULL;
   7.126 -	gchar		*startp = buffer->str;
   7.127 -	gchar		*endp;
   7.128 -	GRegex		*regex = NULL;
   7.129 -	GError		*error = NULL;
   7.130 -	gchar		*body = NULL;
   7.131 -	GList		*capabilities = NULL;
   7.132 -	gchar		*tmp;
   7.133 -	NotifyNotification *notification = NULL;
   7.134 -
   7.135 -	utf8_str = g_string_sized_new(buffer->len);
   7.136 -	while (!g_utf8_validate(startp, buffer->str + buffer->len -
   7.137 -	    startp, (const gchar **)&endp)) {
   7.138 -		g_string_append_len(utf8_str, startp, endp - startp);
   7.139 -		/*
   7.140 -		 * replace each byte that does not belong to a UTF-8-encoded
   7.141 -		 * character with the Unicode REPLACEMENT CHARACTER (U+FFFD)
   7.142 -		 */
   7.143 -		g_string_append(utf8_str, "\357\277\275");
   7.144 -
   7.145 -		startp = endp + ((endp < buffer->str + buffer->len) ? 1 : 0);
   7.146 -	}
   7.147 -	g_string_append_len(utf8_str, startp, buffer->str + buffer->len -
   7.148 -	    startp);
   7.149 -
   7.150 -	/* remove any CR, BEL and trailing space and tabs */
   7.151 -	regex = g_regex_new("([\r\a]+|[ \t\r\a]+$)", G_REGEX_MULTILINE, 0,
   7.152 -	    &error);
   7.153 -	if (error != NULL) {
   7.154 -		g_critical("failed to create regex object: %s",
   7.155 -		    error->message);
   7.156 -		g_error_free(error);
   7.157 -		goto out;
   7.158 -	}
   7.159 -	body = g_regex_replace_literal(regex, utf8_str->str, -1, 0, "", 0,
   7.160 -	    &error);
   7.161 -	if (error != NULL) {
   7.162 -		g_critical("failed to replace control and space characters: "
   7.163 -		    "%s", error->message);
   7.164 -		g_error_free(error);
   7.165 -		goto out;
   7.166 -	}
   7.167 -
   7.168 -	/*
   7.169 -	 * skip empty messages or messages only consisting of whitespace and
   7.170 -	 * control characters
   7.171 -	 */
   7.172 -	if ((strlen(body) == 0) ||
   7.173 -	    !g_regex_match_simple("[^[:space:][:cntrl:]]", body, 0, 0)) {
   7.174 -		retval = TRUE;
   7.175 -		goto out;
   7.176 -	}
   7.177 -
   7.178 -	/*
   7.179 -	 * if the notification daemon supports markup the message needs to be
   7.180 -	 * escaped
   7.181 -	 */
   7.182 -	capabilities = notify_get_server_caps();
   7.183 -	if (g_list_find_custom(capabilities, "body-markup",
   7.184 -	    (GCompareFunc)strcmp) != NULL) {
   7.185 -		tmp = g_markup_escape_text(body, -1);
   7.186 -		g_free(body);
   7.187 -		body = tmp;
   7.188 -	}
   7.189 -
   7.190 -	/* show notification */
   7.191 -	notification = notify_notification_new(_("Message received"),
   7.192 -	    body, "utilities-terminal"
   7.193 -#if !defined(NOTIFY_VERSION_MINOR) || \
   7.194 -    (NOTIFY_VERSION_MAJOR == 0 && NOTIFY_VERSION_MINOR < 7)
   7.195 -	    , NULL
   7.196 -#endif
   7.197 -	    );
   7.198 -	if (notification == NULL) {
   7.199 -		g_critical("failed to create a notification object");
   7.200 -		g_main_loop_quit(loop);
   7.201 -		goto out;
   7.202 -	}
   7.203 -	notify_notification_set_timeout(notification, NOTIFY_EXPIRES_NEVER);
   7.204 -	retval = notify_notification_show(notification, NULL);
   7.205 -
   7.206 -out:
   7.207 -	if (notification != NULL) {
   7.208 -		g_object_unref(G_OBJECT(notification));
   7.209 -	}
   7.210 -	if (capabilities != NULL) {
   7.211 -		g_list_free_full(capabilities, g_free);
   7.212 -	}
   7.213 -	g_free(body);
   7.214 -	if (regex != NULL) {
   7.215 -		g_regex_unref(regex);
   7.216 -	}
   7.217 -	if (utf8_str != NULL) {
   7.218 -		g_string_free(utf8_str, TRUE);
   7.219 -	}
   7.220 -	/* prevent a permanently large buffer */
   7.221 -	g_string_free(buffer, FALSE);
   7.222 -	buffer = g_string_sized_new(BUFSIZ);
   7.223 -
   7.224 -	return (retval);
   7.225 -}
   7.226 -
   7.227 -static gboolean
   7.228 -notify_timeout_cb(gpointer user_data)
   7.229 -{
   7.230 -	if (!send_notification()) {
   7.231 -		g_warning("failed to send notification");
   7.232 -	}
   7.233 -
   7.234 -	notify_timeout_id = 0;
   7.235 -
   7.236 -	return (FALSE);
   7.237 -}
   7.238 -
   7.239 -static gboolean
   7.240 -master_pty_read_cb(GIOChannel *source, GIOCondition cond, gpointer user_data)
   7.241 -{
   7.242 -	gchar		buf[BUFSIZ];
   7.243 -	GIOStatus	status;
   7.244 -	gsize		buf_len;
   7.245 -	GError		*error = NULL;
   7.246 -
   7.247 -	if ((cond & G_IO_IN) || (cond & G_IO_PRI)) {
   7.248 -		/* read message from master pty */
   7.249 -		while ((status = g_io_channel_read_chars(source, buf, BUFSIZ,
   7.250 -		    &buf_len, &error)) == G_IO_STATUS_NORMAL) {
   7.251 -			if (buf_len > 0) {
   7.252 -				g_debug("read %" G_GSSIZE_FORMAT " bytes from "
   7.253 -				    "master pty", buf_len);
   7.254 -				g_string_append_len(buffer, buf,
   7.255 -				    (gssize)buf_len);
   7.256 -			}
   7.257 -		}
   7.258 -		if (error != NULL) {
   7.259 -			g_critical("failed to read from master pty: %s",
   7.260 -			    error->message);
   7.261 -			g_error_free(error);
   7.262 -			g_main_loop_quit(loop);
   7.263 -			return (FALSE);
   7.264 -		}
   7.265 -
   7.266 -		/*
   7.267 -		 * schedule a timeout for sending a notification with the
   7.268 -		 * buffered message
   7.269 -		 */
   7.270 -		if (notify_timeout_id <= 0) {
   7.271 -			notify_timeout_id = g_timeout_add(BUFFER_TIMEOUT,
   7.272 -			    notify_timeout_cb, NULL);
   7.273 -		}
   7.274 -	}
   7.275 -
   7.276 -	if ((cond & G_IO_ERR) || (cond & G_IO_HUP)) {
   7.277 -		g_critical("connection to master pty broken");
   7.278 -		g_main_loop_quit(loop);
   7.279 -		return (FALSE);
   7.280 -	}
   7.281 -
   7.282 -	return (TRUE);
   7.283 -}
   7.284 -
   7.285 -int
   7.286 -main(int argc, char *argv[])
   7.287 -{
   7.288 -	int		status = EXIT_FAILURE;
   7.289 -	GError		*error = NULL;
   7.290 -	XWritedUnique	*app = NULL;
   7.291 -	GOptionContext	*context = NULL;
   7.292 -	struct sigaction sigact;
   7.293 -	GIOChannel	*signal_channel = NULL;
   7.294 -	GIOChannel	*master_pty_channel = NULL;
   7.295 -	int		masterfd = -1;
   7.296 -	int		slavefd = -1;
   7.297 -	char		*slave_name = NULL;
   7.298 -	gboolean	vflag = FALSE;
   7.299 -	gboolean	dflag = FALSE;
   7.300 -	const GOptionEntry options[] = {
   7.301 -	    { "debug", 'd', 0, G_OPTION_ARG_NONE, &dflag,
   7.302 -	    N_("Show extra debugging information"), NULL },
   7.303 -	    { "version", 'V', 0, G_OPTION_ARG_NONE, &vflag,
   7.304 -	    N_("Print the current version and exit"), NULL },
   7.305 -	    { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, 0 }
   7.306 -	};
   7.307 -
   7.308 -	setlocale(LC_ALL, "");
   7.309 -	bindtextdomain(PACKAGE, LOCALEDIR);
   7.310 -	bind_textdomain_codeset(PACKAGE, "UTF-8");
   7.311 -	textdomain(PACKAGE);
   7.312 -
   7.313 -#if !GLIB_CHECK_VERSION(2, 35, 0)
   7.314 -	/* deprecated in glib >= 2.35 */
   7.315 -	g_type_init();
   7.316 -#endif
   7.317 -
   7.318 -	context = g_option_context_new("- display write and wall messages as "
   7.319 -	    "desktop notifications");
   7.320 -	g_option_context_add_main_entries(context, options, PACKAGE);
   7.321 -	g_option_context_set_translation_domain(context, PACKAGE);
   7.322 -	g_option_context_parse(context, &argc, &argv, &error);
   7.323 -	if (error != NULL) {
   7.324 -		g_printerr("%s.\n", error->message);
   7.325 -		g_error_free(error);
   7.326 -		goto out;
   7.327 -	}
   7.328 -
   7.329 -	xwrited_debug_init(dflag);
   7.330 -
   7.331 -	if (vflag) {
   7.332 -		g_print("%s %s\n", PACKAGE, VERSION);
   7.333 -		status = EXIT_SUCCESS;
   7.334 -		goto out;
   7.335 -	}
   7.336 -
   7.337 -	app = xwrited_unique_new("org.guido-berhoerster.code.xwrited");
   7.338 -	if (app == NULL) {
   7.339 -		g_critical("failed to initialize application");
   7.340 -		goto out;
   7.341 -	}
   7.342 -	if (!xwrited_unique_is_unique(app)) {
   7.343 -		g_printerr(_("xwrited is already running in this session.\n"));
   7.344 -		goto out;
   7.345 -	}
   7.346 -
   7.347 -	if (!notify_init(APP_NAME)) {
   7.348 -		g_critical("failed to initialize libnotify");
   7.349 -		goto out;
   7.350 -	}
   7.351 -
   7.352 -	loop = g_main_loop_new(NULL, FALSE);
   7.353 -	if (loop == NULL) {
   7.354 -		g_critical("failed to create main loop");
   7.355 -		goto out;
   7.356 -	}
   7.357 -
   7.358 -	buffer = g_string_sized_new(BUFSIZ);
   7.359 -
   7.360 -	/* open master pty */
   7.361 -	masterfd = posix_openpt(O_RDWR | O_NOCTTY);
   7.362 -	if (masterfd == -1) {
   7.363 -		g_critical("failed to open master pty: %s", g_strerror(errno));
   7.364 -		goto out;
   7.365 -	}
   7.366 -
   7.367 -	/* create slave pty */
   7.368 -	if ((grantpt(masterfd) == -1) || (unlockpt(masterfd) == -1)) {
   7.369 -		g_critical("failed to create slave pty: %s", g_strerror(errno));
   7.370 -		goto out;
   7.371 -	}
   7.372 -	slave_name = ptsname(masterfd);
   7.373 -	if (slave_name == NULL) {
   7.374 -		g_critical("failed to obtain name of slave pty");
   7.375 -		goto out;
   7.376 -	}
   7.377 -
   7.378 -	/*
   7.379 -	 * keep an open fd around order to prevent closing the master fd when
   7.380 -	 * receiving an EOF
   7.381 -	 */
   7.382 -	slavefd = open(slave_name, O_RDWR);
   7.383 -	if (slavefd == -1) {
   7.384 -		g_critical("failed to open slave pty: %s", g_strerror(errno));
   7.385 -		goto out;
   7.386 -	}
   7.387 -
   7.388 -	/* create a GIOChannel for monitoring the master pty for messages */
   7.389 -	master_pty_channel = g_io_channel_unix_new(masterfd);
   7.390 -	g_io_channel_set_flags(master_pty_channel,
   7.391 -	    g_io_channel_get_flags(master_pty_channel) | G_IO_FLAG_NONBLOCK,
   7.392 -	    &error);
   7.393 -	if (error != NULL) {
   7.394 -		g_critical("failed set flags on the master pty channel: %s",
   7.395 -		    error->message);
   7.396 -		g_error_free(error);
   7.397 -		goto out;
   7.398 -	}
   7.399 -	if (!g_io_add_watch(master_pty_channel, G_IO_IN | G_IO_PRI | G_IO_HUP |
   7.400 -	    G_IO_ERR, master_pty_read_cb, NULL)) {
   7.401 -		g_critical("failed to add watch on signal channel");
   7.402 -		goto out;
   7.403 -	}
   7.404 -
   7.405 -	/* create pipe for delivering signals to a listener in the main loop */
   7.406 -	if (pipe(signal_pipe_fd) == -1) {
   7.407 -		g_critical("failed to create signal pipe: %s",
   7.408 -		    g_strerror(errno));
   7.409 -		goto out;
   7.410 -	}
   7.411 -	if (fcntl(signal_pipe_fd[PIPE_W_FD], F_SETFL, O_NONBLOCK) == -1) {
   7.412 -		g_critical("failed to set flags on signal pipe: %s",
   7.413 -		    g_strerror(errno));
   7.414 -		goto out;
   7.415 -	}
   7.416 -
   7.417 -	/* create GIO channel for reading from the signal_pipe */
   7.418 -	signal_channel = g_io_channel_unix_new(signal_pipe_fd[PIPE_R_FD]);
   7.419 -	g_io_channel_set_encoding(signal_channel, NULL, &error);
   7.420 -	if (error != NULL) {
   7.421 -		g_critical("failed to set binary encoding for signal channel: "
   7.422 -		    "%s", error->message);
   7.423 -		g_error_free(error);
   7.424 -		goto out;
   7.425 -	}
   7.426 -	g_io_channel_set_buffered(signal_channel, FALSE);
   7.427 -	g_io_channel_set_flags(signal_channel,
   7.428 -	    g_io_channel_get_flags(signal_channel) | G_IO_FLAG_NONBLOCK,
   7.429 -	    &error);
   7.430 -	if (error != NULL) {
   7.431 -		g_critical("failed set flags on signal channel: %s",
   7.432 -		    error->message);
   7.433 -		g_error_free(error);
   7.434 -		goto out;
   7.435 -	}
   7.436 -	if (g_io_add_watch(signal_channel, G_IO_IN | G_IO_PRI | G_IO_HUP |
   7.437 -	    G_IO_ERR, signal_read_cb, NULL) == 0) {
   7.438 -		g_critical("failed to add watch on the signal channel");
   7.439 -		goto out;
   7.440 -	}
   7.441 -
   7.442 -	/* set up signal handler */
   7.443 -	sigact.sa_handler = on_signal;
   7.444 -	sigact.sa_flags = SA_RESTART;
   7.445 -	sigemptyset(&sigact.sa_mask);
   7.446 -	if ((sigaction(SIGINT, &sigact, NULL) < 0) ||
   7.447 -	    (sigaction(SIGTERM, &sigact, NULL) < 0) ||
   7.448 -	    (sigaction(SIGQUIT, &sigact, NULL) < 0) ||
   7.449 -	    (sigaction(SIGHUP, &sigact, NULL) < 0)) {
   7.450 -		g_critical("failed to set up signal handler");
   7.451 -		goto out;
   7.452 -	}
   7.453 -
   7.454 -	xwrited_utmp_add_entry(masterfd);
   7.455 -
   7.456 -	/* main loop */
   7.457 -	g_main_loop_run(loop);
   7.458 -
   7.459 -	xwrited_utmp_remove_entry(masterfd);
   7.460 -
   7.461 -	status = EXIT_SUCCESS;
   7.462 -
   7.463 -out:
   7.464 -	if (context != NULL) {
   7.465 -		g_option_context_free(context);
   7.466 -	}
   7.467 -
   7.468 -	if (signal_channel != NULL) {
   7.469 -		g_io_channel_shutdown(signal_channel, FALSE, NULL);
   7.470 -		g_io_channel_unref(signal_channel);
   7.471 -	}
   7.472 -
   7.473 -	if (signal_pipe_fd[PIPE_R_FD] != -1) {
   7.474 -		close(signal_pipe_fd[PIPE_R_FD]);
   7.475 -	}
   7.476 -	if (signal_pipe_fd[PIPE_W_FD] != -1) {
   7.477 -		close(signal_pipe_fd[PIPE_W_FD]);
   7.478 -	}
   7.479 -
   7.480 -	if (master_pty_channel != NULL) {
   7.481 -		g_io_channel_shutdown(master_pty_channel, FALSE, NULL);
   7.482 -		g_io_channel_unref(master_pty_channel);
   7.483 -	}
   7.484 -
   7.485 -	if (slavefd != -1) {
   7.486 -		close(slavefd);
   7.487 -	}
   7.488 -
   7.489 -	if (masterfd != -1) {
   7.490 -		close(masterfd);
   7.491 -	}
   7.492 -
   7.493 -	if (buffer != NULL) {
   7.494 -		g_string_free(buffer, FALSE);
   7.495 -	}
   7.496 -
   7.497 -	if (app != NULL) {
   7.498 -		g_object_unref(app);
   7.499 -	}
   7.500 -
   7.501 -	if (loop != NULL) {
   7.502 -		g_main_loop_unref(loop);
   7.503 -	}
   7.504 -
   7.505 -	if (notify_is_initted()) {
   7.506 -		notify_uninit();
   7.507 -	}
   7.508 -
   7.509 -	exit(status);
   7.510 -}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/org.guido-berhoerster.code.xwrited.desktop.in	Sat Jul 28 22:02:24 2018 +0200
     8.3 @@ -0,0 +1,8 @@
     8.4 +[Desktop Entry]
     8.5 +Encoding=UTF-8
     8.6 +Name=xwrited
     8.7 +Comment=Display write and wall messages as desktop notifications
     8.8 +Exec=xwrited
     8.9 +Terminal=false
    8.10 +Type=Application
    8.11 +Categories=System;Monitor;
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/po/LINGUAS	Sat Jul 28 22:02:24 2018 +0200
     9.3 @@ -0,0 +1,2 @@
     9.4 +de
     9.5 +id
    10.1 --- a/po/POTFILES.in	Wed Sep 14 09:46:59 2016 +0200
    10.2 +++ b/po/POTFILES.in	Sat Jul 28 22:02:24 2018 +0200
    10.3 @@ -1,6 +1,5 @@
    10.4 -data/xwrited.desktop.in
    10.5 -main.c
    10.6 -xwrited-debug.c
    10.7 -xwrited-unique.c
    10.8 -xwrited-utmp-utempter.c
    10.9 -xwrited-utmp-utmpx.c
   10.10 +org.guido-berhoerster.code.xwrited.desktop.in
   10.11 +xwd-application.c
   10.12 +xwd-utmp-utempter.c
   10.13 +xwd-utmp-utmpx.c
   10.14 +xwrited.c
    11.1 --- a/po/de.po	Wed Sep 14 09:46:59 2016 +0200
    11.2 +++ b/po/de.po	Sat Jul 28 22:02:24 2018 +0200
    11.3 @@ -1,14 +1,14 @@
    11.4  # German translations for xwrited package
    11.5  # German messages for xwrited.
    11.6 -# Copyright (C) 2011 Guido Berhoerster.
    11.7 +# Copyright (C) 2018 Guido Berhoerster.
    11.8  # This file is distributed under the same license as the xwrited package.
    11.9 -# Guido Berhoerster <guido+xwrited@berhoerster.name>, 2011.
   11.10 +# Guido Berhoerster <guido+xwrited@berhoerster.name>, 2018.
   11.11  #
   11.12  msgid ""
   11.13  msgstr ""
   11.14  "Project-Id-Version: xwrited 1\n"
   11.15  "Report-Msgid-Bugs-To: \n"
   11.16 -"POT-Creation-Date: 2011-05-20 16:48+0200\n"
   11.17 +"POT-Creation-Date: 2018-06-29 10:46+0000\n"
   11.18  "PO-Revision-Date: 2010-07-28 13:00+0200\n"
   11.19  "Last-Translator: Guido Berhoerster <guido+xwrited@berhoerster.name>\n"
   11.20  "Language-Team: German\n"
   11.21 @@ -18,28 +18,26 @@
   11.22  "Content-Transfer-Encoding: 8bit\n"
   11.23  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
   11.24  
   11.25 -#: ../data/xwrited.desktop.in.h:1
   11.26 +#: org.guido-berhoerster.code.xwrited.desktop.in:4
   11.27  msgid "xwrited"
   11.28  msgstr "xwrited"
   11.29  
   11.30 -#: ../data/xwrited.desktop.in.h:2
   11.31 +#: org.guido-berhoerster.code.xwrited.desktop.in:5
   11.32  msgid "Display write and wall messages as desktop notifications"
   11.33  msgstr "Zeigt write und wall Nachrichten as Desktop-Benachrichtigungen an"
   11.34  
   11.35 -#. show notification
   11.36 -#: ../main.c:179
   11.37 +#: xwd-application.c:52
   11.38 +msgid "Enable debugging messages"
   11.39 +msgstr ""
   11.40 +
   11.41 +#: xwd-application.c:54
   11.42 +msgid "Quit running instance of xwrited"
   11.43 +msgstr "Beende laufende Instanz von xwrited"
   11.44 +
   11.45 +#: xwd-application.c:56
   11.46 +msgid "Print the version number and quit"
   11.47 +msgstr "Aktuelle Version zeigen und beenden"
   11.48 +
   11.49 +#: xwd-application.c:252
   11.50  msgid "Message received"
   11.51  msgstr "Nachricht erhalten"
   11.52 -
   11.53 -#: ../main.c:280
   11.54 -msgid "Show extra debugging information"
   11.55 -msgstr "Zusätzliche Debugging-Informationen anzeigen"
   11.56 -
   11.57 -#: ../main.c:282
   11.58 -msgid "Print the current version and exit"
   11.59 -msgstr "Aktuelle Version zeigen und beenden"
   11.60 -
   11.61 -#: ../main.c:321
   11.62 -#, c-format
   11.63 -msgid "xwrited is already running in this session.\n"
   11.64 -msgstr "xwrited läuft bereits in dieser Sitzung.\n"
    12.1 --- a/po/id.po	Wed Sep 14 09:46:59 2016 +0200
    12.2 +++ b/po/id.po	Sat Jul 28 22:02:24 2018 +0200
    12.3 @@ -1,13 +1,13 @@
    12.4  # Indonesian translations for xwrited package.
    12.5 -# Copyright (C) 2014 Guido Berhoerster
    12.6 +# Copyright (C) 2018 Guido Berhoerster
    12.7  # This file is distributed under the same license as the xwrited package.
    12.8 -# Guido Berhoerster <guido+xwrited@berhoerster.name>, 2014.
    12.9 +# Guido Berhoerster <guido+xwrited@berhoerster.name>, 2018.
   12.10  #
   12.11  msgid ""
   12.12  msgstr ""
   12.13  "Project-Id-Version: xwrited 1\n"
   12.14  "Report-Msgid-Bugs-To: \n"
   12.15 -"POT-Creation-Date: 2014-04-27 23:04+0200\n"
   12.16 +"POT-Creation-Date: 2018-06-29 10:46+0000\n"
   12.17  "PO-Revision-Date: 2014-04-27 21:01+0200\n"
   12.18  "Last-Translator: Guido Berhoerster <guido+xwrited@berhoerster.name>\n"
   12.19  "Language-Team: Indonesian\n"
   12.20 @@ -16,28 +16,26 @@
   12.21  "Content-Type: text/plain; charset=ASCII\n"
   12.22  "Content-Transfer-Encoding: 8bit\n"
   12.23  
   12.24 -#: ../data/xwrited.desktop.in.h:1
   12.25 +#: org.guido-berhoerster.code.xwrited.desktop.in:4
   12.26  msgid "xwrited"
   12.27  msgstr "xwrited"
   12.28  
   12.29 -#: ../data/xwrited.desktop.in.h:2
   12.30 +#: org.guido-berhoerster.code.xwrited.desktop.in:5
   12.31  msgid "Display write and wall messages as desktop notifications"
   12.32  msgstr "Tampilkan pesanan write dan wall sebagai notifikasi desktop"
   12.33  
   12.34 -#. show notification
   12.35 -#: ../main.c:179
   12.36 +#: xwd-application.c:52
   12.37 +msgid "Enable debugging messages"
   12.38 +msgstr ""
   12.39 +
   12.40 +#: xwd-application.c:54
   12.41 +msgid "Quit running instance of xwrited"
   12.42 +msgstr ""
   12.43 +
   12.44 +#: xwd-application.c:56
   12.45 +msgid "Print the version number and quit"
   12.46 +msgstr "Tampilkan versi kini dan keluar"
   12.47 +
   12.48 +#: xwd-application.c:252
   12.49  msgid "Message received"
   12.50  msgstr "Pesanan diterima"
   12.51 -
   12.52 -#: ../main.c:280
   12.53 -msgid "Show extra debugging information"
   12.54 -msgstr "Tampilkan informasi debug tambahan"
   12.55 -
   12.56 -#: ../main.c:282
   12.57 -msgid "Print the current version and exit"
   12.58 -msgstr "Tampilkan versi kini dan keluar"
   12.59 -
   12.60 -#: ../main.c:321
   12.61 -#, c-format
   12.62 -msgid "xwrited is already running in this session.\n"
   12.63 -msgstr "xwrited sudah berjalan pada sesi ini.\n"
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/xwd-application.c	Sat Jul 28 22:02:24 2018 +0200
    13.3 @@ -0,0 +1,567 @@
    13.4 +/*
    13.5 + * Copyright (C) 2018 Guido Berhoerster <guido+xwrited@berhoerster.name>
    13.6 + *
    13.7 + * Permission is hereby granted, free of charge, to any person obtaining
    13.8 + * a copy of this software and associated documentation files (the
    13.9 + * "Software"), to deal in the Software without restriction, including
   13.10 + * without limitation the rights to use, copy, modify, merge, publish,
   13.11 + * distribute, sublicense, and/or sell copies of the Software, and to
   13.12 + * permit persons to whom the Software is furnished to do so, subject to
   13.13 + * the following conditions:
   13.14 + *
   13.15 + * The above copyright notice and this permission notice shall be included
   13.16 + * in all copies or substantial portions of the Software.
   13.17 + *
   13.18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   13.19 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   13.20 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   13.21 + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   13.22 + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   13.23 + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   13.24 + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   13.25 + */
   13.26 +
   13.27 +#include <errno.h>
   13.28 +#include <fcntl.h>
   13.29 +#include <glib-unix.h>
   13.30 +#include <glib/gi18n.h>
   13.31 +#include <stdio.h>
   13.32 +#include <stdlib.h>
   13.33 +#include <string.h>
   13.34 +
   13.35 +#include "xwd-application.h"
   13.36 +#include "xwd-utmp.h"
   13.37 +
   13.38 +#define	BUFFER_TIMEOUT	500 /* ms */
   13.39 +
   13.40 +struct _XwdApplication {
   13.41 +	GApplication	parent_instance;
   13.42 +	gint		masterfd;
   13.43 +	gint		slavefd;
   13.44 +	GIOChannel	*master_pty_chan;
   13.45 +	guint		buffer_timeout_id;
   13.46 +	GString		*message_buf;
   13.47 +};
   13.48 +
   13.49 +G_DEFINE_TYPE(XwdApplication, xwd_application, G_TYPE_APPLICATION)
   13.50 +
   13.51 +static void	xwd_application_quit(GSimpleAction *, GVariant *, gpointer);
   13.52 +
   13.53 +static const GOptionEntry cmd_options[] = {
   13.54 +    { "debug", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
   13.55 +    N_("Enable debugging messages"), NULL },
   13.56 +    { "quit", 'q', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
   13.57 +    N_("Quit running instance of xwrited"), NULL },
   13.58 +    { "version", 'V', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
   13.59 +    N_("Print the version number and quit"), NULL },
   13.60 +    { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, NULL, NULL, NULL },
   13.61 +    { NULL }
   13.62 +};
   13.63 +
   13.64 +static const GActionEntry xwd_application_actions[] = {
   13.65 +    { "quit", xwd_application_quit }
   13.66 +};
   13.67 +
   13.68 +static void
   13.69 +xwd_application_quit(GSimpleAction *simple, GVariant *parameter,
   13.70 +    gpointer user_data)
   13.71 +{
   13.72 +	XwdApplication	*self = user_data;
   13.73 +
   13.74 +	g_application_quit(G_APPLICATION(self));
   13.75 +}
   13.76 +
   13.77 +static gboolean
   13.78 +on_signal(gpointer user_data)
   13.79 +{
   13.80 +	XwdApplication	*self = user_data;
   13.81 +
   13.82 +	g_debug("received signal, exiting");
   13.83 +	g_action_group_activate_action(G_ACTION_GROUP(G_APPLICATION(self)),
   13.84 +	    "quit", NULL);
   13.85 +
   13.86 +	return (TRUE);
   13.87 +}
   13.88 +
   13.89 +static GString *
   13.90 +string_copy(GString *dest, GString *src)
   13.91 +{
   13.92 +	g_string_truncate(dest, 0);
   13.93 +	g_string_append(dest, src->str);
   13.94 +
   13.95 +	return (dest);
   13.96 +}
   13.97 +
   13.98 +static void
   13.99 +string_to_valid_utf8(GString *string)
  13.100 +{
  13.101 +	GString		*result;
  13.102 +	gchar		*start = string->str;
  13.103 +	gchar		*end;
  13.104 +	gsize		remaining = string->len;
  13.105 +
  13.106 +	result = g_string_sized_new(string->len);
  13.107 +
  13.108 +	while (remaining > 0) {
  13.109 +		if (g_utf8_validate(start, remaining, (const gchar **)&end)) {
  13.110 +			/* remaining part is valid */
  13.111 +			g_string_append_len(result, start, remaining);
  13.112 +			break;
  13.113 +		}
  13.114 +
  13.115 +		/* append valid part */
  13.116 +		g_string_append_len(result, start, end - start);
  13.117 +		/*
  13.118 +		 * replace first invalid byte with Unicode "REPLACEMENT
  13.119 +		 * CHARACTER" (U+FFFD)
  13.120 +		 */
  13.121 +		g_string_append(result, "\357\277\275");
  13.122 +		remaining -= (end - start) + 1;
  13.123 +		start = end + 1;
  13.124 +	}
  13.125 +
  13.126 +	string_copy(string, result);
  13.127 +	g_string_free(result, TRUE);
  13.128 +}
  13.129 +
  13.130 +static void
  13.131 +string_trim_lines(GString *string)
  13.132 +{
  13.133 +	GString		*result;
  13.134 +	gchar		*p = string->str;
  13.135 +	gchar		*q;
  13.136 +	gsize		line_len;
  13.137 +	gsize		remaining = string->len;
  13.138 +
  13.139 +	result = g_string_sized_new(string->len);
  13.140 +
  13.141 +	while (remaining > 0) {
  13.142 +		q = memchr(p, '\n', remaining);
  13.143 +		if (q == NULL) {
  13.144 +			g_string_append_len(result, p, remaining);
  13.145 +			break;
  13.146 +		}
  13.147 +		line_len = q - p - 1;
  13.148 +		/* convert \r\n to \n */
  13.149 +		if ((line_len > 0) && (p[line_len - 1] == '\r')) {
  13.150 +			line_len--;
  13.151 +		}
  13.152 +		/* trim spaces on the right */
  13.153 +		while ((line_len > 0) && (p[line_len - 1] == ' ')) {
  13.154 +			line_len--;
  13.155 +		}
  13.156 +		g_string_append_len(result, p, line_len);
  13.157 +		g_string_append_c(result, '\n');
  13.158 +		remaining -= q + 1 - p;
  13.159 +		p = q + 1;
  13.160 +	}
  13.161 +
  13.162 +	string_copy(string, result);
  13.163 +	g_string_free(result, TRUE);
  13.164 +}
  13.165 +
  13.166 +static void
  13.167 +string_filter_nonprintable(GString *string)
  13.168 +{
  13.169 +	GString		*result;
  13.170 +	const gchar	*p;
  13.171 +	gunichar	c;
  13.172 +
  13.173 +	result = g_string_sized_new(string->len);
  13.174 +
  13.175 +	for (p = string->str; *p != '\0'; p = g_utf8_next_char(p)) {
  13.176 +		c = g_utf8_get_char(p);
  13.177 +		if (g_unichar_isprint(c) || g_unichar_isspace(c)) {
  13.178 +			g_string_append_unichar(result, c);
  13.179 +		}
  13.180 +	}
  13.181 +
  13.182 +	string_copy(string, result);
  13.183 +	g_string_free(result, TRUE);
  13.184 +}
  13.185 +
  13.186 +static gchar *
  13.187 +hexdumpa(const void *mem, gsize n)
  13.188 +{
  13.189 +	const guchar	*bytes = mem;
  13.190 +	GString		*string;
  13.191 +	gsize		i;
  13.192 +	gsize		j;
  13.193 +
  13.194 +	string = g_string_sized_new((n / 16 + (n % 16 > 0)) * 76);
  13.195 +
  13.196 +	for (i = 0; i < n; i += 16) {
  13.197 +		g_string_append_printf(string, "%08zx ", i);
  13.198 +
  13.199 +		for (j = 0; (i + j < n) && (j < 16); j++) {
  13.200 +			g_string_append_printf(string, " %02x", bytes[i + j]);
  13.201 +		}
  13.202 +		for (; j < 16; j++) {
  13.203 +			g_string_append(string, "   ");
  13.204 +		}
  13.205 +
  13.206 +		g_string_append(string, "  ");
  13.207 +		for (j = 0; (i + j < n) && (j < 16); j++) {
  13.208 +			g_string_append_printf(string, "%c",
  13.209 +			    g_ascii_isprint(bytes[i + j]) ? bytes[i + j] : '.');
  13.210 +		}
  13.211 +
  13.212 +		g_string_append_c(string, '\n');
  13.213 +	}
  13.214 +
  13.215 +	return (g_string_free(string, FALSE));
  13.216 +}
  13.217 +
  13.218 +static void
  13.219 +display_message(XwdApplication *self)
  13.220 +{
  13.221 +	gboolean	enable_debug_logging;
  13.222 +	gchar		*message_dump;
  13.223 +	GString		*message;
  13.224 +	GIcon		*icon;
  13.225 +	GNotification	*notification;
  13.226 +
  13.227 +	if (self->message_buf->len == 0) {
  13.228 +		return;
  13.229 +	}
  13.230 +
  13.231 +	enable_debug_logging = (g_getenv("G_MESSAGES_DEBUG") != NULL);
  13.232 +	if (enable_debug_logging)  {
  13.233 +		message_dump = hexdumpa(self->message_buf->str,
  13.234 +		    self->message_buf->len);
  13.235 +		g_debug("raw message:\n%s", message_dump);
  13.236 +		g_free(message_dump);
  13.237 +	}
  13.238 +
  13.239 +	/*
  13.240 +	 * There is no reliable way to determine the character encoding of the
  13.241 +	 * received message which, depending on the locale of the sender, may
  13.242 +	 * even differ for different messages. A user could even send binary
  13.243 +	 * data. It is thus assumed that messages are in UTF-8 encoding which
  13.244 +	 * should be the most common case on modern systems. Any invalid
  13.245 +	 * sequences are replaced with the Unicode "REPLACEMENT CHARACTER"
  13.246 +	 * (U+FFFD) and non-printable characters are removed. Additionally,
  13.247 +	 * padding typically added by wall(1) implementations is removed in
  13.248 +	 * order to improve readability.
  13.249 +	 */
  13.250 +	message = g_string_new_len(self->message_buf->str,
  13.251 +	    self->message_buf->len);
  13.252 +	string_to_valid_utf8(message);
  13.253 +	string_filter_nonprintable(message);
  13.254 +	string_trim_lines(message);
  13.255 +
  13.256 +	if (enable_debug_logging)  {
  13.257 +		message_dump = hexdumpa(message->str, message->len);
  13.258 +		g_debug("message:\n%s", message_dump);
  13.259 +		g_free(message_dump);
  13.260 +	}
  13.261 +
  13.262 +	icon = g_themed_icon_new("utilities-terminal");
  13.263 +
  13.264 +	notification = g_notification_new(_("Message received"));
  13.265 +	g_notification_set_icon(notification, icon);
  13.266 +	g_notification_set_body(notification, message->str);
  13.267 +	g_application_send_notification(G_APPLICATION(self), NULL,
  13.268 +	    notification);
  13.269 +
  13.270 +	g_object_unref(notification);
  13.271 +	g_object_unref(icon);
  13.272 +	g_string_free(message, TRUE);
  13.273 +	g_string_truncate(self->message_buf, 0);
  13.274 +}
  13.275 +
  13.276 +static gboolean
  13.277 +on_buffer_timeout(gpointer user_data)
  13.278 +{
  13.279 +	XwdApplication	*self = user_data;
  13.280 +
  13.281 +	display_message(self);
  13.282 +
  13.283 +	self->buffer_timeout_id = 0;
  13.284 +
  13.285 +	return (FALSE);
  13.286 +}
  13.287 +
  13.288 +static gboolean
  13.289 +on_master_pty_readable(GIOChannel *source, GIOCondition cond,
  13.290 +    gpointer user_data)
  13.291 +{
  13.292 +	XwdApplication	*self = user_data;
  13.293 +	GIOStatus	status;
  13.294 +	gchar		buf[BUFSIZ];
  13.295 +	gsize		buf_len = 0;
  13.296 +	GError		*error = NULL;
  13.297 +
  13.298 +	if (cond & G_IO_IN) {
  13.299 +		/* read message data from master pty */
  13.300 +		memset(buf, 0, sizeof (buf));
  13.301 +		while ((status = g_io_channel_read_chars(source, (gchar *)&buf,
  13.302 +		    sizeof (buf), &buf_len, &error)) == G_IO_STATUS_NORMAL) {
  13.303 +			if (buf_len > 0) {
  13.304 +				g_debug("read %" G_GSSIZE_FORMAT " bytes from "
  13.305 +				    "master pty", buf_len);
  13.306 +				g_string_append_len(self->message_buf, buf,
  13.307 +				    buf_len);
  13.308 +			}
  13.309 +		}
  13.310 +		if (error != NULL) {
  13.311 +			g_critical("failed to read from master pty: %s",
  13.312 +			    error->message);
  13.313 +			g_error_free(error);
  13.314 +			return (FALSE);
  13.315 +		}
  13.316 +
  13.317 +		/*
  13.318 +		 * a message might be read in several parts and it is not
  13.319 +		 * possible to reliably detect the beginning or end of a
  13.320 +		 * message, so buffer read data until a short timeout is
  13.321 +		 * reached as this works well for a single message which should
  13.322 +		 * be the most common case
  13.323 +		 */
  13.324 +		if (self->buffer_timeout_id == 0) {
  13.325 +			self->buffer_timeout_id = g_timeout_add(BUFFER_TIMEOUT,
  13.326 +			    on_buffer_timeout, self);
  13.327 +		}
  13.328 +	}
  13.329 +
  13.330 +	if (cond & (G_IO_HUP | G_IO_ERR)) {
  13.331 +		g_critical("connection to master pty broken");
  13.332 +		return (FALSE);
  13.333 +	}
  13.334 +
  13.335 +	return (TRUE);
  13.336 +}
  13.337 +
  13.338 +static void
  13.339 +xwd_application_startup(GApplication *application)
  13.340 +{
  13.341 +	XwdApplication	*self = XWD_APPLICATION(application);
  13.342 +	gchar		*slave_name;
  13.343 +	GIOFlags	flags;
  13.344 +	GError		*error = NULL;
  13.345 +
  13.346 +	G_APPLICATION_CLASS(xwd_application_parent_class)->startup(application);
  13.347 +
  13.348 +	/* create actions */
  13.349 +	g_action_map_add_action_entries(G_ACTION_MAP(self),
  13.350 +	    xwd_application_actions, G_N_ELEMENTS(xwd_application_actions),
  13.351 +	    self);
  13.352 +
  13.353 +	/* create signal watchers */
  13.354 +	g_unix_signal_add(SIGINT, on_signal, self);
  13.355 +	g_unix_signal_add(SIGTERM, on_signal, self);
  13.356 +	g_unix_signal_add(SIGHUP, on_signal, self);
  13.357 +
  13.358 +	/* open master pty */
  13.359 +	self->masterfd = posix_openpt(O_RDWR | O_NOCTTY);
  13.360 +	if (self->masterfd == -1) {
  13.361 +		g_critical("failed to open master pty: %s", g_strerror(errno));
  13.362 +		return;
  13.363 +	}
  13.364 +
  13.365 +	/* create slave pty */
  13.366 +	if ((grantpt(self->masterfd) == -1) ||
  13.367 +	    (unlockpt(self->masterfd) == -1)) {
  13.368 +		g_critical("failed to create slave pty: %s", g_strerror(errno));
  13.369 +		return;
  13.370 +	}
  13.371 +	slave_name = ptsname(self->masterfd);
  13.372 +	if (slave_name == NULL) {
  13.373 +		g_critical("failed to obtain name of slave pty");
  13.374 +		return;
  13.375 +	}
  13.376 +
  13.377 +	/*
  13.378 +	 * keep an open fd around order to prevent closing the master fd when
  13.379 +	 * receiving an EOF
  13.380 +	 */
  13.381 +	self->slavefd = open(slave_name, O_RDWR);
  13.382 +	if (self->slavefd == -1) {
  13.383 +		g_critical("failed to open slave pty: %s", g_strerror(errno));
  13.384 +		return;
  13.385 +	}
  13.386 +
  13.387 +	/* create a GIOChannel for monitoring the master pty for messages */
  13.388 +	self->master_pty_chan = g_io_channel_unix_new(self->masterfd);
  13.389 +	/* make it non-blocking */
  13.390 +	flags = g_io_channel_get_flags(self->master_pty_chan);
  13.391 +	if (g_io_channel_set_flags(self->master_pty_chan,
  13.392 +	    flags | G_IO_FLAG_NONBLOCK, &error) != G_IO_STATUS_NORMAL) {
  13.393 +		g_critical("failed set flags on the master pty channel: %s",
  13.394 +		    error->message);
  13.395 +		g_error_free(error);
  13.396 +		return;
  13.397 +	}
  13.398 +	/* make the channel safe for encodings other than UTF-8 */
  13.399 +	if (g_io_channel_set_encoding(self->master_pty_chan, NULL, &error) !=
  13.400 +	    G_IO_STATUS_NORMAL) {
  13.401 +		g_critical("failed set encoding on the master pty channel: %s",
  13.402 +		    error->message);
  13.403 +		g_error_free(error);
  13.404 +		return;
  13.405 +	}
  13.406 +	if (!g_io_add_watch(self->master_pty_chan,
  13.407 +	    G_IO_IN | G_IO_HUP | G_IO_ERR, on_master_pty_readable, self)) {
  13.408 +		g_critical("failed to add watch on master pty channel");
  13.409 +		return;
  13.410 +	}
  13.411 +
  13.412 +	xwd_utmp_add_entry(self->masterfd);
  13.413 +
  13.414 +	/* keep GApplication running */
  13.415 +	g_application_hold(application);
  13.416 +}
  13.417 +
  13.418 +static void
  13.419 +xwd_application_shutdown(GApplication *application)
  13.420 +{
  13.421 +	XwdApplication	*self = XWD_APPLICATION(application);
  13.422 +	GApplicationClass *application_class =
  13.423 +	    G_APPLICATION_CLASS(xwd_application_parent_class);
  13.424 +
  13.425 +	/* display any buffered data before exiting */
  13.426 +	display_message(self);
  13.427 +
  13.428 +	if (self->master_pty_chan != NULL) {
  13.429 +		g_io_channel_shutdown(self->master_pty_chan, FALSE, NULL);
  13.430 +		g_clear_pointer(&self->master_pty_chan,
  13.431 +		    (GDestroyNotify)g_io_channel_unref);
  13.432 +	}
  13.433 +
  13.434 +	if (self->slavefd != -1) {
  13.435 +		close(self->slavefd);
  13.436 +		self->slavefd = -1;
  13.437 +	}
  13.438 +
  13.439 +	if (self->masterfd != -1) {
  13.440 +		close(self->masterfd);
  13.441 +		self->masterfd = -1;
  13.442 +	}
  13.443 +
  13.444 +	xwd_utmp_remove_entry(self->masterfd);
  13.445 +
  13.446 +	/* remove signal watches and buffer timeout */
  13.447 +	while (g_source_remove_by_user_data(self)) {
  13.448 +		continue;
  13.449 +	}
  13.450 +	self->buffer_timeout_id = 0;
  13.451 +
  13.452 +	application_class->shutdown(application);
  13.453 +}
  13.454 +
  13.455 +static gint
  13.456 +xwd_application_handle_local_options(GApplication *application,
  13.457 +    GVariantDict *options)
  13.458 +{
  13.459 +	gchar		**args = NULL;
  13.460 +	gchar		*messages_debug;
  13.461 +	GError		*error = NULL;
  13.462 +
  13.463 +	/* filename arguments are not allowed */
  13.464 +	if (g_variant_dict_lookup(options, G_OPTION_REMAINING, "^a&ay",
  13.465 +	    &args)) {
  13.466 +		g_printerr("invalid argument: \"%s\"\n", args[0]);
  13.467 +		g_free(args);
  13.468 +		return (1);
  13.469 +	}
  13.470 +
  13.471 +	if (g_variant_dict_contains(options, "version")) {
  13.472 +		g_print("%s %s\n", PACKAGE, VERSION);
  13.473 +
  13.474 +		/* quit */
  13.475 +		return (0);
  13.476 +	}
  13.477 +
  13.478 +	if (g_variant_dict_contains(options, "debug")) {
  13.479 +		/* enable debug logging */
  13.480 +		messages_debug = g_strjoin(":", G_LOG_DOMAIN,
  13.481 +		    g_getenv("G_MESSAGES_DEBUG"), NULL);
  13.482 +		g_setenv("G_MESSAGES_DEBUG", messages_debug, TRUE);
  13.483 +		g_free(messages_debug);
  13.484 +	}
  13.485 +
  13.486 +	/*
  13.487 +	 * register with the session bus so that it is possible to discern
  13.488 +	 * between remote and primary instance and that remote actions can be
  13.489 +	 * invoked, this causes the startup signal to be emitted which, in case
  13.490 +	 * of the primary instance, starts to instantiate the
  13.491 +	 * backend with the given values
  13.492 +	 */
  13.493 +	if (!g_application_register(application, NULL, &error)) {
  13.494 +		g_critical("g_application_register: %s", error->message);
  13.495 +		g_error_free(error);
  13.496 +		return (1);
  13.497 +	}
  13.498 +
  13.499 +	if (g_variant_dict_contains(options, "quit")) {
  13.500 +		/* only valid if a remote instance is running */
  13.501 +		if (!g_application_get_is_remote(application)) {
  13.502 +			g_printerr("%s is not running\n", g_get_prgname());
  13.503 +			return (1);
  13.504 +		}
  13.505 +
  13.506 +		/* signal remote instance to quit */
  13.507 +		g_action_group_activate_action(G_ACTION_GROUP(application),
  13.508 +		    "quit", NULL);
  13.509 +
  13.510 +		/* quit local instance */
  13.511 +		return (0);
  13.512 +	}
  13.513 +
  13.514 +	/* proceed with default command line processing */
  13.515 +	return (-1);
  13.516 +}
  13.517 +
  13.518 +static void
  13.519 +xwd_application_activate(GApplication *application) {
  13.520 +	GApplicationClass *application_class =
  13.521 +	    G_APPLICATION_CLASS(xwd_application_parent_class);
  13.522 +
  13.523 +	/* do nothing, implementation required by GApplication */
  13.524 +
  13.525 +	application_class->activate(application);
  13.526 +}
  13.527 +
  13.528 +static void
  13.529 +xwd_application_finalize(GObject *object)
  13.530 +{
  13.531 +	XwdApplication	*self = XWD_APPLICATION(object);
  13.532 +
  13.533 +	g_string_free(self->message_buf, TRUE);
  13.534 +
  13.535 +	G_OBJECT_CLASS(xwd_application_parent_class)->finalize(object);
  13.536 +}
  13.537 +
  13.538 +static void
  13.539 +xwd_application_class_init(XwdApplicationClass *klass)
  13.540 +{
  13.541 +	GObjectClass	*object_class = G_OBJECT_CLASS(klass);
  13.542 +	GApplicationClass *application_class = G_APPLICATION_CLASS(klass);
  13.543 +
  13.544 +	object_class->finalize = xwd_application_finalize;
  13.545 +
  13.546 +	application_class->startup = xwd_application_startup;
  13.547 +	application_class->shutdown = xwd_application_shutdown;
  13.548 +	application_class->handle_local_options =
  13.549 +	    xwd_application_handle_local_options;
  13.550 +	application_class->activate = xwd_application_activate;
  13.551 +}
  13.552 +
  13.553 +static void
  13.554 +xwd_application_init(XwdApplication *self)
  13.555 +{
  13.556 +	g_application_add_main_option_entries(G_APPLICATION(self),
  13.557 +	    cmd_options);
  13.558 +
  13.559 +	self->masterfd = -1;
  13.560 +	self->slavefd = -1;
  13.561 +
  13.562 +	self->message_buf = g_string_sized_new(BUFSIZ);
  13.563 +}
  13.564 +
  13.565 +XwdApplication *
  13.566 +xwd_application_new(void)
  13.567 +{
  13.568 +	return (g_object_new(XWD_TYPE_APPLICATION, "application-id",
  13.569 +	    APPLICATION_ID, NULL));
  13.570 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/xwd-application.h	Sat Jul 28 22:02:24 2018 +0200
    14.3 @@ -0,0 +1,41 @@
    14.4 +/*
    14.5 + * Copyright (C) 2018 Guido Berhoerster <guido+xwd@berhoerster.name>
    14.6 + *
    14.7 + * Permission is hereby granted, free of charge, to any person obtaining
    14.8 + * a copy of this software and associated documentation files (the
    14.9 + * "Software"), to deal in the Software without restriction, including
   14.10 + * without limitation the rights to use, copy, modify, merge, publish,
   14.11 + * distribute, sublicense, and/or sell copies of the Software, and to
   14.12 + * permit persons to whom the Software is furnished to do so, subject to
   14.13 + * the following conditions:
   14.14 + *
   14.15 + * The above copyright notice and this permission notice shall be included
   14.16 + * in all copies or substantial portions of the Software.
   14.17 + *
   14.18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   14.19 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   14.20 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   14.21 + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   14.22 + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   14.23 + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   14.24 + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   14.25 + */
   14.26 +
   14.27 +#ifndef	XWD_APPLICATION_H
   14.28 +#define	XWD_APPLICATION_H
   14.29 +
   14.30 +#include <gio/gio.h>
   14.31 +#include <glib-object.h>
   14.32 +
   14.33 +G_BEGIN_DECLS
   14.34 +
   14.35 +#define	XWD_TYPE_APPLICATION	(xwd_application_get_type())
   14.36 +
   14.37 +G_DECLARE_FINAL_TYPE(XwdApplication, xwd_application, XWD,
   14.38 +    APPLICATION, GApplication)
   14.39 +
   14.40 +XwdApplication *	xwd_application_new(void);
   14.41 +
   14.42 +G_END_DECLS
   14.43 +
   14.44 +#endif /* !XWD_APPLICATION_H */
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/xwd-utmp-utempter.c	Sat Jul 28 22:02:24 2018 +0200
    15.3 @@ -0,0 +1,43 @@
    15.4 +/*
    15.5 + * Copyright (C) 2010 Guido Berhoerster <guido+xwd@berhoerster.name>
    15.6 + *
    15.7 + * Permission is hereby granted, free of charge, to any person obtaining
    15.8 + * a copy of this software and associated documentation files (the
    15.9 + * "Software"), to deal in the Software without restriction, including
   15.10 + * without limitation the rights to use, copy, modify, merge, publish,
   15.11 + * distribute, sublicense, and/or sell copies of the Software, and to
   15.12 + * permit persons to whom the Software is furnished to do so, subject to
   15.13 + * the following conditions:
   15.14 + *
   15.15 + * The above copyright notice and this permission notice shall be included
   15.16 + * in all copies or substantial portions of the Software.
   15.17 + *
   15.18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   15.19 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   15.20 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   15.21 + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   15.22 + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   15.23 + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   15.24 + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   15.25 + */
   15.26 +
   15.27 +#include <stdlib.h>
   15.28 +#include <utempter.h>
   15.29 +
   15.30 +void
   15.31 +xwd_utmp_add_entry(int fd)
   15.32 +{
   15.33 +	char	*pty_name;
   15.34 +
   15.35 +	pty_name = ptsname(fd);
   15.36 +	addToUtmp(pty_name, NULL, fd);
   15.37 +}
   15.38 +
   15.39 +void
   15.40 +xwd_utmp_remove_entry(int fd)
   15.41 +{
   15.42 +	char	*pty_name;
   15.43 +
   15.44 +	pty_name = ptsname(fd);
   15.45 +	removeLineFromUtmp(pty_name, fd);
   15.46 +}
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/xwd-utmp-utmpx.c	Sat Jul 28 22:02:24 2018 +0200
    16.3 @@ -0,0 +1,93 @@
    16.4 +/*
    16.5 + * Copyright (C) 2010 Guido Berhoerster <guido+xwd@berhoerster.name>
    16.6 + *
    16.7 + * Permission is hereby granted, free of charge, to any person obtaining
    16.8 + * a copy of this software and associated documentation files (the
    16.9 + * "Software"), to deal in the Software without restriction, including
   16.10 + * without limitation the rights to use, copy, modify, merge, publish,
   16.11 + * distribute, sublicense, and/or sell copies of the Software, and to
   16.12 + * permit persons to whom the Software is furnished to do so, subject to
   16.13 + * the following conditions:
   16.14 + *
   16.15 + * The above copyright notice and this permission notice shall be included
   16.16 + * in all copies or substantial portions of the Software.
   16.17 + *
   16.18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   16.19 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   16.20 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   16.21 + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   16.22 + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   16.23 + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   16.24 + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   16.25 + */
   16.26 +
   16.27 +#include <glib.h>
   16.28 +#include <stdlib.h>
   16.29 +#include <string.h>
   16.30 +#include <unistd.h>
   16.31 +#include <pwd.h>
   16.32 +#include <utmpx.h>
   16.33 +#include <errno.h>
   16.34 +#include <sys/time.h>
   16.35 +
   16.36 +#ifndef	DEV_PREFIX
   16.37 +#define	DEV_PREFIX	"/dev/"
   16.38 +#endif /* !DEV_PREFIX */
   16.39 +
   16.40 +static void
   16.41 +utmp_write_entry(int fd, gboolean add)
   16.42 +{
   16.43 +	struct utmpx	utmpx;
   16.44 +	char		*line = NULL;
   16.45 +	size_t		line_len;
   16.46 +	char		*id;
   16.47 +	struct passwd	*pwd;
   16.48 +
   16.49 +	line = ptsname(fd);
   16.50 +	if (line == NULL) {
   16.51 +		g_critical("failed to obtain slave pty name");
   16.52 +		return;
   16.53 +	}
   16.54 +	if (g_str_has_prefix(line, DEV_PREFIX)) {
   16.55 +		line += strlen(DEV_PREFIX);
   16.56 +	}
   16.57 +
   16.58 +	line_len = strlen(line);
   16.59 +	id = (line_len >= sizeof (utmpx.ut_pid)) ?
   16.60 +	    line + (line_len - sizeof (utmpx.ut_pid)) :
   16.61 +	    line;
   16.62 +
   16.63 +	pwd = getpwuid(getuid());
   16.64 +	if (pwd == NULL) {
   16.65 +		g_critical("failed to get username: %s", g_strerror(errno));
   16.66 +		return;
   16.67 +	}
   16.68 +
   16.69 +	memset(&utmpx, 0, sizeof (utmpx));
   16.70 +	strncpy(utmpx.ut_name, pwd->pw_name, sizeof (utmpx.ut_name));
   16.71 +	strncpy(utmpx.ut_id, id, sizeof (utmpx.ut_id));
   16.72 +	strncpy(utmpx.ut_line, line, sizeof (utmpx.ut_line));
   16.73 +	utmpx.ut_pid = getpid();
   16.74 +	utmpx.ut_type = add ? USER_PROCESS : DEAD_PROCESS;
   16.75 +	gettimeofday(&utmpx.ut_tv, NULL);
   16.76 +
   16.77 +	setutxent();
   16.78 +	if (pututxline(&utmpx) == NULL) {
   16.79 +		g_critical("failed to write to utmpx database: %s",
   16.80 +		    g_strerror(errno));
   16.81 +		return;
   16.82 +	}
   16.83 +	endutxent();
   16.84 +}
   16.85 +
   16.86 +void
   16.87 +xwd_utmp_add_entry(int fd)
   16.88 +{
   16.89 +	utmp_write_entry(fd, TRUE);
   16.90 +}
   16.91 +
   16.92 +void
   16.93 +xwd_utmp_remove_entry(int fd)
   16.94 +{
   16.95 +	utmp_write_entry(fd, FALSE);
   16.96 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/xwd-utmp.h	Sat Jul 28 22:02:24 2018 +0200
    17.3 @@ -0,0 +1,36 @@
    17.4 +/*
    17.5 + * Copyright (C) 2010 Guido Berhoerster <guido+xwrited@berhoerster.name>
    17.6 + *
    17.7 + * Permission is hereby granted, free of charge, to any person obtaining
    17.8 + * a copy of this software and associated documentation files (the
    17.9 + * "Software"), to deal in the Software without restriction, including
   17.10 + * without limitation the rights to use, copy, modify, merge, publish,
   17.11 + * distribute, sublicense, and/or sell copies of the Software, and to
   17.12 + * permit persons to whom the Software is furnished to do so, subject to
   17.13 + * the following conditions:
   17.14 + *
   17.15 + * The above copyright notice and this permission notice shall be included
   17.16 + * in all copies or substantial portions of the Software.
   17.17 + *
   17.18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   17.19 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   17.20 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   17.21 + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   17.22 + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   17.23 + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   17.24 + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   17.25 + */
   17.26 +
   17.27 +#ifndef	XWD_UTMP_H
   17.28 +#define	XWD_UTMP_H
   17.29 +
   17.30 +#include <glib.h>
   17.31 +
   17.32 +G_BEGIN_DECLS
   17.33 +
   17.34 +void	xwd_utmp_add_entry(int);
   17.35 +void	xwd_utmp_remove_entry(int);
   17.36 +
   17.37 +G_END_DECLS
   17.38 +
   17.39 +#endif /* XWD_UTMP_H */
    18.1 --- a/xwrited-debug.c	Wed Sep 14 09:46:59 2016 +0200
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,69 +0,0 @@
    18.4 -/*
    18.5 - * Copyright (C) 2014 Guido Berhoerster <guido+xwrited@berhoerster.name>
    18.6 - *
    18.7 - * Permission is hereby granted, free of charge, to any person obtaining
    18.8 - * a copy of this software and associated documentation files (the
    18.9 - * "Software"), to deal in the Software without restriction, including
   18.10 - * without limitation the rights to use, copy, modify, merge, publish,
   18.11 - * distribute, sublicense, and/or sell copies of the Software, and to
   18.12 - * permit persons to whom the Software is furnished to do so, subject to
   18.13 - * the following conditions:
   18.14 - *
   18.15 - * The above copyright notice and this permission notice shall be included
   18.16 - * in all copies or substantial portions of the Software.
   18.17 - *
   18.18 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   18.19 - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   18.20 - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   18.21 - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   18.22 - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   18.23 - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   18.24 - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   18.25 - */
   18.26 -
   18.27 -#include <string.h>
   18.28 -#include <stdarg.h>
   18.29 -#include <glib.h>
   18.30 -
   18.31 -#include "xwrited-debug.h"
   18.32 -
   18.33 -#if !GLIB_CHECK_VERSION(2, 32, 0)
   18.34 -static void
   18.35 -dummy_log_handler(const gchar *log_domain, GLogLevelFlags log_level,
   18.36 -    const gchar *message, gpointer data)
   18.37 -{
   18.38 -	/* drop all messages */
   18.39 -}
   18.40 -#endif /* !GLIB_CHECK_VERSION (2,32,0) */
   18.41 -
   18.42 -void
   18.43 -xwrited_debug_init(gboolean debug_mode)
   18.44 -{
   18.45 -	/*
   18.46 -	 * glib >= 2.32 only shows debug messages if the G_MESSAGES_DEBUG
   18.47 -	 * environment variable contains the log domain or "all", earlier glib
   18.48 -	 * version always show debugging output
   18.49 -	 */
   18.50 -#if GLIB_CHECK_VERSION(2, 32, 0)
   18.51 -	const gchar	*debug_env;
   18.52 -	gchar		*debug_env_new;
   18.53 -
   18.54 -	if (debug_mode) {
   18.55 -		debug_env = g_getenv("G_MESSAGES_DEBUG");
   18.56 -
   18.57 -		if (debug_env == NULL) {
   18.58 -			g_setenv("G_MESSAGES_DEBUG", G_LOG_DOMAIN, TRUE);
   18.59 -		} else if (strstr(debug_env, G_LOG_DOMAIN) == NULL) {
   18.60 -			debug_env_new = g_strdup_printf("%s %s", debug_env,
   18.61 -			    G_LOG_DOMAIN);
   18.62 -			g_setenv("G_MESSAGES_DEBUG", debug_env_new, TRUE);
   18.63 -			g_free(debug_env_new);
   18.64 -		}
   18.65 -	}
   18.66 -#else
   18.67 -	if (!debug_mode) {
   18.68 -		g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
   18.69 -		    dummy_log_handler, NULL);
   18.70 -	}
   18.71 -#endif /* GLIB_CHECK_VERSION (2,32,0) */
   18.72 -}
    19.1 --- a/xwrited-debug.h	Wed Sep 14 09:46:59 2016 +0200
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,35 +0,0 @@
    19.4 -/*
    19.5 - * Copyright (C) 2011 Guido Berhoerster <guido+xwrited@berhoerster.name>
    19.6 - *
    19.7 - * Permission is hereby granted, free of charge, to any person obtaining
    19.8 - * a copy of this software and associated documentation files (the
    19.9 - * "Software"), to deal in the Software without restriction, including
   19.10 - * without limitation the rights to use, copy, modify, merge, publish,
   19.11 - * distribute, sublicense, and/or sell copies of the Software, and to
   19.12 - * permit persons to whom the Software is furnished to do so, subject to
   19.13 - * the following conditions:
   19.14 - *
   19.15 - * The above copyright notice and this permission notice shall be included
   19.16 - * in all copies or substantial portions of the Software.
   19.17 - *
   19.18 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   19.19 - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   19.20 - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   19.21 - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   19.22 - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   19.23 - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   19.24 - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   19.25 - */
   19.26 -
   19.27 -#ifndef	XWRITED_DEBUG_H
   19.28 -#define	XWRITED_DEBUG_H
   19.29 -
   19.30 -#include <glib.h>
   19.31 -
   19.32 -G_BEGIN_DECLS
   19.33 -
   19.34 -void	xwrited_debug_init(gboolean);
   19.35 -
   19.36 -G_END_DECLS
   19.37 -
   19.38 -#endif /* XWRITED_DEBUG_H */
    20.1 --- a/xwrited-unique.c	Wed Sep 14 09:46:59 2016 +0200
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,288 +0,0 @@
    20.4 -/*
    20.5 - * Copyright (C) 2014 Guido Berhoerster <guido+xwrited@berhoerster.name>
    20.6 - *
    20.7 - * Permission is hereby granted, free of charge, to any person obtaining
    20.8 - * a copy of this software and associated documentation files (the
    20.9 - * "Software"), to deal in the Software without restriction, including
   20.10 - * without limitation the rights to use, copy, modify, merge, publish,
   20.11 - * distribute, sublicense, and/or sell copies of the Software, and to
   20.12 - * permit persons to whom the Software is furnished to do so, subject to
   20.13 - * the following conditions:
   20.14 - *
   20.15 - * The above copyright notice and this permission notice shall be included
   20.16 - * in all copies or substantial portions of the Software.
   20.17 - *
   20.18 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   20.19 - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   20.20 - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   20.21 - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   20.22 - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   20.23 - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   20.24 - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   20.25 - */
   20.26 -
   20.27 -#include <glib.h>
   20.28 -#ifdef	HAVE_GLIB_GDBUS
   20.29 -#include <gio/gio.h>
   20.30 -#else
   20.31 -#include <dbus/dbus-glib.h>
   20.32 -#endif /* HAVE_GLIB_GDBUS */
   20.33 -#include <dbus/dbus.h>
   20.34 -
   20.35 -#include "xwrited-unique.h"
   20.36 -
   20.37 -G_DEFINE_TYPE(XWritedUnique, xwrited_unique, G_TYPE_OBJECT)
   20.38 -
   20.39 -#define	XWRITED_UNIQUE_GET_PRIVATE(obj)	(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
   20.40 -    XWRITED_TYPE_UNIQUE, XWritedUniquePrivate))
   20.41 -
   20.42 -struct	_XWritedUniquePrivate {
   20.43 -#ifdef HAVE_GLIB_GDBUS
   20.44 -	GDBusProxy	*session_bus_proxy;
   20.45 -#else
   20.46 -	DBusGConnection	*session_bus;
   20.47 -	DBusGProxy	*session_bus_proxy;
   20.48 -#endif /* HAVE_GLIB_GDBUS */
   20.49 -	gchar		*name;
   20.50 -	gboolean	is_unique;
   20.51 -};
   20.52 -
   20.53 -enum {
   20.54 -	PROP_0,
   20.55 -	PROP_NAME,
   20.56 -	PROP_IS_XWRITED_UNIQUE
   20.57 -};
   20.58 -
   20.59 -static gboolean
   20.60 -request_name(XWritedUnique *self)
   20.61 -{
   20.62 -	guint32	request_name_response;
   20.63 -	GError	*error = NULL;
   20.64 -#ifdef HAVE_GLIB_GDBUS
   20.65 -	GVariant *result;
   20.66 -
   20.67 -	g_return_val_if_fail(self->priv->session_bus_proxy != NULL, FALSE);
   20.68 -
   20.69 -	result = g_dbus_proxy_call_sync(self->priv->session_bus_proxy,
   20.70 -	    "RequestName", g_variant_new("(su)", self->priv->name,
   20.71 -	    DBUS_NAME_FLAG_DO_NOT_QUEUE), G_DBUS_CALL_FLAGS_NONE, -1, NULL,
   20.72 -	    &error);
   20.73 -	if (result == NULL) {
   20.74 -		g_warning("failed to acquire service name \"%s\": %s",
   20.75 -		    self->priv->name, error->message);
   20.76 -		g_error_free(error);
   20.77 -		return (FALSE);
   20.78 -	}
   20.79 -
   20.80 -	g_variant_get(result, "(u)", &request_name_response);
   20.81 -	g_variant_unref(result);
   20.82 -#else
   20.83 -
   20.84 -	g_return_val_if_fail(self->priv->session_bus != NULL, FALSE);
   20.85 -	g_return_val_if_fail(self->priv->session_bus_proxy != NULL, FALSE);
   20.86 -	if (dbus_g_proxy_call(self->priv->session_bus_proxy, "RequestName",
   20.87 -	    &error, G_TYPE_STRING, self->priv->name, G_TYPE_UINT,
   20.88 -	    DBUS_NAME_FLAG_DO_NOT_QUEUE, G_TYPE_INVALID, G_TYPE_UINT,
   20.89 -	    &request_name_response, G_TYPE_INVALID) == 0) {
   20.90 -		g_warning("failed to acquire service name \"%s\": %s",
   20.91 -		    self->priv->name, error->message);
   20.92 -		g_error_free(error);
   20.93 -		return (FALSE);
   20.94 -	}
   20.95 -#endif /* HAVE_GLIB_GDBUS */
   20.96 -
   20.97 -	switch (request_name_response) {
   20.98 -	case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
   20.99 -		return (TRUE);
  20.100 -	case DBUS_REQUEST_NAME_REPLY_EXISTS:
  20.101 -		break;
  20.102 -	default:
  20.103 -		g_warning("failed to acquire service name \"%s\"",
  20.104 -		    self->priv->name);
  20.105 -	}
  20.106 -
  20.107 -	return (FALSE);
  20.108 -}
  20.109 -
  20.110 -static void
  20.111 -xwrited_unique_get_property(GObject *gobject, guint property_id, GValue *value,
  20.112 -    GParamSpec *pspec)
  20.113 -{
  20.114 -	XWritedUnique	*app = XWRITED_UNIQUE(gobject);
  20.115 -
  20.116 -	switch (property_id) {
  20.117 -	case PROP_NAME:
  20.118 -		g_value_set_string(value, app->priv->name);
  20.119 -		break;
  20.120 -	case PROP_IS_XWRITED_UNIQUE:
  20.121 -		g_value_set_boolean(value, app->priv->is_unique);
  20.122 -		break;
  20.123 -	default:
  20.124 -		G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id,
  20.125 -		    pspec);
  20.126 -	}
  20.127 -}
  20.128 -
  20.129 -static void
  20.130 -xwrited_unique_set_property(GObject *gobject, guint property_id,
  20.131 -    const GValue *value, GParamSpec *pspec)
  20.132 -{
  20.133 -	XWritedUnique	*app = XWRITED_UNIQUE(gobject);
  20.134 -
  20.135 -	switch (property_id) {
  20.136 -	case PROP_NAME:
  20.137 -		app->priv->name = g_strdup(g_value_get_string(value));
  20.138 -		break;
  20.139 -	default:
  20.140 -		G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id,
  20.141 -		    pspec);
  20.142 -	}
  20.143 -}
  20.144 -
  20.145 -static GObject *
  20.146 -xwrited_unique_constructor(GType gtype, guint n_params,
  20.147 -    GObjectConstructParam *params)
  20.148 -{
  20.149 -	GObjectClass	*parent_class;
  20.150 -	GObject		*gobject;
  20.151 -	XWritedUnique	*app;
  20.152 -	GError		*error = NULL;
  20.153 -
  20.154 -	parent_class = G_OBJECT_CLASS(xwrited_unique_parent_class);
  20.155 -	gobject = parent_class->constructor(gtype, n_params, params);
  20.156 -	app = XWRITED_UNIQUE(gobject);
  20.157 -
  20.158 -#ifdef HAVE_GLIB_GDBUS
  20.159 -	app->priv->session_bus_proxy =
  20.160 -	    g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
  20.161 -		G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
  20.162 -		G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, DBUS_SERVICE_DBUS,
  20.163 -		DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, NULL, &error);
  20.164 -	if (app->priv->session_bus_proxy == NULL) {
  20.165 -		g_warning("failed to create DBus proxy: %s", error->message);
  20.166 -		g_error_free(error);
  20.167 -		goto out;
  20.168 -	}
  20.169 -#else
  20.170 -	app->priv->session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
  20.171 -	if (app->priv->session_bus == NULL) {
  20.172 -		g_warning("failed to connect to DBus session bus: %s",
  20.173 -		    error->message);
  20.174 -		g_error_free(error);
  20.175 -		goto out;
  20.176 -	}
  20.177 -
  20.178 -	app->priv->session_bus_proxy =
  20.179 -	    dbus_g_proxy_new_for_name(app->priv->session_bus,
  20.180 -	    DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
  20.181 -	if (app->priv->session_bus_proxy == NULL) {
  20.182 -		g_warning("failed to create DBus proxy");
  20.183 -		goto out;
  20.184 -	}
  20.185 -#endif /* HAVE_GLIB_GDBUS */
  20.186 -
  20.187 -	if (request_name(app)) {
  20.188 -		app->priv->is_unique = TRUE;
  20.189 -	}
  20.190 -
  20.191 -out:
  20.192 -	return (gobject);
  20.193 -}
  20.194 -
  20.195 -static void
  20.196 -xwrited_unique_dispose(GObject *gobject)
  20.197 -{
  20.198 -	XWritedUnique	*self = XWRITED_UNIQUE(gobject);
  20.199 -
  20.200 -	if (self->priv->session_bus_proxy != NULL) {
  20.201 -		g_object_unref(self->priv->session_bus_proxy);
  20.202 -		self->priv->session_bus_proxy = NULL;
  20.203 -	}
  20.204 -
  20.205 -#ifndef HAVE_GLIB_GDBUS
  20.206 -	if (self->priv->session_bus != NULL) {
  20.207 -		dbus_g_connection_unref(self->priv->session_bus);
  20.208 -		self->priv->session_bus = NULL;
  20.209 -	}
  20.210 -
  20.211 -#endif /* !HAVE_GLIB_GDBUS */
  20.212 -	G_OBJECT_CLASS(xwrited_unique_parent_class)->dispose(gobject);
  20.213 -}
  20.214 -
  20.215 -static void
  20.216 -xwrited_unique_finalize(GObject *gobject)
  20.217 -{
  20.218 -	XWritedUnique	*self = XWRITED_UNIQUE(gobject);
  20.219 -
  20.220 -	g_free(self->priv->name);
  20.221 -
  20.222 -	G_OBJECT_CLASS(xwrited_unique_parent_class)->finalize(gobject);
  20.223 -}
  20.224 -
  20.225 -static void
  20.226 -xwrited_unique_class_init(XWritedUniqueClass *klass)
  20.227 -{
  20.228 -	GObjectClass	*gobject_class = G_OBJECT_CLASS(klass);
  20.229 -	GParamSpec	*pspec;
  20.230 -
  20.231 -	gobject_class->constructor = xwrited_unique_constructor;
  20.232 -	gobject_class->get_property = xwrited_unique_get_property;
  20.233 -	gobject_class->set_property = xwrited_unique_set_property;
  20.234 -	gobject_class->dispose = xwrited_unique_dispose;
  20.235 -	gobject_class->finalize = xwrited_unique_finalize;
  20.236 -
  20.237 -	pspec = g_param_spec_string("name", "Name",
  20.238 -	    "The unique name of the application", NULL, G_PARAM_READABLE |
  20.239 -	    G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME |
  20.240 -	    G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
  20.241 -	g_object_class_install_property(gobject_class, PROP_NAME, pspec);
  20.242 -
  20.243 -	pspec = g_param_spec_boolean("is-unique", "Is unique",
  20.244 -	    "Whether the current application instance is unique", FALSE,
  20.245 -	    G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
  20.246 -	    G_PARAM_STATIC_BLURB);
  20.247 -	g_object_class_install_property(gobject_class, PROP_IS_XWRITED_UNIQUE,
  20.248 -	    pspec);
  20.249 -
  20.250 -	g_type_class_add_private(klass, sizeof (XWritedUniquePrivate));
  20.251 -}
  20.252 -
  20.253 -static void
  20.254 -xwrited_unique_init(XWritedUnique *self)
  20.255 -{
  20.256 -	self->priv = XWRITED_UNIQUE_GET_PRIVATE(self);
  20.257 -
  20.258 -	self->priv->is_unique = FALSE;
  20.259 -#ifndef HAVE_GLIB_GDBUS
  20.260 -	self->priv->session_bus = NULL;
  20.261 -#endif /* !HAVE_GLIB_GDBUS */
  20.262 -	self->priv->session_bus_proxy = NULL;
  20.263 -}
  20.264 -
  20.265 -XWritedUnique *
  20.266 -xwrited_unique_new(const gchar *name)
  20.267 -{
  20.268 -	XWritedUnique	*app;
  20.269 -
  20.270 -	g_return_val_if_fail(name != NULL, NULL);
  20.271 -
  20.272 -	app = g_object_new(XWRITED_TYPE_UNIQUE, "name", name, NULL);
  20.273 -	if (
  20.274 -#ifndef HAVE_GLIB_GDBUS
  20.275 -	    app->priv->session_bus == NULL ||
  20.276 -#endif /* !HAVE_GLIB_GDBUS */
  20.277 -	    app->priv->session_bus_proxy == NULL) {
  20.278 -		g_object_unref(app);
  20.279 -		return (NULL);
  20.280 -	}
  20.281 -
  20.282 -	return (app);
  20.283 -}
  20.284 -
  20.285 -gboolean
  20.286 -xwrited_unique_is_unique(XWritedUnique *self)
  20.287 -{
  20.288 -	g_return_val_if_fail(XWRITED_IS_UNIQUE(self), FALSE);
  20.289 -
  20.290 -	return (self->priv->is_unique);
  20.291 -}
    21.1 --- a/xwrited-unique.h	Wed Sep 14 09:46:59 2016 +0200
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,63 +0,0 @@
    21.4 -/*
    21.5 - * Copyright (C) 2011 Guido Berhoerster <guido+xwrited@berhoerster.name>
    21.6 - *
    21.7 - * Permission is hereby granted, free of charge, to any person obtaining
    21.8 - * a copy of this software and associated documentation files (the
    21.9 - * "Software"), to deal in the Software without restriction, including
   21.10 - * without limitation the rights to use, copy, modify, merge, publish,
   21.11 - * distribute, sublicense, and/or sell copies of the Software, and to
   21.12 - * permit persons to whom the Software is furnished to do so, subject to
   21.13 - * the following conditions:
   21.14 - *
   21.15 - * The above copyright notice and this permission notice shall be included
   21.16 - * in all copies or substantial portions of the Software.
   21.17 - *
   21.18 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   21.19 - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   21.20 - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   21.21 - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   21.22 - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   21.23 - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   21.24 - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   21.25 - */
   21.26 -
   21.27 -#ifndef	XWRITED_UNIQUE_H
   21.28 -#define	XWRITED_UNIQUE_H
   21.29 -
   21.30 -#include <glib.h>
   21.31 -#include <glib-object.h>
   21.32 -
   21.33 -G_BEGIN_DECLS
   21.34 -
   21.35 -#define	XWRITED_TYPE_UNIQUE		(xwrited_unique_get_type())
   21.36 -#define	XWRITED_UNIQUE(obj)		(G_TYPE_CHECK_INSTANCE_CAST((obj), \
   21.37 -    XWRITED_TYPE_UNIQUE, XWritedUnique))
   21.38 -#define	XWRITED_IS_UNIQUE(obj)		(G_TYPE_CHECK_INSTANCE_TYPE((obj), \
   21.39 -    XWRITED_TYPE_UNIQUE))
   21.40 -#define	XWRITED_UNIQUE_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST((klass), \
   21.41 -    XWRITED_TYPE_UNIQUE, XWritedUniqueClass))
   21.42 -#define	XWRITED_IS_UNIQUE_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE((klass), \
   21.43 -    XWRITED_TYPE_UNIQUE))
   21.44 -#define	XWRITED_UNIQUE_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), \
   21.45 -    XWRITED_TYPE_UNIQUE, XWritedUniqueClass))
   21.46 -
   21.47 -typedef struct _XWritedUnique		XWritedUnique;
   21.48 -typedef struct _XWritedUniqueClass	XWritedUniqueClass;
   21.49 -typedef struct _XWritedUniquePrivate	XWritedUniquePrivate;
   21.50 -
   21.51 -struct _XWritedUnique {
   21.52 -	GObject		parent_instance;
   21.53 -	XWritedUniquePrivate *priv;
   21.54 -};
   21.55 -
   21.56 -struct _XWritedUniqueClass {
   21.57 -	GObjectClass	parent_class;
   21.58 -};
   21.59 -
   21.60 -GType		xwrited_unique_get_type(void) G_GNUC_CONST;
   21.61 -gboolean	xwrited_unique_is_unique(XWritedUnique *);
   21.62 -XWritedUnique *	xwrited_unique_new(const gchar *);
   21.63 -
   21.64 -G_END_DECLS
   21.65 -
   21.66 -#endif /* XWRITED_UNIQUE_H */
    22.1 --- a/xwrited-utmp-utempter.c	Wed Sep 14 09:46:59 2016 +0200
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,43 +0,0 @@
    22.4 -/*
    22.5 - * Copyright (C) 2010 Guido Berhoerster <guido+xwrited@berhoerster.name>
    22.6 - *
    22.7 - * Permission is hereby granted, free of charge, to any person obtaining
    22.8 - * a copy of this software and associated documentation files (the
    22.9 - * "Software"), to deal in the Software without restriction, including
   22.10 - * without limitation the rights to use, copy, modify, merge, publish,
   22.11 - * distribute, sublicense, and/or sell copies of the Software, and to
   22.12 - * permit persons to whom the Software is furnished to do so, subject to
   22.13 - * the following conditions:
   22.14 - *
   22.15 - * The above copyright notice and this permission notice shall be included
   22.16 - * in all copies or substantial portions of the Software.
   22.17 - *
   22.18 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   22.19 - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   22.20 - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   22.21 - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   22.22 - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   22.23 - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   22.24 - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   22.25 - */
   22.26 -
   22.27 -#include <stdlib.h>
   22.28 -#include <utempter.h>
   22.29 -
   22.30 -void
   22.31 -xwrited_utmp_add_entry(int fd)
   22.32 -{
   22.33 -	char	*pty_name;
   22.34 -
   22.35 -	pty_name = ptsname(fd);
   22.36 -	addToUtmp(pty_name, NULL, fd);
   22.37 -}
   22.38 -
   22.39 -void
   22.40 -xwrited_utmp_remove_entry(int fd)
   22.41 -{
   22.42 -	char	*pty_name;
   22.43 -
   22.44 -	pty_name = ptsname(fd);
   22.45 -	removeLineFromUtmp(pty_name, fd);
   22.46 -}
    23.1 --- a/xwrited-utmp-utmpx.c	Wed Sep 14 09:46:59 2016 +0200
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,93 +0,0 @@
    23.4 -/*
    23.5 - * Copyright (C) 2010 Guido Berhoerster <guido+xwrited@berhoerster.name>
    23.6 - *
    23.7 - * Permission is hereby granted, free of charge, to any person obtaining
    23.8 - * a copy of this software and associated documentation files (the
    23.9 - * "Software"), to deal in the Software without restriction, including
   23.10 - * without limitation the rights to use, copy, modify, merge, publish,
   23.11 - * distribute, sublicense, and/or sell copies of the Software, and to
   23.12 - * permit persons to whom the Software is furnished to do so, subject to
   23.13 - * the following conditions:
   23.14 - *
   23.15 - * The above copyright notice and this permission notice shall be included
   23.16 - * in all copies or substantial portions of the Software.
   23.17 - *
   23.18 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   23.19 - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   23.20 - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   23.21 - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   23.22 - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   23.23 - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   23.24 - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   23.25 - */
   23.26 -
   23.27 -#include <glib.h>
   23.28 -#include <stdlib.h>
   23.29 -#include <string.h>
   23.30 -#include <unistd.h>
   23.31 -#include <pwd.h>
   23.32 -#include <utmpx.h>
   23.33 -#include <errno.h>
   23.34 -#include <sys/time.h>
   23.35 -
   23.36 -#ifndef	DEV_PREFIX
   23.37 -#define	DEV_PREFIX	"/dev/"
   23.38 -#endif /* !DEV_PREFIX */
   23.39 -
   23.40 -static void
   23.41 -utmp_write_entry(int fd, gboolean add)
   23.42 -{
   23.43 -	struct utmpx	utmpx;
   23.44 -	char		*line = NULL;
   23.45 -	size_t		line_len;
   23.46 -	char		*id;
   23.47 -	struct passwd	*pwd;
   23.48 -
   23.49 -	line = ptsname(fd);
   23.50 -	if (line == NULL) {
   23.51 -		g_critical("failed to obtain slave pty name");
   23.52 -		return;
   23.53 -	}
   23.54 -	if (g_str_has_prefix(line, DEV_PREFIX)) {
   23.55 -		line += strlen(DEV_PREFIX);
   23.56 -	}
   23.57 -
   23.58 -	line_len = strlen(line);
   23.59 -	id = (line_len >= sizeof (utmpx.ut_pid)) ?
   23.60 -	    line + (line_len - sizeof (utmpx.ut_pid)) :
   23.61 -	    line;
   23.62 -
   23.63 -	pwd = getpwuid(getuid());
   23.64 -	if (pwd == NULL) {
   23.65 -		g_critical("failed to get username: %s", g_strerror(errno));
   23.66 -		return;
   23.67 -	}
   23.68 -
   23.69 -	memset(&utmpx, 0, sizeof (utmpx));
   23.70 -	strncpy(utmpx.ut_name, pwd->pw_name, sizeof (utmpx.ut_name));
   23.71 -	strncpy(utmpx.ut_id, id, sizeof (utmpx.ut_id));
   23.72 -	strncpy(utmpx.ut_line, line, sizeof (utmpx.ut_line));
   23.73 -	utmpx.ut_pid = getpid();
   23.74 -	utmpx.ut_type = add ? USER_PROCESS : DEAD_PROCESS;
   23.75 -	gettimeofday(&utmpx.ut_tv, NULL);
   23.76 -
   23.77 -	setutxent();
   23.78 -	if (pututxline(&utmpx) == NULL) {
   23.79 -		g_critical("failed to write to utmpx database: %s",
   23.80 -		    g_strerror(errno));
   23.81 -		return;
   23.82 -	}
   23.83 -	endutxent();
   23.84 -}
   23.85 -
   23.86 -void
   23.87 -xwrited_utmp_add_entry(int fd)
   23.88 -{
   23.89 -	utmp_write_entry(fd, TRUE);
   23.90 -}
   23.91 -
   23.92 -void
   23.93 -xwrited_utmp_remove_entry(int fd)
   23.94 -{
   23.95 -	utmp_write_entry(fd, FALSE);
   23.96 -}
    24.1 --- a/xwrited-utmp.h	Wed Sep 14 09:46:59 2016 +0200
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,36 +0,0 @@
    24.4 -/*
    24.5 - * Copyright (C) 2010 Guido Berhoerster <guido+xwrited@berhoerster.name>
    24.6 - *
    24.7 - * Permission is hereby granted, free of charge, to any person obtaining
    24.8 - * a copy of this software and associated documentation files (the
    24.9 - * "Software"), to deal in the Software without restriction, including
   24.10 - * without limitation the rights to use, copy, modify, merge, publish,
   24.11 - * distribute, sublicense, and/or sell copies of the Software, and to
   24.12 - * permit persons to whom the Software is furnished to do so, subject to
   24.13 - * the following conditions:
   24.14 - *
   24.15 - * The above copyright notice and this permission notice shall be included
   24.16 - * in all copies or substantial portions of the Software.
   24.17 - *
   24.18 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   24.19 - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   24.20 - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   24.21 - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   24.22 - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   24.23 - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   24.24 - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   24.25 - */
   24.26 -
   24.27 -#ifndef	XWRITED_UTMP_H
   24.28 -#define	XWRITED_UTMP_H
   24.29 -
   24.30 -#include <glib.h>
   24.31 -
   24.32 -G_BEGIN_DECLS
   24.33 -
   24.34 -void	xwrited_utmp_add_entry(int);
   24.35 -void	xwrited_utmp_remove_entry(int);
   24.36 -
   24.37 -G_END_DECLS
   24.38 -
   24.39 -#endif /* XWRITED_UTMP_H */
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/xwrited.1.xml	Sat Jul 28 22:02:24 2018 +0200
    25.3 @@ -0,0 +1,141 @@
    25.4 +<?xml version="1.0"?>
    25.5 +<!--
    25.6 +
    25.7 +Copyright (C) 2018 Guido Berhoerster <guido+xwrited@berhoerster.name>
    25.8 +
    25.9 +Permission is hereby granted, free of charge, to any person obtaining
   25.10 +a copy of this software and associated documentation files (the
   25.11 +"Software"), to deal in the Software without restriction, including
   25.12 +without limitation the rights to use, copy, modify, merge, publish,
   25.13 +distribute, sublicense, and/or sell copies of the Software, and to
   25.14 +permit persons to whom the Software is furnished to do so, subject to
   25.15 +the following conditions:
   25.16 +
   25.17 +The above copyright notice and this permission notice shall be included
   25.18 +in all copies or substantial portions of the Software.
   25.19 +
   25.20 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   25.21 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   25.22 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   25.23 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   25.24 +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   25.25 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   25.26 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   25.27 +
   25.28 +-->
   25.29 +<refentry xmlns="http://docbook.org/ns/docbook" xml:lang="en">
   25.30 +  <info>
   25.31 +    <author>
   25.32 +      <personname>
   25.33 +        <firstname>Guido</firstname>
   25.34 +        <surname>Berhoerster</surname>
   25.35 +      </personname>
   25.36 +      <email>guido+xwrited@berhoerster.name</email>
   25.37 +      <personblurb/>
   25.38 +    </author>
   25.39 +    <date>29 June, 2018</date>
   25.40 +  </info>
   25.41 +  <refmeta>
   25.42 +    <refentrytitle>xwrited</refentrytitle>
   25.43 +    <manvolnum>1</manvolnum>
   25.44 +    <refmiscinfo class="source"/>
   25.45 +    <refmiscinfo class="version"/>
   25.46 +    <refmiscinfo class="manual">User Commands</refmiscinfo>
   25.47 +  </refmeta>
   25.48 +  <refnamediv>
   25.49 +    <refname>xwrited</refname>
   25.50 +    <refpurpose>display write and wall messages as desktop
   25.51 +    notifications</refpurpose>
   25.52 +  </refnamediv>
   25.53 +  <refsynopsisdiv>
   25.54 +    <cmdsynopsis>
   25.55 +      <command>xwrited</command>
   25.56 +      <group>
   25.57 +        <arg choice="plain">
   25.58 +          <option>-q</option>
   25.59 +        </arg>
   25.60 +        <arg choice="plain">
   25.61 +          <option>--quit</option>
   25.62 +        </arg>
   25.63 +      </group>
   25.64 +      <group>
   25.65 +        <arg choice="plain">
   25.66 +          <option>-V</option>
   25.67 +        </arg>
   25.68 +        <arg choice="plain">
   25.69 +          <option>--version</option>
   25.70 +        </arg>
   25.71 +      </group>
   25.72 +    </cmdsynopsis>
   25.73 +  </refsynopsisdiv>
   25.74 +  <refsect1>
   25.75 +    <title>Description</title>
   25.76 +    <para>The <command>xwrited</command> utility displays
   25.77 +    <citerefentry><refentrytitle>write</refentrytitle><manvolnum>1</manvolnum>
   25.78 +    </citerefentry> and
   25.79 +    <citerefentry><refentrytitle>wall</refentrytitle><manvolnum>1</manvolnum>
   25.80 +    </citerefentry> messages as desktop notifications. A notification daemon
   25.81 +    compliant to the freedesktop.org Desktop Notification Specification draft
   25.82 +    needs to be running in order to display the notifications.</para>
   25.83 +  </refsect1>
   25.84 +  <refsect1>
   25.85 +    <title>Options</title>
   25.86 +    <para>The following options are supported:</para>
   25.87 +    <variablelist>
   25.88 +      <varlistentry>
   25.89 +        <term>
   25.90 +          <option>-q</option>
   25.91 +        </term>
   25.92 +        <term>
   25.93 +          <option>--quit</option>
   25.94 +        </term>
   25.95 +        <listitem>
   25.96 +          <para>Quit the running instance of
   25.97 +          <command>xwrited</command>.</para>
   25.98 +        </listitem>
   25.99 +      </varlistentry>
  25.100 +      <varlistentry>
  25.101 +        <term>
  25.102 +          <option>-V</option>
  25.103 +        </term>
  25.104 +        <term>
  25.105 +          <option>--version</option>
  25.106 +        </term>
  25.107 +        <listitem>
  25.108 +          <para>Print the version number and exit.</para>
  25.109 +        </listitem>
  25.110 +      </varlistentry>
  25.111 +    </variablelist>
  25.112 +  </refsect1>
  25.113 +  <refsect1>
  25.114 +    <title>Exit Status</title>
  25.115 +    <para>The following exit values are returned:</para>
  25.116 +    <variablelist>
  25.117 +      <varlistentry>
  25.118 +        <term>0</term>
  25.119 +        <listitem>
  25.120 +          <para>Command successfully executed.</para>
  25.121 +        </listitem>
  25.122 +      </varlistentry>
  25.123 +      <varlistentry>
  25.124 +        <term>&gt; 0</term>
  25.125 +        <listitem>
  25.126 +          <para>An error has occured.</para>
  25.127 +        </listitem>
  25.128 +      </varlistentry>
  25.129 +    </variablelist>
  25.130 +  </refsect1>
  25.131 +  <refsect1>
  25.132 +    <title>See Also</title>
  25.133 +    <para><citerefentry><refentrytitle>write</refentrytitle>
  25.134 +    <manvolnum>1</manvolnum></citerefentry>,
  25.135 +    <citerefentry> <refentrytitle>wall</refentrytitle><manvolnum>1</manvolnum>
  25.136 +    </citerefentry></para>
  25.137 +  </refsect1>
  25.138 +  <refsect1>
  25.139 +    <title>Notes</title>
  25.140 +    <para>xwrited assumes that messages are encoded in UTF-8 because there is
  25.141 +    no way for it to determine the character set encoding of the received
  25.142 +    data.</para>
  25.143 +  </refsect1>
  25.144 +</refentry>
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/xwrited.c	Sat Jul 28 22:02:24 2018 +0200
    26.3 @@ -0,0 +1,47 @@
    26.4 +/*
    26.5 + * Copyright (C) 2018 Guido Berhoerster <guido+xwrited@berhoerster.name>
    26.6 + *
    26.7 + * Permission is hereby granted, free of charge, to any person obtaining
    26.8 + * a copy of this software and associated documentation files (the
    26.9 + * "Software"), to deal in the Software without restriction, including
   26.10 + * without limitation the rights to use, copy, modify, merge, publish,
   26.11 + * distribute, sublicense, and/or sell copies of the Software, and to
   26.12 + * permit persons to whom the Software is furnished to do so, subject to
   26.13 + * the following conditions:
   26.14 + *
   26.15 + * The above copyright notice and this permission notice shall be included
   26.16 + * in all copies or substantial portions of the Software.
   26.17 + *
   26.18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   26.19 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   26.20 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   26.21 + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   26.22 + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   26.23 + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   26.24 + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   26.25 + */
   26.26 +
   26.27 +#include <glib/gi18n.h>
   26.28 +#include <locale.h>
   26.29 +#include <stdlib.h>
   26.30 +#include <unistd.h>
   26.31 +
   26.32 +#include "xwd-application.h"
   26.33 +
   26.34 +int
   26.35 +main(int argc, char *argv[])
   26.36 +{
   26.37 +	int		status;
   26.38 +	XwdApplication	*application;
   26.39 +
   26.40 +	bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
   26.41 +	setlocale(LC_ALL, "");
   26.42 +	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
   26.43 +	textdomain(GETTEXT_PACKAGE);
   26.44 +
   26.45 +	application = xwd_application_new();
   26.46 +	status = g_application_run(G_APPLICATION(application), argc, argv);
   26.47 +	g_object_unref(application);
   26.48 +
   26.49 +	exit(status);
   26.50 +}