Re: [PATCH] Make locked paths absolute when current directory is changed
flat view
From: Johannes Sixt <hidden>
Date: 2016-06-15 23:01:58
Am 18.07.2014 15:08, schrieb Nguyễn Thái Ngọc Duy:
quoted hunk ↗ jump to hunk
diff --git a/lockfile.c b/lockfile.c index 8fbcb6a..a70d107 100644 --- a/lockfile.c +++ b/lockfile.c@@ -280,3 +280,19 @@ void rollback_lock_file(struct lock_file *lk) } lk->filename[0] = 0; } + +void make_locked_paths_absolute(void) +{ + struct lock_file *lk; + const char *abspath; + for (lk = lock_file_list; lk != NULL; lk = lk->next) { + if (!lk->filename[0] || lk->filename[0] == '/')
Please use is_absolute_path().
quoted hunk ↗ jump to hunk
+ continue; + abspath = absolute_path(lk->filename); + if (strlen(abspath) >= sizeof(lk->filename)) + warning("locked path %s is relative when current directory " + "is changed", lk->filename); + else + strcpy(lk->filename, abspath); + } +}
quoted hunk ↗ jump to hunk
--- a/run-command.c +++ b/run-command.c@@ -399,7 +399,7 @@ fail_pipe: close(cmd->out); } - if (cmd->dir && chdir(cmd->dir)) + if (cmd->dir && chdir_safe(cmd->dir))
This one shouldn't be necessary: It's in the child, and the child process does not release the locks; see the check for the owner in remove_lock_file.
die_errno("exec '%s': cd to '%s' failed", cmd->argv[0],
cmd->dir);
if (cmd->env) {-- Hannes