~mdw
/
tripe
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
client: Function for inserting arguments.
[tripe]
/
client
/
tripectl.c
diff --git
a/client/tripectl.c
b/client/tripectl.c
index
50678df
..
1331704
100644
(file)
--- a/
client/tripectl.c
+++ b/
client/tripectl.c
@@
-1,13
+1,11
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id$
- *
* Client for TrIPE
*
* (c) 2001 Straylight/Edgeware
*/
* Client for TrIPE
*
* (c) 2001 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of Trivial IP Encryption (TrIPE).
*
*
* This file is part of Trivial IP Encryption (TrIPE).
*
@@
-15,12
+13,12
@@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* TrIPE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* TrIPE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with TrIPE; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* You should have received a copy of the GNU General Public License
* along with TrIPE; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@
-51,6
+49,7
@@
#include <netdb.h>
#include <mLib/alloc.h>
#include <netdb.h>
#include <mLib/alloc.h>
+#include <mLib/daemonize.h>
#include <mLib/darray.h>
#include <mLib/dstr.h>
#include <mLib/mdwopt.h>
#include <mLib/darray.h>
#include <mLib/dstr.h>
#include <mLib/mdwopt.h>
@@
-60,6
+59,7
@@
#include <mLib/selbuf.h>
#include <mLib/sig.h>
#include <mLib/str.h>
#include <mLib/selbuf.h>
#include <mLib/sig.h>
#include <mLib/str.h>
+#include <mLib/versioncmp.h>
#include "util.h"
#include "util.h"
@@
-120,10
+120,7
@@
static void checkbg(char **p)
}
static void checkfg(void)
}
static void checkfg(void)
-{
- if (bgtag)
- die(EXIT_FAILURE, "unexpected foreground response");
-}
+ { if (bgtag) die(EXIT_FAILURE, "unexpected foreground response"); }
static void cline(char *p, size_t len, void *b)
{
static void cline(char *p, size_t len, void *b)
{
@@
-182,7
+179,7
@@
static void cline(char *p, size_t len, void *b)
checkbg(&p);
die(EXIT_FAILURE, "%s", p);
} else
checkbg(&p);
die(EXIT_FAILURE, "%s", p);
} else
- die(EXIT_FAILURE, "unexpected output `%s %s'", q, p);
+ die(EXIT_FAILURE, "unexpected output `%s %s'", q, p);
}
static void sline(char *p, size_t len, void *b)
}
static void sline(char *p, size_t len, void *b)
@@
-273,17
+270,22
@@
static void logfile(const char *name)
static void sighup(int sig, void *v) { logfile(logname); }
static void sighup(int sig, void *v) { logfile(logname); }
-static void cleanup(void)
-{
- if (pidfile)
- unlink(pidfile);
-}
+static void cleanup(void) { if (pidfile) unlink(pidfile); }
static void sigdie(int sig)
static void sigdie(int sig)
+ { cleanup(); signal(sig, SIG_DFL); raise(sig); }
+
+static void putarg(string_v *av, const char *fmt, ...)
{
{
- cleanup();
- signal(sig, SIG_DFL);
- raise(sig);
+ va_list ap;
+ dstr d = DSTR_INIT;
+
+ va_start(ap, fmt);
+ dstr_vputf(&d, fmt, &ap);
+ dstr_putz(&d);
+ va_end(ap);
+ DA_UNSHIFT(av, xstrdup(d.buf));
+ dstr_destroy(&d);
}
static void version(FILE *fp)
}
static void version(FILE *fp)
@@
-317,7
+319,7
@@
Options in full:\n\
-D, --daemon Become a background task after connecting.\n\
-d, --directory=DIR Select current directory [default " CONFIGDIR "].\n\
-a, --admin-socket=FILE Select socket to connect to\n\
-D, --daemon Become a background task after connecting.\n\
-d, --directory=DIR Select current directory [default " CONFIGDIR "].\n\
-a, --admin-socket=FILE Select socket to connect to\n\
-
[default " SOCKETDIR "/tripesock].\n\
+ [default " SOCKETDIR "/tripesock].\n\
-P, --pidfile=FILE Write process-id to FILE.\n\
\n\
-s, --spawn Start server rather than connecting.\n\
-P, --pidfile=FILE Write process-id to FILE.\n\
\n\
-s, --spawn Start server rather than connecting.\n\
@@
-343,6
+345,8
@@
int main(int argc, char *argv[])
if ((p = getenv("TRIPEDIR")) != 0)
dir = p;
if ((p = getenv("TRIPEDIR")) != 0)
dir = p;
+ if ((p = getenv("TRIPESOCK")) != 0)
+ sock = p;
/* --- Parse the arguments --- */
/* --- Parse the arguments --- */
@@
-456,11
+460,11
@@
int main(int argc, char *argv[])
#endif
sigaction(SIGCHLD, &sa, 0);
#endif
sigaction(SIGCHLD, &sa, 0);
- DA_UNSHIFT(&spawnopts, (char *)sock);
- DA_UNSHIFT(&spawnopts, "-a");
- DA_UNSHIFT(&spawnopts, "-d.");
- DA_UNSHIFT(&spawnopts, (char *)spawnpath);
DA_PUSH(&spawnopts, 0);
DA_PUSH(&spawnopts, 0);
+ putarg(&spawnopts, "-a%s", sock);
+ putarg(&spawnopts, "-d.");
+ putarg(&spawnopts, "-F");
+ putarg(&spawnopts, "%s", spawnpath);
if (socketpair(PF_UNIX, SOCK_STREAM, 0, pfd))
die(EXIT_FAILURE, "error from socketpair: %s", strerror(errno));
sigemptyset(&newmask);
if (socketpair(PF_UNIX, SOCK_STREAM, 0, pfd))
die(EXIT_FAILURE, "error from socketpair: %s", strerror(errno));
sigemptyset(&newmask);
@@
-471,15
+475,12
@@
int main(int argc, char *argv[])
if (!kid) {
dup2(pfd[1], STDIN_FILENO);
dup2(pfd[1], STDOUT_FILENO);
if (!kid) {
dup2(pfd[1], STDIN_FILENO);
dup2(pfd[1], STDOUT_FILENO);
- close(pfd[1]);
close(pfd[0]);
close(pfd[0]);
- if (logfp)
- fclose(logfp);
- if (pidfp)
- fclose(pidfp);
+ close(pfd[1]);
+ if (logfp) fclose(logfp);
+ if (pidfp) fclose(pidfp);
closelog();
closelog();
- if (f & f_daemon)
- u_detach();
+ if (f & f_daemon) detachtty();
execvp(DA(&spawnopts)[0], DA(&spawnopts));
die(127, "couldn't exec `%s': %s", spawnpath, strerror(errno));
}
execvp(DA(&spawnopts)[0], DA(&spawnopts));
die(127, "couldn't exec `%s': %s", spawnpath, strerror(errno));
}
@@
-504,7
+505,7
@@
int main(int argc, char *argv[])
}
if (f & f_daemon) {
}
if (f & f_daemon) {
- if (
u_daemon
())
+ if (
daemonize
())
die(EXIT_FAILURE, "error becoming daemon: %s", strerror(errno));
}
if (pidfp) {
die(EXIT_FAILURE, "error becoming daemon: %s", strerror(errno));
}
if (pidfp) {