Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Now it works as a drop-in replacement for ssh-agent. Sweet.

Lots of tidying up still needed, but at least now it works for me.
  • Loading branch information...
commit 38f438139848694d7684c22aabde24306f4687a4 1 parent 9f3a152
Wesley Darlington authored
Showing with 50 additions and 18 deletions.
  1. +41 −14 charade.c
  2. +8 −1 eprintf.c
  3. +1 −3 eprintf.h
55 charade.c
View
@@ -473,6 +473,44 @@ handle_key_requests_forever(void)
}
}
+void
+redirect(FILE *f, char *basename)
+{
+ char buf[MAXPATHLEN] = "";
+
+ int ret = snprintf(buf, sizeof(buf), "%s/%s.%ld",
+ socket_dir, basename, (long)getpid());
+ if (ret >= sizeof(buf)) {
+ EPRINTF(0, "Can't open %s to redirect %s: Too long (%d >= %d).\n",
+ buf, basename, ret, sizeof(buf));
+ } else {
+ EPRINTF(1, "Redirecting %s to %s.\n", basename, buf);
+
+ if (!freopen(buf, "w", f)) {
+ EPRINTF(0, "can't freopen %s.\n", basename);
+ }
+
+ // Turn off buffering...
+ setvbuf(f, NULL, _IONBF, 0);
+
+ EPRINTF(1, "Redirected %s to %s.\n", basename, buf);
+ }
+}
+
+void
+redirect_stdall(void)
+{
+ fclose(stdin);
+
+ if (get_loudness() <= 0) {
+ fclose(stdout);
+ fclose(stderr);
+ } else {
+ redirect(stdout, "stdout");
+ redirect(stderr, "stderr");
+ }
+}
+
pid_t
fork_off_key_handler(void)
{
@@ -486,27 +524,16 @@ fork_off_key_handler(void)
return handler_pid;
}
- fprintf(stderr, "In the child process\n");
- fflush(stdout);
-
// OK, we're the child agent process now...
- int newfd = creat("/tmp/loggy2", O_CREAT);
- dup2(2, newfd);
- close(newfd);
-
- /*
- fprintf(f, "Hello.\n");
- fflush(f);
- */
+ // Make this controllable by cmdline, do it only with -v
+ redirect_stdall();
- // TODO: Do the setsid thing
- /*
+ // Do the setsid thing
if (setsid() == -1) {
EPRINTF(0, "error from setsid(): %s.\n", strerror(errno));
exit(1);
}
- */
chdir("/");
9 eprintf.c
View
@@ -8,7 +8,7 @@
#include "eprintf.h"
-unsigned int g_volume = 1;
+static int g_volume = 0;
void
louder(void)
@@ -17,6 +17,13 @@ louder(void)
}
int
+get_loudness(void)
+{
+ return g_volume;
+}
+
+
+int
eprintf(int level, const char *fmt, ...)
{
if (level > g_volume)
4 eprintf.h
View
@@ -9,16 +9,14 @@
extern "C" {
#endif // #ifdef __cplusplus
-extern unsigned int g_volume;
-
#define EPRINTF(Level, Format, Args...) \
eprintf(Level, "%s: " Format, __func__, ##Args)
int eprintf(int level, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
-// Increase the verbosity...
void louder(void);
+int get_loudness(void);
#ifdef __cplusplus
}
Please sign in to comment.
Something went wrong with that request. Please try again.