[systemd-devel] [PATCH] core: reuse the same /tmp and /var/tmp
Michal Schmidt
mschmidt at redhat.com
Fri Feb 1 08:41:23 PST 2013
On 02/01/2013 04:09 PM, Michal Sekletar wrote:
> All Execs within the service, will get mounted the same /tmp and /var/tmp
> directories, if service is configured with PrivateTmp=yes. Temporary
> directories are cleaned up by service itself, rather than relying on
> systemd-tmpfiles.
Thank you taking on this long-standing issue. The general approach looks
good to me.
...
>
> +int setup_tmpdirs(ExecContext *context) {
> + int r = 0;
> + bool remove_tmp = false, remove_var_tmp = false;
> + mode_t u;
> + char *d = NULL;
> + char tmp_dir[] = "/tmp/systemd-private-XXXXXX",
> + var_tmp_dir[] = "/var/tmp/systemd-private-XXXXXX";
> +
> + assert(context);
> +
> + if (!context->tmp_dir) {
> + d = mktemp(tmp_dir);
> + if (!d) {
> + r = -errno;
> + goto fail;
> + }
> +
> + context->tmp_dir = strdup(d);
> + if (!context->tmp_dir) {
> + r = log_oom();
> + goto fail;
> + }
> +
> + u = umask(0000);
> + r = mkdir(tmp_dir, 0777);
> + umask(u);
> + if (r < 0) {
Suppose that a mkdir failure happens...
> + r = -errno;
> + goto fail;
> + }
> + remove_tmp = true;
> +
> + if (chmod(tmp_dir, 0777 | S_ISVTX) < 0) {
> + r = -errno;
> + goto fail;
> + }
> + }
[...]
... remove_tmp is still false, so this code won't free and reset
context->tmp_dir:
> +fail:
> + if (remove_tmp) {
> + free(context->tmp_dir);
> + context->tmp_dir = NULL;
> + rmdir(tmp_dir);
> + }
More information about the systemd-devel
mailing list