小编Mat*_*ice的帖子

未找到新的系统调用(Linux内核3.0.0)我应该从哪里开始查找?

我创建了两个新的系统调用,但是当我尝试测试它们时,我收到以下错误:

matt@ubuntu:~/test$ gcc test.c 
test.c: In function ‘newcall’:
test.c:6:17: error: ‘sys_get_slob_amnt_free’ undeclared (first use in this function)
test.c:6:17: note: each undeclared identifier is reported only once for each function it appears in
matt@ubuntu:~/test$ 
Run Code Online (Sandbox Code Playgroud)

我也用syscall(sys_get_slob_amnt_free)尝试了相同的结果.

这是测试代码:

#include <unistd.h>
#include <stdio.h>

unsigned long newcall()
{
        return syscall(__NR_get_slob_amnt_free);
}
int main()
{
        printf("%d\n", newcall());
        return 0;
}
Run Code Online (Sandbox Code Playgroud)

为了添加这些,我将它们放在syscall表中(/usr/src/linux-3.0/include/asm-generic/unistd.h)

#define __NR_sendmmsg 269
__SC_COMP(__NR_sendmmsg, sys_ sendmmsg, compat_sys_sendmmsg)
/** my changes here **/
#define __NR_get_slob_amnt_free 270
__SYSCALL(__NR__get_slob_amnt_free, sys_get_slob_amnt_free)
#define __NR_get_slob_amnt_claimed 271)
__SYSCALL(__NR_get_slob_amnt_claimed, sys_get_slob_amnt_claimed)
/**  /my changes …
Run Code Online (Sandbox Code Playgroud)

linux kernel system-calls

20
推荐指数
1
解决办法
3271
查看次数

为什么 pathlib.Path(__file__).parent.parent 对我的工作目录敏感?

我有一个位于两个目录下的脚本。

\n
\xe2\x9d\xaf tree\n.\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 foo\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 bar\n        \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 test.py\n\xe2\x9d\xaf cd foo/bar\n\xe2\x9d\xaf cat test.py\n\n    from pathlib import Path\n    print(Path(__file__).parent)\n    print(Path(__file__).parent.parent)\n
Run Code Online (Sandbox Code Playgroud)\n

当我从包含该文件的目录运行它时,PathLib 认为该文件的祖父与其父级相同。

\n
\xe2\x9d\xaf python test.py\n\n    . # <-- same\n    . # <-- directories\n
Run Code Online (Sandbox Code Playgroud)\n

但是当我从顶层运行它时,PathLib 行为正确。

\n
\xe2\x9d\xaf cd ../..\n\xe2\x9d\xaf python foo/bar/test.py\n\n    foo/bar # <-- different\n    foo     # <-- directories\n
Run Code Online (Sandbox Code Playgroud)\n

我是否误解了 PathLib 的 API,或者是否有其他原因导致其输出对我的工作目录敏感?

\n

python pathlib

7
推荐指数
1
解决办法
6768
查看次数

如何授予服务帐户访问特定机密的权限?

我想授予服务帐户访问 Google Secrets Manager 中的机密的权限。

可以像这样访问秘密:

gcloud beta secrets versions access 1 --secret="thesecret" --project="myproject"
Run Code Online (Sandbox Code Playgroud)

但是当我的服务帐户尝试相同的命令时,gcloud 会发出以下错误:

错误:(gcloud.beta.secrets.versions.access)PERMISSION_DENIED:请求的身份验证范围不足。

主要问题是:我还需要做什么来确保服务帐户可以访问机密?


我已在 Terraform 中授予该服务帐户“roles/secretmanager.secretAccessor”,如下所示:

resource google_project_iam_binding the-binding {
  project = myproject
  role = "roles/secretmanager.secretAccessor"
  members = [
    "serviceAccount:theserviceaccount@someotherproject.iam.gserviceaccount.com",
  ]
}

Run Code Online (Sandbox Code Playgroud)

我可以验证它在 gcp 控制台中是否具有该角色,如下所示:

gcloud projects get-iam-policy myproject  \
--flatten="bindings[].members" \                         
--format='table(bindings.role)' \
--filter="bindings.members:theserviceaccount@someotherproject.iam.gserviceaccount.com"

    ROLE
    roles/secretmanager.secretAccessor
Run Code Online (Sandbox Code Playgroud)

但是文档中有这个概念:

如果成员只需要访问单个机密的值,则不要授予该成员访问所有机密的能力。例如,您可以针对单个密钥授予服务帐户 Secret Accessor 角色 (roles/secretmanager.secretAccessor)。

因此,就像 iam-policy-binding 可以对特定秘密具有亲和力,但我不确定我可以使用哪些 gcloud 命令或 terraform 资源来创建这种亲和力。

google-cloud-platform terraform google-secret-manager

6
推荐指数
1
解决办法
826
查看次数

如何防止 IntelliJ 的 JavaDoc 格式删除我的缩进

这是我写的 javadoc 注释:

  /**
   * This utility allows the user to do the following.
   * <ul>
   *   <li>A cool feature</li>
   *   <li>Another cool feature</li>
   * </ul>
   */
  public static void main(String[] args) {
Run Code Online (Sandbox Code Playgroud)

这是相同的评论,由 IntelliJ 重新格式化

  /**
   * This utility allows the user to do the following.
   * <ul>
   * <li>A cool feature</li>
   * <li>Another cool feature</li>
   * </ul>
   */
  public static void main(String[] args) {
Run Code Online (Sandbox Code Playgroud)

如何防止自动套用格式功能破坏我的意图?


为了防止 IntelliJ 删除我的换行符,我选中了一个复选框:

设置 > 编辑器 > 代码样式 > Java > JavaDoc > …

java javadoc intellij-idea

5
推荐指数
0
解决办法
1511
查看次数

我可以使用 Docker buildkit 向非 root 用户提供 ssh 密钥吗?

RUN --mount=type=ssh我在以非 root 用户身份使用 buildkit 时遇到了麻烦。

使用这个命令:

eval $(ssh-agent)
ssh-add ~/.ssh/id_ed25519
DOCKER_BUILDKIT=1 docker build --ssh default=${SSH_AUTH_SOCK} .
Run Code Online (Sandbox Code Playgroud)

还有这个 Dockerfile:

FROM docker.io/apache/airflow
USER root
RUN apt update && apt install -y git openssh-client

# uncommenting this breaks it
#USER airflow

RUN mkdir -m 700 ~/.ssh
RUN ssh-keyscan github.com > ~/.ssh/known_hosts
RUN --mount=type=ssh ssh -vvvT git@github.com
Run Code Online (Sandbox Code Playgroud)

有用。我得到的输出如下:

 > [5/5] RUN --mount=type=ssh ssh -vvvT git@github.com:
...
#8 0.931 debug1: Will attempt key: matt@ChoedanKal ED25519 SHA256:2IGNbnSt122LtFaH5Z6u5eQf9B+aG0khsfNUxOKfHJU agent
#8 0.931 debug1: Will attempt key: …
Run Code Online (Sandbox Code Playgroud)

ssh pip dockerfile docker-buildkit

5
推荐指数
1
解决办法
921
查看次数

如何使用CMake安装脚本?

我有一个构建多个可执行文件并安装它们的项目。对于可执行文件,相关的CMake代码为:

add_executable(foo "foo.cpp")
add_executable(bar "bar.cpp;qux.cpp")
install(TARGETS foo bar "/usr/bin")
Run Code Online (Sandbox Code Playgroud)

然后,我创建了一个.deb包,当它安装,我可以运行foo,并bar通过命令行。我想做这样的事情:

add_executable(foo "foo.cpp")
add_executable(bar "bar.cpp;qux.cpp")
add_script(hello "hello.sh")
install(TARGETS foo bar hello)
Run Code Online (Sandbox Code Playgroud)

...因此可以hello从命令行执行。但是实际上并没有一个名为的CMake命令add_script。我该如何实现?

install cmake deb cpack

3
推荐指数
2
解决办法
1559
查看次数