tDetach safe-agent from controlling terminal by default - safe - password protected secret keeper
 (HTM) git clone git://git.z3bra.org/safe.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 6907eb1ddbe9042e63a63d9fca702a2cd20302d2
 (DIR) parent abc98ebaee60796bd9e4340ddd4fe6afbd2645fe
 (HTM) Author: Willy Goiffon <dev@z3bra.org>
       Date:   Mon, 24 Jun 2019 08:59:49 +0200
       
       Detach safe-agent from controlling terminal by default
       
       Diffstat:
         M safe-agent.1                        |       4 +++-
         M safe-agent.c                        |      11 +++++++++--
       
       2 files changed, 12 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/safe-agent.1 b/safe-agent.1
       t@@ -6,7 +6,7 @@
        .Nd Digital safe for your secrets
        .Sh SYNOPSIS
        .Nm
       -.Op Fl h
       +.Op Fl hd
        .Op Fl t Ar timeout
        .Op Fl f Ar socket
        .Sh DESCRIPTION
       t@@ -22,6 +22,8 @@ to the running agent.
        .Bl -tag -width Ds
        .It Fl h
        Print a quick usage text.
       +.It Fl d
       +Do not detach the process from the controlling terminal.
        .It Fl t Ar timeout
        Retain the key for
        .Ar timeout
 (DIR) diff --git a/safe-agent.c b/safe-agent.c
       t@@ -135,7 +135,7 @@ sighandler(int signal)
                        unlink(sockp);
                        rmdir(dirname(sockp));
                        exit(0);
       -                /* FALLTHROUGH */
       +                /* NOTREACHED */
                case SIGALRM:
                case SIGUSR1:
                        forgetkey();
       t@@ -183,13 +183,16 @@ int
        main(int argc, char *argv[])
        {
                pid_t pid;
       -        int timeout;
       +        int dflag, timeout;
                size_t dirlen;
                char path[PATH_MAX] = SOCKDIR;
        
                pid = getpid();
        
                ARGBEGIN {
       +        case 'd':
       +                dflag = 1;
       +                break;
                case 'f':
                        sockp = EARGF(usage());
                        break;
       t@@ -214,6 +217,10 @@ main(int argc, char *argv[])
                printf("SAFE_PID=%d\n", pid);
                printf("SAFE_SOCK=%s\n", sockp);
                printf("export SAFE_PID SAFE_SOCK\n");
       +        fflush(stdout);
       +
       +        if (!dflag)
       +                daemon(0, 0);
        
                signal(SIGINT, sighandler);
                signal(SIGTERM, sighandler);