summaryrefslogtreecommitdiff
path: root/p11-kit
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2018-02-26 17:27:44 +0100
committerDaiki Ueno <ueno@gnu.org>2018-02-27 12:27:45 +0100
commitf73868b710d4463cc0cff6f8ea2f3a171f86c8e2 (patch)
treebc2a5044e3a822e9501be13e36d628afd3f8c134 /p11-kit
parentadc760e5ce90d49f7c6183c689f95868341f6fb7 (diff)
server: Print envvars even when running in foreground
Diffstat (limited to 'p11-kit')
-rw-r--r--p11-kit/server.c61
1 files changed, 39 insertions, 22 deletions
diff --git a/p11-kit/server.c b/p11-kit/server.c
index d8ffd78..e64890c 100644
--- a/p11-kit/server.c
+++ b/p11-kit/server.c
@@ -321,6 +321,36 @@ check_credentials (int fd,
return true;
}
+static bool
+print_environment (pid_t pid, const char *socket_path, bool csh)
+{
+ char *path, *address;
+ int rc;
+
+ path = p11_path_encode (socket_path);
+ rc = asprintf (&address, "unix:path=%s", path);
+ free (path);
+ if (rc < 0)
+ return false;
+ if (csh) {
+ printf ("setenv %s %s;\n",
+ P11_KIT_SERVER_ADDRESS_ENV,
+ address);
+ printf ("setenv %s %d;\n",
+ P11_KIT_SERVER_PID_ENV,
+ pid);
+ } else {
+ printf ("%s=%s; export %s;\n",
+ P11_KIT_SERVER_ADDRESS_ENV, address,
+ P11_KIT_SERVER_ADDRESS_ENV);
+ printf ("%s=%d; export %s;\n",
+ P11_KIT_SERVER_PID_ENV, pid,
+ P11_KIT_SERVER_PID_ENV);
+ }
+ free (address);
+ return true;
+}
+
static int
server_loop (Server *server,
bool foreground,
@@ -363,29 +393,8 @@ server_loop (Server *server,
close (STDOUT_FILENO);
}
if (pid != 0) {
- char *path, *address;
-
- path = p11_path_encode (server->socket_name);
- rc = asprintf (&address, "unix:path=%s", path);
- free (path);
- if (rc < 0)
+ if (!print_environment (pid, server->socket_name, csh))
return 1;
- if (csh) {
- printf ("setenv %s %s;\n",
- P11_KIT_SERVER_ADDRESS_ENV,
- address);
- printf ("setenv %s %d;\n",
- P11_KIT_SERVER_PID_ENV,
- pid);
- } else {
- printf ("%s=%s; export %s;\n",
- P11_KIT_SERVER_ADDRESS_ENV, address,
- P11_KIT_SERVER_ADDRESS_ENV);
- printf ("%s=%d; export %s;\n",
- P11_KIT_SERVER_PID_ENV, pid,
- P11_KIT_SERVER_PID_ENV);
- }
- free (address);
exit (0);
}
if (setsid () == -1) {
@@ -402,6 +411,14 @@ server_loop (Server *server,
sigprocmask (SIG_BLOCK, &blockset, NULL);
+ /* for testing purposes, even when started in foreground,
+ * print the envvars */
+ if (foreground) {
+ if (!print_environment (getpid (), server->socket_name, csh))
+ return 1;
+ fflush (stdout);
+ }
+
/* accept connections */
ret = 0;
for (;;) {