FreeBSD Bugzilla – Attachment 200370 Details for
Bug 234276
x11/rxvt-unicode: Enhance urxvtd and urxvtc integration with service managers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch to enhance urxvtd and urxvtc
patch-modern-socket (text/plain), 10.96 KB, created by
Jonathan de Boyne Pollard
on 2018-12-22 17:48:16 UTC
(
hide
)
Description:
patch to enhance urxvtd and urxvtc
Filename:
MIME Type:
Creator:
Jonathan de Boyne Pollard
Created:
2018-12-22 17:48:16 UTC
Size:
10.96 KB
patch
obsolete
>--- ./src/rxvtdaemon.C.orig 2014-12-13 01:00:23.000000000 +0000 >+++ ./src/rxvtdaemon.C 2018-12-22 11:01:36.726728469 +0000 >@@ -40,6 +40,22 @@ > > if (!path) > { >+ const char * run = getenv ("XDG_RUNTIME_DIR"); >+ if (run) >+ { >+ snprintf (name, PATH_MAX, "%s/urxvt", run); >+ mkdir (name, 0755); >+ >+ // The Base Directory Specification guarantees that the runtime directory is private to both user and machine. >+ // So there is no need to differentiate amongst sockets by host name; making it simpler for socket units. >+ // Conventionally, subdirectories here do not use hidden names, either. >+ snprintf (name, PATH_MAX, "%s/urxvt/daemon", run); >+ path = name; >+ } >+ } >+ >+ if (!path) >+ { > struct utsname u; > uname (&u); > >--- ./src/rxvtd.C.orig 2014-12-26 22:34:13.000000000 +0000 >+++ ./src/rxvtd.C 2018-12-22 11:01:36.726728469 +0000 >@@ -75,13 +75,18 @@ > > void accept_cb (ev::io &w, int revents); ev::io accept_ev; > >- unix_listener (const char *sockname); >+ unix_listener (int sockfd); >+ static int open (const char * sockname); > }; > >-unix_listener::unix_listener (const char *sockname) >+unix_listener::unix_listener (int sockfd) : fd(sockfd) > { > accept_ev.set<unix_listener, &unix_listener::accept_cb> (this); >+ accept_ev.start (fd, ev::READ); >+} > >+int unix_listener::open (const char * sockname) >+{ > sockaddr_un sa; > > if (strlen (sockname) >= sizeof(sa.sun_path)) >@@ -90,6 +95,7 @@ > exit (EXIT_FAILURE); > } > >+ int fd; > if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) > { > perror ("unable to create listening socket"); >@@ -120,7 +126,7 @@ > exit (EXIT_FAILURE); > } > >- accept_ev.start (fd, ev::READ); >+ return fd; > } > > void unix_listener::accept_cb (ev::io &w, int revents) >@@ -224,6 +230,48 @@ > return err (); > } > >+enum { LISTEN_SOCKET_FILENO = 3 }; >+ >+// This mechanism is available on operating systems other than Linux and from softwares other than systemd. >+static int get_pre_opened_listen_fd() >+{ >+ const char * old; >+ >+ const char * listen_pid (getenv ("LISTEN_PID")); >+ if (!listen_pid) >+ return -1; >+ old = listen_pid; >+ unsigned long lp(strtoul (listen_pid, const_cast<char **>(&listen_pid), 0)); >+ if (*listen_pid || old == listen_pid) >+ return -1; >+ >+ const int pid (getpid ()); >+ if (0 > pid) >+ return -1; >+ if (static_cast<unsigned long>(pid) != lp) >+ return -1; >+ >+ const char * listen_fds (getenv ("LISTEN_FDS")); >+ if (!listen_fds) >+ return -1; >+ old = listen_fds; >+ unsigned long lf(strtoul (listen_fds, const_cast<char **>(&listen_fds), 0)); >+ if (*listen_fds || old == listen_fds) >+ return -1; >+ >+ if (INT_MAX < lf || lf < 1) >+ return -1; >+ int n = static_cast<int>(lf); >+ >+ unsetenv ("LISTEN_PID"); >+ unsetenv ("LISTEN_FDS"); >+ unsetenv ("LISTEN_FDNAMES"); >+ for (int i(0U); i < n; ++i) >+ fcntl (LISTEN_SOCKET_FILENO + i, F_SETFD, FD_CLOEXEC); >+ >+ return LISTEN_SOCKET_FILENO; >+} >+ > int > main (int argc, char *argv[]) > { >@@ -275,18 +323,23 @@ > if (const char *dpy = getenv ("DISPLAY")) > displays.get (dpy ? dpy : ":0"); // move string logic into rxvt_display maybe? > >- char *sockname = rxvt_connection::unix_sockname (); >- unix_listener l (sockname); >- >- chdir ("/"); >- >- if (!opt_quiet) >+ int sockfd = get_pre_opened_listen_fd(); >+ if (-1 == sockfd) > { >- printf ("rxvt-unicode daemon listening on %s.\n", sockname); >- fflush (stdout); >+ char *sockname = rxvt_connection::unix_sockname (); >+ sockfd = unix_listener::open (sockname); >+ if (!opt_quiet) >+ rxvt_log ("%s: daemon listening on %s.\n", argv[0], sockname); >+ free (sockname); >+ } else { >+ fcntl (sockfd, F_SETFL, O_NONBLOCK); // in case the socket unit is wrong >+ if (!opt_quiet) >+ rxvt_log ("%s: daemon using pre-opened listening fd %d.\n", argv[0], sockfd); > } > >- free (sockname); >+ unix_listener l (sockfd); >+ >+ chdir ("/"); > > pid_t pid = 0; > if (opt_fork) >--- ./doc/rxvtd.1.pod.orig 2014-12-26 22:51:35.000000000 +0000 >+++ ./doc/rxvtd.1.pod 2018-12-22 11:10:29.570692003 +0000 >@@ -36,8 +36,10 @@ > > =item B<-q>, B<--quiet> > >-Normally, B<@@RXVT_NAME@@d> outputs the message C<< rxvt-unicode daemon >-listening on <path> >> after binding to its control socket. This option >+Normally, B<@@RXVT_NAME@@d> outputs the message C<< @@RXVT_NAME@@d: daemon >+listening on <path> >> after binding to its control socket, or the >+message C<< @@RXVT_NAME@@d: daemon using pre-opened listening fd <n> >> >+if it is using an already opened socket. This option > will suppress this message (errors and warnings will still be logged). > > =item B<-o>, B<--opendisplay> >@@ -98,12 +100,31 @@ > > =over 4 > >+=item B<LISTEN_PID>, B<LISTEN_FDS>, B<LISTEN_FDNAMES> >+ >+@@RXVT_NAME@@d takes an already-open file descriptor for its listening >+socket if these environment variables are set in accordance with the >+systemd conventions (which are also employed by some other tools). In >+this case, it does not create a listening socket itself. >+ > =item B<RXVT_SOCKET> > >-Both B<@@RXVT_NAME@@c> and B<@@RXVT_NAME@@d> use the environment >-variable F<RXVT_SOCKET> to create a listening socket and to contact >-the @@RXVT_NAME@@d, respectively. If the variable is missing then >-F<<< $HOME/.urxvt/urxvtd-I<< <nodename> >> >>> is used. >+@@RXVT_NAME@@d uses the environment variable F<RXVT_SOCKET> if >+present, to create a listening socket. The variable must specify the >+absolute path of the local-address-family socket to create. >+ >+=item B<XDG_RUNTIME_DIR> >+ >+If the F<RXVT_SOCKET> variable is missing, @@RXVT_NAME@@d uses the >+environment variable F<XDG_RUNTIME_DIR> to create the listening >+socket, naming it F<<< $XDG_RUNTIME_DIR/urxvt/daemon >>>. >+ >+=item B<HOME> >+ >+If both of those environment variables are missing, >+F<<< $HOME/.urxvt/urxvtd-I<< <nodename> >> >>> is used, falling >+back to F<<< /tmp/.urxvt/urxvtd-I<< <nodename> >> >>> if even that environment >+variable is missing. > > =item B<DISPLAY> > >--- ./doc/rxvtc.1.man.in.orig 2016-01-23 20:09:22.000000000 +0000 >+++ ./doc/rxvtc.1.man.in 2018-12-22 11:10:29.596692206 +0000 >@@ -185,11 +185,21 @@ > started directly. > .IP "\fB\s-1RXVT_SOCKET\s0\fR" 4 > .IX Item "RXVT_SOCKET" >-Both @@RXVT_NAME@@c and @@RXVT_NAME@@d use the environment variable >-\&\fI\s-1RXVT_SOCKET\s0\fR to create a listening socket and to contact the >-@@RXVT_NAME@@d, respectively. If the variable is missing, >-\&\fI\f(CI$HOME\fI/.urxvt/urxvtd\-\fI<nodename>\fI\fR is used. The variable must >-specify the absolute path of the socket to create. >+@@RXVT_NAME@@c uses the environment variable \&\fI\s-1RXVT_SOCKET\s0\fR, if >+present, to contact the @@RXVT_NAME@@d. The variable must specify the >+absolute path of the local-address-family socket to connect to. >+.IP "\fB\s-1XDG_RUNTIME_DIR\s0\fR" 4 >+.IX Item "XDG_RUNTIME_DIR" >+If the \&\fI\s-1RXVT_SOCKET\s0\fR variable is missing, @@RXVT_NAME@@c uses the >+environment variable \fB\s-1XDG_RUNTIME_DIR\s0\fR to contact the >+@@RXVT_NAME@@d, connecting to the socket named >+\&\fI\f(CI$XDG_RUNTIME_DIR\fI/urxvt/daemon\fR. >+.IP "\fB\s-1HOME\s0\fR" 4 >+.IX Item "HOME" >+If both of those environment variables are missing, >+\&\fI\f(CI$HOME\fI/.urxvt/urxvtd\-\fI<nodename>\fI\fR is used, falling >+back to \&\fI/tmp/.urxvt/urxvtd\-\fI<nodename>\fI\fR if even that environment >+variable is missing. > .SH "SEE ALSO" > .IX Header "SEE ALSO" > @@RXVT_NAME@@(7), @@RXVT_NAME@@d(1) >--- ./doc/rxvtd.1.man.in.orig 2016-01-23 20:09:22.000000000 +0000 >+++ ./doc/rxvtd.1.man.in 2018-12-22 11:10:29.549693349 +0000 >@@ -169,8 +169,10 @@ > options is not yet supported. > .IP "\fB\-q\fR, \fB\-\-quiet\fR" 4 > .IX Item "-q, --quiet" >-Normally, \fB@@RXVT_NAME@@d\fR outputs the message \f(CW\*(C`rxvt\-unicode daemon >-listening on <path>\*(C'\fR after binding to its control socket. This option >+Normally, \fB@@RXVT_NAME@@d\fR outputs the message \f(CW\*(C`@@RXVT_NAME@@d: daemon >+listening on <path>\*(C'\fR after binding to its control socket, or the >+message \f(CW\*(C`@@RXVT_NAME@@d: daemon using pre-opened listening fd <n>\*(C'\fR >+if it is using an already opened socket. This option > will suppress this message (errors and warnings will still be logged). > .IP "\fB\-o\fR, \fB\-\-opendisplay\fR" 4 > .IX Item "-o, --opendisplay" >@@ -223,12 +225,30 @@ > \&\fB@@RXVT_NAME@@d\fR is killed. > .SH "ENVIRONMENT" > .IX Header "ENVIRONMENT" >+.IP "\fB\s-1LISTEN_PID\s0\fR,\fB\s-1LISTEN_FDS\s0\fR,\fB\s-1LISTEN_FDNAMES\s0\fR," 4 >+.IX Item "LISTEN_PID" >+.IX Item "LISTEN_FDS" >+.IX Item "LISTEN_FDNAMES" >+@@RXVT_NAME@@d takes an already-open file descriptor for its listening >+socket if these environment variables are set in accordance with the >+systemd conventions (which are also employed by some other tools). In >+this case, it does not create a listening socket itself. > .IP "\fB\s-1RXVT_SOCKET\s0\fR" 4 > .IX Item "RXVT_SOCKET" >-Both \fB@@RXVT_NAME@@c\fR and \fB@@RXVT_NAME@@d\fR use the environment >-variable \fI\s-1RXVT_SOCKET\s0\fR to create a listening socket and to contact >-the @@RXVT_NAME@@d, respectively. If the variable is missing then >-\&\fI\f(CI$HOME\fI/.urxvt/urxvtd\-\fI<nodename>\fI\fR is used. >+@@RXVT_NAME@@d uses the environment variable \&\fI\s-1RXVT_SOCKET\s0\fR, if >+present, to create a listening socket. The variable must specify the >+absolute path of the local-address-family socket to create. >+.IP "\fB\s-1XDG_RUNTIME_DIR\s0\fR" 4 >+.IX Item "XDG_RUNTIME_DIR" >+If the \&\fI\s-1RXVT_SOCKET\s0\fR variable is missing, @@RXVT_NAME@@d uses the >+environment variable \fB\s-1XDG_RUNTIME_DIR\s0\fR to create the listening >+socket, naming it \&\fI\f(CI$XDG_RUNTIME_DIR\fI/urxvt/daemon\fR. >+.IP "\fB\s-1HOME\s0\fR" 4 >+.IX Item "HOME" >+If both of those environment variables are missing, >+\&\fI\f(CI$HOME\fI/.urxvt/urxvtd\-\fI<nodename>\fI\fR is used, falling >+back to \&\fI/tmp/.urxvt/urxvtd\-\fI<nodename>\fI\fR if even that environment >+variable is missing. > .IP "\fB\s-1DISPLAY\s0\fR" 4 > .IX Item "DISPLAY" > Only used when the \f(CW\*(C`\-\-opendisplay\*(C'\fR option is specified. Must contain a >--- ./doc/rxvtc.1.pod.orig 2014-11-16 12:22:34.000000000 +0000 >+++ ./doc/rxvtc.1.pod 2018-12-22 11:01:36.727728234 +0000 >@@ -52,11 +52,23 @@ > > =item B<RXVT_SOCKET> > >-Both @@RXVT_NAME@@c and @@RXVT_NAME@@d use the environment variable >-F<RXVT_SOCKET> to create a listening socket and to contact the >-@@RXVT_NAME@@d, respectively. If the variable is missing, >-F<<< $HOME/.urxvt/urxvtd-I<< <nodename> >> >>> is used. The variable must >-specify the absolute path of the socket to create. >+@@RXVT_NAME@@c uses the environment variable F<RXVT_SOCKET> if >+present, to contact the @@RXVT_NAME@@d. The variable must specify the >+absolute path of the local-address-family socket to connect to. >+ >+=item B<XDG_RUNTIME_DIR> >+ >+If the F<RXVT_SOCKET> variable is missing, @@RXVT_NAME@@c uses the >+environment variable F<XDG_RUNTIME_DIR> to contact the >+@@RXVT_NAME@@d, connecting to the socket named >+F<<< $XDG_RUNTIME_DIR/urxvt/daemon >>>. >+ >+=item B<HOME> >+ >+If both of those environment variables are missing, >+F<<< $HOME/.urxvt/urxvtd-I<< <nodename> >> >>> is used, falling >+back to F<<< /tmp/.urxvt/urxvtd-I<< <nodename> >> >>> if even that environment >+variable is missing. > > =back >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 234276
: 200370