/* non-empty token path can't be combined with invalid token FD */
        if (token_path && token_path[0] != '\0' && token_fd < 0)
                return ERR_PTR(-EINVAL);
+       /* empty token path can't be combined with valid token FD */
+       if (token_path && token_path[0] == '\0' && token_fd > 0)
+               return ERR_PTR(-EINVAL);
+       /* if user didn't specify bpf_token_path/bpf_token_fd explicitly,
+        * check if LIBBPF_BPF_TOKEN_PATH envvar was set and treat it as
+        * bpf_token_path option
+        */
+       if (token_fd == 0 && !token_path)
+               token_path = getenv("LIBBPF_BPF_TOKEN_PATH");
+       /* empty token_path is equivalent to invalid token_fd */
        if (token_path && token_path[0] == '\0') {
-               /* empty token path can't be combined with valid token FD */
-               if (token_fd > 0)
-                       return ERR_PTR(-EINVAL);
-               /* empty token_path is equivalent to invalid token_fd */
                token_path = NULL;
                token_fd = -1;
        }
 
         * attempt to create BPF token from default BPF FS mount point
         * (/sys/fs/bpf), in case this default behavior is undesirable.
         *
+        * If bpf_token_path and bpf_token_fd are not specified, libbpf will
+        * consult LIBBPF_BPF_TOKEN_PATH environment variable. If set, it will
+        * be taken as a value of bpf_token_path option and will force libbpf
+        * to either create BPF token from provided custom BPF FS path, or
+        * will disable implicit BPF token creation, if envvar value is an
+        * empty string.
+        *
         * bpf_token_path and bpf_token_fd are mutually exclusive and only one
-        * of those options should be set.
+        * of those options should be set. Either of them overrides
+        * LIBBPF_BPF_TOKEN_PATH envvar.
         */
        int bpf_token_fd;
        /* Path to BPF FS mount point to derive BPF token from.
         * point (/sys/fs/bpf), in case this default behavior is undesirable.
         *
         * bpf_token_path and bpf_token_fd are mutually exclusive and only one
-        * of those options should be set.
+        * of those options should be set. Either of them overrides
+        * LIBBPF_BPF_TOKEN_PATH envvar.
         */
        const char *bpf_token_path;