Skip to content

Commit 1d1ab79

Browse files
committed
Default to tmp workdir and echo path to logfile
1 parent f6a0781 commit 1d1ab79

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

bin/pcmd-dev

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# Always set working dir to the pcmd project root, where the logs and lockfiles
99
# will be gitignored.
10-
cd $(dirname $0)/..
10+
workdir=$(dirname $0)/../.pcmd
1111

1212
make --silent build
13-
build/pcmd $@
13+
build/pcmd -workdir $workdir $@

pcmd.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ var (
2525
func main() {
2626
config := parseConfig()
2727
maybeShowVersionAndExit(config)
28-
createAndChangeToWorkDir(config)
28+
createWorkDir(config)
29+
30+
fmt.Fprintf(os.Stderr, "View logs at %s\n", config.LogFilePath)
2931

3032
ctx, cancel := context.WithCancel(context.Background())
3133
defer cancel()
@@ -241,15 +243,8 @@ CleanupAndWaitForGracePeriod:
241243
}
242244
}
243245

244-
func createAndChangeToWorkDir(config Config) {
245-
workDir := config.WorkDir
246-
filesPath := filepath.Join(workDir, ".pcmd")
247-
248-
if err := os.MkdirAll(filesPath, 0755); err != nil {
249-
log.Fatal(err)
250-
}
251-
252-
if err := os.Chdir(workDir); err != nil {
246+
func createWorkDir(config Config) {
247+
if err := os.MkdirAll(config.WorkDir, 0755); err != nil {
253248
log.Fatal(err)
254249
}
255250
}
@@ -465,7 +460,9 @@ func parseConfig() Config {
465460

466461
flagSet := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
467462

468-
flagSet.StringVar(&config.WorkDir, "workdir", ".", "Working directory for lock files, logs, unix sockets, etc.")
463+
tmpDir := filepath.Join(getTempDir(), "pcmd")
464+
465+
flagSet.StringVar(&config.WorkDir, "workdir", tmpDir, "Working directory for lock files, logs, unix sockets, etc.")
469466
flagSet.IntVar(&config.GracePeriod, "grace-period", 300, "Number of seconds to allow for cleanup once the proxying is complete")
470467
flagSet.BoolVar(&config.Lock, "lock", false, "Only allow one instance of ProxyCommand to run at a time. Implied by -control-path")
471468
flagSet.StringVar(&config.SSHUser, "r", "", "The SSH remote user. This should be set to %r. See TOKENS in SSH_CONFIG(5) for more details.")
@@ -506,7 +503,7 @@ func parseConfig() Config {
506503
}
507504

508505
func baseName(config Config) (bn string) {
509-
bn = ".pcmd/pcmd"
506+
bn = filepath.Join(config.WorkDir, "pcmd")
510507

511508
if config.SSHUser != "" {
512509
bn = bn + "." + config.SSHUser
@@ -529,3 +526,11 @@ func ensureSSHConfigPresent(config Config) {
529526
os.Exit(1)
530527
}
531528
}
529+
530+
func getTempDir() string {
531+
envTempDir, exists := os.LookupEnv("TMPDIR")
532+
if exists {
533+
return envTempDir
534+
}
535+
return "/tmp"
536+
}

0 commit comments

Comments
 (0)