From 413489e622d294a3030b3bbc430183fb0582d3c3 Mon Sep 17 00:00:00 2001 From: Manvendra Bhangui Date: Tue, 12 Nov 2024 16:04:49 +0530 Subject: [PATCH] envidir: add -p option to set PATH before call to execve 1. daemontools.spec, debian/control: use libqmail-devel > 1.3 for pathexec_env_plus() function in libqmail 2. envdir.c: added -p option to set PATH variable before the call to execve 3. Updated envdir, supervise, svscan man pages --- daemontools-x/daemontools.spec.in | 4 ++-- daemontools-x/debian/control.in | 2 +- daemontools-x/doc/ChangeLog | 4 ++++ daemontools-x/envdir.8 | 21 +++++++++++++++++++-- daemontools-x/envdir.c | 16 ++++++++++++---- daemontools-x/supervise.8 | 8 ++++---- daemontools-x/svscan.9 | 14 +++++++------- 7 files changed, 49 insertions(+), 20 deletions(-) diff --git a/daemontools-x/daemontools.spec.in b/daemontools-x/daemontools.spec.in index f59561db2..34aed6e87 100644 --- a/daemontools-x/daemontools.spec.in +++ b/daemontools-x/daemontools.spec.in @@ -1,6 +1,6 @@ # # -# $Id: daemontools.spec.in,v 1.49 2024-07-01 20:11:30+05:30 Cprogrammer Exp mbhangui $ +# $Id: daemontools.spec.in,v 1.50 2024-11-12 16:02:00+05:30 Cprogrammer Exp mbhangui $ %undefine _missing_build_ids_terminate_build %global _unpackaged_files_terminate_build 1 @@ -78,7 +78,7 @@ BuildRequires: mariadb-connector-c-devel %else BuildRequires: mysql-devel %endif -BuildRequires: libqmail-devel +BuildRequires: libqmail-devel > 1.3 ##################################### OBS #################################### %if %build_on_obs == 1 diff --git a/daemontools-x/debian/control.in b/daemontools-x/debian/control.in index f6a91f059..cae337fc2 100644 --- a/daemontools-x/debian/control.in +++ b/daemontools-x/debian/control.in @@ -3,7 +3,7 @@ Section: admin Priority: extra Maintainer: @email@ Standards-Version: 3.9.1 -Build-Depends: cdbs, debhelper (>= 9), gcc, automake, libqmail-dev, m4, gawk +Build-Depends: cdbs, debhelper (>= 9), gcc, automake, libqmail-dev (>= 1.4), m4, gawk Homepage: https://github.com/indimail/indimail-mta Package: daemontools diff --git a/daemontools-x/doc/ChangeLog b/daemontools-x/doc/ChangeLog index 31268f4f5..f3ba3e474 100644 --- a/daemontools-x/doc/ChangeLog +++ b/daemontools-x/doc/ChangeLog @@ -27,6 +27,10 @@ 17. supervise.c: prevent restart of service on SIGTERM 18. svscan.c: added killsvc function to shutdown non-log and log services 19. svscan.c: refactored shutdown handling +- 12/11/2024 +20. daemontools.spec, debian/control: use libqmail-devel > 1.3 for + pathexec_env_plus() function in libqmail +21. envdir.c: added -p option to set PATH variable before the call to execve * Tue Aug 06 2024 12:48:42 +0000 Manvendra Bhangui 1.1.5-1.1%{?dist} Release 1.1.5-1.1 Start 05/02/2024 End 06/08/2024 diff --git a/daemontools-x/envdir.8 b/daemontools-x/envdir.8 index 2a61e3817..8d1aeaf27 100644 --- a/daemontools-x/envdir.8 +++ b/daemontools-x/envdir.8 @@ -5,14 +5,24 @@ envdir \- runs another program with environment modified according to files in a specified directory. .SH SYNOPSIS -\fBenvdir\fR [ -cwi ] \fId\fR \fIchild\fR +\fBenvdir\fR [ -cwip ] \fId\fR \fIchild\fR .SH DESCRIPTION \fId\fR is a single argument. \fIchild\fR consists of one or more arguments. \fBenvdir\fR sets various environment variables as specified by files in -the directory named \fId\fR. It then runs \fIchild\R. +the directory named \fId\fR. It then runs \fIchild\fR with the environment +variables passed to \fBexecve\fR(2). These environment variables are not +set before the call to \fBexecve\fR(2). You can however set these +environment variables before the call to \fBexecve\fR(2) like this + +.EX + envdir \fId\fR envdir \fId\fR \fIchild\fR +.EE + +For the \fBPATH\fR variable to be set before the call to \fBexecve\fR(2), +you can use the \fB\-p\fR option. If \fId\fR contains a file named \fIs\fR whose first line is \fIt\fR, \fBenvdir\fR removes an environment variable named \fIs\fR if one exists, @@ -80,6 +90,13 @@ This option ignores if it cannot read a file in \fId\fR. This allows the system administrator to specify different access to different users for any environment variable +.TP +.B \-p +This options sets the PATH environment variable if defined in \fId\fR +before the call to \fBexecve\fR(2). This may be useful for \fBexecve\fR(2) +to be able to execute \fIchild\fR passed to \fBenvdir\fR without the full +path. + .SH EXIT CODES \fBenvdir\fR exits 111 if it has trouble reading \fId\fR, if it runs out of memory for environment variables, or if it cannot run \fIchild\fR. diff --git a/daemontools-x/envdir.c b/daemontools-x/envdir.c index e50cda69e..053be5867 100644 --- a/daemontools-x/envdir.c +++ b/daemontools-x/envdir.c @@ -1,5 +1,8 @@ /* * $Log: envdir.c,v $ + * Revision 1.9 2024-11-12 16:03:28+05:30 Cprogrammer + * added -p option to set PATH variable before the call to execve + * * Revision 1.8 2024-05-09 22:39:36+05:30 mbhangui * fix discarded-qualifier compiler warnings * @@ -55,10 +58,10 @@ main(int argc, char **argv) const char *fn, *err = (char *) 0; char **e; int i, opt, warn_on_error = 0, ignore_unreadable = 0, - unreadable_count = 0; + unreadable_count = 0, set_path = 0, j = 0; orig_env = environ; - while ((opt = getopt(argc, argv, "cwi")) != opteof) { + while ((opt = getopt(argc, argv, "cwip")) != opteof) { switch (opt) { case 'c': @@ -70,6 +73,9 @@ main(int argc, char **argv) case 'i': ignore_unreadable = 1; break; + case 'p': + set_path = 1; + break; default: die_usage(0); break; @@ -87,7 +93,9 @@ main(int argc, char **argv) strerr_die5sys(111, FATAL, envdir_str(i), ": ", err, ": "); strerr_warn5(WARN, envdir_str(i), ": ", err, ": ", &strerr_sys); } - if (i || (!ignore_unreadable && unreadable_count)) { /*- original envdir behaviour */ + if (set_path) + j = pathexec_env_plus("PATH=", 5); + if (i || j || (!ignore_unreadable && unreadable_count)) { /*- original envdir behaviour */ pathexec_clear(); /*- clear environment variables picked by pathexec */ environ = orig_env; } @@ -103,7 +111,7 @@ main(int argc, char **argv) void getversion_envdir_main_c() { - const char *x = "$Id: envdir.c,v 1.8 2024-05-09 22:39:36+05:30 mbhangui Exp mbhangui $"; + const char *x = "$Id: envdir.c,v 1.9 2024-11-12 16:03:28+05:30 Cprogrammer Exp mbhangui $"; x++; } diff --git a/daemontools-x/supervise.8 b/daemontools-x/supervise.8 index 1f2b0c330..2d2bcb30c 100644 --- a/daemontools-x/supervise.8 +++ b/daemontools-x/supervise.8 @@ -14,10 +14,10 @@ service. If the directory \fIrun/svscan\fR exists, \fBsupervise\fR creates the directory \fIdir/supervise\fR in \fIrun/svscan\fR where \fIrun\fR is either \fI/run\fR or \fI/var/run\fR tmpfs filesystem (depending on your operating system). The directory \fIrun\fR/\fIsvscan\fR is created by -\fBsvscan\fR(8) when \fBDISABLE_RUN\fR isn't set. It also opens -\fIdir/supervise/lock\fR in exclusive mode to prevent multiple copies of -supervise run for the same service. It exits 100 if it cannot open -\fIdir/supervise/lock\fR. The directory \fIdir\fR must be writable to +\fBsvscan\fR(8) when \fBDISABLE_RUN\fR environment variable isn't set. It +also opens \fIdir/supervise/lock\fR in exclusive mode to prevent multiple +copies of supervise run for the same service. It exits 100 if it cannot +open \fIdir/supervise/lock\fR. The directory \fIdir\fR must be writable to \fBsupervise\fR. This directory is used to maintain status information in binary format and also create few named pipes. The status information can be read by \fBsvstat\fR(8). If \fBDISABLE_RUN\fR is set, or if your system diff --git a/daemontools-x/svscan.9 b/daemontools-x/svscan.9 index 1799e6e9a..d39114fed 100644 --- a/daemontools-x/svscan.9 +++ b/daemontools-x/svscan.9 @@ -1,19 +1,19 @@ .\" vim: tw=75 .TH svscan 8 .SH NAME -svscan \- starts and monitors a collection of services +svscan \- start and monitor a collection of services .SH SYNOPSIS .B svscan [ -vs ] [-n count] [ \fIscandir\fR ] .SH DESCRIPTION \fBsvscan\fR(8) starts one \fBsupervise\fR(8) process for each subdirectory -of the current directory, up to a limit of subdirectories as default. You -can change the default by passing -n option, in which case \fBsvscan\fR -will allocate memory for \fIcount\fR service slots. You can override using -current directory by passing \fIscandir\fR as an argument. If \fBsvscan\fR -is given a command-line argument \fIdir\fR, it switches to that directory -when it starts. +of the current directory, up to a limit of 1000 subdirectories as default. +You can change the default by using -n \fIcount\fR, in which case +\fBsvscan\fR will allocate memory for \fIcount\fR service slots. You can +override using current directory by passing \fIscandir\fR as an argument. +If \fBsvscan\fR is given a command-line argument \fIdir\fR, it switches to +that directory when it starts. \fBsvscan\fR skips subdirectory names starting with dots. \fBsupervise\fR must be in \fBsvscan\fR's path. If the environment variable \fBSETSID\fR is