Re: [PATCH] Make locked paths absolute when current directory is changed
- From
Johannes Sixt <j6t@kdbg.org>
- Date
- Jul 18, 2014, 20:44 UTC
- Message-ID
- <53C98717.3060600@kdbg.org>
- In-Reply-To
- <1405688937-22925-1-git-send-email-pclouds@gmail.com>
Am 18.07.2014 15:08, schrieb Nguyễn Thái Ngọc Duy:
Show 15 quoted lines
> 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().
Show 9 quoted lines
> + 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);
> + }
> +}Show 8 quoted lines
> --- 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