util.c (542898c5aa5c6a3179dffb1d1606884a63f75fed) util.c (67fd18924647bdcafab18c2945a79ddea73653de)
1// SPDX-License-Identifier: GPL-2.0
2#include "util.h"
3#include "debug.h"
4#include "event.h"
5#include <api/fs/fs.h>
6#include <sys/stat.h>
7#include <sys/utsname.h>
8#include <dirent.h>

--- 417 unchanged lines hidden (view full) ---

426 */
427 if (!di->set)
428 setenv("DEBUGINFOD_URLS", "", 1);
429 else if (di->urls && strcmp(di->urls, "system"))
430 setenv("DEBUGINFOD_URLS", di->urls, 1);
431
432 pr_debug("DEBUGINFOD_URLS=%s\n", getenv("DEBUGINFOD_URLS"));
433}
1// SPDX-License-Identifier: GPL-2.0
2#include "util.h"
3#include "debug.h"
4#include "event.h"
5#include <api/fs/fs.h>
6#include <sys/stat.h>
7#include <sys/utsname.h>
8#include <dirent.h>

--- 417 unchanged lines hidden (view full) ---

426 */
427 if (!di->set)
428 setenv("DEBUGINFOD_URLS", "", 1);
429 else if (di->urls && strcmp(di->urls, "system"))
430 setenv("DEBUGINFOD_URLS", di->urls, 1);
431
432 pr_debug("DEBUGINFOD_URLS=%s\n", getenv("DEBUGINFOD_URLS"));
433}
434
435/*
436 * Return a new filename prepended with task's root directory if it's in
437 * a chroot. Callers should free the returned string.
438 */
439char *filename_with_chroot(int pid, const char *filename)
440{
441 char buf[PATH_MAX];
442 char proc_root[32];
443 char *new_name = NULL;
444 int ret;
445
446 scnprintf(proc_root, sizeof(proc_root), "/proc/%d/root", pid);
447 ret = readlink(proc_root, buf, sizeof(buf) - 1);
448 if (ret <= 0)
449 return NULL;
450
451 /* readlink(2) does not append a null byte to buf */
452 buf[ret] = '\0';
453
454 if (!strcmp(buf, "/"))
455 return NULL;
456
457 if (strstr(buf, "(deleted)"))
458 return NULL;
459
460 if (asprintf(&new_name, "%s/%s", buf, filename) < 0)
461 return NULL;
462
463 return new_name;
464}